Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { operPriority } from './operPriority';
- import Columns from './columns';
- class Visualization extends React.Component {
- constructor (props) {
- super(props);
- //this.handleChange = this.handleChange.bind(this);
- this.state = {
- inf: this.props.exp,
- car: [],
- post: [],
- msg: '',
- tog: this.props.toggle
- }
- }
- render() {
- let letterNumber = /^[0-9a-zA-Z]+$/;
- for (let i=0; i < this.state.inf.length; i++) {
- let c = this.state.inf[i];
- if (c.match(letterNumber)) {
- this.setState({inf: this.state.inf.shift()});
- this.setState({msg: 'Είναι αριθμός, συνεπώς περνάει απευθείας στο αποτέλεσμα.'});
- this.setState({post: this.state.post.push(c)});
- }
- else if (c === "(") {
- this.setState({inf: this.state.inf.shift()});
- this.setState({msg: 'Είναι (, συνεπώς παραμένει ως κρατούμενο.'});
- this.setState({car: this.state.car.push(c)});
- }
- else if (c === ")") {
- while (this.state.car.length > 0 && this.state.car[this.state.car.length-1] !== "(") {
- this.setState({inf: this.state.inf.shift()});
- this.setState({post: this.state.post.push(this.state.car.pop())});
- this.setState({msg: 'Είναι ), συνεπώς η έκφραση έκλεισε και παύει να είναι κρατούμενο.'});
- }
- if (this.state.car.length > 0 && this.state.car[this.state.car.length-1] !== "(") {
- this.setState({msg: 'Invalid Expression'});
- }
- else {
- this.setState({inf: this.state.inf.shift()});
- this.setState({car: this.state.car.pop()});
- this.setState({msg: 'Είναι ), συνεπώς η έκφραση έκλεισε και παύει να είναι κρατούμενο και έχουμε το τελικό αποτέλεσμα.'});
- }
- }
- else {
- while(this.state.car.length > 0 && operPriority(c) <= operPriority(this.state.car[this.state.car.length-1])) {
- this.setState({inf: this.state.inf.shift()});
- this.setState({post: this.state.post.push(this.state.car.pop())});
- this.setState({msg: 'Ο Operator έχει μεγαλύτερη προταιρεότητα από τον αμέσως προηγούμενο του.'});
- }
- this.setState({car: this.state.car.push(c)});
- this.setState({msg: 'Invalid Expression'});
- }
- }
- while (this.state.car.length > 0) {
- this.setState({inf: this.state.inf.shift()});
- this.setState({post: this.state.post.push(this.state.car.pop())});
- this.setState({msg: 'add to carry'});
- }
- return(
- <div>
- <Columns
- spec = 'Specifications: '
- infix = {this.state.inf}
- carry = {this.state.car}
- postfix = {this.state.post}
- message = {this.state.msg}
- toggle = {this.state.tog}
- />
- </div>
- );
- }
- }
- export default Visualization;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement