void Interpretador::expressao() { termo(); string op; while (palavraAtual == "+" || palavraAtual == "-") { op = palavraAtual; palavraAtual= arquivo->proximaPalavra(); termo(); Expressao *exp1 = pilha->top(); pilha->pop(); Expressao *exp2 = pilha->top(); pilha->pop(); pilha->push(new ExpBinaria(op,exp1,exp2)); } }
/*** Função que confere a expressao linha(usado pra remover recursão a esquerda) ***/ int exprl() { //printf("EXPRL\n"); if(match(PLUS)) { if(termo()) { if(exprl()) { return 1; } else return 0; } else return 0; } else if(match(MINUS)) { if(termo()) { if(exprl()) { return 1; } else return 0; } else return 0; } else return 1; }
/*** Função que confere uma expressao ***/ int expr() { //printf("EXPR\n"); if(termo()) { if(exprl()) { return 1; } else return 1; } else return 0; }
int expressao_simples(void) { int tipo1, tipo2; tipo1 = tipo2 = 0; tipo1 = termo(); while((tk.cod == SUM) || (tk.cod == SUB) || (tk.cod == OR)){ tk = analex(); tipo2 = termo(); if(tipo1 != tipo2){ erro(lin, 12); } } return tipo1; }