3 public class ASTDeclaration : ASTStmtOrDecl
7 // ASTSpecifier extStorage;
9 // AccessMode declMode;
11 ASTDeclaration ::parse(SpecsList specs, InitDeclList decls)
14 if(nextToken.type == '{')
15 return DeclarationInstance::parse(specs, decls);
16 else if(nextToken.type == ';')
18 return DeclarationInit { specifiers = specs, declarators = decls };
22 public class DeclarationInit : ASTDeclaration
26 InitDeclList declarators;
33 if(declarators) Print(" ");
35 if(declarators) declarators.print();
40 public class DeclarationInstance : ASTDeclaration
42 ASTInstantiation inst;
44 DeclarationInstance ::parse(SpecsList specs, InitDeclList decls)
46 ASTInstantiation inst = ASTInstantiation::parse(specs, decls);
47 if(peekToken().type == ';')
51 return { inst = inst };
66 public class DeclarationDefine : ASTDeclaration
72 public class ASTFunctionDefinition : ASTNode
76 ASTDeclarator declarator;
77 List<ASTDeclaration> oldStyleDeclarations;
97 ASTFunctionDefinition ::parse(SpecsList specs, InitDeclList decls)
99 ASTFunctionDefinition function { };
100 ASTDeclarator decl = (decls && decls[0]) ? decls[0].declarator : null;
101 if(decl && decls[0]) decls[0].declarator = null;
103 function.specifiers = specs;
104 function.declarator = decl;
105 function.body = StmtCompound::parse();
110 OldList attached; // For IDE
117 bool propertyNoThis; // Not used yet; might use to support both this = and return syntax for conversion properties
121 class ASTImport : ASTNode
128 PrintLn(importString);
135 ASTFunctionDefinition function;
137 ASTDeclaration declaration;
147 ImportType importType;
151 public ASTDeclarator GetFuncDecl(ASTDeclarator decl)
153 ASTDeclarator funcDecl = null;
154 while(decl && decl._class != class(DeclIdentifier))
156 if(decl._class == class(DeclFunction))
158 decl = decl.declarator;
163 public class AST : ASTList<ASTNode>
165 ASTNode ::ParseExternalDeclaration()
167 SpecsList specs = null;
168 InitDeclList decls = null;
171 if(nextToken.type == IMPORT)
173 ASTImport astImport { };
176 if(nextToken.type == STATIC)
180 else if(nextToken.type == IDENTIFIER)
185 if(nextToken.type == STRING_LITERAL)
188 astImport.importString = CopyString(token.text);
194 specs = SpecsList::parse();
195 decls = InitDeclList::parse();
196 if(nextToken.type == '{')
198 ASTDeclarator funcDecl = GetFuncDecl((decls && decls[0]) ? decls[0].declarator : null);
200 return ASTFunctionDefinition::parse(specs, decls);
202 return ASTDeclaration::parse(specs, decls);
204 else if(specs || decls)
205 return ASTDeclaration::parse(specs, decls);
208 readToken(); // Error
217 while(peekToken().type)
219 ASTNode n = ParseExternalDeclaration();