public void Visit(ArithmeticExpr node)
 {
     VisitChildren (node);
     ApplyOperatorToOperands (node);
 }
Пример #2
0
        private Expression ExprAdd()
        {
            if ((Token.Types)currentToken.Type == Token.Types.Addition ||
                (Token.Types)currentToken.Type == Token.Types.Subtraction) {

                ArithmeticExpr arithmeticExpr;

                if ((Token.Types)currentToken.Type == Token.Types.Addition) {
                    Match (Token.Types.Addition);
                    arithmeticExpr = new ArithmeticExpr ("+", currentToken.Row, currentToken.Column);
                } else {
                    Match (Token.Types.Subtraction);
                    arithmeticExpr = new ArithmeticExpr ("-", currentToken.Row, currentToken.Column);
                }

                arithmeticExpr.AddChild (Term ());
                Expression expression = ExprAdd ();

                if (expression.Name != null) {
                    arithmeticExpr.AddChild (expression);
                }

                return arithmeticExpr;
            } else if ((Token.Types)currentToken.Type == Token.Types.Equal ||
                       (Token.Types)currentToken.Type == Token.Types.Less ||
                       (Token.Types)currentToken.Type == Token.Types.And ||
                       (Token.Types)currentToken.Type == Token.Types.RightParenthesis ||
                       (Token.Types)currentToken.Type == Token.Types.Range ||
                       (Token.Types)currentToken.Type == Token.Types.Do ||
                       (Token.Types)currentToken.Type == Token.Types.Semicolon) {
                return new ArithmeticExpr(null, currentToken.Row, currentToken.Column);
            }

            throw new SyntaxError ("invalid type " + currentToken.Type, currentToken.Row,
                currentToken.Column);
        }