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; }
void Parser::parseDeclarations(){ if(isNext(tc_VAR)){ match(tc_VAR); EntryList ids = *(new EntryList()); parseIdentifierList(ids); match(tc_COLON); if(m_parserError){ TokenCode synch[] = {tc_ARRAY, tc_INTEGER, tc_REAL, tc_NONE}; recover(synch); // if(isNext(tc_COLON)){ // match(tc_COLON); // } } parseType(); m_code->generateVariables(ids); match(tc_SEMICOL); if(m_parserError){ TokenCode synch[] = {tc_VAR, tc_FUNCTION, tc_BEGIN, tc_PROCEDURE, tc_NONE}; recover(synch); // if(isNext(tc_SEMICOL)){ // match(tc_SEMICOL); // } } parseDeclarations(); } }
IdentifiersPtr Parser::parseIdentifierList_r() { if (match(TokenType::Comma)) { return parseIdentifierList(); } return IdentifiersPtr(); }
bool DbcParser::parseSectionBu(CanDb &candb, DbcParser::DbcTokenList &tokens) { QStringList strings; QString s; if (!parseIdentifierList(tokens, &strings, true)) { return false; } foreach(s, strings) { candb.getOrCreateNode(s); }
bool DbcParser::parseSection(CanDb &candb, DbcTokenList &tokens) { bool retval = true; QString sectionName; QStringList strings; while (retval) { if (tokens.isEmpty()) { break; } if (expectIdentifier(tokens, §ionName, true, true)) { if (sectionName == "VERSION") { retval &= parseSectionVersion(candb, tokens); } else if (sectionName == "NS_") { strings.clear(); retval &= parseIdentifierList(tokens, &strings); } else if (sectionName == "BS_") { retval &= parseSectionBs(tokens); } else if (sectionName == "BU_") { retval &= parseSectionBu(candb, tokens); } else if (sectionName == "BO_") { retval &= parseSectionBo(candb, tokens); } else if (sectionName == "CM_") { retval &= parseSectionCm(candb, tokens); } else if (sectionName == "VAL_") { retval &= parseSectionVal(candb, tokens); } else { skipUntilSectionEnding(tokens); } } else { retval = false; } } if (!retval) { Backend::instance().logMessage(log_level_error, "dbc parse error"); } return retval; /* if (sectionName == "BA_") { return tokSectionBa; } if (sectionName == "BA_REL_") { return tokSectionBaRel; } if (sectionName == "BA_DEF_") { return tokSectionBaDef; } if (sectionName == "BA_DEF_DEF_") { return tokSectionBaDefDef; } if (sectionName == "BA_DEF_DEF_REL_") { return tokSectionBaDefDefRel; } */ }
void Parser::parseParameterList(){ EntryList ids = *(new EntryList()); parseIdentifierList(ids); match(tc_COLON); if(m_parserError){ TokenCode synch[] = {tc_ARRAY, tc_INTEGER, tc_REAL, tc_NONE}; recover(synch); // if(isNext(tc_COLON)){ // match(tc_COLON); // } } parseType(); m_code->generateFormals(ids); parseParameterListPrime(); }
ProgramPtr Parser::parseProgram() { if (!match(TokenType::Program)) { reportError(ErrorCodes::ExpectedProgram); panic(programFollow, programFollowSize); return ProgramPtr(); } IdentifierPtr programName = parseIdentifier(); if (m_errorCode > ErrorCodes::NoError) { panic(programFollow, programFollowSize); return ProgramPtr(); } if (!match(TokenType::LParen)) { reportError(ErrorCodes::ExpectedLParen); panic(programFollow, programFollowSize); return ProgramPtr(); } IdentifiersPtr inputOutput = parseIdentifierList(); if (m_errorCode > ErrorCodes::NoError) { panic(programFollow, programFollowSize); return ProgramPtr(); } if (!match(TokenType::RParen)) { reportError(ErrorCodes::ExpectedRParen); panic(programFollow, programFollowSize); return ProgramPtr(); } if (!match(TokenType::Semicolon)) { reportError(ErrorCodes::ExpectedSemicolon); panic(programFollow, programFollowSize); return ProgramPtr(); } DeclarationsPtr globalVariables = parseDeclarations(); if (m_errorCode > ErrorCodes::NoError) { panic(programFollow, programFollowSize); return ProgramPtr(); } SubprogramDeclarationsPtr functions = parseSubprogramDeclarations(); if (m_errorCode > ErrorCodes::NoError) { panic(programFollow, programFollowSize); return ProgramPtr(); } CompoundStatementPtr mainProgram = parseCompoundStatement(); if (m_errorCode > ErrorCodes::NoError) { panic(programFollow, programFollowSize); return ProgramPtr(); } if (!match(TokenType::Period)) { reportError(ErrorCodes::ExpectedPeriod); panic(programFollow, programFollowSize); return ProgramPtr(); } ProgramPtr program(new Program); program->programName = programName; program->inputOutput = inputOutput; program->variables = globalVariables; program->functions = functions; program->mainProgram = mainProgram; return program; }