Skip to content
Snippets Groups Projects
Commit 68ab49e9 authored by BAUQUIN Niels's avatar BAUQUIN Niels
Browse files

dfg

parent 086b4789
No related branches found
No related tags found
No related merge requests found
......@@ -25,40 +25,42 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override
public Void visit(SaDecTab node) throws Exception {
String nomTableau = node.getNom();
Type typeTableau = node.getType();
int tailleTableau = node.getTaille();
String idTab = node.getNom();
Type typeTab = node.getType();
int tailleTab = node.getTaille();
System.out.println(node);
if (context == Context.GLOBAL) {
if (tableGlobale.getVar(nomTableau) != null) {
throw new ErrorException(Error.TS, "Le tableau " + nomTableau + " est déjà défini.");
if (tableGlobale.getVar(idTab) != null) {
throw new ErrorException(Error.TS, "Le tableau " + idTab + " est déjà défini.");
}
tableGlobale.addTab(nomTableau, typeTableau, tailleTableau);
node.tsItem = tableGlobale.addTab(idTab, typeTab, tailleTab);
}
return null;
}
@Override
public Void visit(SaDecFonc node) throws Exception {
String nomFonction = node.getNom();
String idFct = node.getNom();
SaLDecVar parameters = node.getParametres();
SaLDecVar variable = node.getVariable();
SaInst corps = node.getCorps();
if (tableGlobale.getFct(nomFonction) != null) {
throw new ErrorException(Error.TS, "La fonction " + nomFonction + " est déjà définie.");
if (tableGlobale.getFct(idFct) != null) {
throw new ErrorException(Error.TS, "La fonction " + idFct + " est déjà définie.");
}
Ts table = new Ts();
tableLocaleCourante = table;
int param = 0;
int nbArgs = 0;
if (parameters != null) {
context = Context.PARAM;
parameters.accept(this);
param = parameters.length();
nbArgs = parameters.length();
}
if (variable != null) {
context = Context.LOCAL;
variable.accept(this);
}
node.tsItem = tableGlobale.addFct(nomFonction, node.getTypeRetour(), param, table, node);
node.tsItem = tableGlobale.addFct(idFct, node.getTypeRetour(), nbArgs, table, node);
if (corps != null) {
context = Context.LOCAL;
corps.accept(this);
......@@ -69,70 +71,70 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override
public Void visit(SaDecVar node) throws Exception {
String nomVar = node.getNom();
String idVar = node.getNom();
Type typeVar = node.getType();
if (context == Context.LOCAL) {
if (tableLocaleCourante.getVar(nomVar) != null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie.");
if (tableLocaleCourante.getVar(idVar) != null) {
throw new ErrorException(Error.TS, "La variable " + idVar + " est déjà définie dans la fonction.");
}
node.setTsItem(tableLocaleCourante.addVar(nomVar, typeVar));
node.setTsItem(tableLocaleCourante.addVar(idVar, typeVar));
} else if (context == Context.PARAM) {
if (tableLocaleCourante.getVar(nomVar) != null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie.");
if (tableLocaleCourante.getVar(idVar) != null) {
throw new ErrorException(Error.TS, "La variable " + idVar + " est déjà définie dans les parametres.");
}
node.setTsItem(tableLocaleCourante.addParam(nomVar, typeVar));
node.setTsItem(tableLocaleCourante.addParam(idVar, typeVar));
} else if (context == Context.GLOBAL) {
if (tableGlobale.getVar(nomVar) != null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie.");
if (tableGlobale.getVar(idVar) != null) {
throw new ErrorException(Error.TS, "La variable " + idVar + " est déjà définie dans la table globale.");
}
node.setTsItem(tableGlobale.addVar(nomVar, typeVar));
node.setTsItem(tableGlobale.addVar(idVar, typeVar));
}
return null;
}
@Override
public Void visit(SaVarSimple node) throws Exception {
String nomVar = node.getNom();
String idVar = node.getNom();
TsItemVarSimple varSimple = node.getTsItem();
if (context == Context.LOCAL) {
if (tableLocaleCourante.getVar(nomVar) == null && tableGlobale.getVar(nomVar) == null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie.");
if (tableLocaleCourante.getVar(idVar) == null && tableGlobale.getVar(idVar) == null) {
throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie.");
}
if (tableLocaleCourante.getVar(nomVar) != null) {
node.tsItem = (TsItemVarSimple) tableLocaleCourante.getVar(nomVar);
if (tableLocaleCourante.getVar(idVar) != null) {
node.tsItem = (TsItemVarSimple) tableLocaleCourante.getVar(idVar);
} else {
node.tsItem = (TsItemVarSimple) tableGlobale.getVar(nomVar);
node.tsItem = (TsItemVarSimple) tableGlobale.getVar(idVar);
}
} else if (context == Context.PARAM) {
if (tableLocaleCourante.getVar(nomVar) == null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie.");
if (tableLocaleCourante.getVar(idVar) == null) {
throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie.");
}
} else if (context == Context.GLOBAL) {
if (tableGlobale.getVar(nomVar) == null || varSimple.getTaille() > 1) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie.");
if (tableGlobale.getVar(idVar) == null || varSimple.getTaille() > 1) {
throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie.");
}
node.tsItem = (TsItemVarSimple) tableGlobale.getVar(nomVar);
node.tsItem = (TsItemVarSimple) tableGlobale.getVar(idVar);
}
return null;
}
@Override
public Void visit(SaAppel node) throws Exception {
String nomFonction = node.getNom();
String idFct = node.getNom();
SaLExp arguments = node.getArguments();
int args = 0;
int nbArgs = 0;
if (arguments != null) {
arguments.accept(this);
args = arguments.length();
nbArgs = arguments.length();
}
if (tableGlobale.getFct(nomFonction) == null) {
throw new ErrorException(Error.TS, "La fonction " + nomFonction + " n'est pas définie.");
if (tableGlobale.getFct(idFct) == null) {
throw new ErrorException(Error.TS, "La fonction " + idFct + " n'est pas définie.");
}
if (this.tableGlobale.getFct(nomFonction).getNbArgs() != args) {
if (this.tableGlobale.getFct(idFct).getNbArgs() != nbArgs) {
throw new ErrorException(Error.TS, "Le nombre d'arguments est incorrect."
+ this.tableGlobale.getFct(nomFonction).getNbArgs() + " requis.");
+ this.tableGlobale.getFct(idFct).getNbArgs() + " requis.");
}
node.tsItem = tableGlobale.getFct(node.getNom());
......@@ -141,10 +143,10 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override
public Void visit(SaVarIndicee node) throws Exception {
String nomVar = node.getNom();
String idVar = node.getNom();
SaExp indice = node.getIndice();
if (tableGlobale.getVar(nomVar) == null && tableGlobale.getVar(nomVar).getTaille() == 1)
throw new ErrorException(Error.TS, "indice " + nomVar + " incorrect.");
if (tableGlobale.getVar(idVar) == null && tableGlobale.getVar(idVar).getTaille() == 1)
throw new ErrorException(Error.TS, "indice " + idVar + " incorrect.");
node.tsItem = tableGlobale.getVar(node.getNom());
indice.accept(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment