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

Correções de erros encontrados durante o testes do lexico #7

Merged
merged 1 commit into from
Sep 13, 2022
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
4 changes: 2 additions & 2 deletions compilador/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>compil{LPD}ador</title>
<title>compi{LPD}lador</title>

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link rel="stylesheet" href="styles/compilador.css" />
Expand Down Expand Up @@ -41,7 +41,7 @@

<div id="nav" class="menu">
<div style="display: flex; width: 100%; justify-content: space-between;">
<h1 class="logo">compil{<span class="logo_snip">LPD</span>}ador</h1>
<h1 class="logo">compi{<span class="logo_snip">LPD</span>}lador</h1>

<div onclick="openNav()" class="menu_btn" id="menu_icon">
<span class="material-icons"> menu </span>
Expand Down
57 changes: 43 additions & 14 deletions compilador/js/lexico.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function tokenizar(data) {
/**
* Identifica tokens.
* @param {string} data Código em LPD a ser identificado.
* @returns {lexema:string,simbolo:string} uma lista de tokens identificados em data
* @returns {list({lexema:string,simbolo:string})} uma lista de tokens identificados em data
* @throws {Error} Caso encontre um caractere estranho indicando a linha e coluna do erro
*/

Expand All @@ -16,6 +16,7 @@ function tokenizar(data) {
let listaTokens = [];
let linha = 1;
let coluna = 1;
let ultimoComentario = { linha: 0, coluna: 0 }; // Armazena a linha e coluna do último comentário aberto
for (let i = 0; i < data.length; i++) {
let caracter = data[i];
coluna++;
Expand All @@ -34,6 +35,7 @@ function tokenizar(data) {
// Se o caracter atual for o início do comentário, incrementa o bloco de comentário
if (caracter == "{") {
isComment++;
ultimoComentario = { linha, coluna };
continue;
} else if (caracter == "}") {
// Se o caracter atual for o final do comentário, decrementa o bloco de comentário
Expand Down Expand Up @@ -146,20 +148,47 @@ function tokenizar(data) {
) {
let token;
if (caracter == "!") {
token = {
lexema: "!",
simbolo: "Snao",
};
// Se o caracter seguinte for "=", trata como operador relacional
if (data[i + 1] == "=") {
token = {
lexema: "!=",
simbolo: "Sdiferente",
};
i++;
} else {
token = {
lexema: "!",
simbolo: "Snao",
};
}
} else if (caracter == "<") {
token = {
lexema: "<",
simbolo: "Smenor",
};
// Se o caracter seguinte for "=", trata como operador relacional
if (data[i + 1] == "=") {
token = {
lexema: "<=",
simbolo: "Smenorig",
};
i++;
} else {
token = {
lexema: "<",
simbolo: "Smenor",
};
}
} else if (caracter == ">") {
token = {
lexema: ">",
simbolo: "Smaior",
};
// Se o caracter seguinte for "=", trata como operador relacional
if (data[i + 1] == "=") {
token = {
lexema: ">=",
simbolo: "Smaiorig",
};
i++;
} else {
token = {
lexema: ">",
simbolo: "Smaior",
};
}
} else if (caracter == "=") {
token = {
lexema: "=",
Expand Down Expand Up @@ -218,7 +247,7 @@ function tokenizar(data) {
// Se o bloco de comentário não estiver fechado, lança um erro
if (isComment > 0) {
throw new Error(
`Erro léxico: comentário não fechado - linha ${linha} e coluna ${coluna}`
`Erro léxico: comentário não fechado - linha ${ultimoComentario.linha} e coluna ${ultimoComentario.coluna}`
);
}

Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>compil{LPD}ador</title>
<title>compi{LPD}lador</title>
<link rel="stylesheet" href="styles/dracula-theme.css" />

<link rel="stylesheet" href="styles/main.css" />
Expand All @@ -25,7 +25,7 @@

<header id="nav" class="menu">

<h1 class="logo">compil{<span class="logo_snip">LPD</span>}ador</h1>
<h1 class="logo">compi{<span class="logo_snip">LPD</span>}lador</h1>


<div id="button-container">
Expand Down