Skip to content
Snippets Groups Projects
Commit c636511c authored by ZaynouneFatimaZahrae's avatar ZaynouneFatimaZahrae
Browse files

sa2ts

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