bool ParserThread::ParseScopeQueue(ScopeQueue& scopeQueue) { Token * currentToken = ConsumeToken(); assert(currentToken->type_id() == TKN_IDENTIFIER); ScopeBlock scope; scope.name = *currentToken;// add the name ParseArgumentList(scope.templateArgumentList); scopeQueue.push_back(scope); while(PeekToken()->type_id()==TKN_DOUBLE_COLON && PeekToken(2)->type_id()==TKN_IDENTIFIER) { //scope.name.Clear(); should reset the Token scope.templateArgumentList.clear(); //Read the Argument list // fill the *it.templateArgumentList // if the fill function return false, which, we should skip to ; or } ConsumeToken(); //consume :: currentToken = ConsumeToken(); // get id scope.name = *currentToken;// add the name bool parseResult = ParseArgumentList(scope.templateArgumentList); if (!parseResult) // this means we have the format A<......;, this is not a template { m_Context.EndStatement(); return false; } scopeQueue.push_back(scope); } return true; }
Sentencia* Sintactico::ParseProcedureStatement(string nombre_procedimiento ) { if ( proximo_token.GetTipo() == punt_puntocoma) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); list<Expresion*> lista_vacia; FunctionCall* llamada_proc = new FunctionCall(nombre_procedimiento,lista_vacia); return new SentenciaProcedimiento(llamada_proc); } else if ( proximo_token.GetTipo() == punt_parentizq ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); list<Expresion*> args = ParseArgumentList(); if ( proximo_token.GetTipo() == punt_parentder ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); if (proximo_token.GetTipo() == punt_puntocoma ) proximo_token = analizador_lexico->ObtenerSiguienteToken(); else throw SyntaxException("Falta un punto y coma",analizador_lexico->GetLineaActual() ); } else throw SyntaxException("Falta un parentesis derecho", analizador_lexico->GetLineaActual() ); FunctionCall* llamada_proc = new FunctionCall(nombre_procedimiento,args); return new SentenciaProcedimiento(llamada_proc); } else throw SyntaxException("Token no valido ",analizador_lexico->GetLineaActual() ); }
AST* ParseFunctionCall(ParserState* parser) { Value* funcId = Match(parser, TOKEN_ID); AST* funcNode = CreateASTNode(SEM_FUNCCALL, funcId); Match(parser, TOKEN_LEFTBRACKET); AST* arglist = ParseArgumentList(parser); Match(parser, TOKEN_RIGHTBRACKET); AddASTChild(funcNode, arglist); return funcNode; }
list<Expresion*> Sintactico::ParseFunctionCall() { if ( proximo_token.GetTipo() == punt_parentizq ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); list<Expresion*> argument_list = ParseArgumentList(); if( proximo_token.GetTipo() == punt_parentder ) proximo_token = analizador_lexico->ObtenerSiguienteToken(); else throw SyntaxException("Falta un parentesis derecho, produccion Params",analizador_lexico->GetLineaActual()); return argument_list; } else throw SyntaxException("Se esperaba un token de parentesis izquierdo",analizador_lexico->GetLineaActual()); }
AST* ParseValue(ParserState* parser) { AST* node; if(parser->currentToken.type == TOKEN_NUMBER || parser->currentToken.type == TOKEN_STRING) { node = CreateASTNode(SEM_CONSTANT, parser->currentToken.value); Match(parser, parser->currentToken.type); } else { if(parser->nextToken.type == TOKEN_LEFTBRACKET) return ParseFunctionCall(parser); Value *id = Match(parser, TOKEN_ID); /* XXX: Factor this out */ if(parser->currentToken.type == TOKEN_LEFT_SQUARE_BRACKET) { Match(parser, TOKEN_LEFT_SQUARE_BRACKET); AST* size = ParseExpression(parser); Match(parser, TOKEN_RIGHT_SQUARE_BRACKET); node = CreateASTNode(SEM_INDEX, id); AddASTChild(node, size); } else if(parser->currentToken.type == TOKEN_DOT) { Match(parser, TOKEN_DOT); Value* field_name = Match(parser, TOKEN_FIELD); if(parser->currentToken.type == TOKEN_LEFTBRACKET) { node = CreateASTNode(SEM_METHOD_CALL, VALUE_EMPTY); AST* field_node = CreateASTNode(SEM_FIELD, id); AddASTChild(field_node, CreateASTNode(SEM_CONSTANT, field_name)); AddASTChild(node, field_node); Match(parser, TOKEN_LEFTBRACKET); AddASTChild(node, ParseArgumentList(parser)); Match(parser, TOKEN_RIGHTBRACKET); } else { node = CreateASTNode(SEM_FIELD, id); AddASTChild(node, CreateASTNode(SEM_CONSTANT, field_name)); } } else { node = CreateASTNode(SEM_ID, id); } } return node; }
AST* ParseFunctionDefinition(ParserState* parser) { Match(parser, TOKEN_FUNCTION); Value* name = NULL; if(parser->currentToken.type == TOKEN_ID) { name = Match(parser, TOKEN_ID); } AST* function = CreateASTNode(SEM_FUNCTION, name); Match(parser, TOKEN_LEFTBRACKET); AST* arglist = ParseArgumentList(parser); Match(parser, TOKEN_RIGHTBRACKET); AST* code = ParseBlock(parser); AddASTChild(function, arglist); AddASTChild(function, code); return function; }
//CString CParser::ParseProcedureHead() void CParser::ParseProcedureHead() { m_sProgress = m_sProgress + GetTabs(4) + "ParseProcedureHead\r\n"; //CString sRetVal,sRetVal2="true"; //sRetVal = ParseProcedureScope(); ParseProcedureScope(); ParseProcedureStatic(); ParseProcedureType(5); ParseID(5); ParseProcedureStartBracket(); ParseArgumentList(); ParseProcedureEndBracket(); ParseProcedureReturn(); } // ParseProcedureHead()