sptr<Node> Parser::ParseBodyBlock() { ParseConstDecl(); ParseTypeDecl(); ParseVarDecl(); return ParseBlock(); }
void Parser::ParseDecl() { while (true) { if (t.GetValue() == "var") ParseVarDecl(); else if(t.GetValue() == "type") ParseTypeDecl(); else if(t.GetValue() == "const") ParseConstDecl(); else if(t.GetValue() == "procedure") ParseProc(); else if(t.GetValue() == "function") ParseFunc(); else break; } }
int Parser::Parse() { Tag *tagList; TypeDecl *typeDecl; Statement *stmt; // keep going until there are no more tokens! while(t) { TOKEN allowed[] = { TOK_LENGTHIS, TOK_SIZEIS, TOK_IGNORE, TOK_STRING, TOK_OFFSET, TOK_ALIGN, TOK_BITFLAG, TOK_STYLE, TOK_DISPLAY, TOK_ENDIAN, TOK_SWITCHIS, TOK_CASE, TOK_NAME, TOK_ENUM, TOK_EXPORT, TOK_ASSOC, TOK_NULL }; // save any whitespace before the tags FILEREF fileRef; lex_fileref(&fileRef); if(!ParseTags(&tagList, allowed)) return 0; // // Decide what kind of statement/construct we need to parse // switch(t) { case TOK_INCLUDE: // include-statement (not the same as #include which // is a C-preprocessor thing) if((stmt = ParseInclude()) == 0) { return 0; } curFile->stmtList.push_back(stmt); break; default: size_t s1 = globalFileHistory.size(); // anything else must be a type-declaration if((typeDecl = ParseTypeDecl(tagList, globalIdentifierList, false, true)) == 0) return 0; size_t s2 = globalFileHistory.size(); // store in the global list typeDecl->fileRef = fileRef; globalTypeDeclList.push_back(typeDecl); //curFile->typeDeclList.push_back(typeDecl); curFile->stmtList.push_back(new Statement(typeDecl)); // every type-declaration must end with a ';' if(!Expected(';')) return 0; // record any whitespace that appears after the type-decl lex_fileref(&typeDecl->postRef); break; } } ExportStructs(); return (errcount == 0) ? 1 : 0; }