Skip to content

Commit

Permalink
Merge pull request #41 from iaglourenco/28-implementar-fator
Browse files Browse the repository at this point in the history
analisa fator
  • Loading branch information
iaglourenco authored Sep 20, 2022
2 parents d218dbc + c163563 commit de297ce
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compilador/js/erros.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const messages = {
sxs5: "Erro sintático: Esperado ':'",
sxs6: "Erro sintático: Tipo de variável inválido",
sxs7: "Erro sintático: Esperado 'inicio'",
sxs8: "Erro sintático: Esperado 'fim'",
sxs9: "Erro sintático: Parenteses não fechados",
sxs10: "Erro sintático: Simbolo não esperado",
};

export class ErroLexico extends Error {
Expand Down
53 changes: 53 additions & 0 deletions compilador/js/sintatico.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,59 @@ function analisaComandoCondicional() {}
function analisaComandoEnquanto() {}
function analisaComandoLeitura() {}
function analisaComandoEscrita() {}
function analisaTermo() {}
function analisaFator() {
/**
* <fator> ::= (<variável> |
* <número> |
* <chamada de função> |
* (<expressão>) | verdadeiro | falso |
* nao <fator>)
*
*/
if (lexico.tokenAtual.simbolo == "Sidentificador") {
//semantico
// if (pesquisaTabela(lexico.tokenAtual.lexema, nível, ind)) {
// if (
// tabelaSimbolos[ind].tipo == "funcao int" ||
// tabelaSimbolos[ind].tipo == "funcao booleano"
// ) {
// analisaChamadaFuncao();
// }else lexico.proximoToken();
// }
// else{ ERRO}
} else if (lexico.tokenAtual.simbolo == "Snumero") {
lexico.proximoToken();
} else if (lexico.tokenAtual.simbolo == "Snao") {
lexico.proximoToken();
analisaFator();
} else if (lexico.tokenAtual.simbolo == "Sabre_parenteses") {
lexico.proximoToken();
analisaExpressao();
if (lexico.tokenAtual.simbolo == "Sfecha_parenteses") {
lexico.proximoToken();
} else {
throw new ErroSintatico(
"sxs9",
lexico.tokenAtual.lexema,
lexico.tokenAtual.linha,
lexico.tokenAtual.coluna
);
}
} else if (
lexico.tokenAtual.simbolo == "Sverdadeiro" ||
lexico.tokenAtual.simbolo == "Sfalso"
) {
lexico.proximoToken();
} else {
throw new ErroSintatico(
"sxs10",
lexico.tokenAtual.lexema,
lexico.tokenAtual.linha,
lexico.tokenAtual.coluna
);
}
}

function analisaTipo() {
/**
Expand Down

0 comments on commit de297ce

Please sign in to comment.