Skip to content

Commit

Permalink
Novo operador ou não
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelrvg committed Oct 14, 2023
1 parent d5caca3 commit 4e84bec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fontes/avaliador-sintatico/avaliador-sintatico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,15 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface<SimboloIn
bitOu(): Construto {
let expressao = this.bitE();

const ouNao = (this.verificarTipoProximoSimbolo(tiposDeSimbolos.NAO) || this.verificarTipoProximoSimbolo(tiposDeSimbolos.NÃO))
&& this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.OU);
if (ouNao) {
const operador = this.simbolos[this.atual - 1];
const simboloAnterior = this.avancarEDevolverAnterior();
const simbolo = { ...operador, lexema: `${operador.lexema} ${simboloAnterior.lexema}`, tipo: tiposDeSimbolos.BIT_XOR }
const direito = this.bitE();
return new Binario(this.hashArquivo, expressao, simbolo, direito);
}
while (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.BIT_OR, tiposDeSimbolos.BIT_XOR)) {
const operador = this.simbolos[this.atual - 1];
const direito = this.bitE();
Expand Down
2 changes: 2 additions & 0 deletions fontes/lexador/palavras-reservadas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const palavrasReservadas = {
importar: tiposDeSimbolos.IMPORTAR,
isto: tiposDeSimbolos.ISTO,
leia: tiposDeSimbolos.LEIA,
nao: tiposDeSimbolos.NAO,
não: tiposDeSimbolos.NÃO,
nulo: tiposDeSimbolos.NULO,
ou: tiposDeSimbolos.OU,
padrao: tiposDeSimbolos.PADRAO,
Expand Down
2 changes: 2 additions & 0 deletions fontes/tipos-de-simbolos/delegua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default {
MODULO_IGUAL: 'MODULO_IGUAL',
MULTIPLICACAO: 'MULTIPLICACAO',
MULTIPLICACAO_IGUAL: 'MULTIPLICACAO_IGUAL',
NAO: 'NAO',
NÃO: 'NÃO',
NEGACAO: 'NEGACAO',
NULO: 'NULO',
NUMERO: 'NUMERO',
Expand Down
9 changes: 9 additions & 0 deletions testes/interpretador.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@ describe('Interpretador', () => {

expect(retornoInterpretador.erros).toHaveLength(0);
});

it('Operações lógicas - ou não', async () => {
const retornoLexador = lexador.mapear(["1 ou não 2"], -1);
const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1);

const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes);

expect(retornoInterpretador.erros).toHaveLength(0);
});
});

describe('Escolha - Caso', () => {
Expand Down

0 comments on commit 4e84bec

Please sign in to comment.