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); }
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); } }
public static void CheckForEachStatement(RangeFinderState s, ForEachStatement a) { CheckToken(s, a.IteratorVariable); CheckAny(s, a.SequenceExpression); CheckAny(s, a.Body); }