SubprogramDeclarationsPtr Parser::parseSubprogramDeclarations() { if (m_curToken.tokenType() != TokenType::Function && m_curToken.tokenType() != TokenType::Procedure) { return SubprogramDeclarationsPtr(); } SubprogramDeclarationPtr declaration = parseSubprogramDeclaration(); if (m_errorCode <= ErrorCodes::NoError) { if (!match(TokenType::Semicolon)) { reportError(ErrorCodes::ExpectedSemicolon); panic(subprogramDeclarationsFollow, subprogramDeclarationsFollowSize); return SubprogramDeclarationsPtr(); } SubprogramDeclarationsPtr subprograms(new SubprogramDeclarations); subprograms->list.push_back(declaration); SubprogramDeclarationsPtr rest = parseSubprogramDeclarations(); if (rest) { subprograms->list.insert(subprograms->list.end(), rest->list.begin(), rest->list.end()); } return subprograms; } return SubprogramDeclarationsPtr(); }
void Parser::parseSubprogramDeclarations(){ if(isNext(tc_FUNCTION) || isNext(tc_PROCEDURE)){ parseSubprogramDeclaration(); match(tc_SEMICOL); if(m_parserError){ TokenCode synch[] = {tc_FUNCTION, tc_PROCEDURE, tc_BEGIN, tc_NONE}; recover(synch); // if(isNext(tc_SEMICOL)){ // match(tc_SEMICOL); // } } parseSubprogramDeclarations(); } }