Skip to content

Adição da palavra reservada mod para operações de módulo. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fontes/lexador/palavras-reservadas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const palavrasReservadas = {
log: tiposDeSimbolos.METODO_BIBLIOTECA_GLOBAL,
logn: tiposDeSimbolos.METODO_BIBLIOTECA_GLOBAL,
logico: tiposDeSimbolos.LOGICO,
mod: tiposDeSimbolos.MODULO,
nao: tiposDeSimbolos.NEGACAO, // Exceção
on: tiposDeSimbolos.ON,
off: tiposDeSimbolos.OFF,
Expand Down
52 changes: 52 additions & 0 deletions testes/interpretador.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,58 @@ describe('Interpretador', () => {

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

it('Números Primos', async () => {
// Aqui vamos simular a resposta para uma variável de `leia()`.
const respostas = [
"50"
];
(interpretador as any).interfaceEntradaSaida = {
question: (mensagem: string, callback: Function) => {
callback(respostas.shift());
}
};

let _saidas = '';
const retornoLexador = lexador.mapear(
[
`Algoritmo "NumerosPrimos"
Var
Fatorial,Numero,Primo,Resposta : Inteiro
Flag : Logico
inicio
Limpatela
Escreva("Deseja até que número primo: ")
leia(Numero)
Escreval(" ")
Escreva(" 1") // montagem
Para Primo de 2 ate Numero faca
Fatorial<- 2
Flag <- Falso
enquanto (Primo<>fatorial) faca
Resposta <- Primo MOD Fatorial
Fatorial <- Fatorial + 1
se Resposta = 0 entao
Flag <- Verdadeiro
fimse
fimenquanto
se (Nao Flag) entao
escreva(" , ",Primo)
fimse
fimpara
Escreval(" ")
Fimalgoritmo`
], -1);

interpretador.funcaoDeRetorno = (saida: any) => {
_saidas += saida;
}

const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1);
const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes);

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