public override object Visit(For forStatement) { var result = new ForStatement(); var location = LocationsBag.GetLocations(forStatement); result.AddChild(new CSharpTokenNode(Convert(forStatement.loc), ForStatement.ForKeywordRole), ForStatement.ForKeywordRole); if (location != null) result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar); AddStatementOrList(result, forStatement.Initializer, ForStatement.InitializerRole); if (location != null && location.Count > 1) result.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.Semicolon), Roles.Semicolon); if (forStatement.Condition != null) result.AddChild((Expression)forStatement.Condition.Accept(this), Roles.Condition); if (location != null && location.Count >= 3) result.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.Semicolon), Roles.Semicolon); AddStatementOrList(result, forStatement.Iterator, ForStatement.IteratorRole); if (location != null && location.Count >= 4) result.AddChild(new CSharpTokenNode(Convert(location [3]), Roles.RPar), Roles.RPar); if (forStatement.Statement != null) result.AddChild((Statement)forStatement.Statement.Accept(this), Roles.EmbeddedStatement); return result; }
public override object Visit (For forStatement) { var result = new ForStatement (); var location = LocationsBag.GetLocations (forStatement); result.AddChild (new CSharpTokenNode (Convert (forStatement.loc), "for".Length), ForStatement.Roles.Keyword); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ForStatement.Roles.LPar); if (forStatement.InitStatement != null) result.AddChild ((INode)forStatement.InitStatement.Accept (this), ForStatement.Roles.Initializer); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ForStatement.Roles.Semicolon); if (forStatement.Test != null) result.AddChild ((INode)forStatement.Test.Accept (this), ForStatement.Roles.Condition); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), ForStatement.Roles.Semicolon); if (forStatement.Increment != null) result.AddChild ((INode)forStatement.Increment.Accept (this), ForStatement.Roles.Iterator); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), ForStatement.Roles.RPar); result.AddChild ((INode)forStatement.Statement.Accept (this), ForStatement.Roles.EmbeddedStatement); return result; }
void AddStatementOrList(ForStatement forStatement, Mono.CSharp.Statement init, Role<Statement> role) { if (init == null) return; var stmtList = init as StatementList; if (stmtList != null) { foreach (var stmt in stmtList.Statements) { forStatement.AddChild((Statement)stmt.Accept(this), role); } } else if (init is Mono.CSharp.EmptyStatement) { } else { forStatement.AddChild((Statement)init.Accept(this), role); } }
void AddStatementOrList (ForStatement forStatement, Statement init, int role) { if (init == null) return; if (init is StatementList) { foreach (var stmt in ((StatementList)init).Statements) { forStatement.AddChild ((AstNode)stmt.Accept (this), role); } } else { forStatement.AddChild ((AstNode)init.Accept (this), role); } }
void AddStatementOrList (ForStatement forStatement, Mono.CSharp.Statement init, Role<Statement> role) { if (init == null) return; if (init is StatementList) { foreach (var stmt in ((StatementList)init).Statements) { forStatement.AddChild ((Statement)stmt.Accept (this), role); } } else { forStatement.AddChild ((Statement)init.Accept (this), role); } }
void AddStatementOrList (ForStatement forStatement, Mono.CSharp.Statement init, Role<Statement> role) { if (init == null) return; if (init is StatementList) { foreach (var stmt in ((StatementList)init).Statements) { Console.WriteLine ("stmt:" + stmt); forStatement.AddChild ((Statement)stmt.Accept (this), role); } } else if (init is Mono.CSharp.EmptyStatement) { } else { forStatement.AddChild ((Statement)init.Accept (this), role); } }
public ForStatement forStatement() { EnterRule_forStatement(); EnterRule("forStatement", 19); TraceIn("forStatement", 19); ForStatement st = default(ForStatement); IToken identifier36 = default(IToken); ForStruct forList37 = default(ForStruct); List<Statement> statement38 = default(List<Statement>); st = new ForStatement(); try { DebugEnterRule(GrammarFileName, "forStatement"); DebugLocation(392, 5); try { // D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:397:6: ( FOR identifier EQUAL forList DO statement ) DebugEnterAlt(1); // D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:397:8: FOR identifier EQUAL forList DO statement { DebugLocation(397, 8); Match(input,FOR,Follow._FOR_in_forStatement1336); DebugLocation(398, 7); PushFollow(Follow._identifier_in_forStatement1344); identifier36=identifier(); PopFollow(); DebugLocation(399, 7); st.SetIdentifier(identifier36); DebugLocation(402, 7); Match(input,EQUAL,Follow._EQUAL_in_forStatement1360); DebugLocation(403, 7); PushFollow(Follow._forList_in_forStatement1368); forList37=forList(); PopFollow(); DebugLocation(404, 7); st.SetForStruct(forList37); DebugLocation(407, 7); Match(input,DO,Follow._DO_in_forStatement1384); DebugLocation(408, 7); PushFollow(Follow._statement_in_forStatement1392); statement38=statement(); PopFollow(); DebugLocation(409, 7); foreach(var child in statement38) { st.AddChild(child); } } } catch (RecognitionException e) { throw e; } finally { TraceOut("forStatement", 19); LeaveRule("forStatement", 19); LeaveRule_forStatement(); } DebugLocation(415, 5); } finally { DebugExitRule(GrammarFileName, "forStatement"); } return st; }