private AST_statement_list Parse_statement_list() { IncrementDepth(); DebugPrint("statement_list"); Token t = LookAheadToken(); AST_statement_list statement_list = new AST_statement_list(); do { statement_list.Add_statement(Parse_statement(Semicolon)); t = LookAheadToken(); if (t.Kind == Semicolon) { Match(Semicolon); } else { Error("';' expected, " + t.ToString() + " found.", t); SkipUntilFollow(Semicolon); if (!AtEndOfSource()) { Match(Semicolon); } } } while (IsStatementStarter(LookAheadToken().Kind)); statement_list.Row = t.Row; statement_list.Column = t.Column; DecrementDepth(); return(statement_list); }
private AST_program Parse_program() { AST_statement_list statement_list = Parse_statement_list(); Match(EndOfSource); return(new AST_program(statement_list)); }
public virtual void Visit(AST_statement_list statement_list) { IncrementDepth(); foreach (AST_statement statement in statement_list.statement_list) { if (statement != null) { statement.Accept(this); } } DecrementDepth(); }
private AST_for_statement Parse_for_statement() { IncrementDepth(); DebugPrint("for_statement"); AST_for_statement for_statement = null; AST_expression from = null; AST_expression to = null; AST_statement_list statement_list = null; Match(for_Keyword); AST_identifier identifier = Parse_identifier(in_Keyword); bool skipForDo = false; bool skipAll = false; if (!Match(in_Keyword)) { Error("'in' expected.", lastReadToken); // Prefer to skip for .. do and still process the statement_list, // worst case is to skip everything until 'end for' SkipUntilFollow(do_Keyword | end_Keyword); if (LookAheadToken().Kind == end_Keyword) { Match(end_Keyword); Match(for_Keyword); skipAll = true; } else { Match(do_Keyword); skipForDo = true; } } if (!skipAll) { if (!skipForDo) { from = Parse_expression(RangeDots); if (!Match(RangeDots)) { SkipUntilFollow(do_Keyword | end_Keyword); if (LookAheadToken().Kind == end_Keyword) { Match(end_Keyword); Match(for_Keyword); skipAll = true; } else { Match(do_Keyword); skipForDo = true; } } if (!skipAll && !skipForDo) { to = Parse_expression(do_Keyword | end_Keyword); if (!Match(do_Keyword)) { Error("'do' expected.", lastReadToken); ReuseToken(); } } } if (!skipAll) { statement_list = Parse_statement_list(); if (!Match(end_Keyword)) { Error("'end for' or a statement expected.", lastReadToken); SkipUntilFollow(Semicolon); } else { if (!Match(for_Keyword)) { Error("'end for' expected.", lastReadToken); SkipUntilFollow(Semicolon); } } } } for_statement = new AST_for_statement(identifier, from, to, statement_list); DecrementDepth(); return(for_statement); }
override public void Visit(AST_statement_list statement_list) { base.Visit(statement_list); }