public TerminalExp CreateExpression(List <Token> tokens) { int index = 0; foreach (var token in tokens) { if (token.TokenType == TokenType.Minus) { index = tokens.IndexOf(token); break; } } foreach (var token in tokens) { if (token.TokenType == TokenType.Plus) { index = tokens.IndexOf(token); break; } } foreach (var token in tokens) { if (token.TokenType == TokenType.Divide) { index = tokens.IndexOf(token); break; } } foreach (var token in tokens) { if (token.TokenType == TokenType.Multiple) { index = tokens.IndexOf(token); break; } } TerminalExp exp1 = TerminalExpressionAnalyser.Analyse(tokens.GetRange(0, index)); TerminalExp exp2 = TerminalExpressionAnalyser.Analyse(tokens.GetRange( index + 1, tokens.Count - index - 1)); switch (tokens[index].TokenType) { case TokenType.Multiple: return(new MultipleExp(exp1, exp2)); case TokenType.Divide: return(new DivideExp(exp1, exp2)); case TokenType.Plus: return(new PlusExp(exp1, exp2)); case TokenType.Minus: return(new MinusExp(exp1, exp2)); } return(null); }
public TerminalExp CreateExpression(List <Token> tokens) { int index = 0; foreach (var token in tokens) { if ((token.TokenType == TokenType.Equal) || (token.TokenType == TokenType.More) || (token.TokenType == TokenType.Less) || (token.TokenType == TokenType.UpEqual) || (token.TokenType == TokenType.DownEqual)) { index = tokens.IndexOf(token); break; } } TerminalExp exp1 = TerminalExpressionAnalyser.Analyse(tokens.GetRange(0, index)); TerminalExp exp2 = TerminalExpressionAnalyser.Analyse(tokens.GetRange( index + 1, tokens.Count - index - 1)); if (exp1 is StringConstExp && exp2 is StringConstExp && tokens[index].TokenType == TokenType.Equal) { return(new EqualsExp(exp1, exp2)); } switch (tokens[index].TokenType) { case TokenType.Equal: return(new EqualsExp(exp1, exp2)); case TokenType.More: return(new MoreExp(exp1, exp2)); case TokenType.Less: return(new LessExp(exp1, exp2)); case TokenType.UpEqual: return(new UpEqualExp(exp1, exp2)); case TokenType.DownEqual: return(new DownEqualExp(exp1, exp2)); } return(null); }
public MinusExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }
public DownEqualExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }
public ParanhesisExp(TerminalExp exp) { _exp = exp; }
public LessExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }
public MoreExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }
public EqualsExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }
public DivideExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }
public MultipleExp(TerminalExp exp1, TerminalExp exp2) { _exp1 = exp1; _exp2 = exp2; }