Exemplo n.º 1
0
        public Node ParseAdd()
        {
            // NOTE(patrik): Parse Plus and minus operations

            Node left = ParseMul();

            while (lexer.CurrentToken == TokenType.PLUS ||
                   lexer.CurrentToken == TokenType.MINUS)
            {
                TokenType op = lexer.CurrentToken;
                lexer.NextToken();

                Node right = ParseMul();

                left = new BinaryOpNode(left, right, op);
            }

            return(left);
        }
Exemplo n.º 2
0
        public Node ParseMul()
        {
            // NOTE(patrik): Parse Multiply, Divide and modulo operation

            Node left = ParseOperand();

            while (lexer.CurrentToken == TokenType.MULTIPLY ||
                   lexer.CurrentToken == TokenType.DIVIDE ||
                   lexer.CurrentToken == TokenType.MODULO)
            {
                TokenType op = lexer.CurrentToken;
                lexer.NextToken();

                Node right = ParseOperand();

                left = new BinaryOpNode(left, right, op);
            }

            return(left);
        }