Exemplo n.º 1
0
 internal void Accept(NodeAs a)
 {
     a.value.Visit(this);
     a.type.Visit(this);
     builder.OpAs();
 }
Exemplo n.º 2
0
 void ASTVisitor.Accept(NodeAs value)
 {
     Accept(value);
 }
Exemplo n.º 3
0
 private Node Postfix(Node node, bool allowPostfixInvocation)
 {
     if (node == null || !TokensRemain)
         return node;
     // handle { i+ = 1 } assign operators
     if (HasNextToken && Current.type == OPERATOR && Next.type == ASSIGN)
     {
         string op = Current.image;
         Advance(); Advance();
         var right = Expression();
         if (right == null)
         {
             // TODO error
         }
         return new NodeAssign(node, new NodeInfix(node, right, op));
     }
     switch (Current.type)
     {
         case ASSIGN: Advance(); return new NodeAssign(node, Expression());
         case OPEN_BRACE:
             if (Location.line != node.EndLine || !allowPostfixInvocation)
                 break;
             Advance();
             List<Node> args;
             if (!Check(CLOSE_BRACE))
                 args = CommaExpressions();
             else args = new List<Node>();
             Expect(CLOSE_BRACE, "Expected a close brace (')') to end the function argument list.");
             return Postfix(new NodeInvoke(node, args), allowPostfixInvocation);
         case OPEN_SQUARE_BRACE:
             if (Location.line != node.EndLine)
                 break;
             Advance();
             if (Check(OPERATOR) && HasNextToken && Next.type == CLOSE_SQUARE_BRACE)
             {
                 node = new NodeOperatorIndex(node, Current.image);
                 Advance();
             }
             else if (Check(CLOSE_SQUARE_BRACE))
             {
                 Advance();
                 log.Error(Location, "At least one argument is needed to index an object.");
                 return node;
             }
             else node = new NodeIndex(node, CommaExpressions());
             Expect(CLOSE_SQUARE_BRACE, "Expected a close brace (']') to end the operator index.");
             return Postfix(node, allowPostfixInvocation);
         case DOT:
             Advance();
             // TODO do other checks, such as infix/prefix/as
             // for now, just check identifier indexing.
             string ident;
             ExpectIdentifier(out ident, "Identifier expected for field indexing.");
             return Postfix(new NodeFieldIndex(node, ident), allowPostfixInvocation);
         case AS:
             Advance();
             if (!TokensRemain)
             {
                 log.Error(tokens[-1].location, "Expected expression for 'as' cast, but the end of the file was reached.");
                 break;
             }
             var type = PrimaryExpression();
             if (type == null)
             {
                 log.Error(tokens[-1].location, "Expected expression for 'as' cast.");
                 break;
             }
             var a = new NodeAs(node, type);
             return a;
     }
     return node;
 }