Esempio n. 1
0
        public Node SimpleExpression()
        {
            Node node = null;

            if (Has(TokenCategory.PARENTHESIS_OPEN))
            {
                Expect(TokenCategory.PARENTHESIS_OPEN);
                node = Expression();
                Expect(TokenCategory.PARENTHESIS_CLOSE);
            }
            else if (Has(TokenCategory.IDENTIFIER))
            {
                node = Node.fromToken(Expect(TokenCategory.IDENTIFIER));
                // May be a call
                if (Has(TokenCategory.PARENTHESIS_OPEN))
                {
                    var call_node = new CallNode()
                    {
                        AnchorToken = node.AnchorToken
                    };
                    Expect(TokenCategory.PARENTHESIS_OPEN);
                    if (Has(firstOfExpression))
                    {
                        call_node.Add(Expression());
                        call_node.Add(ZeroOrMore(TokenCategory.COMMA, Expression, true));
                    }
                    Expect(TokenCategory.PARENTHESIS_CLOSE);
                    node = call_node;
                }
            }
            else if (Has(firstOfLiteral))
            {
                node = Literal();
            }
            else
            {
                throw new SyntaxError(firstOfSimpleExpression, tokenStream.Current);
            }

            if (Has(TokenCategory.BRACKET_OPEN))
            {
                Expect(TokenCategory.BRACKET_OPEN);
                var indexNode = new ListIndexNode()
                {
                    node, Expression()
                };
                Expect(TokenCategory.BRACKET_CLOSE);
                return(indexNode);
            }
            return(node);
        }
Esempio n. 2
0
        public Node Call()
        {
            Expect(TokenCategory.INITPARENTHESIS);
            //if(CurrentToken == TokenCategory.NOT | CurrentToken == TokenCategory.SUBSTRACT | CurrentToken == TokenCategory.INTEGERLITERAL | CurrentToken == TokenCategory.STRINGLITERAL | CurrentToken == TokenCategory.BOOLEANITERAL | CurrentToken == TokenCategory.IDENTIFIER){
            var result = new CallNode()
            {
            };

            if (firstOfSimpleExpression.Contains(CurrentToken))
            {
                result.Add(Expression());
                while (CurrentToken == TokenCategory.COMMA)
                {
                    Expect(TokenCategory.COMMA);
                    result.Add(Expression());
                }
            }
            Expect(TokenCategory.CLOSINGPARENTHESIS);
            return(result);
        }