-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…closes #722) * possibilitando expressão em tamanho de vetor/matriz * utilizando expressões em declaracões de tamanho de vetor/matriz * Detalhando mensagem de erro * novos casos de teste
- Loading branch information
Showing
12 changed files
with
638 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
409 changes: 409 additions & 0 deletions
409
.../br/univali/portugol/nucleo/analise/semantica/AnalisadorDeclaracaoTamanhoVetorMatriz.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...a/br/univali/portugol/nucleo/analise/semantica/erros/ErroExpressaoTamanhoVetorMatriz.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package br.univali.portugol.nucleo.analise.semantica.erros; | ||
|
||
import br.univali.portugol.nucleo.asa.NoBloco; | ||
import br.univali.portugol.nucleo.asa.NoDeclaracaoBase; | ||
import br.univali.portugol.nucleo.asa.NoDeclaracaoMatriz; | ||
import br.univali.portugol.nucleo.asa.NoDeclaracaoVetor; | ||
import br.univali.portugol.nucleo.asa.NoExpressao; | ||
import br.univali.portugol.nucleo.mensagens.ErroSemantico; | ||
|
||
/** | ||
* | ||
* @author fillipi | ||
*/ | ||
public class ErroExpressaoTamanhoVetorMatriz extends ErroSemantico | ||
{ | ||
private NoDeclaracaoBase declaracao; | ||
private NoBloco tamanho; | ||
private String valorErrado; | ||
private String codigo = "ErroSemantico.ErroTamanhoVetorMatriz."; | ||
|
||
public ErroExpressaoTamanhoVetorMatriz(NoDeclaracaoBase declaracao, NoBloco tamanho, String valorErrado) | ||
{ | ||
super(tamanho.getTrechoCodigoFonte(),"ErroSemantico.ErroTamanhoVetorMatriz"); | ||
this.declaracao = declaracao; | ||
this.tamanho = tamanho; | ||
this.valorErrado = valorErrado; | ||
} | ||
|
||
public ErroExpressaoTamanhoVetorMatriz(NoDeclaracaoBase declaracao, NoBloco tamanho) | ||
{ | ||
super(tamanho.getTrechoCodigoFonte(),"ErroSemantico.ErroTamanhoVetorMatriz"); | ||
this.declaracao = declaracao; | ||
this.tamanho = tamanho; | ||
} | ||
|
||
@Override | ||
protected String construirMensagem() | ||
{ | ||
if(this.valorErrado == null || this.valorErrado.equals("")) | ||
{ | ||
if (declaracao instanceof NoDeclaracaoVetor) | ||
{ | ||
codigo += "1"; | ||
super.setCodigo(codigo); | ||
|
||
return String.format("O tamanho do vetor '%s' deve ser um valor ou uma constante do tipo inteiro e positivo \n Ex: vetor[3]", declaracao.getNome()); | ||
} | ||
else | ||
{ | ||
String aux = (tamanho == ((NoDeclaracaoMatriz) declaracao).getNumeroLinhas())? "linhas" : "colunas"; | ||
codigo += "2"; | ||
super.setCodigo(codigo); | ||
|
||
return String.format("O número de %s da matriz '%s' deve ser um valor ou uma constante do tipo inteiro e positivo \n Ex: matriz[5][4]", aux, declaracao.getNome()); | ||
} | ||
} | ||
else | ||
{ | ||
if (declaracao instanceof NoDeclaracaoVetor) | ||
{ | ||
codigo += "1"; | ||
super.setCodigo(codigo); | ||
|
||
return String.format("A variavel '%s' do tamanho do vetor '%s' deve ser uma variavel ou valor constante do tipo inteiro e positivo \n Ex: \n const inteiro x = 3 \n vetor[x]",this.valorErrado, declaracao.getNome()); | ||
} | ||
else | ||
{ | ||
String aux = (tamanho == ((NoDeclaracaoMatriz) declaracao).getNumeroLinhas())? "linhas" : "colunas"; | ||
codigo += "2"; | ||
super.setCodigo(codigo); | ||
|
||
return String.format("A variavel '%s' no número de %s da matriz '%s' deve ser um valor ou uma constante do tipo inteiro e positivo \n Ex: \n const inteiro x = 3 \n matriz[x][5]",this.valorErrado, aux, declaracao.getNome()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.