/** * Function representing the <i_list_prime> productions */ ParamList* RecursiveDescentParser::i_list_prime() { ParamList* pList = NULL; if(errorCondition) return pList; if(token == TK_COMMA) { #if DEBUG_PARSER std::cout << "<i_list_prime> --> ,<var><i_list_prime>\n"; #endif token = scanner->getToken(); VariableEntry* ve = var(); pList = i_list_prime(); pList->push_front(ve); } else if(token == TK_SEMICOLON) { #if DEBUG_PARSER std::cout << "<i_list_prime> --> e\n"; #endif pList = new ParamList(); } else { errorHandler(); } return pList; }
/** * Function representing <par_dec_list> prods */ ParamList* RecursiveDescentParser::par_dec_list() { ParamList* retVal = NULL; if(errorCondition) return retVal; if(token == TK_INT || token == TK_CHAR) { #if DEBUG_PARSER std::cout << "<par_dec_list> --> <type><par_spec><par_dec_list_prime>;<par_dec_list>\n"; #endif Type t = type(); VariableEntry* va = par_spec(t); retVal = par_dec_list_prime(t); retVal->push_front(va); match(TK_SEMICOLON); ParamList* pList = par_dec_list(); retVal->splice(retVal->end(), *pList); delete(pList); } else if(token == TK_LEFT_BRACE) { #if DEBUG_PARSER std::cout << "<par_dec_list> --> e\n"; #endif retVal = new ParamList(); } else { errorHandler(); } return retVal; }
/** * Function representing the <i_list> productions */ ParamList* RecursiveDescentParser::i_list() { ParamList* pList = NULL; if(errorCondition) return pList; if(token == TK_IDENTIFIER) { #if DEBUG_PARSER std::cout << "<i_list> --> <var><i_list_prime>\n"; #endif VariableEntry* ve = var(); pList = i_list_prime(); pList->push_front(ve); } else { errorHandler(); } return pList; }
/** * Function representing the <par_dec_list_prime> prods */ ParamList* RecursiveDescentParser::par_dec_list_prime(Type type) { ParamList* paramList = NULL; if(errorCondition) return paramList; if(token == TK_COMMA) { #if DEBUG_PARSER std::cout << "<par_dec_list_prime> --> ,<par_spec><par_dec_list_prime>\n"; #endif token = scanner->getToken(); VariableEntry* ve = par_spec(type); ve->setParamFlag(); if(!ve) { // error recovery: consume tokens until we find another comma or a semicolon while(token != TK_EOF) { if(token == TK_LEFT_BRACE) { break; } if(token == TK_COMMA || token == TK_SEMICOLON) { return par_dec_list_prime(type); } token = scanner->getToken(); } return new ParamList(); } paramList = par_dec_list_prime(type); paramList->push_front(ve); } else if(token == TK_SEMICOLON) { #if DEBUG_PARSER std::cout << "<par_dec_list_prime> --> e\n"; #endif paramList = new ParamList(); } else { //errorHandler(); errorHandler("missing semicolon at the end of parameter declaration", token); } return paramList; }