{
ASTStmtOrDecl ::parse()
{
- SpecsList specs;
- InitDeclList decls;
+ SpecsList specs = null;
+ InitDeclList decls = null;
+ bool isType = false;
peekToken();
- if(nextToken.type == INT || nextToken.type == CHAR || nextToken.type == VOID)
+ if(nextToken.type.isSpecifier || (nextToken.type == IDENTIFIER && isType))
{
specs = SpecsList::parse();
decls = InitDeclList::parse();
}
else if(nextToken.type == IDENTIFIER)
{
+ ASTStatement stmt;
int a = pushAmbiguity();
- specs = SpecsList::parse();
- decls = InitDeclList::parse();
- if(specs && decls)
+ stmt = ASTStatement::parse();
+ if(stmt)
{
clearAmbiguity();
- return ASTDeclaration::parse(specs, decls);
+ return stmt;
}
popAmbiguity(a);
+ specs = SpecsList::parse();
+ if(specs)
+ decls = InitDeclList::parse();
+ if(specs && decls)
+ return ASTDeclaration::parse(specs, decls);
+ else
+ return null;
}
- return ASTStatement::parse();
+ else
+ return ASTStatement::parse();
}
}
StmtExpression stmt { expressions = exp };
if(peekToken().type == ';')
readToken();
- return stmt;
+ else
+ {
+ if(ambiguous)
+ delete stmt;
+ }
+ return stmt;
}
return null;
}
StmtCompound stmt { };
if(peekToken().type == '{')
{
+ bool inDecls = true;
readToken();
while(true)
{
{
if(eClass_IsDerived(sod._class, class(ASTDeclaration)))
{
+ ASTDeclaration decl = (ASTDeclaration)sod;
if(!stmt.declarations) stmt.declarations = { };
- stmt.declarations.Add((ASTDeclaration)sod);
+ if(inDecls)
+ stmt.declarations.Add(decl);
+ else
+ stmt.statements.Add(StmtDecl { decl = decl });
}
else
{
+ ASTStatement s = (ASTStatement)sod;
if(!stmt.statements) stmt.statements = { };
- stmt.statements.Add((ASTStatement)sod);
+ stmt.statements.Add(s);
+ inDecls = false;
}
}
else
public class StmtDecl : ASTStatement
{
- Declaration decl;
+ ASTDeclaration decl;
+
+ void print()
+ {
+ if(decl) decl.print();
+ }
}