/* <Parameter> ::= <IDs> : <Qualifier> */ bool SyntaxAnalyzer::Parameter() { if(IDs()) { if(rrr == s_colon) { NextRecord(); if(Qualifier()) { logger.Log("<Parameter> ::= <IDs> : <Qualifier>"); return true; } else { insert(k_int); return true; } } else { insert(s_colon); return true; } } else { // no error return false; } }
Parser::Decl Parser::Type() { Decl d; const char *p = lex.Pos(); Qualifier(); SimpleType(); Declarator(d, p); return Finish(d, p); }
bool syntaxparser::Declaration(){ bool bDeclaration = false; if (displayFlag){ cout << "<Declaration> ::= <Qualifier> <IDs>" << endl; printproduction("<Declaration> ::= <Qualifier> <IDs>"); } cout<<endl; Qualifier(); cout<<endl; IDs(); bDeclaration = true; return bDeclaration; }
/* <Declaration> ::= <Qualifier> <IDs> */ bool SyntaxAnalyzer::Declaration() { if(Qualifier()) { IDs(); logger.Log("<Declaration> ::= <Qualifier> <IDs>"); return true; } else { return false; } }
bool syntaxparser::Parameter(){ bool Parameter = false; if (displayFlag){ cout<<"<Parameter> ::= <IDS> : <Qualifier>"<<endl; printproduction("<Parameter> ::= <IDS> : <Qualifier>"); } IDs(); if(lexeme ==":"){ print(); //print the colon Lexer(); //get next token Qualifier(); Parameter = true; }else{ error("Missing ':'"); } return Parameter; }
Array<Parser::Decl> Parser::Declaration(bool l0, bool more) { Array<Decl> r; Decla d; const char *p = lex.Pos(); if(Key(tk_typedef)) { r = Declaration(); r.Top().type_def = true; r.Top().natural = String(p, lex.Pos()); return r; } if(Key(tk_friend)) d.isfriend = true; // if(Key(tk_template)) { // d.istemplate = true; // d.template_params = TemplateParams(d.tnames); // } for(;;) { if(Key(tk_static)) d.s_static = true; else if(Key(tk_extern)) d.s_extern = true; else if(Key(tk_auto)) d.s_auto = true; else if(Key(tk_register)) d.s_register = true; else if(Key(tk_mutable)) d.s_mutable = true; else if(Key(tk_explicit)) d.s_explicit = true; else if(Key(tk_virtual)) d.s_virtual = true; else if(!Key(tk_inline)) break; } Qualifier(); bool isdestructor = Key('~'); if(l0 && context.typenames.Find(lex) >= 0 && lex[1] == '(') { Decl& a = r.Add(); a.name = lex.GetId(); a.isdestructor = isdestructor; a.function = true; a.istructor = true; a.header = String(p, lex.Pos()); ++lex; ParamList(a); const char *p1 = lex.Pos(); Qualifier(); a.ender = String(p1, lex.Pos()); a.natural = String(p, lex.Pos()); EatInitializers(); return r; } if(lex == tk_operator) { Decl& a = r.Add(); (Decla&)a = d; a.name = ReadOper(); a.header = String(p, lex.Pos()); Key('('); ParamList(a); const char *p1 = lex.Pos(); Qualifier(); a.ender = String(p1, lex.Pos()); a.function = true; a.natural = String(p, lex.Pos()); return r; } String st = SimpleType(); if(!st.IsEmpty()) { Decl& a = r.Add(); a.name = st; a.isdestructor = st.Find('~') > 0; a.function = true; a.istructor = true; a.header = String(p, lex.Pos()); if(Key('(')) ParamList(a); const char *p1 = lex.Pos(); Qualifier(); a.ender = String(p1, lex.Pos()); a.natural = String(p, lex.Pos()); EatInitializers(); return r; } String natural1 = String(p, lex.Pos()); do { const char *p1 = lex.Pos(); Decl& a = r.Add(); (Decla&)a = d; Declarator(a, p); a.natural = natural1 + String(p1, lex.Pos()); p = lex.Pos(); } while(more && Key(',')); return r; }
void Parser::Declarator(Decl& d, const char *p) { int n = RPtr(); if(n) { while(n--) lex.Get(); Declarator(d, p); d.isptr = true; return; } if(Key('&')) { Declarator(d, p); return; } if(Key(tk_const)) { Declarator(d, p); return; } if(Key('(')) { Declarator(d, p); if(d.isptr) d.nofn = true; CheckKey(')'); } if(lex == tk_operator) d.name = ReadOper(); else if(lex.IsId() || lex == t_dblcolon) { d.name = Name(); if(Key(':')) if(!Key(t_integer)) Name(); } if(Key('(')) { if((lex < 256 || lex == tk_true || lex == tk_false) && lex != ')') { int level = 0; for(;;) { if(lex == t_eof) break; if(Key('(')) level++; else if(Key(')')) { if(--level < 0) break; } else ++lex; } return; } else { d.header = String(p, lex.Pos() - 1); d.function = !d.nofn; ParamList(d); p = lex.Pos(); Qualifier(); d.ender = String(p, lex.Pos()); } } EatInitializers(); while(Key('[')) { const char *p = lex.Pos(); int level = 1; while(level && lex != t_eof) { if(Key('[')) level++; else if(Key(']')) level--; else ++lex; } } if(Key('=')) { Constant(); } }