Esempio n. 1
0
        private Node ParseTerm(int precedence)
        {
            Node result = null;

            switch (Current.Kind)
            {
                case TokenType.NumericLiteral:
                    result = Constant();
                    AdvanceToken();
                    break;
                case TokenType.Identifier:
                    var next = Next;
                    if (next == null)
                    {
                        result = Variable();
                        AdvanceToken();
                        break;
                    }

                    if (next.Kind == TokenType.Dot)
                    {
                        return ParsePropertyAccess();
                    }

                    if (next.Kind == TokenType.OpenParen)
                    {
                        return ParseFunctionCall();
                    }

                    result = Variable();
                    AdvanceToken();
                    break;
                case TokenType.OpenParen:
                    AdvanceToken();
                    result = ParseExpression(0);
                    AdvanceToken(TokenType.CloseParen);
                    break;
                default:
                    ReportError("Expected a number, a variable, a function or a parenthesized expression");
                    break;
            }

            return result;
        }
Esempio n. 2
0
 private Parser(IList<Token> tokens)
 {
     result = new ParseResult();
     this.tokens = tokens;
     length = tokens.Count;
 }