예제 #1
0
 public static void PrintForEachStatement(PrintState s, ForEachStatement a)
 {
     PrintLine(s, "ForEachStatement");
     Indent(s);
     PrintDescWithAny(s, "IteratorVariable", a.IteratorVariable);
     PrintDescWithAny(s, "SequenceExpression", a.SequenceExpression);
     PrintDescWithAny(s, "Body", a.Body);
     UnIndent(s);
 }
예제 #2
0
 private static object ParseForStatement(ParserState s)
 {
     ReadToken(s);
     if (s.Token.Type == TokenType.Semicolon)
     {
         return(ParseForIndexStatementTail(s, null));
     }
     else if (s.Token.Type == TokenType.Identifier)
     {
         var id = s.Token;
         ReadToken(s);
         if (s.Token.Type == TokenType.Identifier && s.Token.Value == "in")
         {
             ReadToken(s);
             var st = new ForEachStatement {
                 IteratorVariable = id, SequenceExpression = ParseExpression(s, 0, false)
             };
             st.Body = ParseBlockStatement(s);
             return(st);
         }
         else if (s.Token.Type == TokenType.Comma)
         {
             ReadToken(s);
             var indexId = ParseTokenWithType(s, TokenType.Identifier);
             if (s.Token.Type != TokenType.Identifier || s.Token.Value != "in")
             {
                 Expected(s, "in");
             }
             ReadToken(s);
             var st = new ForEachStatement {
                 IteratorVariable = id, IndexIteratorVariable = indexId, SequenceExpression = ParseExpression(s, 0, false)
             };
             st.Body = ParseBlockStatement(s);
             return(st);
         }
         else if (s.Token.Type == TokenType.Operator && s.Token.Value == ":=")
         {
             return(ParseForIndexStatementTail(s, id));
         }
         else
         {
             var st = new ForEachStatement();
             st.SequenceExpression = ParseExpressionTail(s, id, 0, false);
             st.Body = ParseBlockStatement(s);
             return(st);
         }
     }
     else
     {
         var st = new ForEachStatement();
         st.SequenceExpression = ParseExpression(s, 0, false);
         st.Body = ParseBlockStatement(s);
         return(st);
     }
 }
예제 #3
0
 public static void CheckForEachStatement(RangeFinderState s, ForEachStatement a)
 {
     CheckToken(s, a.IteratorVariable);
     CheckAny(s, a.SequenceExpression);
     CheckAny(s, a.Body);
 }