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);
        }
예제 #3
0
 public MinusExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }
예제 #4
0
 public DownEqualExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }
예제 #5
0
 public ParanhesisExp(TerminalExp exp)
 {
     _exp = exp;
 }
예제 #6
0
 public LessExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }
예제 #7
0
 public MoreExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }
예제 #8
0
 public EqualsExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }
예제 #9
0
 public DivideExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }
예제 #10
0
 public MultipleExp(TerminalExp exp1, TerminalExp exp2)
 {
     _exp1 = exp1;
     _exp2 = exp2;
 }