Skip to content
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

Permitindo retorno dicionario literal #654

Merged
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
11 changes: 6 additions & 5 deletions fontes/avaliador-sintatico/avaliador-sintatico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface<SimboloIn
tiposDeSimbolos.SUPER,
tiposDeSimbolos.TEXTO,
tiposDeSimbolos.VERDADEIRO,
tiposDeSimbolos.CHAVE_ESQUERDA
].includes(this.simbolos[this.atual].tipo)
) {
valor = this.expressao();
Expand Down Expand Up @@ -1091,13 +1092,13 @@ export class AvaliadorSintatico implements AvaliadorSintaticoInterface<SimboloIn
this.consumir(tiposDeSimbolos.CHAVE_ESQUERDA, "Esperado chave esquerda para abertura de bloco em declaração 'tendo'.");
const blocoCorpo = this.blocoEscopo();
return new TendoComo(
simboloTendo.linha,
simboloTendo.hashArquivo,
simboloNomeVariavel,
expressaoInicializacao,
simboloTendo.linha,
simboloTendo.hashArquivo,
simboloNomeVariavel,
expressaoInicializacao,
new Bloco(
simboloTendo.linha,
simboloTendo.hashArquivo,
simboloTendo.hashArquivo,
blocoCorpo
)
);
Expand Down
10 changes: 5 additions & 5 deletions fontes/interpretador/interpretador-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export class InterpretadorBase implements InterpretadorInterface {

regexInterpolacao = /\${(.*?)}/g;
private tiposNumericos = [
tipoDeDadosDelegua.INTEIRO,
tipoDeDadosDelegua.NUMERO,
tipoDeDadosDelegua.NÚMERO,
tipoDeDadosDelegua.INTEIRO,
tipoDeDadosDelegua.NUMERO,
tipoDeDadosDelegua.NÚMERO,
tipoDeDadosDelegua.REAL
];

Expand Down Expand Up @@ -528,7 +528,7 @@ export class InterpretadorBase implements InterpretadorInterface {
return Math.pow(valorEsquerdo, valorDireito);

case tiposDeSimbolos.MAIOR:
if (tipoEsquerdo === tipoDeDadosDelegua.NUMERO && tipoDireito === tipoDeDadosDelegua.NUMERO) {
if ((tipoEsquerdo === tipoDeDadosDelegua.NUMERO) || (tipoEsquerdo === tipoDeDadosDelegua.NÚMERO) && (tipoDireito === tipoDeDadosDelegua.NUMERO) || (tipoDireito === tipoDeDadosDelegua.NÚMERO)) {
return Number(valorEsquerdo) > Number(valorDireito);
}

Expand All @@ -539,7 +539,7 @@ export class InterpretadorBase implements InterpretadorInterface {
return Number(valorEsquerdo) >= Number(valorDireito);

case tiposDeSimbolos.MENOR:
if (tipoEsquerdo === tipoDeDadosDelegua.NUMERO && tipoDireito === tipoDeDadosDelegua.NUMERO) {
if ((tipoEsquerdo === tipoDeDadosDelegua.NUMERO) || (tipoEsquerdo === tipoDeDadosDelegua.NÚMERO) && (tipoDireito === tipoDeDadosDelegua.NUMERO) || (tipoDireito === tipoDeDadosDelegua.NÚMERO)) {
return Number(valorEsquerdo) < Number(valorDireito);
}

Expand Down
21 changes: 18 additions & 3 deletions testes/analisador-semantico.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ describe('Analisador semântico', () => {
expect(retornoAnalisadorSemantico.diagnosticos[0].mensagem).toBe('A função não pode ter nenhum tipo de retorno.');
});

it('Função retorna Dicionario literal', async () => {
const retornoLexador = lexador.mapear(
[
'funcao executar() {',
' retorna { "chave": 100 }',
'}',
'escreva(executar())',
],
-1
);
const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1);

expect(retornoAvaliadorSintatico.erros.length).toBeGreaterThanOrEqual(0);
});

it('Não retornando o tipo que a função definiu - texto', () => {
const retornoLexador = lexador.mapear([
"funcao executar(valor1, valor2): texto {",
Expand Down Expand Up @@ -769,10 +784,10 @@ describe('Analisador semântico', () => {
const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1);
const retornoAnalisadorSemantico = analisadorSemantico.analisar(retornoAvaliadorSintatico.declaracoes);
expect(retornoAnalisadorSemantico).toBeTruthy();
expect(retornoAnalisadorSemantico.diagnosticos.filter(item=> item.severidade === DiagnosticoSeveridade.AVISO)).toHaveLength(1);
expect(retornoAnalisadorSemantico.diagnosticos.filter(item => item.severidade === DiagnosticoSeveridade.AVISO)).toHaveLength(1);
expect(retornoAnalisadorSemantico.diagnosticos).toHaveLength(1);
});
});
});
});

describe('Cenários variáveis não inicializada', () => {
Expand Down Expand Up @@ -840,7 +855,7 @@ describe('Analisador semântico', () => {
expect(retornoAnalisadorSemantico.diagnosticos).toHaveLength(1);
expect(retornoAnalisadorSemantico.diagnosticos.filter(item => item.severidade === DiagnosticoSeveridade.AVISO)).toHaveLength(1);
});

it('Sucesso - variável tipo texto não inicializada', () => {
const retornoLexador = lexador.mapear([
"classe Teste {}",
Expand Down
Loading