Skip to content
Snippets Groups Projects
Commit 0ce89edf authored by BAZIZI Zakaria's avatar BAZIZI Zakaria
Browse files

Merge remote-tracking branch 'origin/main'

parents b3f8fe45 c636511c
No related branches found
No related tags found
No related merge requests found
package ts; package ts;
import lParser.node.AType;
import lParser.node.ATypeType;
import sa.*; import sa.*;
import util.Error; import util.Error;
...@@ -11,7 +9,7 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -11,7 +9,7 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
PARAM PARAM
} }
private Ts tableGlobale; private final Ts tableGlobale;
private Ts tableLocaleCourante; private Ts tableLocaleCourante;
private Context context; private Context context;
...@@ -25,20 +23,29 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -25,20 +23,29 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
context = Context.GLOBAL; context = Context.GLOBAL;
} }
public Void visit(SaDecVar node) { public Void visit(SaDecVar node) throws Exception{
if (tableLocaleCourante.getVar(node.getNom()) == null) { defaultIn(node);
if (node.getTsItem() == null) { TsItemVar ts = null;
tableLocaleCourante.addVar(node.getNom(),node.getType()); try {
} else { if (context == Context.PARAM) {
if (node.getTsItem().isParam) { ts = tableLocaleCourante.addParam(node.getNom(), node.getType());
tableLocaleCourante.addParam(node.getNom(),node.getType()); } else if (context == Context.LOCAL) {
if (tableLocaleCourante.getVar(node.getNom()) != null)
throw new ErrorException(Error.TS, "Variable locale");
ts = tableLocaleCourante.addVar(node.getNom(), node.getType());
} else { } else {
tableLocaleCourante.addVar(node.getNom(),node.getType()); if (tableGlobale.getVar(node.getNom()) != null)
throw new ErrorException(Error.TS, "Variable globale");
ts = tableLocaleCourante.addVar(node.getNom(),node.getType());
} }
}catch(ErrorException e){
System.err.print("Erreur dans la declaration de variable");
System.err.println(e.getMessage());
System.exit(e.getCode());
} }
} else { node.setTsItem(ts);
System.err.println("La variable/ le paramètre" + node.getNom() + "existe déjà !"); defaultOut(node);
} System.out.println(tableGlobale.variables);
return null; return null;
} }
...@@ -100,32 +107,39 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -100,32 +107,39 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
node.tsItem = tsItemVar; node.tsItem = tsItemVar;
return null; return null;
} }
public Void visit(SaVarIndicee node){ public Void visit(SaVarIndicee node) throws Exception {
TsItemVar var = tableGlobale.getVar(node.getNom()); defaultIn(node);
if(var == null) if(tableGlobale.getVar(node.getNom()) != null){
System.err.println("Introuvable"); node.tsItem = tableGlobale.getVar(node.getNom());
else node.getIndice().accept(this);
node.tsItem = var; }
else if(tableLocaleCourante.getVar(node.getNom()) != null){
node.tsItem = tableLocaleCourante.getVar(node.getNom());
node.getIndice().accept(this);
}
else{
throw new ErrorException(Error.TS,"");
}
defaultOut(node);
return null; return null;
} }
public Void visit(SaAppel node){ public Void visit(SaAppel node) throws Exception {
String nom = node.getNom(); defaultIn(node);
int nbArgs; if(node.getArguments().length() == tableGlobale.getFct(node.getNom()).getNbArgs()){
if(node.getArguments() == null) node.getArguments().accept(this);
nbArgs = 0; node.tsItem = tableGlobale.getFct(node.getNom());
else }
nbArgs = node.getArguments().length(); else if(node.getArguments() == null && tableGlobale.getFct(node.getNom()).getNbArgs() == 0) {
TsItemFct tsItemFct = tableGlobale.getFct(nom); node.tsItem = tableGlobale.getFct(node.getNom());
}
if(tableGlobale.getFct(nom) == null) else {
throw new RuntimeException(("Erreur")); throw new ErrorException(Error.TS,"");
}
if(nbArgs != tsItemFct.nbArgs) context = Context.LOCAL;
throw new RuntimeException("Erreur"); node.tsItem = tableGlobale.getFct(node.getNom());
node.tsItem = tsItemFct; context = Context.GLOBAL;
defaultOut(node);
return null; return null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment