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; } }
void ParseDecl() { if(Token==TOK_INLINE || Token==TOK_FINLINE) { Match(); Out(" "); } ParseType(); /* if(Token==TOK_SCOPE) // must be constrcutor... { Match(); if(Token==TOK_NEG) Match(); Match(TOK_TYPE); } else*/ { Out(" "); ParseVarDecl(); } if(Token==TOK_OPEN) { Match(TOK_OPEN); ParseParamList(); Match(TOK_CLOSE); if(Token==TOK_CONST) { Match(); Out(" "); } if(Token==TOK_BOPEN) { //ParseBlock(); ParseCondBlock(); NewLine(); } else if(Token==TOK_ASSIGN) { Match(TOK_ASSIGN); Match(TOK_VALUE); } else if(Token==TOK_COLON) { Match(); ParseInitList(); } else { Match(TOK_SEMI); } } else { while(Token==TOK_COMMA) { Match(TOK_COMMA); ParseVarDecl(); } Match(TOK_SEMI); } }
void ParseType1(sInt withname) { while(Token==TOK_STATIC||Token==TOK_EXTERN||Token==TOK_AUTO||Token==TOK_REGISTER) { if(Token!=TOK_EXTERN) { Match(); Out(" "); } else { Match(); Out(" "); if(Token==TOK_VALUE) { Match(); Out(" "); if(Token==TOK_BOPEN) ParseBlock(); } } } if(Token==TOK_CONST||Token==TOK_VOLATILE) { Match(); Out(" "); } if(Token==TOK_STRUCT||Token==TOK_CLASS||Token==TOK_UNION) { Match(); Out(" "); if(Token==TOK_NAME) { AddType(Value); Match(TOK_NAME); } else { Match(TOK_TYPE); } if(Token==TOK_COLON) { Match(); if(Token==TOK_PROTECTED||Token==TOK_PRIVATE||Token==TOK_PUBLIC) { Match(); Out(" "); } /*else Match(TOK_PUBLIC); // provoke error*/ Match(TOK_TYPE); } if(Token==TOK_BOPEN) { MatchBOpen(); while(Token!=TOK_BCLOSE) { switch(Token) { case TOK_PROTECTED: case TOK_PRIVATE: case TOK_PUBLIC: Out("\n"); Match(); Match(TOK_COLON); break; case TOK_PRE: Out("\n"); Match(); break; default: NewLine(); ParseDecl(); break; } } MatchBClose(); } } else if(Token==TOK_ENUM) { Match(); Out(" "); if(Token==TOK_NAME) { AddType(Value); Match(TOK_NAME); } else { Match(TOK_TYPE); } if(Token==TOK_BOPEN) { MatchBOpen(); ParseInitialiser(); while(Token==TOK_COMMA) { Match(TOK_COMMA); ParseInitialiser(); } MatchBClose(); } } else { sInt gotspec=0; while(Token==TOK_LONG || Token==TOK_SHORT || Token==TOK_SIGNED || Token==TOK_UNSIGNED) { Match(); Out(" "); gotspec=1; } if(Token==TOK_INT||Token==TOK_FLOAT||Token==TOK_CHAR||Token==TOK_FLOAT||Token==TOK_DOUBLE||Token==TOK_TYPE) { Match(); } else if(!gotspec) Error("type error"); } if(withname) Out(" "); while(Token==TOK_MUL) Match(); if(Token==TOK_AND) Match(); if(withname==1) { ParseVarDecl(); } while(Token==TOK_SOPEN) { Match(); if(Token!=TOK_SCLOSE) ParseExpr(); Match(TOK_SCLOSE); } if(withname==2 && Token==TOK_OPEN) { Match(); ParseVarDecl(); Match(TOK_CLOSE); Match(TOK_OPEN); ParseParamList(); Match(TOK_CLOSE); } }