4 public class ASTPropertyWatch : ASTNode
8 List<ASTIdentifier> properties;
13 class AsmField : struct
18 Expression expression;
23 public class ASTStmtOrDecl : ASTNode
25 ASTStmtOrDecl ::parse()
27 SpecsList specs = null;
28 InitDeclList decls = null;
32 if(nextToken.type.isSpecifier || (nextToken.type == IDENTIFIER && isType))
34 specs = SpecsList::parse();
35 decls = InitDeclList::parse();
36 return ASTDeclaration::parse(specs, decls);
38 else if(nextToken.type == IDENTIFIER)
41 int a = pushAmbiguity();
42 stmt = ASTStatement::parse();
49 specs = SpecsList::parse();
51 decls = InitDeclList::parse();
53 return ASTDeclaration::parse(specs, decls);
58 return ASTStatement::parse();
62 public class ASTStatement : ASTStmtOrDecl
67 ASTStatement ::parse()
69 switch(peekToken().type)
71 case ';': readToken(); return { };
72 case '{': return StmtCompound::parse();
73 case IF: return StmtIf::parse();
74 case SWITCH: return StmtSwitch::parse();
76 case CASE: return StmtCase::parse();
77 case WHILE: return StmtWhile::parse();
78 case DO: return StmtDoWhile::parse();
79 case FOR: return StmtFor::parse();
80 case BREAK: return StmtBreak::parse();
81 case GOTO: return StmtGoto::parse();
82 case RETURN: return StmtReturn::parse();
83 case CONTINUE: return StmtContinue::parse();
87 int a = pushAmbiguity();
88 stmt = StmtLabeled::parse();
96 default: return StmtExpression::parse();
106 public class StmtExpression : ASTStatement
112 if(expressions) expressions.print();
116 StmtExpression ::parse()
118 ExpList exp = ExpList::parse();
121 StmtExpression stmt { expressions = exp };
122 if(peekToken().type == ';')
138 for(i = 0; i < indent; i++)
144 public class StmtCompound : ASTStatement
146 List<ASTDeclaration> declarations;
147 List<ASTStatement> statements;
158 for(d : declarations)
171 if(s._class == class(StmtCase))
173 if(s._class != class(StmtLabeled) && s._class != class(StmtCompound))
176 if(s._class == class(StmtExpression))
181 if(indent == caseIndent)
187 StmtCompound ::parse()
189 StmtCompound stmt { };
190 if(peekToken().type == '{')
196 if(peekToken().type == '}')
205 ASTStmtOrDecl sod = ASTStmtOrDecl::parse();
208 if(eClass_IsDerived(sod._class, class(ASTDeclaration)))
210 ASTDeclaration decl = (ASTDeclaration)sod;
211 if(!stmt.declarations) stmt.declarations = { };
213 stmt.declarations.Add(decl);
215 stmt.statements.Add(StmtDecl { decl = decl });
219 ASTStatement s = (ASTStatement)sod;
220 if(!stmt.statements) stmt.statements = { };
221 stmt.statements.Add(s);
229 if(token == ';' || token == '}') break;*/
239 public class StmtIf : ASTStatement
243 ASTStatement elseStmt;
252 if(stmt._class != class(StmtCompound)) indent++;
255 if(stmt._class == class(StmtExpression)) PrintLn("");
256 if(stmt._class != class(StmtCompound)) indent--;
262 if(elseStmt._class != class(StmtCompound)) { PrintLn(""); indent++; }
264 if(elseStmt._class != class(StmtCompound)) elseStmt.print();
265 if(elseStmt._class == class(StmtExpression)) PrintLn("");
274 if(peekToken().type == '(')
277 stmt.exp = ExpList::parse();
278 if(peekToken().type == ')') readToken();
279 stmt.stmt = ASTStatement::parse();
280 if(peekToken().type == ELSE)
283 stmt.elseStmt = ASTStatement::parse();
292 public class StmtSwitch : ASTStatement
299 int backCaseIndent = caseIndent;
305 caseIndent = indent+1;
307 indent = caseIndent-1;
309 caseIndent = backCaseIndent;
316 if(peekToken().type == '(')
319 stmt.exp = ExpList::parse();
320 if(peekToken().type == ')') readToken();
321 stmt.stmt = ASTStatement::parse();
327 public class StmtLabeled : ASTStatement
336 if(stmt) stmt.print();
339 StmtLabeled ::parse()
341 ASTIdentifier id = ASTIdentifier::parse();
342 if(peekToken().type == ':')
343 return StmtLabeled { id = id, stmt = ASTStatement::parse() };
349 public class StmtCase : ASTStatement
366 if(stmt._class != class(StmtCompound)) indent++;
369 if(stmt._class == class(StmtExpression)) PrintLn("");
376 if(readToken().type == CASE)
377 stmt.exp = ExpConditional::parse();
378 if(peekToken().type == ':')
381 stmt.stmt = ASTStatement::parse();
387 public class StmtWhile : ASTStatement
396 if(peekToken().type == '(')
399 stmt.exp = ExpList::parse();
400 if(peekToken().type == ')') readToken();
401 stmt.stmt = ASTStatement::parse();
407 public class StmtDoWhile : ASTStatement
412 StmtDoWhile ::parse()
414 StmtDoWhile stmt { };
416 stmt.stmt = ASTStatement::parse();
417 if(peekToken().type == WHILE)
420 if(peekToken().type == '(')
423 stmt.exp = ExpList::parse();
424 if(peekToken().type == ')') readToken();
426 if(peekToken().type == ';') readToken();
432 public class StmtFor : ASTStatement
458 if(stmt._class != class(StmtCompound)) indent++;
461 if(stmt._class == class(StmtExpression)) PrintLn("");
462 if(stmt._class != class(StmtCompound)) indent--;
470 if(peekToken().type == '(')
473 stmt.init = ASTStatement::parse();
474 stmt.check = ASTStatement::parse();
475 stmt.increment = ExpList::parse();
476 if(peekToken().type == ')')
479 stmt.stmt = ASTStatement::parse();
486 public class StmtBreak : ASTStatement
496 if(peekToken().type == ';') readToken();
501 public class StmtContinue : ASTStatement
505 PrintLn("continue;");
508 StmtContinue ::parse()
511 if(peekToken().type == ';') readToken();
516 public class StmtReturn : ASTStatement
534 if(peekToken().type != ';') stmt.exp = ExpList::parse();
535 if(peekToken().type == ';') readToken();
540 public class StmtGoto : ASTStatement
555 stmt.id = ASTIdentifier::parse();
556 if(peekToken().type == ';') readToken();
561 public class StmtAsm : ASTStatement
565 List<String> inputFields;
566 List<String> outputFields;
567 List<String> clobberedFields;
570 public class StmtWatch : ASTStatement
572 ASTExpression watcher, object;
573 List<ASTPropertyWatch> watches;
576 public class StmtFireWatch : ASTStatement
578 ASTExpression watcher, object;
579 List<ASTIdentifiers> watches;
582 public class StmtStopWatching : ASTStatement
584 ASTExpression watcher, object;
585 List<ASTIdentifiers> watches;
588 public class StmtForEach : ASTStatement
596 public class StmtDecl : ASTStatement
602 if(decl) { decl.print(); PrintLn(""); }