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

testing again

parent 959ed44c
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
<component name="libraryTable">
<library name="sablecc">
<CLASSES>
<root url="jar://$PROJECT_DIR$/sablecc/sablecc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/2024-compilation-bazizii.iml" filepath="$PROJECT_DIR$/2024-compilation-bazizii.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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; package ts;
import lParser.node.AType;
import lParser.node.ATypeType;
import sa.*; import sa.*;
import util.Error; import util.Error;
...@@ -13,7 +15,9 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -13,7 +15,9 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
private Ts tableLocaleCourante; private Ts tableLocaleCourante;
private Context context; private Context context;
public Ts getTableGlobale(){return this.tableGlobale;} public Ts getTableGlobale() {
return this.tableGlobale;
}
public Sa2ts() { public Sa2ts() {
tableGlobale = new Ts(); tableGlobale = new Ts();
...@@ -21,6 +25,110 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -21,6 +25,110 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
context = Context.GLOBAL; 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) public void defaultIn(SaNode node)
{ {
// System.out.println("<" + node.getClass().getSimpleName() + ">"); // System.out.println("<" + node.getClass().getSimpleName() + ">");
...@@ -31,5 +139,4 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -31,5 +139,4 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
// System.out.println("</" + node.getClass().getSimpleName() + ">"); // 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