int Recipe::ParseRecipe(Lexer &l) { lex= &l; lex->token(cur_tok); try { topNode=ParseStatementList(); } catch (const char *p) { l.errmsg(p); return (-1); } #if NEED_NONCONST_EXCEPTIONS catch (char *p) { l.errmsg(p); return (-1); } #endif if (cur_tok.Type() != cur_tok.eof) { l.errmsg("Syntax error."); return (-1); } return (0); }
void CParser::ParseStatementIf(int nTabs) { CString sToken = m_oToken.GetCurrentToken(); m_sProgress = m_sProgress + GetTabs(nTabs) + "ParseStatemenIf " + sToken + "\r\n"; /* If condition Then [statements] [ElseIf condition-n Then [elseifstatements] ... [Else [elsestatements]] End If */ m_oToken.GetNextToken(); //skip current if token ParseCondition(nTabs+1); ParseStatementIfThen(nTabs+1); ParseStatementList(nTabs+1); //temp code to reach end (of if) //while(sToken != "End" && sToken !="") //sToken = m_oToken.GetNextToken(); //skip end if //m_oToken.GetNextToken(); //skip end ParseStatementEnd(nTabs); m_oToken.GetNextToken(); //skip if //parse then //parse statement list //parse else if list (do it only if time possible) //parse end if }
Sentencia* Sintactico::ParseProgramContent() { if ( proximo_token.GetTipo() == html ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); return ParseProgramContent(); } else if ( proximo_token.GetTipo() == punt_delimpascalizq ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); Sentencia* stmt = ParseStatementList(); //Sentencia* stmt = ParseStatement(); if (proximo_token.GetTipo() == punt_delimpascalder ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); Sentencia* p_content = ParseProgramContent(); stmt->SetSiguiente( p_content ); return stmt; } else throw SyntaxException("Falta el delimitador %>",analizador_lexico->GetLineaActual()); } else return 0; }
Sentencia* Sintactico::ParseRepeatStatement() { if ( proximo_token.GetTipo() == kw_repeat ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); Sentencia* stmt = ParseStatementList(); if ( proximo_token.GetTipo() == kw_until ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); Expresion* expr = ParseExpression(); if ( proximo_token.GetTipo() == punt_puntocoma ) proximo_token = analizador_lexico->ObtenerSiguienteToken(); else throw SyntaxException("Falta un punto y coma, sentencia repeat",analizador_lexico->GetLineaActual() ); return new SentenciaRepeat(stmt,expr); } else throw SyntaxException("Falta la kw until: produccion RepeatStatement",analizador_lexico->GetLineaActual()); } else throw SyntaxException("Falta la kw repeat: produccion Repeat Statement",analizador_lexico->GetLineaActual()); }
//CString CParser::ParseProcedureBody() void CParser::ParseProcedureBody() { int nTabs = 4; m_sProgress = m_sProgress + GetTabs(nTabs) + "ParseProcedureBody\r\n"; ParseStatementList(nTabs+1); }
void TParser::ParseCompound(void) { GetTokenAppend(); //--<stmt-list> ParseStatementList(tcEND); //--END CondGetTokenAppend(tcEND, errMissingEND); }
void CParser::ParseStatementWhile(int nTabs) { CString sToken = m_oToken.GetCurrentToken(); m_sProgress = m_sProgress + GetTabs(nTabs) + "ParseStatemenWhile " + sToken + "\r\n"; m_oToken.GetNextToken(); //skip current while token ParseCondition(nTabs+1); ParseStatementList(nTabs+1); ParseStatementWend(nTabs); }
void TParser::ParseREPEAT(void) { GetTokenAppend(); //--<stmt-list> ParseStatementList(tcUNTIL); //--UNTIL CondGetTokenAppend(tcUNTIL, errMissingUNTIL); //--<expr> : must be boolean InsertLineMarker(); CheckBoolean(ParseExpression()); }
Sentencia* Sintactico::ParseCompoundStatement() { if (proximo_token.GetTipo() == kw_begin ) { proximo_token = analizador_lexico->ObtenerSiguienteToken(); Sentencia* stmt = ParseStatementList(); if ( proximo_token.GetTipo() == kw_end ) proximo_token = analizador_lexico->ObtenerSiguienteToken(); else throw SyntaxException("Error falta la palabra clave END",analizador_lexico->GetLineaActual()); return stmt; } else throw SyntaxException("Falta la palabra clave begin",analizador_lexico->GetLineaActual()); }
RecipeNode *Recipe::ParseStatement() { RecipeNode *n, *o; switch (cur_tok.Type()) { case Token::tokenif: lex->token(cur_tok); if (cur_tok.Type() != Token::lparen) throw "Syntax error after if"; lex->token(cur_tok); n=alloc(RecipeNode::ifelse); o=ParseExpr(); n->AppendSibling(o); if (cur_tok.Type() != Token::rparen) throw "Missing )"; lex->token(cur_tok); if (cur_tok.Type() != Token::semicolon) // Newline/semicolon throw "Syntax error after )"; lex->token(cur_tok); n->AppendSibling(ParseSubStatement()); if (cur_tok.Type() == Token::tokenelse) { lex->token(cur_tok); if (cur_tok.Type() != Token::semicolon) // Newline/semicolon throw "Syntax error after else"; lex->token(cur_tok); n->AppendSibling(ParseSubStatement()); } return (n); case Token::tokenwhile: lex->token(cur_tok); if (cur_tok.Type() != Token::lparen) throw "Syntax error after while"; lex->token(cur_tok); n=alloc(RecipeNode::whileloop); o=ParseExpr(); n->AppendSibling(o); if (cur_tok.Type() != Token::rparen) throw "Missing )"; lex->token(cur_tok); if (cur_tok.Type() != Token::semicolon) // Newline/semicolon throw "Syntax error after else"; lex->token(cur_tok); n->AppendSibling(ParseSubStatement()); return (n); case Token::lbrace: lex->token(cur_tok); n=ParseStatementList(); if (cur_tok.Type() != Token::rbrace) throw "Missing }"; lex->token(cur_tok); if (cur_tok.Type() != Token::semicolon) { throw "Syntax error after }"; } lex->token(cur_tok); return (n); case Token::tokento: lex->token(cur_tok); n=alloc(RecipeNode::deliver); o=ParseExpr(); n->AppendSibling(o); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::tokencc: lex->token(cur_tok); n=alloc(RecipeNode::delivercc); o=ParseExpr(); n->AppendSibling(o); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::exception: lex->token(cur_tok); if (cur_tok.Type() != Token::lbrace) throw "Syntax error."; n=alloc(RecipeNode::exception); o=ParseStatement(); n->AppendSibling(o); return (n); case Token::echo: lex->token(cur_tok); n=alloc(RecipeNode::echo); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::tokenxfilter: lex->token(cur_tok); n=alloc(RecipeNode::xfilter); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::dotlock: lex->token(cur_tok); n=alloc(RecipeNode::dotlock); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::lbrace) throw "Syntax error."; n->AppendSibling( ParseStatement() ); return (n); case Token::flock: lex->token(cur_tok); n=alloc(RecipeNode::flock); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::lbrace) throw "Syntax error."; n->AppendSibling( ParseStatement() ); return (n); case Token::logfile: lex->token(cur_tok); n=alloc(RecipeNode::logfile); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::log: lex->token(cur_tok); n=alloc(RecipeNode::log); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::include: lex->token(cur_tok); n=alloc(RecipeNode::include); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::exit: lex->token(cur_tok); n=alloc(RecipeNode::exit); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::foreach: lex->token(cur_tok); n=alloc(RecipeNode::foreach); n->AppendSibling( ParseExpr()); if (n->firstChild->nodeType != RecipeNode::strregexp && n->firstChild->nodeType != RecipeNode::regexpr) throw "Syntax error."; if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); n->AppendSibling( ParseSubStatement() ); return (n); case Token::importtoken: lex->token(cur_tok); n=alloc(RecipeNode::importtoken); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); case Token::unset: lex->token(cur_tok); n=alloc(RecipeNode::unset); n->AppendSibling( ParseExpr()); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); default: break; } n=ParseExpr(); if (cur_tok.Type() != Token::semicolon) throw "Syntax error."; lex->token(cur_tok); return (n); }