Skip to content

Commit

Permalink
Adapta lexador para mapear variáveis e inicia caminha de tratamento d…
Browse files Browse the repository at this point in the history
…e valores
  • Loading branch information
VitBrandao committed Feb 13, 2025
1 parent 907aba4 commit 8dbbb8c
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion fontes/lexador/lexador.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class Lexador implements LexadorInterface {
atual: number;
inicioSimbolo: number;

contemVariaveis: boolean;

constructor() {
this.codigo = [""];

Expand All @@ -27,6 +29,8 @@ export class Lexador implements LexadorInterface {
this.atual = 0;
this.linha = 0;
this.inicioSimbolo = 0;

this.contemVariaveis = false;
}

/**
Expand Down Expand Up @@ -108,7 +112,7 @@ export class Lexador implements LexadorInterface {

avancar(): void {
this.atual += 1;

if (this.eFinalDaLinha() && !this.eUltimaLinha()) {
this.linha++;
this.atual = 0;
Expand Down Expand Up @@ -210,6 +214,49 @@ export class Lexador implements LexadorInterface {
this.adicionarSimbolo(tiposDeSimbolos.TEXTO, valor);
}

analisarVariaveis(): void {

Check warning on line 217 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
this.linha = 0;

Check warning on line 218 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
let indexBase = 0;

Check warning on line 219 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const indexLimite = this.simbolos.length;

Check warning on line 220 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const declaracoesVariaveis: Array<Simbolo[]> = [];

Check warning on line 222 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const atribuicoesVariaveis: Array<Simbolo[]> = [];

Check warning on line 223 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

while (!this.eFinalDoCodigo() && indexBase < indexLimite) {

Check warning on line 225 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 225 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
// console.log(this.simbolos[indexBase]);

if (this.simbolos[indexBase].tipo === tiposDeSimbolos.VARIAVEL) {
const variavelDeclarada = [];

Check warning on line 229 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
while (this.simbolos[indexBase].tipo !== tiposDeSimbolos.PONTO_E_VIRGULA) {
// this.simbolos[indexBase].literal = indexBase; // !!!!
variavelDeclarada.push(this.simbolos[indexBase]);

Check warning on line 232 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
indexBase += 1;

Check warning on line 233 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 234 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

if (variavelDeclarada.length === 2) {
atribuicoesVariaveis.push(variavelDeclarada);

Check warning on line 237 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else {
// variavelDeclarada.forEach((variavel) => {
// this.simbolos.splice(variavel.literal, 1);
// });
declaracoesVariaveis.push(variavelDeclarada);

Check warning on line 242 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 243 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 243 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 243 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
} else {
indexBase += 1;

Check warning on line 245 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 246 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 246 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 246 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
this.avancar();

Check warning on line 247 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 248 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
console.log('VARIAVEIS DECLARADAS:', declaracoesVariaveis);

Check warning on line 249 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
console.log('VARIAVEIS ATRIBUÍDAS:', atribuicoesVariaveis);

Check warning on line 250 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
console.log('SIMBOLOS', this.simbolos);

Check warning on line 251 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

// PRÓXIMOS OBJETIVOS:
// 1. Guardar valores de declaracoesVariaveis (tudo que vem depois de DOIS_PONTOS) declarados
// 2. Excluir declaracoesVariaveis de this.símbolos
// 3. Substituir os dois objetos de atribuicoesVariaveis em this.simbolos por um único objeto contendo o valor guardado

}

identificarPalavraChave(): void {
while (this.eAlfabetoOuDigito(this.caractereAtual())) {
this.avancar();
Expand Down Expand Up @@ -361,6 +408,9 @@ export class Lexador implements LexadorInterface {
case "@":
this.analisarDiretiva();
break;
case "$":
this.adicionarSimbolo(tiposDeSimbolos.VARIAVEL, null, '$');

Check warning on line 412 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
this.contemVariaveis = true;

Check warning on line 413 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 413 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
default:
if (this.eDigito(caractere)) this.analisarNumero();
else if (this.eAlfabeto(caractere))
Expand Down Expand Up @@ -390,6 +440,10 @@ export class Lexador implements LexadorInterface {
this.inicioSimbolo = this.atual;
this.analisarToken();
}

if (this.contemVariaveis) {
this.analisarVariaveis();

Check warning on line 445 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 446 in fontes/lexador/lexador.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

return {
simbolos: this.simbolos,
Expand Down

0 comments on commit 8dbbb8c

Please sign in to comment.