/*void translationunit(void){ globaldeclaration(); translationunit(); }*/ void globaldeclaration(void){ typespecifier(); pointers(); match(ID); if(lookahead == '('){ match('('); parameters(); match(')'); match('{'); declarations(); statements(); match('}'); } else{ if(lookahead == '['){ match('['); match(NUM); match(']'); } if(lookahead == ','){ declaratorlist(); } match(';'); } }
DeclarationsPtr Parser::parseArgumentList() { IdentifiersPtr identifiers = parseIdentifierList(); if (m_errorCode > ErrorCodes::NoError) { return DeclarationsPtr(); } if (!match(TokenType::Colon)) { reportError(ErrorCodes::ExpectedColon); return DeclarationsPtr(); } TypePtr type = parseType(); if (m_errorCode > ErrorCodes::NoError) { return DeclarationsPtr(); } DeclarationsPtr declarations(new Declarations); for (std::vector<IdentifierPtr>::const_iterator i = identifiers->list.begin(); i != identifiers->list.end(); ++i) { DeclarationPtr declaration(new Declaration); declaration->id = *i; declaration->type = type; declarations->list.push_back(declaration); } DeclarationsPtr rest = parseArgumentList_r(); if (rest) { declarations->list.insert(declarations->list.end(), rest->list.begin(), rest->list.end()); } return declarations; }
int declarations() { if(dtype()) { if(idlist()) { if(T[nt++].t==27) { if(declarations()) return 1; else return 0; } else { strcpy(miss,";"); return 0; } } else return 0; } else return 1; }
void statement(void){ if(lookahead == '{') { match('{'); declarations(); statements(); match('}'); } else if (lookahead == RET) { match(RET); expression(); match(';'); } else if (lookahead == WHILE) { match(WHILE); match('('); expression(); match(')'); statement(); } else if (lookahead == IF) { match(IF); match('('); expression(); match(')'); statement(); if (lookahead == ELSE) { match(ELSE); statement(); } } else { expression(); match(';'); } }
void declarations(void){ if(lookahead == CHAR || lookahead == INT){ declaration(); declarations(); } }
/* * mypas -> programID declarations blockstmt '.' */ void mypas(void) { programID(); declarations(); blockstmt(); match('.'); }
int program() { if(T[nt++].t==10) { if(T[nt++].t==20) { if(T[nt++].t==21) { if(T[nt++].t==22) { if(declarations()) { if(statlist()) { if(T[nt++].t==23) return 1; else { strcpy(miss,"}"); return 0; } } else return 0; } else return 0; } else { strcpy(miss,"{"); return 0; } } else { strcpy(miss,")"); return 0; } } else { strcpy(miss,"("); return 0; } } else { strcpy(miss,"main"); return 0; } }
int declarations() { if(dtype()) { if(idlist()) { if(T[nt++].t==27) { if(declarations()) return 1; else return -1; } else return -1; } else return -1; } else return 1; }
int program() { if(T[nt++].t==10) { if(T[nt++].t==20) { if(T[nt++].t==21) { if(T[nt++].t==22) { if(declarations()) { if(statlist()) { if(T[nt++].t==23) return -1; else return -1; } else return -1; } else return -1; } else return -1; } else return -1; } else return -1; } else return -1; }