Beispiel #1
0
        AST Term()
        {
            AST node = Factor();

            while (new[] { TokenKind.Mul, TokenKind.IntDiv, TokenKind.FloatDiv }.Contains(CurrentToken.Type))
            {
                Token operation = CurrentToken;
                if (operation.Type == TokenKind.Mul)
                {
                    Eat(TokenKind.Mul);
                }

                if (operation.Type == TokenKind.IntDiv)
                {
                    Eat(TokenKind.IntDiv);
                }

                if (operation.Type == TokenKind.FloatDiv)
                {
                    Eat(TokenKind.FloatDiv);
                }

                node = new BinaryOperation(node, operation, Factor());
            }

            return(node);
        }
Beispiel #2
0
        AST Expr()
        {
            AST node = Term();

            while (new[] { TokenKind.Plus, TokenKind.Minus }.Contains(CurrentToken.Type))
            {
                Token operation = CurrentToken;
                if (operation.Type == TokenKind.Plus)
                {
                    Eat(TokenKind.Plus);
                }

                else if (operation.Type == TokenKind.Minus)
                {
                    Eat(TokenKind.Minus);
                }

                node = new BinaryOperation(node, operation, Term());
            }

            return(node);
        }