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

Merge remote-tracking branch 'origin/main'

# Conflicts:
#	.idea/.gitignore
#	.idea/modules.xml
parents f5f94809 45b4410a
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
package ts;
import lParser.node.AType;
import lParser.node.ATypeType;
import sa.*;
import util.Error;
......@@ -13,7 +15,9 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
private Ts tableLocaleCourante;
private Context context;
public Ts getTableGlobale(){return this.tableGlobale;}
public Ts getTableGlobale() {
return this.tableGlobale;
}
public Sa2ts() {
tableGlobale = new Ts();
......@@ -21,6 +25,110 @@ 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());
} else {
tableLocaleCourante.addVar(node.getNom(),node.getType());
}
}
} else {
System.err.println("La variable/ le paramètre" + node.getNom() + "existe déjà !");
}
return null;
}
public Void visit(SaDecTab node) {
defaultIn(node);
if (tableGlobale.getVar(node.getNom()) != null)
node.setTsItem(this.tableGlobale.addTab(node.getNom(),node.getType(),node.getTaille()));
else
throw new RuntimeException("Erreur");
defaultOut(node);
return null;
}
public Void visit(SaDecFonc node) throws Exception {
defaultIn(node);
tableLocaleCourante = new Ts();
int nbArgs = 0;
this.context = Context.GLOBAL;
if(tableGlobale.getFct(node.getNom()) == null){
tableLocaleCourante.addFct(node.getNom(),node.getTypeRetour(),nbArgs,tableLocaleCourante, node);
}
else{
nbArgs = node.getParametres().length();
tableLocaleCourante.addFct(node.getNom(),node.getTypeRetour(),nbArgs,tableLocaleCourante, node);
}
this.context = Context.PARAM;
if(node.getParametres() == null){
node.getParametres().accept(this);
}
this.context = Context.LOCAL;
if(node.getVariable() == null){
node.getParametres().accept(this);
}
if(node.getCorps() == null){
node.getCorps().accept(this);
}
defaultOut(node);
return null;
}
public Void visit(SaDecVarSimple node) {
boolean isGlobal = false;
if (tableLocaleCourante.getVar(node.getNom()) != null) {
if (tableGlobale.getVar(node.getNom()) != null) {
throw new RuntimeException("Erreur");
} else {
isGlobal = true;
}
}
TsItemVar tsItemVar;
if(isGlobal){
tsItemVar = tableGlobale.getVar(node.getNom());
}else{
tsItemVar = tableLocaleCourante.getVar(node.getNom());
}
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;
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;
return null;
}
public void defaultIn(SaNode node)
{
// System.out.println("<" + node.getClass().getSimpleName() + ">");
......@@ -31,5 +139,4 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
// System.out.println("</" + node.getClass().getSimpleName() + ">");
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment