// <expression> ::= <simple expression> // | <simple expression> <ifstatement><simple expression> void SyntaxAnalyzer::expression() { simpleExpression(); if(relOps.find(symbol) != relOps.end()) { relationOperator(); simpleExpression(); } } // expression( );
TypePtr expression (void) { //------------------------------------ // Grab the first simple expression... TypePtr resultType = simpleExpression(); if (tokenIn(relationalOperatorList)) { //--------------------------------------- // Snatch the second simple expression... getToken(); TypePtr secondType = simpleExpression(); checkRelationalOpTypes(resultType, secondType); resultType = BooleanTypePtr; } return(resultType); }
//Produção Expression' ExpressionNode* expressionLinha(ExpressionNode* sexprE){ printf("Expression'\n"); if (lookaheadPertenceFirst(Rel_Op) == 1){ int relOpVar = relOp(); ExpressionNode* sexprD = simpleExpression(); if(sexprD == NULL) return NULL; else return new RelOpNode(relOpVar,sexprE,sexprD); }else return sexprE; }
//Produção Simple_Exp' ExpressionNode* simpleExpressionLinha(ExpressionNode* addExpE){ printf("Simple_Exp'\n"); if (lookaheadPertenceFirst(Add_Op) == 1){ int addOpVar = addOp(); ExpressionNode* addExpD = simpleExpression(); if(addExpD == NULL) return NULL; else return new AddOpNode(addOpVar,addExpE,addExpD ); }else return addExpE; }
bool multiplicationExpression(char s[], int &position) { int current = position; if (simpleExpression(s, current) && multiplicationExpressionDash(s, current)) { position = current; return true; } else { return false; } }
//Produção Expression ExpressionNode* expression(){ printf("Expression\n"); if (lookahead == LITERAL ){ int iLiteral = retornaIndiceLexemaAtual(); LiteralNode* literal = new LiteralNode(iLiteral); match(LITERAL,followExpression, &iLiteral); if (lookaheadPertenceFirst(ExpressionDuasLinhas) == 1) return expressionDuasLinhas(literal); else return literal; }else{ ExpressionNode* simpExp = simpleExpression(); ExpressionNode* exprelinha = expressionLinha(simpExp); ExpressionNode* expreDuasLinhas = expressionDuasLinhas(exprelinha); return expreDuasLinhas; } }
bool multiplicationExpressionDash(char s[], int &position) { if ( isStarOrSlash(s[position]) ) { int current = position + 1; if (simpleExpression(s, current) && multiplicationExpressionDash(s, current)) { position = current; return true; } else return true; } else { return true; } }