示例#1
0
        public Node CallStatement(Token identifier)
        {
            var callStatement = new Call_Statement()
            {
                AnchorToken = identifier
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);
            if (CurrentToken != TokenCategory.PARENTHESIS_CLOSE)
            {
                var expr1 = Expression();
                while (CurrentToken == TokenCategory.COMMA)
                {
                    var expr2 = new Identifier()
                    {
                        AnchorToken = Expect(TokenCategory.COMMA)
                    };
                    expr2.Add(expr1);
                    expr2.Add(Expression());
                    expr1 = expr2;
                }
                Expect(TokenCategory.PARENTHESIS_CLOSE);
                Expect(TokenCategory.EOL);

                callStatement.Add(expr1);
            }
            else
            {
                Expect(TokenCategory.PARENTHESIS_CLOSE);
                Expect(TokenCategory.EOL);
            }

            return(callStatement);
        }
示例#2
0
 public Node AssignmentOrCallStatement()
 {
     var id_node = Node.fromToken(Expect(TokenCategory.IDENTIFIER));
     Node node = null;
     if (Has(TokenCategory.PARENTHESIS_OPEN))
     {
         node = new Call_Statement()
         {
             AnchorToken = id_node.AnchorToken
         };
         Expect(TokenCategory.PARENTHESIS_OPEN);
         node.Add(Optional(firstOfExpression, () =>
                                         {
                                             var list = new List<Node>() { Expression() };
                                             list.AddRange(ZeroOrMore(TokenCategory.COMMA, Expression, true));
                                             return list;
                                         }));
         Expect(TokenCategory.PARENTHESIS_CLOSE);
     }
     else if (Has(TokenCategory.BRACKET_OPEN) || Has(TokenCategory.COLON_EQUAL))
     {
         node = new Assignment_Statement();
         if (Has(TokenCategory.BRACKET_OPEN))
         {
             Expect(TokenCategory.BRACKET_OPEN);
             var expression_node = Expression();
             Expect(TokenCategory.BRACKET_CLOSE);
             node.Add(new ListIndexNode() { id_node, expression_node });
         }
         else
         {
             node.Add(id_node);
         }
         node.AnchorToken = Expect(TokenCategory.COLON_EQUAL);
         node.Add(Expression());
     }
     else
     {
         throw new SyntaxError(firstOfAssignmentOrCallStatement, tokenStream.Current);
     }
     Expect(TokenCategory.SEMICOLON);
     return node;
 }