diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/libraries/sablecc.xml b/.idea/libraries/sablecc.xml new file mode 100644 index 0000000000000000000000000000000000000000..74b628481c6e9b5845788e82f71de945e301a370 --- /dev/null +++ b/.idea/libraries/sablecc.xml @@ -0,0 +1,9 @@ +<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 diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..858f920818c7123a61aeef7250aa1c106689e0de --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" project-jdk-name="azul-22" project-jdk-type="Android SDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..5ebed7af629916bd8feccd53c97273b2e6a85427 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/2024-compilation-seck-wendy01.iml" filepath="$PROJECT_DIR$/2024-compilation-seck-wendy01.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?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 diff --git a/2024-compilation-seck-wendy01.iml b/2024-compilation-seck-wendy01.iml new file mode 100644 index 0000000000000000000000000000000000000000..c90834f2d607afe55e6104d8aa2cdfffb713f688 --- /dev/null +++ b/2024-compilation-seck-wendy01.iml @@ -0,0 +1,11 @@ +<?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 diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 871caa1526ad40a35eb85fb1032681e585fa4fba..0000000000000000000000000000000000000000 --- a/src/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*\.class -*/*\.class -*/*/*\.class -*~ \ No newline at end of file diff --git a/src/C3aVM.java b/src/C3aVM.java index a8bb3410c1eda526ffc8aae1f831508bfb67fcca..9ae9e2acadcb70b7b978c450b442757cff7d31cb 100644 --- a/src/C3aVM.java +++ b/src/C3aVM.java @@ -1,38 +1,35 @@ import java.io.IOException; import c3a.C3a; +import c3a.C3aParser; import c3a.C3aEval; -import c3a.LoadC3a; import ts.Ts; import ts.TsParser; public class C3aVM { private int verboseLevel = 0; private TsParser stParser; + private C3aParser c3aParser; private String symbolsTableFileName; private String C3AFileName; private int stackSize; - private C3a code; - private Ts globalTable; - private LoadC3a loadC3a; public C3aVM(String symbolsTableFileName, String C3AFileName, int stackSize, int verboseLevel){ this.stackSize = stackSize; this.verboseLevel = verboseLevel; this.symbolsTableFileName = symbolsTableFileName; this.C3AFileName = C3AFileName; - stParser = new TsParser(); - this.globalTable = stParser.parse(symbolsTableFileName); - loadC3a = new LoadC3a(C3AFileName, this.globalTable); - this.code = loadC3a.getC3a(); } public void run() throws IOException { + stParser = new TsParser(); + Ts symbolTable = stParser.parse(symbolsTableFileName); + c3aParser = new C3aParser(); + C3a code = c3aParser.parse(C3AFileName, symbolTable); if(verboseLevel > 0) code.affiche(null); - C3aEval c3aEval = new C3aEval(code, globalTable, stackSize, verboseLevel); - code.accept(c3aEval); - c3aEval.affiche(null); + C3aEval eval = new C3aEval(code, symbolTable, stackSize, verboseLevel); + eval.affiche(null); // eval.affiche(C3AFileName.substring(0, C3AFileName.length() - 4)); } diff --git a/src/Compiler.java b/src/Compiler.java index 415870c9f17eb4b7a0530a3e6f18a8a2f8dd750b..6cdcaafc3bc70f4447b86e3cf3159b1eb3ef501e 100644 --- a/src/Compiler.java +++ b/src/Compiler.java @@ -1,218 +1,150 @@ -import lParser.parser.*; -import lParser.lexer.*; -import lParser.node.*; +import c3a.C3a; +import c3a.Sa2c3a; +import nasm.C3a2nasm; +import nasm.Nasm; +import sa.Sa2Xml; +import sa.SaNode; +import sc.analysis.Sc2sa; +import sc.parser.*; +import sc.lexer.*; +import sc.node.*; +import ts.Sa2ts; +import ts.Ts; + import java.io.*; -import sc.*; import sa.*; import ts.*; import c3a.*; import nasm.*; import fg.*; import ig.*; -import util.Error; public class Compiler { - private static String baseName = null; - private static String inputFileName = null; - private static int verboseLevel = 0; - private static Start scRoot = null; - private static SaProg saRoot = null; - private static Ts tableGlobale = null; - private static C3a c3a = null; - private static Nasm nasm = null; - private static Fg flowGraph = null; - private static FgSolution flowGraphSolution = null; - private static Ig interferenceGraph = null; - - - public static void main(String[] args) { - processCommandLine(args); - System.out.println("[BUILD SC] "); - buildSc(); - /* System.out.println("[BUILD SA] "); - buildSa(); - System.out.println("[BUILD TS] "); - buildTs(); - System.out.println("[TYPE CHECKING]"); - typeCheck(); - System.out.println("[BUILD C3A] "); - buildC3a(); - System.out.println("[BUILD PRE NASM] "); - buildPreNasm(); - System.out.println("[BUILD FLOW GRAPH] "); - buildFg(); - System.out.println("[SOLVE FLOW GRAPH]"); - solveFg(); - System.out.println("[BUILD INTERFERENCE GRAPH] "); - buildIg(); - System.out.println("[ALLOCATE REGISTERS]"); - interferenceGraph.allocateRegisters(); - System.out.println("[PRINT NASM]"); - nasm.afficheNasm(baseName); - System.exit(Error.NOERROR.code());*/ - } - - private static void processCommandLine(String[] args) { - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-v")) { - verboseLevel = Integer.parseInt(args[++i]); - } else { - inputFileName = args[i]; - baseName = removeSuffix(inputFileName, ".l"); - } - } - if (inputFileName == null) { - System.out.println("java Compiler input_file -v verbose_level"); - System.exit(1); - } - } - - private static void buildSc() { - PushbackReader fileReader = null; - Parser parser = null; - try { - fileReader = new PushbackReader(new FileReader(inputFileName)); - } catch (IOException e) { - System.err.println("cannot open input file"); - e.printStackTrace(); - } - try { - parser = new Parser(new Lexer(fileReader)); - scRoot = parser.parse(); - } catch (ParserException e) { - System.err.println("syntax error"); - e.printStackTrace(); - System.exit(Error.SYNT.code()); - } catch (LexerException e) { - System.err.println("lexical error"); - e.printStackTrace(); - System.exit(Error.LEX.code()); - } catch (IOException e) { - e.printStackTrace(); - } - if (verboseLevel > 1) { - System.out.println("[PRINT SC]"); - scRoot.apply(new Sc2Xml(baseName)); - } - } - - private static void buildSa() { - try { - Sc2sa sc2sa = new Sc2sa(); - scRoot.apply(sc2sa); - saRoot = sc2sa.getRoot(); - } catch (Exception ignored) { - System.out.println("exception construction arbre abstrait"); - ignored.printStackTrace(); - } - PrintStream out = System.out; - if (verboseLevel > 1) { - System.out.println("[PRINT SA]"); - try { - out = new PrintStream(baseName + ".sa"); - } - catch (IOException e) { - System.err.println("Error: " + e.getMessage()); - } - out.println(saRoot); - //new Sa2Xml(saRoot, baseName); - } - } - - private static void buildTs() { - try { - Sa2ts sa2ts = new Sa2ts(); - saRoot.accept(sa2ts); - tableGlobale = sa2ts.getTableGlobale(); - SaCheckLinkage saCheckLinkage = new SaCheckLinkage(); - saCheckLinkage.visit(saRoot); - if (tableGlobale.getFct("main") == null) - throw new ErrorException(Error.TS, "la fonction main n'est pas définie"); - } catch (ErrorException e) { - System.err.print("ERREUR TABLE DES SYMBOLES : "); - System.err.println(e.getMessage()); - System.exit(e.getCode()); - } catch (Exception e) { - e.printStackTrace(); - } - if (verboseLevel > 1) { - System.out.println("[PRINT TS]"); - tableGlobale.afficheTout(baseName); - } - } - - private static void typeCheck() { - new SaTypeCheck(saRoot); - } - - private static void buildC3a() { - try{ - Sa2c3a sa2c3a = new Sa2c3a(saRoot, tableGlobale); - saRoot.accept(sa2c3a); - c3a = sa2c3a.getC3a(); - } - catch(Exception e){} - - if (verboseLevel > 1) { - System.out.println("[PRINT C3A] "); - c3a.affiche(baseName); - } + public static void main(String[] args) + { + PushbackReader br = null; + String baseName = null; + String inputFileName = null; + int verboseLevel = 0; + + for (int i = 0; i < args.length; i++) { + if(args[i].equals("-v")){ + verboseLevel = Integer.parseInt(args[++i]); + } + else{ + inputFileName = args[i]; + } } - - private static void buildPreNasm() { - C3a2nasm c3a2nasm = new C3a2nasm(c3a, tableGlobale); - c3a.accept(c3a2nasm); - nasm = c3a2nasm.getNasm(); - if (verboseLevel > 1) { - System.out.println("[PRINT PRE NASM] "); - nasm.affichePreNasm(baseName); - } + + if(inputFileName == null){ + System.out.println("java Compiler input_file -v verbose_level"); + System.exit(1); } - - - private static void buildFg() { - flowGraph = new Fg(nasm); - if (verboseLevel > 1) { - System.out.println("[PRINT FLOW GRAPH] "); - flowGraph.affiche(baseName); - } + + try { + br = new PushbackReader(new FileReader(inputFileName)); + baseName = removeSuffix(inputFileName, ".l"); } + catch (IOException e) { + e.printStackTrace(); + } + try { + Parser p = new Parser(new Lexer(br)); + System.out.println("[BUILD SC] "); + Start tree = p.parse(); + + if(verboseLevel > 1){ + System.out.println("[PRINT SC]"); + tree.apply(new Sc2Xml(baseName)); + } + + + + System.out.println("[BUILD SA] "); + Sc2sa sc2sa = new Sc2sa(); + tree.apply(sc2sa); + SaNode saRoot = sc2sa.getReturnValue(); + + if(verboseLevel > 1){ + System.out.println("[PRINT SA]"); + new Sa2Xml(saRoot, baseName); + } + + System.out.println("[BUILD TS] "); + Ts tableGlobale = new Sa2ts(saRoot).getTableGlobale(); + + if(verboseLevel > 1){ + System.out.println("[PRINT TS]"); + tableGlobale.afficheTout(baseName); + } + + + System.out.println("[BUILD C3A] "); + C3a c3a = new Sa2c3a(saRoot, tableGlobale).getC3a(); + + if(verboseLevel > 1){ + System.out.println("[PRINT C3A] "); + c3a.affiche(baseName); + } + + + System.out.println("[BUILD PRE NASM] "); + Nasm nasm = new C3a2nasm(c3a, tableGlobale).getNasm(); + if(verboseLevel > 1){ + System.out.println("[PRINT PRE NASM] "); + nasm.affichePreNasm(baseName); + } + + + System.out.println("[BUILD FG] "); + Fg fg = new Fg(nasm); + + if(verboseLevel > 1){ + System.out.println("[PRINT FG] "); + fg.affiche(baseName); + } + + System.out.println("[SOLVE FG]"); + FgSolution fgSolution = new FgSolution(nasm, fg); + if(verboseLevel > 1){ + System.out.println("[PRINT FG SOLUTION] "); + fgSolution.affiche(baseName); + } + + + + System.out.println("[BUILD IG] "); + Ig ig = new Ig(fgSolution); + + if(verboseLevel > 1){ + System.out.println("[PRINT IG] "); + ig.affiche(baseName); + } + + System.out.println("[ALLOCATE REGISTERS]"); + ig.allocateRegisters(); + + System.out.println("[PRINT NASM]"); + nasm.afficheNasm(baseName); - private static void solveFg() { - flowGraphSolution = new FgSolution(nasm, flowGraph); - if (verboseLevel > 1) { - System.out.println("[PRINT FLOW GRAPH SOLUTION] "); - flowGraphSolution.affiche(baseName); - } - } - private static void buildIg() { - interferenceGraph = new Ig(flowGraphSolution); - if (verboseLevel > 1) { - System.out.println("[PRINT INTERFERENCE GRAPH] "); - interferenceGraph.affiche(baseName); - } } - - - - /*catch (Exception e) - { - e.printStackTrace(); - System.out.println(e.getMessage()); - System.exit(1); + catch(Exception e){ + e.printStackTrace(); + System.out.println(e.getMessage()); + System.exit(1); } - }*/ + } public static String removeSuffix(final String s, final String suffix) { - if (s != null && suffix != null && s.endsWith(suffix)){ - return s.substring(0, s.length() - suffix.length()); - } - return s; + if (s != null && suffix != null && s.endsWith(suffix)){ + return s.substring(0, s.length() - suffix.length()); + } + return s; } - + } diff --git a/src/Makefile b/src/Makefile index b64a54cfb52d4ed71cb744d8ded611b48cd6b86c..f9de22f751700530a3f847b11b49c3cf3063a6fb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,41 +1,31 @@ -all: Compiler C3aVM NasmVM SaVM +all: parser Compiler C3aVM NasmVM SaVM -SaVM: SaVM.java saParser - javac SaVM.java +SaVM: sa/*.java SaVM.java + javac sa/*.java + javac -cp ".:../xerces-2_12_1/*" SaVM.java NasmVM.jar : NasmVM jar cmf NasmVM.mf NasmVM.jar NasmVM.class nasm -C3aVM: C3aVM.java c3aParser - javac C3aVM.java - -NasmVM: NasmVM.java nasmParser +NasmVM: nasm/*.java NasmVM.java + javac nasm/*.java javac NasmVM.java +C3aVM: c3a/*.java C3aVM.java + javac c3a/*.java + javac C3aVM.java + Compiler.jar : Compiler - jar cmf Compiler.mf Compiler.jar *.class sc sa ts nasm util c3a fg ig lParser + jar cmf Compiler.mf Compiler.jar *.class sc sa ts nasm util c3a fg ig -Compiler: Compiler.java lParser +Compiler: Compiler.java javac Compiler.java -lParser: l.cfg - java -jar ../sablecc/sablecc.jar l.cfg - -saParser: sa.cfg - java -jar ../sablecc/sablecc.jar sa.cfg - -c3aParser: c3a.cfg - java -jar ../sablecc/sablecc.jar c3a.cfg - -nasmParser: nasm.cfg - java -jar ../sablecc/sablecc.jar nasm.cfg - -ualParser: ual.cfg - java -jar ../sablecc/sablecc.jar ual.cfg +parser: grammaireL.sablecc + java -jar ../sablecc/sablecc.jar grammaireL.sablecc clean: -rm *.class - -rm sc/*.class -rm sa/*.class -rm c3a/*.class -rm ts/*.class @@ -44,9 +34,5 @@ clean: -rm ig/*.class -rm util/intset/*.class -rm util/graph/*.class - -rm util/*.class - -rm -r lParser - -rm -r saParser - -rm -r c3aParser - -rm -r nasmParser +#java -cp ".:../xerces-2_12_1/*" SaVM -sa add1.sa diff --git a/src/NasmVM.java b/src/NasmVM.java index 28c41c611bdced47859ae5ccb6aee7a1630ff342..8f1f8aa7525fe3c0f20c5de2674051e70fd43e36 100644 --- a/src/NasmVM.java +++ b/src/NasmVM.java @@ -1,8 +1,8 @@ import ts.Ts; import ts.TsParser; +import nasm.NasmParser; import nasm.NasmEval; import nasm.Nasm; -import nasm.LoadNasm; import java.io.IOException; @@ -19,8 +19,8 @@ public class NasmVM { } public void run() throws IOException { - LoadNasm loadNasm = new LoadNasm(nasmFileName); - this.code = loadNasm.getNasm(); + var nasmParser = new NasmParser(); + code = nasmParser.parse(nasmFileName); if(verboseLevel > 0) code.afficheNasm(null); diff --git a/src/SaVM.java b/src/SaVM.java index 0588a6e4ac553f63b493023ac81fa096643e8dde..737940056e33c34f59164d540e70897162622fe1 100644 --- a/src/SaVM.java +++ b/src/SaVM.java @@ -1,41 +1,466 @@ +import org.apache.xerces.parsers.*; +import org.w3c.dom.*; import sa.*; import ts.*; + public class SaVM { + public static String getType(Node node){ + return ((Element)node).getAttribute("type"); + } + + public static String getNom(Node node){ + return ((Element)node).getAttribute("nom"); + } + + public static String getTaille(Node node){ + return ((Element)node).getAttribute("taille"); + } + + public static String getVal(Node node){ + return ((Element)node).getAttribute("val"); + } + + public static SaProg processSaProg(Node node){ + SaLDec variables = null; + SaLDec fonctions = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("variables")) + variables = processSaLDec(child); + else if(child.getNodeName().equals("fonctions")) + fonctions = processSaLDec(child); + } + return new SaProg(variables, fonctions); + } + + /* les listes */ + + public static SaLDec processSaLDec(Node node){ + SaDec tete = null; + SaLDec queue = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("tete")) + tete = processSaDec(child); + else if(child.getNodeName().equals("queue")) + queue = processSaLDec(child); + } + return new SaLDec(tete, queue); + } + + public static SaLExp processSaLExp(Node node){ + SaExp tete = null; + SaLExp queue = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("tete")) + tete = processSaExp(child); + else if(child.getNodeName().equals("queue")) + queue = processSaLExp(child); + } + return new SaLExp(tete, queue); + } + + public static SaLInst processSaLInst(Node node){ + SaInst tete = null; + SaLInst queue = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("tete")) + tete = processSaInst(child); + else if(child.getNodeName().equals("queue")) + queue = processSaLInst(child); + } + return new SaLInst(tete, queue); + } + + + /* declarations */ + + public static SaDec processSaDec(Node node){ + + String decType = getType(node); + if(decType.equals("SaDecFonc")) + return processSaDecFonc(node); + if(decType.equals("SaDecVar")) + return processSaDecVar(node); + if(decType.equals("SaDecTab")) + return processSaDecTab(node); + return null; + } + + public static SaDecVar processSaDecVar(Node node){ + return new SaDecVar(getNom(node)); + } + + public static SaDecTab processSaDecTab(Node node){ + return new SaDecTab(getNom(node),Integer.parseInt(getTaille(node))); + } + + public static SaDecFonc processSaDecFonc(Node node){ + String nom = getNom(node); + SaLDec parametres = null; + SaLDec variables = null; + SaInst corps = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("parametres")) + parametres = processSaLDec(child); + else if(child.getNodeName().equals("variables")) + variables = processSaLDec(child); + else if(child.getNodeName().equals("corps")) + corps = processSaInst(child); + } + return new SaDecFonc(nom, parametres, variables, corps); + } + + /* instructions */ + + + public static SaInst processSaInst(Node node){ + + String instType = getType(node); + if(instType.equals("SaInstAffect")) + return processSaInstAffect(node); + if(instType.equals("SaInstTantQue")) + return processSaInstTantQue(node); + if(instType.equals("SaInstBloc")) + return processSaInstBloc(node); + if(instType.equals("SaInstEcriture")) + return processSaInstEcriture(node); + if(instType.equals("SaInstRetour")) + return processSaInstRetour(node); + if(instType.equals("SaInstSi")) + return processSaInstSi(node); + if(instType.equals("SaAppel")) + return processSaAppel(node); + return null; + } + + public static SaInstAffect processSaInstAffect(Node node){ + SaVar lhs = null; + SaExp rhs = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("lhs")) + lhs = processSaVar(child); + else if(child.getNodeName().equals("rhs")) + rhs = processSaExp(child); + } + return new SaInstAffect(lhs, rhs); + } + + + public static SaInstTantQue processSaInstTantQue(Node node){ + SaExp test = null; + SaInst faire = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("test")) + test = processSaExp(child); + else if(child.getNodeName().equals("faire")) + faire = processSaInst(child); + } + return new SaInstTantQue(test, faire); + } + + public static SaInstBloc processSaInstBloc(Node node){ + SaLInst val = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("val")) + val = processSaLInst(child); + } + return new SaInstBloc(val); + } + + + public static SaInstEcriture processSaInstEcriture(Node node){ + SaExp arg = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("arg")) + arg = processSaExp(child); + } + return new SaInstEcriture(arg); + } + + public static SaInstRetour processSaInstRetour(Node node){ + SaExp val = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("val")) + val = processSaExp(child); + } + return new SaInstRetour(val); + } + + public static SaInstSi processSaInstSi(Node node){ + SaExp test = null; + SaInst alors = null; + SaInst sinon = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("test")) + test = processSaExp(child); + else if(child.getNodeName().equals("alors")) + alors = processSaInst(child); + else if(child.getNodeName().equals("sinon")) + sinon = processSaInst(child); + } + return new SaInstSi(test, alors, sinon); + } + + /* appel de fonction */ + + public static SaAppel processSaAppel(Node node){ + String nom = getNom(node); + SaLExp arguments = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("arguments")) + arguments = processSaLExp(child); + } + return new SaAppel(nom, arguments); + } + + /* expressions */ + + + public static SaExp processSaExp(Node node){ + + String expType = getType(node); + if(expType.equals("SaExpAdd")) + return processSaExpAdd(node); + if(expType.equals("SaExpSub")) + return processSaExpSub(node); + if(expType.equals("SaExpMult")) + return processSaExpMult(node); + if(expType.equals("SaExpDiv")) + return processSaExpDiv(node); + + if(expType.equals("SaExpAnd")) + return processSaExpAnd(node); + if(expType.equals("SaExpOr")) + return processSaExpOr(node); + if(expType.equals("SaExpNot")) + return processSaExpNot(node); + + + if(expType.equals("SaExpInf")) + return processSaExpInf(node); + if(expType.equals("SaExpEqual")) + return processSaExpEqual(node); + + if(expType.equals("SaExpVar")) + return processSaExpVar(node); + if(expType.equals("SaExpInt")) + return processSaExpInt(node); + if(expType.equals("SaExpLire")) + return processSaExpLire(node); + if(expType.equals("SaExpAppel")) + return processSaExpAppel(node); + + return null; + } + + + + public static SaExpInf processSaExpInf(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpInf(op1, op2); + } + + public static SaExpVar processSaExpVar(Node node){ + SaVar var = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("var")) + var = processSaVar(child); + } + return new SaExpVar(var); + } + + public static SaExpInt processSaExpInt(Node node){ + return new SaExpInt(Integer.parseInt(getVal(node))); + } + + public static SaExpAdd processSaExpAdd(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpAdd(op1, op2); + } + + + public static SaExpAnd processSaExpAnd(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpAnd(op1, op2); + } + + public static SaExpLire processSaExpLire(Node node){ + return new SaExpLire(); + } + + public static SaExpAppel processSaExpAppel(Node node){ + SaAppel val = null; + + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("val")) + val = processSaAppel(child); + } + return new SaExpAppel(val); + } + + public static SaExpNot processSaExpNot(Node node){ + SaExp op1 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + } + return new SaExpNot(op1); + } + + public static SaExpDiv processSaExpDiv(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpDiv(op1, op2); + } + + public static SaExpOr processSaExpOr(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpOr(op1, op2); + } + + public static SaExpMult processSaExpMult(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpMult(op1, op2); + } + + public static SaExpEqual processSaExpEqual(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpEqual(op1, op2); + } + + public static SaExpSub processSaExpSub(Node node){ + SaExp op1 = null; + SaExp op2 = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("op1")) + op1 = processSaExp(child); + else if(child.getNodeName().equals("op2")) + op2 = processSaExp(child); + } + return new SaExpSub(op1, op2); + } + + + /* acces aux variables */ + + public static SaVar processSaVar(Node node){ + String varType = getType(node); + if(varType.equals("SaVarIndicee")) + return processSaVarIndicee(node); + if(varType.equals("SaVarSimple")) + return processSaVarSimple(node); + return null; + } + + public static SaVarIndicee processSaVarIndicee(Node node){ + String nom = getNom(node); + SaExp indice = null; + for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()){ + if(child.getNodeName().equals("indice")) + indice = processSaExp(child); + } + return new SaVarIndicee(nom, indice); + } + + public static SaVarSimple processSaVarSimple(Node node){ + return new SaVarSimple(getNom(node)); + } + public static void main(String[] args) { + Document document = null; + DOMParser parser = null; int verboseLevel = 0; String saFileName = null; try { - for (int i = 0; i < args.length; i++) { - if(args[i].equals("-v")) - verboseLevel = Integer.parseInt(args[++i]); - else if(args[i].equals("-sa")) - saFileName = args[++i]; - } - if(saFileName == null){ - System.out.println("java SaVM -sa saFile -v verboseLevel"); - System.exit(1); - } - + for (int i = 0; i < args.length; i++) { + if(args[i].equals("-v")) + verboseLevel = Integer.parseInt(args[++i]); + else if(args[i].equals("-sa")) + saFileName = args[++i]; + } + if(saFileName == null){ + System.out.println("java -cp \".:../xerces-2_12_1/*\" saVM -sa saFile -v verboseLevel"); + System.exit(1); + } + + + parser = new DOMParser(); if(verboseLevel > 0) - System.err.println("parsing xml document"); + System.err.println("parsing xml document"); + parser.parse(saFileName); + document = parser.getDocument(); + Node rootNode=document.getDocumentElement(); if(verboseLevel > 0) - System.err.println("building sa tree"); + System.err.println("building sa tree"); - SaProg prog = new LoadSa(saFileName).getRoot(); + SaProg prog = processSaProg(rootNode); if(verboseLevel > 0) - System.out.println(prog); + new Sa2Xml(prog, null); if(verboseLevel > 0) - System.err.println("building symbol table"); - Sa2ts sa2ts = new Sa2ts(); - prog.accept(sa2ts); - Ts tableGlobale = sa2ts.getTableGlobale(); + System.err.println("building symbol table"); + Ts tableGlobale = new Sa2ts(prog).getTableGlobale(); if(verboseLevel > 0) - System.err.println("evaluating sa tree"); + System.err.println("evaluating sa tree"); SaEval saEval = new SaEval(prog, tableGlobale); saEval.affiche(null); diff --git a/src/sc/Sc2Xml.java b/src/Sc2Xml.java similarity index 90% rename from src/sc/Sc2Xml.java rename to src/Sc2Xml.java index a70781c44459ff2a62334043b223762448126d62..5e693910a76ee371a870fd066b216c1b53986444 100644 --- a/src/sc/Sc2Xml.java +++ b/src/Sc2Xml.java @@ -1,9 +1,8 @@ -package sc; import java.io.*; -import lParser.analysis.*; -import lParser.node.*; +import sc.analysis.*; +import sc.node.*; -public class Sc2Xml extends DepthFirstAdapter +class Sc2Xml extends DepthFirstAdapter { private int indentation; private String baseFileName; diff --git a/src/c3a.cfg b/src/c3a.cfg deleted file mode 100644 index 0737c8bfa0ab825607216415bdcd5941de62244f..0000000000000000000000000000000000000000 --- a/src/c3a.cfg +++ /dev/null @@ -1,113 +0,0 @@ -Package c3aParser; - -Helpers - -lettre = [['a' .. 'z'] + ['A' .. 'Z']]; -chiffre = ['0' .. '9']; -alpha = [lettre + ['_' + '$']]; -alphanum = [lettre + chiffre]; - -Tokens - -espaces = (' ' | 13 | 10 | 9)+; -commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); - - -co = '['; -cf = ']'; -call = 'call'; -stop = 'stop'; -fbegin = 'fbegin'; -fend = 'fend'; -aff = '='; -noteq = '!='; -inf = '<'; -infeq = '<='; -sup = '>'; -supeq = '>='; -eq = '=='; -goto = 'goto'; -param = 'param'; -ret = 'ret'; -if = 'if'; -moins = '-'; -plus = '+'; -fois = '*'; -divise = '/'; -write = 'write'; -read = 'read'; -nombre = chiffre+; -prefixe_temp = '@'; -identif = alpha alphanum*; - - -Ignored Tokens - -espaces, commentaire; - -Productions - -prog = listeinst; - -listeinst = {recursif} inst listeinst | - {final} inst - ; - -inst = {add} add | - {sub} sub | - {mul} mul | - {div} div | - {aff} affect | - {jmp} jmp | - {jmpeg} jmpeg | - {jmpneg} jmpneg | - {jmpinf} jmpinf | - {jminfeg} jmpinfeg | - {jmpsup} jmpsup | - {jmpsupeg} jmpsupeg | - {fcall} fcall | - {iwrite} iwrite | - {iread} iread | - {arg} arg | - {return} return | - {begin} begin | - {end} end | - {stop} istop - ; - -add = etiqop [result]:tv aff [op1]:ctv plus [op2]:ctv; -sub = etiqop [result]:tv aff [op1]:ctv moins [op2]:ctv; -mul = etiqop [result]:tv aff [op1]:ctv fois [op2]:ctv; -div = etiqop [result]:tv aff [op1]:ctv divise [op2]:ctv; -affect = etiqop [result]:tv aff [op1]:ctv; -jmpeg = etiqop if [op1]:ctv eq [op2]:ctv goto [result]:constante; -jmpneg = etiqop if [op1]:ctv noteq [op2]:ctv goto [result]:constante; -jmpinf = etiqop if [op1]:ctv inf [op2]:ctv goto [result]:constante; -jmpinfeg = etiqop if [op1]:ctv infeq [op2]:ctv goto [result]:constante; -jmpsup = etiqop if [op1]:ctv sup [op2]:ctv goto [result]:constante; -jmpsupeg = etiqop if [op1]:ctv supeq [op2]:ctv goto [result]:constante; -jmp = etiqop goto [result]:constante; -begin = identif fbegin; -end = etiqop fend; -fcall = etiqop [result]:tv aff call identif; -iwrite = etiqop write ctv; -iread = etiqop [result]:tv aff read; -arg = etiqop param ctv; -return = etiqop ret ctv; -istop = etiqop stop ctv; - - -ctv = {c} constante | {t} temporaire | {v} variable; -tv = {t} temporaire | {v} variable; - -constante = nombre; - -temporaire = prefixe_temp nombre; - -variable = {scalaire} identif | - {tab} identif co ctv cf - ; - -etiqop = {cte} nombre | - {vide} - ; diff --git a/src/c3a/C3a.java b/src/c3a/C3a.java index 9fe8ad58c8b423dc159a6e45c540be0709907942..17d21406c228a0965f86cb327119c7e91f537385 100644 --- a/src/c3a/C3a.java +++ b/src/c3a/C3a.java @@ -23,13 +23,11 @@ public class C3a{ this.True = new C3aConstant(1); // constantes utilisées partout this.False = new C3aConstant(0); // constantes utilisées partout } + + public int getTempCounter(){return this.tempCounter;} + public void setTempCounter(int value){this.tempCounter = value;} - public int getTempCounter(){return this.tempCounter;} - public void setTempCounter(int value){this.tempCounter = value;} - public int getLabelCounter(){return this.labelCounter;} - public void setLableCounter(int value){this.labelCounter = value;} - - public void ajouteInst(C3aInst inst){ + public void ajouteInst(C3aInst inst){ if(this.nextLabel != null){ inst.setLabel(this.nextLabel); this.nextLabel = null; @@ -79,9 +77,6 @@ public class C3a{ out.println(iter.next()); } } - public <T> T accept(C3aVisitor <T> visitor) { - return visitor.visit(this); - } } diff --git a/src/c3a/C3aBooleanConstant.java b/src/c3a/C3aBooleanConstant.java deleted file mode 100644 index 419e5e9594910662e0a16ff356dd60ba0d3951b2..0000000000000000000000000000000000000000 --- a/src/c3a/C3aBooleanConstant.java +++ /dev/null @@ -1,15 +0,0 @@ -package c3a; - -public class C3aBooleanConstant extends C3aOperand{ - public boolean val; - - public C3aBooleanConstant(boolean val){ - this.val = val; - } - - public String toString(){return String.valueOf(this.val);} - - public <T> T accept(C3aVisitor <T> visitor) { - return visitor.visit(this); - } -} diff --git a/src/c3a/C3aEval.java b/src/c3a/C3aEval.java index e1f2fd28fd1a611ce78cdb94d17202a07710edc8..7bfc9c547b51bdc9d5ce4e4619f7c72c6eed8547 100644 --- a/src/c3a/C3aEval.java +++ b/src/c3a/C3aEval.java @@ -2,42 +2,38 @@ package c3a; import java.util.*; import java.io.*; import ts.*; -import util.Memory; -import util.Type; public class C3aEval implements C3aVisitor <Integer> { - private C3a c3a; - private Ts tableGlobale; + private C3a c3a; + private Ts tableGlobale; private int nbReg; - private int[] reg; - private int[] stack; - private Memory varGlob; - private int eip; - private int ebp; - private int esp; - private int stackSize; - private Map< Integer, Integer> label2index; - private Map< String, Integer> function2index; - private boolean debug; - private boolean stop; - private ArrayList<String> programOutput = new ArrayList<String>(); - private TsItemFct currentFct; - private Stack<TsItemFct> stackCurrentFct; - - private C3aOperand storeReturnValue; - private Stack<C3aOperand> stackStoreReturnValue; - private int verboseLevel; + private int[] reg; + private int[] stack; + private int[] varGlob; + private int eip; + private int ebp; + private int esp; + private int stackSize; + private Map< Integer, Integer> label2index; + private Map< String, Integer> function2index; + private boolean debug; + private boolean stop; + private ArrayList<String> programOutput = new ArrayList<String>(); + private TsItemFct currentFct; + private Stack<TsItemFct> stackCurrentFct; + + private C3aOperand storeReturnValue; + private Stack<C3aOperand> stackStoreReturnValue; public C3aEval(C3a c3a, Ts tableGlobale, int stackSize, int verboseLevel){ - debug = true; - this.verboseLevel = verboseLevel; - this.c3a = c3a; + debug = true; + this.c3a = c3a; stack = new int[stackSize]; nbReg = c3a.getTempCounter(); reg = new int[nbReg]; esp = 0; - varGlob = new Memory(tableGlobale.getAdrVarCourante(), 0); + varGlob = new int[tableGlobale.nbVar()]; this.tableGlobale = tableGlobale; this.currentFct = null; storeReturnValue = null; @@ -58,12 +54,17 @@ public class C3aEval implements C3aVisitor <Integer> { function2index.put(identif, i); } } - + stop = false; + while(!stop){ + c3aInst = c3a.listeInst.get(eip); + // System.out.println("<" + c3aInst.getClass().getSimpleName() + ">"); + if(verboseLevel > 0) + afficheEtat(c3aInst); + + c3aInst.accept(this); + } } - public C3a getC3a(){ - return this.c3a; - } public void afficheEtat(C3aInst inst){ System.out.println("---------------------------------------------"); System.out.println("eip = " + eip + "\tesp = " + esp + "\tebp = " + ebp); @@ -145,41 +146,21 @@ public class C3aEval implements C3aVisitor <Integer> { esp--; return stack[esp]; } - - public Integer visit(C3a c3a){ - stop = false; - C3aInst c3aInst; - while(!stop){ - c3aInst = c3a.listeInst.get(eip); - // System.out.println("<" + c3aInst.getClass().getSimpleName() + ">"); - if(verboseLevel > 0) - afficheEtat(c3aInst); - - c3aInst.accept(this); - } - return 0; - } + public Integer visit(C3aConstant constant){ return constant.val; } - public Integer visit(C3aBooleanConstant constant){ - return (constant.val == true)? 1 : 0; - } - public Integer visit(C3aTemp temp){ return reg[temp.num]; } public Integer visit(C3aVar var){ int adresse = var.item.adresse; - Type type = var.item.type; // variable globale if(var.item.portee == this.tableGlobale){ int offset = (var.index != null)? var.index.accept(this) : 0; - // return varGlob[adresse/4 + offset]; - // System.out.println("adresse = " + adresse + " taille = " + type.taille()); - return varGlob.readNBytes(adresse + offset * type.taille(), type.taille()); + return varGlob[adresse/4 + offset]; } if(var.item.isParam){ // parametre int nbArgs = this.currentFct.nbArgs; @@ -193,11 +174,10 @@ public class C3aEval implements C3aVisitor <Integer> { if(op instanceof C3aVar){ C3aVar var = (C3aVar) op; int adresse = var.item.adresse; - int size = var.item.getType().taille(); // variable globale if(var.item.portee == this.tableGlobale){ int offset = (var.index != null)? var.index.accept(this) : 0; - varGlob.writeInt(adresse + offset * size, val); + varGlob[adresse/4 + offset] = val; } else if(var.item.isParam){ // parametre int nbArgs = this.currentFct.nbArgs; diff --git a/src/c3a/C3aInstJumpIfEqual.java b/src/c3a/C3aInstJumpIfEqual.java index 98bdb79305249c803e12a07c334ea4337d6958b7..64b6f6c997fa679e45b0c3e0844aa6beb55e3d6c 100644 --- a/src/c3a/C3aInstJumpIfEqual.java +++ b/src/c3a/C3aInstJumpIfEqual.java @@ -16,7 +16,7 @@ public class C3aInstJumpIfEqual extends C3aInst{ String s = ""; if(this.label != null) s = s + this.label; - s = s + "\tif " + this.op1 + " == " + this.op2 + " goto " + this.result; + s = s + "\tif " + this.op1 + " = " + this.op2 + " goto " + this.result; return s; } diff --git a/src/c3a/C3aLabel.java b/src/c3a/C3aLabel.java index f70d1c3eca89af48274a5d9160811dec67d98997..119edd9895dad0e04b7021c0aedb6a2bb2d5bf2a 100644 --- a/src/c3a/C3aLabel.java +++ b/src/c3a/C3aLabel.java @@ -15,8 +15,9 @@ public class C3aLabel extends C3aOperand{ public int getNumber(){return this.number;} public int getLine(){return this.line;} - public String toString(){return String.valueOf(this.number);} -// public String toString(){return "l" + this.number;} + public String toString(){ + return "l" + this.number; + } public void affect(C3aLabel other) { this.number = other.number; diff --git a/src/c3a/C3aParser.java b/src/c3a/C3aParser.java new file mode 100644 index 0000000000000000000000000000000000000000..2ff543985409e87041dd6f8c5fb43ebc1f54cf74 --- /dev/null +++ b/src/c3a/C3aParser.java @@ -0,0 +1,246 @@ +package c3a; + +import c3a.*; +import ts.Ts; +import ts.TsParser; +import ts.TsItemVar; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Stack; + + +public class C3aParser { + private enum OperandPosition{LEFT, RIGHT}; + + private Ts symbolTable; + private C3a instructions; + private String[] lineArgs; + private C3aInst currentInstr; + private HashMap<String, C3aLabel> labelNameToLabel; + private HashMap<String, C3aTemp> tempNameToTemp; + private String currentFctName; + + public C3a parse(String c3aFilePath, Ts symbolTable){ + this.symbolTable = symbolTable; + instructions = new C3a(); + labelNameToLabel = new HashMap<>(); + tempNameToTemp = new HashMap<>(); + currentFctName =""; + try{ + Files.lines(Paths.get(c3aFilePath)).forEachOrdered(this::processLine); + } catch (IOException e) { + e.printStackTrace(); + } + return instructions; + } + + private void processLine(String line){ + lineArgs = line.split("([ ]|[\t])+"); + currentInstr = null; + addLabelToNextInstr(line); + if(line.contains("call")) + parseCallInstr(); + else if(line.contains("stop")) + parseStopInstr(); + else if(line.contains("fbegin")) + parseFbeginInstr(); + else if(line.contains("=") && !line.contains("if")) + parseEqualInstr(); + else if(line.contains("write")) + parseWriteInstr(); + else if(line.contains("fend")) + parseFendInstr(); + else if(line.contains("if")) + parseIfInstr(); + else if(line.contains("goto")) + parseGotoInstr(); + else if(line.contains("ret")) + parseRetInstr(); + else if(line.contains("param")) + parseParamInstr(); + instructions.ajouteInst(currentInstr); + } + + private void addLabelToNextInstr(String line){ + if(!line.contains("fbegin") && !lineArgs[0].equals("")){ + var labelName = lineArgs[0]; + var label = labelNameToLabel.get(labelName); + if(label == null) { + label = instructions.newAutoLabel(); + labelNameToLabel.put(lineArgs[0], label); + } + instructions.addLabelToNextInst(label); + } + } + + private void parseCallInstr(){ + var itemFct = symbolTable.getFct(lineArgs[4]); + var res = chooseRightOperandType(lineArgs[1], OperandPosition.LEFT); + currentInstr = new C3aInstCall(new C3aFunction(itemFct), res, " "); + } + + private void parseStopInstr(){ + var numTemp = Integer.parseInt(lineArgs[2].replace("t", "")); + currentInstr = new C3aInstStop(new C3aTemp(numTemp), ""); + } + + private void parseFbeginInstr(){ + currentFctName = lineArgs[0]; + var itemFct = symbolTable.getFct(lineArgs[0]); + currentInstr = new C3aInstFBegin(itemFct, ""); + } + + private void parseEqualInstr() { + var res = chooseRightOperandType(lineArgs[1], OperandPosition.LEFT); + var op1 = chooseRightOperandType(lineArgs[3], OperandPosition.RIGHT); + if (haveInnerMathInstr()) { + var op2 = chooseRightOperandType(lineArgs[5], OperandPosition.RIGHT); + switch (lineArgs[4]) { + case "+" : {currentInstr = new C3aInstAdd(op1, op2, res, ""); break;} + case "-" : {currentInstr = new C3aInstSub(op1, op2, res, ""); break;} + case "*" : {currentInstr = new C3aInstMult(op1, op2, res, ""); break;} + case "/" : {currentInstr = new C3aInstDiv(op1, op2, res, ""); break;} + } + } + else + currentInstr = new C3aInstAffect(op1, res, ""); + } + + private boolean haveInnerMathInstr(){ + return lineArgs.length == 6; + } + + private C3aOperand chooseRightOperandType(String op, OperandPosition pos){ + try{ + return getConstantOp(op); + } catch(NumberFormatException e) { + if(isTempOp(op)) + return getTempOp(op, pos); + else + return getVarOp(op); + } + } + + private C3aConstant getConstantOp(String op) throws NumberFormatException{ + var ctValue = Integer.parseInt(op); + return new C3aConstant(ctValue); + } + + private boolean isTempOp(String op){ + return op.contains("t") && !(op.contains("[") && op.contains("]")); + } + + private C3aTemp getTempOp(String op, OperandPosition pos){ + if(pos == OperandPosition.RIGHT) + return tempNameToTemp.get(op); + else { + var temp = tempNameToTemp.get(op); + if(temp == null) { + temp = instructions.newTemp(); + tempNameToTemp.put(op, temp); + } + return temp; + } + } + + private C3aVar getVarOp(String op){ + if(isArray(op)){ + var realName = op.split("\\[")[0]; + var startIndex = op.indexOf('[') + 1; + var endIndex = op.lastIndexOf(']'); + var indexStr = op.substring(startIndex, endIndex); + var index = chooseRightOperandType(indexStr, OperandPosition.RIGHT); + var varItem = symbolTable.getVar(realName); + return new C3aVar(varItem, index); + } + else { + var varItem = symbolTable.getTableLocale(currentFctName).getVar(op); + if (varItem == null) + varItem = symbolTable.getVar(op); + return new C3aVar(varItem ,null); + } + } + + private boolean isArray(String op){ + return op.contains("[") && op.contains("]"); + } + + + + private void parseWriteInstr(){ + var op = chooseRightOperandType(lineArgs[2], OperandPosition.RIGHT); + currentInstr = new C3aInstWrite(op, ""); + } + + private void parseFendInstr(){ + currentInstr = new C3aInstFEnd(" "); + } + + private void parseIfInstr(){ + var label = labelNameToLabel.get(lineArgs[6]); + if(label == null) { + label = instructions.newAutoLabel(); + labelNameToLabel.put(lineArgs[6], label); + } + + var op1 = chooseRightOperandType(lineArgs[2], OperandPosition.RIGHT); + var op2 = chooseRightOperandType(lineArgs[4], OperandPosition.RIGHT); + if(lineArgs[3].equals("=")){ + currentInstr = new C3aInstJumpIfEqual(op1, op2, label, ""); + } + else if(lineArgs[3].equals("<")){ + currentInstr = new C3aInstJumpIfLess(op1, op2, label, ""); + } + else if(lineArgs[3].equals("!=")){ + currentInstr = new C3aInstJumpIfNotEqual(op1, op2, label, ""); + } + else{ + throw new IllegalStateException("Unexpected value: " + lineArgs[3]); + } + + /* + switch (lineArgs[3]) { + case "=" : currentInstr = new C3aInstJumpIfEqual(op1, op2, label, ""); + case "<" : currentInstr = new C3aInstJumpIfLess(op1, op2, label, ""); + case "!=" : currentInstr = new C3aInstJumpIfNotEqual(op1, op2, label, ""); + default : throw new IllegalStateException("Unexpected value: " + lineArgs[3]); + }*/ + } + + private void parseGotoInstr(){ + var label = labelNameToLabel.get(lineArgs[2]); + if(label == null) { + label = instructions.newAutoLabel(); + labelNameToLabel.put(lineArgs[2], label); + } + labelNameToLabel.put(lineArgs[2], label); + currentInstr = new C3aInstJump(label, ""); + } + + private void parseRetInstr(){ + var op = chooseRightOperandType(lineArgs[2], OperandPosition.RIGHT); + currentInstr = new C3aInstReturn(op, ""); + } + + private void parseParamInstr(){ + var op = chooseRightOperandType(lineArgs[2], OperandPosition.RIGHT); + currentInstr = new C3aInstParam(op, ""); + } + + public static void main(String[] args){ + var parser = new C3aParser(); + var stParser = new TsParser(); + var st = stParser.parse("tabl.ts"); + var c3a = parser.parse("tabl.c3a", st); + System.out.println("Info C3A :"); + System.out.println("Temp counter :" + c3a.getTempCounter()); + System.out.println("Code :"); + for(var instr : c3a.listeInst){ + System.out.println("-----------------"); + System.out.println(instr); + } + } +} diff --git a/src/c3a/C3aTemp.java b/src/c3a/C3aTemp.java index 6958c45b43d7823215f39f77d5d2642e5acda957..4662fe62971900364772de070afb0b974a8ca55c 100644 --- a/src/c3a/C3aTemp.java +++ b/src/c3a/C3aTemp.java @@ -8,7 +8,7 @@ public class C3aTemp extends C3aOperand{ } public String toString(){ - return "@" + this.num; + return "t" + this.num; } public <T> T accept(C3aVisitor <T> visitor) { return visitor.visit(this); diff --git a/src/c3a/C3aVisitor.java b/src/c3a/C3aVisitor.java index b8f2b96f99869605b801ddd21d33239ac703ae7d..708590dace340d0be51ef90567ce10a2f27bb7ed 100644 --- a/src/c3a/C3aVisitor.java +++ b/src/c3a/C3aVisitor.java @@ -1,7 +1,6 @@ package c3a; public interface C3aVisitor <T> { - public T visit(C3a c3a); public T visit(C3aInstAdd inst); public T visit(C3aInstCall inst); public T visit(C3aInstFBegin inst); @@ -22,7 +21,6 @@ public interface C3aVisitor <T> { public T visit(C3aInstStop inst); public T visit(C3aConstant oper); - public T visit(C3aBooleanConstant oper); public T visit(C3aLabel oper); public T visit(C3aTemp oper); public T visit(C3aVar oper); diff --git a/src/c3a/LoadC3a.java b/src/c3a/LoadC3a.java deleted file mode 100644 index c321ea9b5c125cab957ab3f4e97e7cf0bedb99a5..0000000000000000000000000000000000000000 --- a/src/c3a/LoadC3a.java +++ /dev/null @@ -1,473 +0,0 @@ -package c3a; -import c3aParser.analysis.DepthFirstAdapter; -import ts.*; -import c3aParser.lexer.Lexer; -import c3aParser.lexer.LexerException; -import c3aParser.node.*; -import c3aParser.parser.Parser; -import c3aParser.parser.ParserException; -import util.Error; - -import java.io.FileReader; -import java.io.IOException; -import java.io.PushbackReader; - -public class LoadC3a extends DepthFirstAdapter { - private C3a c3a; - private C3aInst inst; - private C3aOperand operand; - private C3aLabel label; - private Ts tableGlobale; - private Ts tableLocale = null; - - public LoadC3a(String c3aFileName, Ts tableGlobale) { - this.tableGlobale = tableGlobale; - PushbackReader fileReader = null; - Parser parser = null; - Start root = null; - try { - fileReader = new PushbackReader(new FileReader(c3aFileName)); - } catch (IOException e) { - System.err.println("cannot open input file"); - e.printStackTrace(); - } - try { - parser = new Parser(new Lexer(fileReader)); - root = parser.parse(); - } catch (ParserException e) { - System.err.println("syntax error"); - e.printStackTrace(); - System.exit(Error.SYNT.code()); - } catch (LexerException e) { - System.err.println("lexical error"); - e.printStackTrace(); - System.exit(Error.LEX.code()); - } catch (IOException e) { - e.printStackTrace(); - } - root.apply(this); - } - - public void defaultIn(Node node) - { - //System.out.println("<" + node.getClass().getSimpleName() + ">"); - } - - public void defaultOut(Node node) - { - //System.out.println("</" + node.getClass().getSimpleName() + ">"); - } - - public C3a getC3a(){return c3a;} - //prog = listeinst; - @Override - public void caseAProg(AProg node) - { - inAProg(node); - c3a = new C3a(); - if(node.getListeinst() != null) - { - node.getListeinst().apply(this); - } - outAProg(node); - } -//listeinst = {recursif} inst listeinst - @Override - public void caseARecursifListeinst(ARecursifListeinst node) - { - inARecursifListeinst(node); - node.getInst().apply(this); - c3a.ajouteInst(inst); - label = null; - node.getListeinst().apply(this); - outARecursifListeinst(node); - } - -// listeinst = {final} inst - @Override - public void caseAFinalListeinst(AFinalListeinst node) - { - inAFinalListeinst(node); - node.getInst().apply(this); - c3a.ajouteInst(inst); - label = null; - outAFinalListeinst(node); - } - - //add = etiqop [result]:tv aff [op1]:ctv plus [op2]:ctv; - @Override - public void caseAAdd(AAdd node) - { - inAAdd(node); - if(node.getEtiqop() != null) - { - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - } - node.getResult().apply(this); - C3aOperand result = operand; - node.getOp1().apply(this); - C3aOperand op1 = operand; - node.getOp2().apply(this); - C3aOperand op2 = operand; - inst = new C3aInstAdd(op1, op2, result, ""); - outAAdd(node); - } - - //sub = etiqop [result]:tv aff [op1]:ctv moins [op2]:ctv; - @Override - public void caseASub(ASub node) - { - inASub(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getResult().apply(this); - C3aOperand result = operand; - - node.getOp1().apply(this); - C3aOperand op1 = operand; - - node.getOp2().apply(this); - C3aOperand op2 = operand; - - inst = new C3aInstSub(op1, op2, result, ""); - outASub(node); - } - - //mul = etiqop [result]:tv aff [op1]:ctv fois [op2]:ctv; - @Override - public void caseAMul(AMul node) - { - inAMul(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getResult().apply(this); - C3aOperand result = operand; - - node.getOp1().apply(this); - C3aOperand op1 = operand; - - node.getOp2().apply(this); - C3aOperand op2 = operand; - - inst = new C3aInstMult(op1,op2, result, ""); - outAMul(node); - } - - //div = etiqop [result]:tv aff [op1]:ctv divise [op2]:ctv; - @Override - public void caseADiv(ADiv node) - { - inADiv(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getResult().apply(this); - C3aOperand result = operand; - - node.getOp1().apply(this); - C3aOperand op1 = operand; - - node.getOp2().apply(this); - C3aOperand op2 = operand; - - inst = new C3aInstDiv(op1,op2, result, ""); - outADiv(node); - } - - - //istop = etiqop stop ctv; - @Override - public void caseAIstop(AIstop node) - { - inAIstop(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getCtv().apply(this); - C3aOperand op1 = operand; - - inst = new C3aInstStop(op1, ""); - outAIstop(node); - } - -// iwrite = etiqop write ctv; - - @Override - public void caseAIwrite(AIwrite node) - { - inAIwrite(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getCtv().apply(this); - C3aOperand op = operand; - - inst = new C3aInstWrite(op, ""); - outAIwrite(node); - } - - // iread = etiqop [result]:tv aff read; - - @Override - public void caseAIread(AIread node) - { - inAIread(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getResult().apply(this); - C3aOperand result = operand; - - inst = new C3aInstRead(result, ""); - outAIread(node); - } - - // end = etiqop fend; -@Override -public void caseAEnd(AEnd node) -{ - inAEnd(node); - if(node.getEtiqop() != null) - { - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - } - inst = new C3aInstFEnd(""); - outAEnd(node); -} - -// affect = etiqop [result]:tv aff [op1]:ctv; - - @Override - public void caseAAffect(AAffect node) - { - inAAffect(node); - if(node.getEtiqop() != null) - { - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - } - node.getResult().apply(this); - C3aOperand result = operand; - - node.getOp1().apply(this); - C3aOperand op1 = operand; - inst = new C3aInstAffect(op1, result, ""); - outAAffect(node); - } - -// jmpeg = etiqop if [op1]:ctv aff [op2]:ctv goto [result]:constante; -@Override -public void caseAJmpeg(AJmpeg node) -{ - inAJmpeg(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getOp1().apply(this); - C3aOperand op1 = operand; - - node.getOp2().apply(this); - C3aOperand op2 = operand; - - node.getResult().apply(this); - C3aOperand result = operand; - - inst = new C3aInstJumpIfEqual(op1, op2, result, ""); - outAJmpeg(node); -} - -// jmpinf = etiqop if [op1]:ctv inf [op2]:ctv goto [result]:constante; -@Override -public void caseAJmpinf(AJmpinf node) -{ - inAJmpinf(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getOp1().apply(this); - C3aOperand op1 = operand; - - node.getOp2().apply(this); - C3aOperand op2 = operand; - - node.getResult().apply(this); - C3aOperand result = operand; - - inst = new C3aInstJumpIfLess(op1, op2, result, ""); - outAJmpinf(node); -} - -// jmpneg = etiqop if [op1]:ctv noteg [op2]:ctv goto [result]:constante; -@Override -public void caseAJmpneg(AJmpneg node) -{ - inAJmpneg(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getOp1().apply(this); - C3aOperand op1 = operand; - - node.getOp2().apply(this); - C3aOperand op2 = operand; - - node.getResult().apply(this); - C3aOperand result = operand; - - inst = new C3aInstJumpIfNotEqual(op1, op2, result, ""); - outAJmpneg(node); -} - - @Override - public void caseAJmp(AJmp node) - { - inAJmp(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getResult().apply(this); - C3aOperand result = operand; - - inst = new C3aInstJump(result, ""); - outAJmp(node); - } - - - //arg = etiqop param ctv; - @Override - public void caseAArg(AArg node) - { - inAArg(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - - node.getCtv().apply(this); - C3aOperand op1 = operand; - inst = new C3aInstParam(op1, ""); - outAArg(node); - } -//return = etiqop ret ctv; - - @Override - public void caseAReturn(AReturn node) - { - inAReturn(node); - node.getEtiqop().apply(this); - c3a.addLabelToNextInst(label); - node.getCtv().apply(this); - C3aOperand op1 = operand; - inst = new C3aInstReturn(op1, ""); - outAReturn(node); - } - -//temporaire = prefixe_temp constante; - @Override - public void caseATemporaire(ATemporaire node) - { - inATemporaire(node); - int num = Integer.parseInt(node.getNombre().getText()); - if(num >= c3a.getTempCounter()) - c3a.setTempCounter(num + 1); - operand = new C3aTemp(num); - outATemporaire(node); - } - -//constante = nombre; -@Override -public void caseAConstante(AConstante node) { - inAConstante(node); - int num = Integer.parseInt(node.getNombre().getText()); - operand = new C3aConstant(num); - outAConstante(node); -} - -@Override - public void caseAVideEtiqop(AVideEtiqop node) - { - inAVideEtiqop(node); - outAVideEtiqop(node); - } - //etiqop = {cte} constante; - @Override - public void caseACteEtiqop(ACteEtiqop node) - { - inACteEtiqop(node); - int num = Integer.parseInt(node.getNombre().getText()); - this.label = new C3aLabel(num); - if (num >= c3a.getLabelCounter()) - c3a.setLableCounter(num + 1); - outACteEtiqop(node); - } - -// variable = {scalaire} identif - @Override - public void caseAScalaireVariable(AScalaireVariable node) - { - inAScalaireVariable(node); - String identif = node.getIdentif().getText(); - TsItemVarSimple tsItemVarSimple = null; - if(tableLocale != null) - tsItemVarSimple = (TsItemVarSimple) tableLocale.getVar(identif); - if(tsItemVarSimple == null) - tsItemVarSimple = (TsItemVarSimple) tableGlobale.getVar(identif); - operand = new C3aVar(tsItemVarSimple, null); - outAScalaireVariable(node); - } - -// variable = {tab} identif co ctv cf - @Override - public void caseATabVariable(ATabVariable node) - { - inATabVariable(node); - String identif = node.getIdentif().getText(); - TsItemVarTab tsItemVarTab = null; - if(tableLocale != null) - tsItemVarTab = (TsItemVarTab) tableLocale.getVar(identif); - if(tsItemVarTab == null) - tsItemVarTab = (TsItemVarTab) tableGlobale.getVar(identif); - node.getCtv().apply(this); - C3aOperand index = operand; - operand = new C3aVar(tsItemVarTab, index); - outATabVariable(node); - } - - - @Override - public void caseABegin(ABegin node) - { - inABegin(node); - - String functionName = node.getIdentif().getText(); - TsItemFct tsItemFct = tableGlobale.getFct(functionName); - tableLocale = tsItemFct.getTable(); - inst = new C3aInstFBegin(tsItemFct, ""); - outABegin(node); - } - - //fcall = etiqop [result]:tv aff call identif; - @Override - public void caseAFcall(AFcall node) - { - inAFcall(node); - if(node.getEtiqop() != null) - { - node.getEtiqop().apply(this); - } - node.getResult().apply(this); - C3aOperand result = operand; - - C3aFunction op1 = new C3aFunction(tableGlobale.getFct(node.getIdentif().getText())); - inst = new C3aInstCall(op1, result, ""); - - outAFcall(node); - } - - -} - - - diff --git a/src/c3a/Sa2c3a.java b/src/c3a/Sa2c3a.java index 8e1a01f8920f5c383c6ec223d7a1bdfb1df11b55..0206d0cb76c739fec3d581535144edb05172fd17 100644 --- a/src/c3a/Sa2c3a.java +++ b/src/c3a/Sa2c3a.java @@ -1,8 +1,8 @@ package c3a; +import java.util.*; import ts.*; import sa.*; - public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> { private C3a c3a; int indentation; @@ -15,35 +15,461 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> { c3a.ajouteInst(new C3aInstCall(fct, result, "")); c3a.ajouteInst(new C3aInstStop(result, "")); indentation = 0; + root.accept(this); } public void defaultIn(SaNode node) { - //for(int i = 0; i < indentation; i++){System.out.print(" ");} - //indentation++; - //System.out.println("<" + node.getClass().getSimpleName() + ">"); + for(int i = 0; i < indentation; i++){System.out.print(" ");} + indentation++; + System.out.println("<" + node.getClass().getSimpleName() + ">"); } public void defaultOut(SaNode node) { - //indentation--; - // for(int i = 0; i < indentation; i++){System.out.print(" ");} - // System.out.println("</" + node.getClass().getSimpleName() + ">"); + indentation--; + for(int i = 0; i < indentation; i++){System.out.print(" ");} + System.out.println("</" + node.getClass().getSimpleName() + ">"); } - - // EXP -> op2 EXP EXP - public C3aOperand visit(SaExpAdd node) throws Exception - { - defaultIn(node); - C3aOperand op1 = node.getOp1().accept(this); - C3aOperand op2 = node.getOp2().accept(this); - C3aOperand result = c3a.newTemp(); - c3a.ajouteInst(new C3aInstAdd(op1, op2, result, "")); + + + + public C3aOperand visit(SaProg node) + { + defaultIn(node); + if(node.getVariables() != null) + node.getVariables().accept(this); + if(node.getFonctions() != null) + return node.getFonctions().accept(this); + defaultOut(node); + return null; + } + + // DEC -> var id taille + /*public C3aOperand visit(SaDecTab node){ + defaultIn(node); + defaultOut(node); + return null; + }*/ + + public C3aOperand visit(SaExp node) + { + defaultIn(node); + C3aOperand exp = node.accept(this); + defaultOut(node); + return exp; + } + + // EXP -> entier + public C3aOperand visit(SaExpInt node) + { + defaultIn(node); + C3aOperand result = new C3aConstant(node.getVal()); + defaultOut(node); + return result ; + } + + public C3aOperand visit(SaExpVar node) + { + defaultIn(node); + C3aOperand result = node.getVar().accept(this); + defaultOut(node); + return result; + } + + public C3aOperand visit(SaInstEcriture node) + { + defaultIn(node); + C3aOperand exp = node.getArg().accept(this); + C3aInstWrite result = new C3aInstWrite(exp,""); + c3a.ajouteInst(result); + defaultOut(node); + return exp; + } + + public C3aOperand visit(SaInstTantQue node) + { + + defaultIn(node); + C3aLabel test = c3a.newAutoLabel(); + C3aLabel suite = c3a.newAutoLabel(); + c3a.addLabelToNextInst(test); + C3aOperand result = node.getTest().accept(this); + c3a.ajouteInst(new C3aInstJumpIfEqual(result,c3a.False,suite,"")); + if (node.getFaire() != null) + node.getFaire().accept(this); + defaultOut(node); + c3a.ajouteInst(new C3aInstJump(test,"")); + c3a.addLabelToNextInst(suite); + return null; + } + + + public C3aOperand visit(SaLInst node) + { + defaultIn(node); + C3aOperand tete = null; + if(node != null){ + if(node.getTete() != null){ + tete = node.getTete().accept(this); + } + if(node.getQueue() != null) node.getQueue().accept(this); + } + defaultOut(node); + return tete; + } + + + // A corriger eventuellement + // DEC -> fct id LDEC LDEC LINST + public C3aOperand visit(SaDecFonc node) + { + defaultIn(node); + c3a.ajouteInst(new C3aInstFBegin(node.tsItem,"entree fonction")); + + /*if(node.getParametres() != null){ + node.getParametres().accept(this); + } + if(node.getVariable() != null) node.getVariable().accept(this);*/ + + if(node.getCorps() != null){ + C3aOperand corps = node.getCorps().accept(this); + c3a.ajouteInst(new C3aInstFEnd("")); + return corps; + } + + c3a.ajouteInst(new C3aInstFEnd("")); + defaultOut(node); + return null; + } + + // DEC -> var id + /*public C3aOperand visit(SaDecVar node) + { + defaultIn(node); + defaultOut(node); + return null; + }*/ + +// a CORRIGER EVENTUELLEMENT + public C3aOperand visit(SaInstAffect node) + { + defaultIn(node); + + C3aOperand var = node.getLhs().accept(this); + + C3aOperand exp = node.getRhs().accept(this); + c3a.ajouteInst(new C3aInstAffect(exp,var,"")); + + defaultOut(node); + return var; + } + + // LDEC -> DEC LDEC + // LDEC -> null + /*public C3aOperand visit(SaLDec node) + { + defaultIn(node); + node.getTete().accept(this); + if(node.getQueue() != null) node.getQueue().accept(this); + defaultOut(node); + return null; + } + */ + +// A CORRIGER EVENTUELLEMNT + public C3aOperand visit(SaVarSimple node) + { + defaultIn(node); + C3aOperand result = new C3aVar(node.tsItem,null); + defaultOut(node); + return result; + } + + +// A CORRIGER EVENTUELLEMNT + public C3aOperand visit(SaAppel node) + { + /* + defaultIn(node); + C3aOperand result = c3a.newTemp(); + if(node.getArguments() != null){ + C3aOperand arg = node.getArguments().getTete().accept(this); + c3a.ajouteInst(new C3aInstParam(arg,"")); + SaLExp queue = node.getArguments().getQueue(); + for (int i =0;i<node.getArguments().length()-1;i++){ + if (queue!=null){ + C3aOperand arg1 = queue.accept(this); + c3a.ajouteInst(new C3aInstParam(arg1,"")); + queue = queue.getQueue(); + } + + } + c3a.ajouteInst(new C3aInstCall(new C3aFunction(node.tsItem),result,"")); + } + else { + c3a.ajouteInst(new C3aInstCall(new C3aFunction(node.tsItem),result,"")); + + } + + defaultOut(node); + return result; + */ + defaultIn(node); + C3aTemp result = c3a.newTemp(); + C3aFunction fct = new C3aFunction(node.tsItem); + if(node.getArguments() != null) node.getArguments().accept(this); + c3a.ajouteInst(new C3aInstCall(fct, result, "")); defaultOut(node); return result; - } + + } + + public C3aOperand visit(SaExpAppel node) + { + defaultIn(node); + defaultOut(node); + return node.getVal().accept(this); + } + + // EXP -> add EXP EXP + public C3aOperand visit(SaExpAdd node) + { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + c3a.ajouteInst(new C3aInstAdd(op1,op2,result,"")); + defaultOut(node); + return result; + } + + // EXP -> sub EXP EXP + public C3aOperand visit(SaExpSub node) + { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + c3a.ajouteInst(new C3aInstSub(op1,op2,result,"")); + defaultOut(node); + return result; + } + + // EXP -> mult EXP EXP + public C3aOperand visit(SaExpMult node) + { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + c3a.ajouteInst(new C3aInstMult(op1,op2,result,"")); + defaultOut(node); + return result; + } + + // EXP -> div EXP EXP + public C3aOperand visit(SaExpDiv node) + { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + c3a.ajouteInst(new C3aInstDiv(op1,op2,result,"")); + defaultOut(node); + return result; + } + + // EXP -> inf EXP EXP + public C3aOperand visit(SaExpInf node) + { + defaultIn(node); + C3aLabel suite = c3a.newAutoLabel(); + C3aOperand result = c3a.newTemp(); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + c3a.ajouteInst(new C3aInstAffect(c3a.True, result,"")); + + c3a.ajouteInst(new C3aInstJumpIfLess(op1,op2,suite,"")); + c3a.ajouteInst(new C3aInstAffect(c3a.False, result,"")); + c3a.addLabelToNextInst(suite); + defaultOut(node); + return result; + } + + // EXP -> eq EXP EXP + public C3aOperand visit(SaExpEqual node) + { + defaultIn(node); + C3aLabel suite = c3a.newAutoLabel(); + C3aOperand result = c3a.newTemp(); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + c3a.ajouteInst(new C3aInstAffect(c3a.True, result,"")); + c3a.ajouteInst(new C3aInstJumpIfEqual(op1,op2,suite,"")); + c3a.ajouteInst(new C3aInstAffect(c3a.False, result,"")); + c3a.addLabelToNextInst(suite); + defaultOut(node); + return result; + } + + // EXP -> and EXP EXP + public C3aOperand visit(SaExpAnd node) + { + defaultIn(node); + C3aLabel suite = c3a.newAutoLabel(); + C3aLabel faux = c3a.newAutoLabel(); + C3aOperand result = c3a.newTemp(); + C3aOperand op1 = node.getOp1().accept(this); + c3a.ajouteInst(new C3aInstJumpIfEqual(op1,c3a.False,faux,"")); + C3aOperand op2 = node.getOp2().accept(this); + c3a.ajouteInst(new C3aInstJumpIfEqual(op2,c3a.False,faux,"")); + c3a.ajouteInst(new C3aInstAffect(c3a.True,result,"")); + c3a.ajouteInst(new C3aInstJump(suite,"")); + c3a.addLabelToNextInst(faux); + c3a.ajouteInst(new C3aInstAffect(c3a.False,result,"")); + c3a.addLabelToNextInst(suite); + + return result; + } + + + // EXP -> or EXP EXP + public C3aOperand visit(SaExpOr node) + { + defaultIn(node); + C3aLabel suite = c3a.newAutoLabel(); + C3aLabel vrai = c3a.newAutoLabel(); + C3aOperand result = c3a.newTemp(); + + C3aOperand op1 = node.getOp1().accept(this); + c3a.ajouteInst(new C3aInstJumpIfNotEqual(op1,c3a.False,vrai,"")); + C3aOperand op2 = node.getOp2().accept(this); + c3a.ajouteInst(new C3aInstJumpIfNotEqual( op2,c3a.False,vrai,"")); + c3a.ajouteInst(new C3aInstAffect(c3a.False,result,"")); + c3a.ajouteInst(new C3aInstJump(suite,"")); + c3a.addLabelToNextInst(vrai); + c3a.ajouteInst(new C3aInstAffect(c3a.True, result,"")); + c3a.addLabelToNextInst(suite); + + defaultOut(node); + return result; + } + + // EXP -> not EXP + public C3aOperand visit(SaExpNot node) + { + defaultIn(node); + C3aLabel suite = c3a.newAutoLabel(); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand result = c3a.newTemp(); + c3a.ajouteInst(new C3aInstAffect(c3a.True, result,"")); + c3a.ajouteInst(new C3aInstJumpIfEqual(op1, c3a.False, suite, "")); + c3a.ajouteInst(new C3aInstAffect(c3a.False, result,"")); + c3a.addLabelToNextInst(suite); + defaultOut(node); + return result; + } + + + public C3aOperand visit(SaExpLire node) + { + defaultIn(node); + C3aOperand result = c3a.newTemp(); + c3a.ajouteInst(new C3aInstRead(result,"")); + defaultOut(node); + return result; + } + public C3aOperand visit(SaInstBloc node) + { + defaultIn(node); + + defaultOut(node); + return node.getVal().accept(this); + } + + public C3aOperand visit(SaInstSi node) + { + defaultIn(node); + C3aLabel faux = c3a.newAutoLabel(); + C3aLabel suite = c3a.newAutoLabel(); + C3aOperand test = node.getTest().accept(this); + + if(node.getSinon() == null){ + c3a.ajouteInst(new C3aInstJumpIfEqual(test, c3a.False,suite,"" )); + if (node.getAlors() != null){ + C3aOperand alors = node.getAlors().accept(this); + } + } + else { + c3a.ajouteInst(new C3aInstJumpIfEqual(test, c3a.False,faux,"" )); + if (node.getAlors() != null){ + C3aOperand alors = node.getAlors().accept(this); + c3a.ajouteInst(new C3aInstJump(suite,"")); + } + c3a.addLabelToNextInst(faux); + C3aOperand sinon = node.getSinon().accept(this); + + } + c3a.addLabelToNextInst(suite); + + defaultOut(node); + return null; + } + + // INST -> ret EXP + public C3aOperand visit(SaInstRetour node) + { + defaultIn(node); + C3aOperand val = node.getVal().accept(this); + c3a.ajouteInst(new C3aInstReturn(val,"")); + c3a.ajouteInst(new C3aInstFEnd("")); + defaultOut(node); + return val; + } + + + public C3aOperand visit(SaLExp node) + { + /* + defaultIn(node); + C3aOperand tete = null; + if (node.getTete()!=null){ + tete = node.getTete().accept(this); + } + if(node.getQueue() != null){ + node.getQueue().accept(this); + } + defaultOut(node); + return tete; + */ + defaultIn(node); + C3aOperand res = node.getTete().accept(this); + c3a.ajouteInst(new C3aInstParam(res, "")); + + if(node.getQueue() != null) + node.getQueue().accept(this); + defaultOut(node); + return null; + } + + public C3aOperand visit(SaVarIndicee node) + { + defaultIn(node); + C3aOperand indice = node.getIndice().accept(this); + //C3aOperand result = new C3aVar(node.tsItem,indice); + defaultOut(node); + return new C3aVar(node.tsItem, indice); + } } + + + + + + + diff --git a/src/fg/Fg.java b/src/fg/Fg.java index c306fd59e2633583fd7a07b50244db85c790c57b..86999db9e52f59da9ad21905b471289db8d87c9a 100644 --- a/src/fg/Fg.java +++ b/src/fg/Fg.java @@ -12,39 +12,177 @@ public class Fg implements NasmVisitor <Void> { Map< String, NasmInst> label2Inst; public Fg(Nasm nasm){ - this.nasm = nasm; - this.inst2Node = new HashMap< NasmInst, Node>(); - this.node2Inst = new HashMap< Node, NasmInst>(); - this.label2Inst = new HashMap< String, NasmInst>(); - this.graph = new Graph(); + this.nasm = nasm; + this.inst2Node = new HashMap< NasmInst, Node>(); + this.node2Inst = new HashMap< Node, NasmInst>(); + this.label2Inst = new HashMap< String, NasmInst>(); + this.graph = new Graph(); + + for(NasmInst nasmInst : nasm.sectionText){ + // System.out.println("<" + nasmInst.getClass().getSimpleName() + ">"); + if(nasmInst.label != null) this.label2Inst.put(((NasmLabel)nasmInst.label).val, nasmInst); + Node n = this.graph.newNode(); + this.inst2Node.put(nasmInst, n); + this.node2Inst.put(n, nasmInst); + if (nasmInst.label != null){ + this.label2Inst.put(nasmInst.label.toString(),nasmInst); + + } + } + + int instNb = nasm.sectionText.size(); + for (int i = 0; i < instNb; i++) { + + NasmInst nasmInst = nasm.sectionText.get(i); + // System.out.println("<" + nasmInst.getClass().getSimpleName() + ">"); + if(nasmInst instanceof NasmJmp){ + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel)((NasmJmp)nasmInst).address).val))); + continue; + } + + if (nasmInst instanceof NasmJe ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + + + + if (nasmInst instanceof NasmJe ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + + if (nasmInst instanceof NasmJg ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + if (nasmInst instanceof NasmJge ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + + if (nasmInst instanceof NasmJl ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + + if (nasmInst instanceof NasmJle ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + + + if (nasmInst instanceof NasmJne ){ + + this.graph.addEdge(this.inst2Node.get(nasmInst), this.inst2Node.get(this.label2Inst.get(((NasmLabel) nasmInst.address).val))); + + if (nasm.sectionText.get(i+1) != null){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + if (nasmInst instanceof NasmCall){ + if ( i<instNb-1){ + + NasmLabel dest = (NasmLabel) nasmInst.address; + if (dest!=null){ + System.out.println(dest.val); + if (!dest.val.equals("iprintLF")&&!dest.val.equals("atoi")&&!dest.val.equals("readline")){ + this.graph.addEdge( + this.inst2Node.get(nasmInst), + this.inst2Node.get(this.label2Inst.get(((NasmLabel)(nasmInst).address).val))); + + + } + + } + + } + + + } + + else { + + if ( i<instNb-1){ + NasmInst prochaineInst = nasm.sectionText.get(i+1); + this.graph.addEdge(this.inst2Node.get(nasmInst),this.inst2Node.get(prochaineInst)); + } + + } + + + + + + + } } + public void affiche(String baseFileName){ - String fileName; - PrintStream out = System.out; - - if (baseFileName != null){ - try { - baseFileName = baseFileName; - fileName = baseFileName + ".fg"; - out = new PrintStream(fileName); - } - - catch (IOException e) { - System.err.println("Error: " + e.getMessage()); - } - } - - for(NasmInst nasmInst : nasm.sectionText){ - Node n = this.inst2Node.get(nasmInst); - out.print(n + " : ( "); - for(NodeList q=n.succ(); q!=null; q=q.tail) { - out.print(q.head.toString()); - out.print(" "); - } - out.println(")\t" + nasmInst); - } - + String fileName; + PrintStream out = System.out; + + if (baseFileName != null){ + try { + baseFileName = baseFileName; + fileName = baseFileName + ".fg"; + out = new PrintStream(fileName); + } + + catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + + for(NasmInst nasmInst : nasm.sectionText){ + Node n = this.inst2Node.get(nasmInst); + out.print(n + " : ( "); + for(NodeList q=n.succ(); q!=null; q=q.tail) { + out.print(q.head.toString()); + out.print(" "); + } + out.println(")\t" + nasmInst); + } + } public Void visit(NasmAdd inst){return null;} @@ -71,17 +209,16 @@ public class Fg implements NasmVisitor <Void> { public Void visit(NasmSub inst){return null;} public Void visit(NasmEmpty inst){return null;} public Void visit(NasmInt inst){return null;} + public Void visit(NasmAddress operand){return null;} public Void visit(NasmConstant operand){return null;} public Void visit(NasmLabel operand){return null;} public Void visit(NasmRegister operand){return null;} + public Void visit(NasmResb pseudoInst){return null;} public Void visit(NasmResw pseudoInst){return null;} public Void visit(NasmResd pseudoInst){return null;} public Void visit(NasmResq pseudoInst){return null;} public Void visit(NasmRest pseudoInst){return null;} - public Void visit(NasmExpPlus exp){return null;} - public Void visit(NasmExpMinus exp){return null;} - public Void visit(NasmExpTimes exp){return null;} - public Void visit(NasmExp exp){return null;} + } diff --git a/src/fg/FgSolution.java b/src/fg/FgSolution.java index 0970759509bbf4365786cb26710f8aecbd3766b0..414b40deb1eb76e94fae0717ecc0b0c536db60d8 100644 --- a/src/fg/FgSolution.java +++ b/src/fg/FgSolution.java @@ -6,46 +6,212 @@ import java.io.*; import java.util.*; public class FgSolution{ - int iterNum = 0; - public Nasm nasm; - Fg fg; - public Map< NasmInst, IntSet> use; - public Map< NasmInst, IntSet> def; - public Map< NasmInst, IntSet> in; - public Map< NasmInst, IntSet> out; - - public FgSolution(Nasm nasm, Fg fg){ - this.nasm = nasm; - this.fg = fg; - this.use = new HashMap< NasmInst, IntSet>(); - this.def = new HashMap< NasmInst, IntSet>(); - this.in = new HashMap< NasmInst, IntSet>(); - this.out = new HashMap< NasmInst, IntSet>(); - } - - public void affiche(String baseFileName){ - String fileName; - PrintStream out = System.out; - - if (baseFileName != null){ - try { - baseFileName = baseFileName; - fileName = baseFileName + ".fgs"; - out = new PrintStream(fileName); - } - - catch (IOException e) { - System.err.println("Error: " + e.getMessage()); - } + int iterNum = 0; + public Nasm nasm; + Fg fg; + public Map< NasmInst, IntSet> use; + public Map< NasmInst, IntSet> def; + public Map< NasmInst, IntSet> in; + public Map< NasmInst, IntSet> out; + + public FgSolution(Nasm nasm, Fg fg){ + this.nasm = nasm; + this.fg = fg; + this.use = new HashMap< NasmInst, IntSet>(); + this.def = new HashMap< NasmInst, IntSet>(); + this.in = new HashMap< NasmInst, IntSet>(); + this.out = new HashMap< NasmInst, IntSet>(); + this.FgSolve(); } - - out.println("iter num = " + iterNum); - for(NasmInst nasmInst : this.nasm.sectionText){ - out.println("use = "+ this.use.get(nasmInst) + " def = "+ this.def.get(nasmInst) + "\tin = " + this.in.get(nasmInst) + "\t \tout = " + this.out.get(nasmInst) + "\t \t" + nasmInst); + + public void affiche(String baseFileName){ + String fileName; + PrintStream out = System.out; + + if (baseFileName != null){ + try { + baseFileName = baseFileName; + fileName = baseFileName + ".fgs"; + out = new PrintStream(fileName); + } + + catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + + out.println("iter num = " + iterNum); + for(NasmInst nasmInst : this.nasm.sectionText){ + out.println("use = "+ this.use.get(nasmInst) + " def = "+ this.def.get(nasmInst) + "\tin = " + this.in.get(nasmInst) + "\t \tout = " + this.out.get(nasmInst) + "\t \t" + nasmInst); + } + } - - } + + public void FgSolve() + { + + +// intialisation de def et use + int nbrInst = nasm.sectionText.size(); + int nbTemp = nasm.getTempCounter(); + + for (int i = 0;i<nbrInst;i++) { + + NasmInst nasmInst = nasm.sectionText.get(i); + ArrayList<Integer> regUse = new ArrayList<>(); + ArrayList<Integer> regDef = new ArrayList<>(); + IntSet useReg = new IntSet(nbTemp); + IntSet defReg = new IntSet(nbTemp); + + if (nasmInst.destDef && nasmInst.destination.isGeneralRegister()) { + NasmRegister register = (NasmRegister) nasmInst.destination; + //regDef.add(register.val); + defReg.add(register.val); + } + + if (nasmInst.destUse && nasmInst.destination.isGeneralRegister()) { + NasmRegister register = (NasmRegister) nasmInst.destination; + useReg.add(register.val); + } + + if (nasmInst.srcDef && nasmInst.source.isGeneralRegister()) { + NasmRegister register = (NasmRegister) nasmInst.source; + defReg.add(register.val); + } + + + if (nasmInst.srcUse && nasmInst.source.isGeneralRegister()) { + + NasmRegister register = (NasmRegister) nasmInst.source; + useReg.add(register.val); + } + + + if (nasmInst.source instanceof NasmAddress ) { + NasmAddress address = (NasmAddress) nasmInst.source; + if (address.base.isGeneralRegister()) { + NasmRegister register = (NasmRegister) address.base; + + useReg.add(register.val); + } + if (address.offset.isGeneralRegister()) { + NasmRegister register = (NasmRegister) address.offset; + useReg.add(register.val); + } + + } + + if (nasmInst.destination instanceof NasmAddress) { + NasmAddress address = (NasmAddress) nasmInst.destination; + if (address.base.isGeneralRegister()) { + NasmRegister register = (NasmRegister) address.base; + + useReg.add(register.val); + } + if (address.offset.isGeneralRegister()) { + NasmRegister register = (NasmRegister) address.offset; + useReg.add(register.val); + } + + } + + + //System.out.println(regDef); + //System.out.println(regUse); + + + this.use.put(nasmInst, useReg); + this.def.put(nasmInst, defReg); + + } + + + + for (int j = 0;j<nbrInst;j++) { + NasmInst nasmInst1 = nasm.sectionText.get(j); + in.put(nasmInst1,new IntSet(nbTemp)); + out.put(nasmInst1,new IntSet(nbTemp)); + + } + + + + boolean change; + + // actualisation de in et out + + do { + + IntSet[] intSetInPrimTab = new IntSet[nbrInst]; + IntSet[] intSetOutPrimTab = new IntSet[nbrInst]; + + + for (Node n : fg.graph.nodeArray()) { + + NasmInst nasmInst1 = fg.node2Inst.get(n); + IntSet inPrim = in.get(nasmInst1).copy(); + IntSet outPrm = out.get(nasmInst1).copy(); + + + intSetInPrimTab[n.label()] = inPrim; + intSetOutPrimTab[n.label()] = outPrm; + IntSet inS = in.get(nasmInst1); + + inS= use.get(nasmInst1).copy().union((out.get(nasmInst1).copy().minus(def.get(nasmInst1).copy()))); + in.replace(nasmInst1,inS); + + + + IntSet union = new IntSet(nbTemp); + + NodeList succ = n.succ(); + + + while (succ!=null){ + if (!in.get(fg.node2Inst.get(succ.head)).copy().isEmpty()){ + IntSet inSuccesseur = in.get(fg.node2Inst.get(succ.head)).copy(); + union = union.union(inSuccesseur); + } + if (succ.tail!=null){ + succ = succ.tail; + } + else + succ = null; + + } + + out.replace(nasmInst1,union); + + } + + + // verification changement + int diff = 0; + for (Node n : fg.graph.nodeArray()) { + NasmInst nasmInstruction = fg.node2Inst.get(n); + IntSet i = in.get(nasmInstruction); + if (!in.get(nasmInstruction).equal(intSetInPrimTab[n.label()])){ + diff = 1; + break; + } + if (!out.get(nasmInstruction).equal(intSetOutPrimTab[n.label()])){ + diff = 1; + break; + } + + } + change = diff == 1; + iterNum++; + }while (change); + + + + } + + } + + diff --git a/src/grammaireL.sablecc b/src/grammaireL.sablecc new file mode 100644 index 0000000000000000000000000000000000000000..0a140052d0eae06652550213037f9a4dd2be5f56 --- /dev/null +++ b/src/grammaireL.sablecc @@ -0,0 +1,192 @@ +Package sc; + +Helpers + +lettre = [['a' .. 'z'] + ['A' .. 'Z']]; +chiffre = ['0' .. '9']; +alpha = [lettre + ['_' + '$']]; +alphanum = [lettre + chiffre]; + +Tokens + +espaces = (' ' | 13 | 10)+; +commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); + +parenthese_fermante = ')'; +accolade_ouvrante = '{'; +accolade_fermante = '}'; +crochet_ouvrant = '['; +crochet_fermant = ']'; +virgule = ','; +p_virgule = ';'; +nombre = chiffre+; +entier = 'entier'; +parenthese_ouvrante = '('; +ou = '|'; +et = '&'; +plus = '+'; +moins = '-'; +division = '/'; +multiplication = '*'; +egal = '='; +inferieur = '<'; +non = '!'; + +si = 'si'; +alors = 'alors'; +sinon = 'sinon'; +tantque = 'tantque'; +faire = 'faire'; +retour = 'retour'; +ecrire = 'ecrire'; +lire = 'lire'; +epsilon = ' '; + +identif = lettre (lettre | chiffre)* ; + + + + +Ignored Tokens + +espaces, commentaire; + +Productions + +program = {program} ldvo ldf; + +ldvo = {ldvo} ldv p_virgule | {epsilon}; + +ldv = {l_dv} dv ldvb | {epsilon}; + +dv = {dec_var} entier identif | {dec_var2} entier identif crochet_ouvrant nombre crochet_fermant; + +ldvb = {l_dvb} virgule dv ldvb | {epsilon} ; + + + +ldf = {ldf} df ldf | {epsilon} ; + +df = {df} identif lparam ldvo ib; + +lparam = {params} parenthese_ouvrante ldv parenthese_fermante; + + + +ib = {ibloc} accolade_ouvrante li accolade_fermante ; + + +li = {liste_i} i li | {epsilon}; + + +i = {i_aff} iaffectation + | {i_si} isi + | {i_tq} itantque + | {i_ret} iret + | {i_app} iappel + | {i_ecr} iecrire + ; + +iaffectation = {affectation} v egal expression p_virgule; + +v = {id} identif + | {idtab} identif crochet_ouvrant expression crochet_fermant; + + +expression = {t1} t1 | {ou} expression ou t1; + + + +t1 = + {t2} t2 + | {et} t1 et t2 ; + +t2 = + {t3} t3 + | {egal} t2 egal t3 + | {inferieur} t2 inferieur t3 ; + +t3 = + {t4} t4 + | {plus} t3 plus t4 + | {moins} t3 moins t4 ; + +t4 = + {t5} t5 + | {multiplication} t4 multiplication t5 + | {division} t4 division t5 ; + +t5 = + {t6} t6 + | {non} non t5 ; + +t6 = + {expression} parenthese_ouvrante expression parenthese_fermante + | {x1} nombre | {x2} v | {app} appel; + + + + +appel = identif parenthese_ouvrante le parenthese_fermante; + + +le = {liste_exp} expression leb | {epsilon}; + +leb = {liste_exp_b} virgule expression leb | {epsilon}; + + + +isi = {si} si expression alors ib + | {sisinon} si expression alors [cas1]:ib sinon [cas2]:ib; + + +itantque = {tantque} tantque expression faire ib; + + +iret = {retourner} retour expression p_virgule; + + + +iappel = {iappel} appel p_virgule; + + + +iecrire = {iecrire} ecrire parenthese_ouvrante expression parenthese_fermante p_virgule; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ig/Ig.java b/src/ig/Ig.java index eaf4886ff148177147648092d82af66a28a03af4..1871a634ce86c20b16390a9f0c29e331b2017724 100644 --- a/src/ig/Ig.java +++ b/src/ig/Ig.java @@ -13,7 +13,7 @@ public class Ig { public int regNb; public Nasm nasm; public Node int2Node[]; - + public Ig(FgSolution fgs){ this.fgs = fgs; @@ -23,10 +23,93 @@ public class Ig { this.int2Node = new Node[regNb]; this.build(); } - + public void build(){ + + for(int i =0; i<regNb; i++){ + int2Node[i] = graph.newNode(); + } + + int nbSommet = nasm.sectionText.size(); + for (int i= 0 ; i<nbSommet;i++){ + NasmInst inst = nasm.sectionText.get(i); + int inInsetSize = fgs.in.get(inst).getSize(); + if (!fgs.in.get(inst).isEmpty()){ + for (int r = 0;r<inInsetSize;r++){ + + for (int r1 = 0; r1<inInsetSize;r1++){ + if(r != r1 && fgs.in.get(inst).isMember(r) && fgs.in.get(inst).isMember(r1)){ + graph.addNOEdge(int2Node[r],int2Node[r1]); + } + + } + } + } + + int outsetSize = fgs.out.get(inst).getSize(); + if(!fgs.out.get(inst).isEmpty()) { + + for (int r = 0; r < outsetSize; r++) { + + for (int r1 = 0; r1 < outsetSize; r1++) { + if (r != r1 && fgs.out.get(inst).isMember(r) && fgs.out.get(inst).isMember(r1)) { + graph.addNOEdge(int2Node[r], int2Node[r1]); + } + + } + } + } + } + } + public int[] getPrecoloredTemporaries() + { + int[] colors = new int[regNb]; + int nbInst = nasm.sectionText.size(); + for (int i= 0 ; i<nbInst;i++){ + NasmInst inst = nasm.sectionText.get(i); + + if (inst.source != null && inst.source.isGeneralRegister()){ + NasmRegister register = (NasmRegister) inst.source; + colors[register.val] = register.color; + } + + if (inst.destination != null && inst.destination.isGeneralRegister()){ + NasmRegister register = (NasmRegister) inst.destination; + colors[register.val] = register.color; + } + + } + + return colors; + } + + + public void allocateRegisters(){ + ColorGraph coloredGraph = new ColorGraph(this.graph,4,getPrecoloredTemporaries()); + coloredGraph.color(); + + int nbInst = nasm.sectionText.size(); + for (int i= 0 ; i<nbInst;i++){ + + NasmInst inst = nasm.sectionText.get(i); + if (inst.source != null && inst.source.isGeneralRegister()){ + NasmRegister register = (NasmRegister) inst.source; + register.color = coloredGraph.color[register.val]; + } + + if (inst.destination != null && inst.destination.isGeneralRegister()){ + NasmRegister register = (NasmRegister) inst.destination; + register.color = coloredGraph.color[register.val]; + } + + } + + + } + + public void affiche(String baseFileName){ String fileName; PrintStream out = System.out; diff --git a/src/io.asm b/src/io.asm new file mode 100644 index 0000000000000000000000000000000000000000..411fa0a0692a7f4eaa81636681c3e30aab27f296 --- /dev/null +++ b/src/io.asm @@ -0,0 +1,205 @@ + global iprintLF +;------------------------------------------ +; void readline +; Read a line from stdin, store string after [$eax] +; WARNING: does not check for buffer overflow - insecure! +readline: + push edx ; preserve edx on stack to be restored after function + push ecx ; preserve ecx on stack to be restored after function + push ebx ; preserve ebx on stack to be restored after function + push eax ; preserve eax on stack to be restored after function + mov ecx, eax ; address where store result +continue_reading: + mov eax, 3 ; syscall is read = 3 + mov ebx, 0 ; fd is stdin = 0 + mov edx, 1 ; nb. of bytes to read + int 80h ; call interruption + cmp eax, 0 ; if no byte read, then we reached EOF, stop + je end_reading + cmp BYTE [ecx], 10 ; Found '\n', stop reading string + je end_reading + cmp BYTE [ecx], 13 ; Found '\r', stop reading string + je end_reading + inc ecx ; None of above, increment pointer and read next byte + jmp continue_reading +end_reading: + mov BYTE [ecx], 0 ; Add zero to yield null-terminated string + pop eax ; restore eax from value pushed onto stack at start + pop ebx ; restore eax from value pushed onto stack at start + pop ecx ; restore eax from value pushed onto stack at start + pop edx ; restore eax from value pushed onto stack at start + ret + +;------------------------------------------ +; void iprint(Integer number) +; Integer printing function (itoa) +iprint: + push eax ; preserve eax on the stack to be restored after function runs + push ecx ; preserve ecx on the stack to be restored after function runs + push edx ; preserve edx on the stack to be restored after function runs + push esi ; preserve esi on the stack to be restored after function runs + + cmp eax, 0 + jge positive + push eax ; preserve eax value + mov ebx, '-' + push ebx + mov eax, esp + call sprint + pop eax ; remove '-' sign + pop eax ; retrieve eax value + neg eax +positive: + mov ecx, 0 ; counter of how many bytes we need to print in the end +divideLoop: + inc ecx ; count each byte to print - number of characters + mov edx, 0 ; empty edx + mov esi, 10 ; mov 10 into esi + idiv esi ; divide eax by esi + add edx, 48 ; convert edx to it's ascii representation - edx holds the remainder after a divide instruction + push edx ; push edx (string representation of an intger) onto the stack + cmp eax, 0 ; can the integer be divided anymore? + jnz divideLoop ; jump if not zero to the label divideLoop + +printLoop: + dec ecx ; count down each byte that we put on the stack + mov eax, esp ; mov the stack pointer into eax for printing + call sprint ; call our string print function + pop eax ; remove last character from the stack to move esp forward + cmp ecx, 0 ; have we printed all bytes we pushed onto the stack? + jnz printLoop ; jump is not zero to the label printLoop + + pop esi ; restore esi from the value we pushed onto the stack at the start + pop edx ; restore edx from the value we pushed onto the stack at the start + pop ecx ; restore ecx from the value we pushed onto the stack at the start + pop eax ; restore eax from the value we pushed onto the stack at the start + ret + + +;------------------------------------------ +; void iprintLF(Integer number) +; Integer printing function with linefeed (itoa) +iprintLF: + call iprint ; call our integer printing function + + push eax ; push eax onto the stack to preserve it while we use the eax register in this function + mov eax, 0Ah ; move 0Ah into eax - 0Ah is the ascii character for a linefeed + push eax ; push the linefeed onto the stack so we can get the address + mov eax, esp ; move the address of the current stack pointer into eax for sprint + call sprint ; call our sprint function + pop eax ; remove our linefeed character from the stack + pop eax ; restore the original value of eax before our function was called + ret + + +;------------------------------------------ +; int slen(String message) +; String length calculation function +slen: + push ebx + mov ebx, eax + +nextchar: + cmp byte [eax], 0 + jz finished + inc eax + jmp nextchar + +finished: + sub eax, ebx + pop ebx + ret + + +;------------------------------------------ +; void sprint(String message) +; String printing function +sprint: + push edx + push ecx + push ebx + push eax + call slen + + mov edx, eax + pop eax + + mov ecx, eax + mov ebx, 1 + mov eax, 4 + int 80h + + pop ebx + pop ecx + pop edx + ret + + +;------------------------------------------ +; void sprintLF(String message) +; String printing with line feed function +sprintLF: + call sprint + + push eax + mov eax, 0AH + push eax + mov eax, esp + call sprint + pop eax + pop eax + ret + + +;------------------------------------------ +; void exit() +; Exit program and restore resources +quit: + mov ebx, 0 + mov eax, 1 + int 80h + ret + +;------------------------------------------ +; int atoi(Integer number) +; Ascii to integer function (atoi) +atoi: + push ebx ; preserve ebx on the stack to be restored after function runs + push ecx ; preserve ecx on the stack to be restored after function runs + push edx ; preserve edx on the stack to be restored after function runs + push esi ; preserve esi on the sr_par=')'tack to be restored after function runs + xor ebx, ebx ; initialize forming answer + xor ecx, ecx ; initialize sign flag + mov esi, eax +atoi1: + lodsb ; scan off whitespace + cmp al, ' ' ; ignore leading blanks + je atoi1 + cmp al, '+' ; if + sign proceed + je atoi2 + cmp al, '-' ; is it - sign? + jne atoi3 ; no, test if numeric + dec ecx ; was - sign, set flag for negative result +atoi2: + lodsb ; get next character +atoi3: + cmp al,'0' ; is character valid? + jb atoi4 ; jump if not '0' to '9' + cmp al,'9' + ja atoi4 ; jump if not '0' to '9' + and eax, 000fh ; isolate lower four bits + xchg ebx, eax ; multiply answer x 10 + mov edx, 10 + mul edx + add ebx, eax ; add this digit + jmp atoi2 ; convert next digit +atoi4: + mov eax,ebx ; result into AX + jcxz atoi5 ; jump if sign flag clear + neg eax ; make result negative +atoi5: + pop esi ; restore esi from the value we pushed onto the stack at the start + pop edx ; restore edx from the value we pushed onto the stack at the start + pop ecx ; restore ecx from the value we pushed onto the stack at the start + pop ebx ; restore ebx from the value we pushed onto the stack at the start + ret diff --git a/src/l.cfg b/src/l.cfg deleted file mode 100644 index d255ffd8509e8e4f2d4a54a21bdd8b50ab4ae95f..0000000000000000000000000000000000000000 --- a/src/l.cfg +++ /dev/null @@ -1,155 +0,0 @@ -Package sc; - -Helpers - -lettre = [['a' .. 'z'] + ['A' .. 'Z']]; -chiffre = ['0' .. '9']; -alpha = [lettre + ['_' + '$']]; -alphanum = [lettre + chiffre]; - -Tokens - -espaces = (' ' | 13 | 10)+; -commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); -virgule = ','; -nombre = chiffre+; -ecrire = 'ecrire'; -retour = 'retour'; -ptvirgule = ';' ; -parenthouvrante = '('; -parenthfermante = ')'; -crochetouvrant = '['; -crochetfermant = ']'; -accolateouvrant = '{'; -accolatefermant = '}'; - - -egal = '='; -plus = '+'; -moins = '-'; -mult = '*'; -div= '/'; -modulo = '%'; -ou = '|'; -et = '&'; -negation = '!'; -inferieur = '<'; -superieur = '>'; - - - - -vrai = 'vrai'; -faux = 'faux'; - -si = 'si'; -sinon = 'sinon'; -alors = 'alors'; -tantque = 'tantque'; -faire = 'faire'; -lire = 'lire'; -entier = 'entier'; -bool = 'bool'; - - - -concat = ' '; - -identif = alpha alphanum*; -Ignored Tokens - -espaces, commentaire; - -Productions - -programme = listedecvar listedecfonc; - -listedecvar = - {liste_des_variables} decvar listedecvarp | {vide}; - -listedecvarp = - {liste_des_variables_prime} virgule decvar listedecvarp | {vide}; - -decvar = - {type1} type identif | {type2} type identif crochetouvrant nombre crochetfermant ; - -listedecfonc = - {liste_des_fonctions} decfonc listedecfonc | {vide}; - -decfonc = - typeop identif parenthouvrante [parametre]:listedecvar parenthfermante [varloc]:listedecvar blocinst ; - -type = - {entier} entier | {boolean} bool ; - -typeop = - {type} type | {vide}; - -blocinst = - accolateouvrant listeinst accolatefermant ; - -listeinst = - {liste_instruction} inst listeinst | {vide} ; - -inst = - {variable} var egal expr ptvirgule | - {condition_si} si expr alors blocinst | - {condition_sinon} si expr alors [blocinstsi] : blocinst sinon [blocinstsinon] : blocinst | - {condition_tantque} tantque expr faire blocinst | - {condition_appelle_de_fonction} identif parenthouvrante listeexpr parenthfermante ptvirgule | - {ecrire} ecrire parenthouvrante expr parenthfermante ptvirgule | - {condition_return} retour expr ptvirgule ; - -listeexpr = - {liste_expression} expr listeexprp | {vide} ; - -listeexprp = - {liste_expression_prime} virgule expr listeexprp | {vide} ; - -expr = - {condition_ou} expr ou expr1 | - {expr1} expr1 ; - -expr1 = - {condition_et} expr1 et expr2 | - {expr2} expr2 ; - -expr2 = - {condition_egal} expr2 egal expr3 | - {condition_inf} expr2 inferieur expr3 | - {expr3} expr3 ; - -expr3 = - {condtion_plus} expr3 plus expr4 | - {condition_moins} expr3 moins expr4 | - {expr4} expr4 ; - -expr4 = - {condition_mult} expr4 mult expr5 | - {condition_div} expr4 div expr5 | - {expr5} expr5 ; - -expr5 = - {condition_negation} negation expr5 | - {expr6} expr6 ; - -expr6 = - {expr} parenthouvrante expr parenthfermante | - {nombre} nombre | - {vrai} vrai | - {faux} faux | - {identifiant} identif parenthouvrante listeexpr parenthfermante | - {lire} lire parenthouvrante parenthfermante | - {variable} var ; - -expr7 = {condition_concat} expr7 concat expr8 | {expr} expr8; -expr8 = {identif} identif | parenthouvrante expr7 parenthfermante ; - - - -var = - {id1} identif | - {id2}identif crochetouvrant expr crochetfermant ; - - - diff --git a/src/nasm.cfg b/src/nasm.cfg deleted file mode 100644 index cbc3812ff198b459a7b8ef13cd583983504283d9..0000000000000000000000000000000000000000 --- a/src/nasm.cfg +++ /dev/null @@ -1,210 +0,0 @@ -Package nasmParser; - -Helpers - -letter = [['a' .. 'z'] + ['A' .. 'Z']]; -digit = ['0' .. '9']; -alpha = [letter + ['_' + '$']]; -alphanum = [letter + digit]; - -Tokens - -spaces = (' ' | 13 | 10 | 9)+; -comment= ';' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); - -plus = '+'; -minus = '-'; -times = '*'; -brackopen = '['; -brackclose = ']'; -semicol = ':'; -comma = ','; -quote = '''; -dot = '.'; -percentage = '%'; -byte = 'byte'; -word = 'word'; -dword = 'dword'; -prefix_register = '@'; - -inc = 'include'; -section = 'section'; - -data = '.data'; -definebyte = 'db'; -defineword = 'dw'; -definedoubleword = 'dd'; -definequadword = 'dq'; -definetenbytes = 'dt'; - -bss = '.bss'; -reservebyte = 'resb'; -reserveword = 'resw'; -reservedoubleword = 'resd'; -reservequadword = 'resq'; -reservetenbytes = 'rest'; - -text = '.text'; - -global = 'global'; - -mov = 'mov'; -push = 'push'; -pop = 'pop'; -add = 'add'; -sub = 'sub'; -imul = 'imul'; -idiv = 'idiv'; -and = 'and'; -or = 'or'; -xor = 'xor'; -not = 'not'; -cmp = 'cmp'; -jmp = 'jmp'; -je = 'je'; -jne = 'jne'; -jg = 'jg'; -jge = 'jge'; -jl = 'jl'; -jle = 'jle'; -call = 'call'; -ret = 'ret'; -int = 'int 0x80'; - -eax = 'eax'; -ebx = 'ebx'; -ecx = 'ecx'; -edx = 'edx'; -ebp = 'ebp'; -esp = 'esp'; - -number = digit+; - -id = alpha alphanum*; - -Ignored Tokens - -spaces, comment; - -Productions - -prog = linclude secdata secbss sectext; - -linclude = {rec} include linclude - | {empty}; - -include = percentage inc [open]: quote filename [close]: quote ; - -filename = {simple} label - | {complex} [prefix]: label dot [suffix]: label - ; - -secdata = {nonempty} section data lconst - | {empty} - ; - -lconst = {rec} const lconst - | {empty} ; - -const = {db} label definebyte numconst - | {dw} label defineword numconst - | {dd} label definedoubleword numconst - | {dq} label definequadword numconst - | {dt} label definetenbytes numconst - ; - -secbss = {nonempty} section bss lvar - | {empty} - ; - -lvar = {rec} var lvar - | {empty} - ; - -var = {resb} label semicol reservebyte number - | {resw} label semicol reserveword number - | {resd} label semicol reservedoubleword number - | {resq} label semicol reservequadword number - | {rest} label semicol reservetenbytes number - ; - -sectext = section text lglobal linst; - -lglobal = {rec} global label lglobal - | {empty} - ; - -linst = {rec} inst linst | - {last} inst - ; - -inst = {mov} oplabel mov ar comma acr - | {push} oplabel push acr - | {pop} oplabel pop ar - | {add} oplabel add ar comma acr - | {sub} oplabel sub ar comma acr - | {imul} oplabel imul ar comma acr - | {idiv} oplabel idiv ar - | {and} oplabel and ar comma acr - | {or} oplabel or ar comma acr - | {xor} oplabel xor ar comma acr - | {not} oplabel not ar - | {cmp} oplabel cmp ar comma acr - | {jmp} oplabel jmp label - | {je} oplabel je label - | {jne} oplabel jne label - | {jg} oplabel jg label - | {jge} oplabel jge label - | {jl} oplabel jl label - | {call} oplabel call label - | {ret} oplabel ret - | {inter} oplabel int - ; - -acr = {address} address - | {numconst} numconst - | {register} register - ; - -ar = {address} address - | {register} register - ; - -address = opsizeof brackopen exp brackclose; - -opsizeof = {byte} byte - | {word} word - | {dword} dword - | {empty} - ; - -exp = {plus} exp plus exp1 - | {minus} exp minus exp1 - | {next} exp1 - ; - -exp1 = {times} exp1 times exp2 - | {next} exp2 - ; - -exp2 = {label} label - | {numconst} numconst - | {register} register - ; - -numconst = number; - -register = {temp} prefix_register number - | {eax} eax - | {ebx} ebx - | {ecx} ecx - | {edx} edx - | {ebp} ebp - | {esp} esp - ; - -oplabel = {label} label semicol - | {empty} - ; - -label = id; diff --git a/src/nasm/C3a2nasm.java b/src/nasm/C3a2nasm.java index de33f5cf53abc9f77d42922fa678d27e59974e96..cc69a3ea804752385172bc8a1a904208913bc163 100644 --- a/src/nasm/C3a2nasm.java +++ b/src/nasm/C3a2nasm.java @@ -11,49 +11,342 @@ public class C3a2nasm implements C3aVisitor <NasmOperand> { private NasmRegister esp; private NasmRegister ebp; - public C3a2nasm(C3a c3a, Ts tableGlobale){ - this.c3a = c3a; - nasm = new Nasm(tableGlobale); - nasm.setTempCounter(c3a.getTempCounter()); + this.c3a = c3a; + nasm = new Nasm(tableGlobale); + nasm.setTempCounter(c3a.getTempCounter()); + System.out.println("temp counter nb " + nasm.getTempCounter()); + + this.tableGlobale = tableGlobale; + this.currentFct = null; + esp = new NasmRegister(-1); + esp.colorRegister(Nasm.REG_ESP); - this.tableGlobale = tableGlobale; - this.currentFct = null; - esp = new NasmRegister(-1); - esp.colorRegister(Nasm.REG_ESP); + ebp = new NasmRegister(-1); + ebp.colorRegister(Nasm.REG_EBP); - ebp = new NasmRegister(-1); - ebp.colorRegister(Nasm.REG_EBP); + NasmOperand res; + for(C3aInst c3aInst : c3a.listeInst){ + // System.out.println("<" + c3aInst.getClass().getSimpleName() + ">"); + res = c3aInst.accept(this); + } + System.out.println("temp counter nb " + nasm.getTempCounter()); } public Nasm getNasm(){return nasm;} + /*-------------------------------------------------------------------------------------------------------------- + transforme une opérande trois adresses en une opérande asm selon les règles suivantes : + + C3aConstant -> NasmConstant + C3aTemp -> NasmRegister + C3aLabel -> NasmLabel + C3aFunction -> NasmLabel + C3aVar -> NasmAddress + --------------------------------------------------------------------------------------------------------------*/ + + public NasmOperand visit(C3aConstant oper) + { + return new NasmConstant(oper.val); + } + + public NasmOperand visit(C3aLabel oper) + { + return new NasmLabel(oper.toString()); + } + + public NasmOperand visit(C3aTemp oper) + { + return new NasmRegister(oper.num); + } + + public NasmOperand visit(C3aVar oper) + { + if (oper.index == null){ + if (oper.item.isParam){ + return new NasmAddress(ebp,'+',new NasmConstant(8+(4* oper.item.portee.nbArg())-oper.item.adresse)); + } + else if (!oper.item.portee.equals(tableGlobale)){ + return new NasmAddress(ebp,'-',new NasmConstant(4+oper.item.adresse)); + } + else { + + return new NasmAddress(new NasmLabel(oper.item.identif)); + } + + } + NasmOperand index = oper.index.accept(this); + NasmRegister register = nasm.newRegister(); + nasm.ajouteInst(new NasmMov(null,register,index,"")); + nasm.ajouteInst(new NasmMul(null,register,new NasmConstant(4),"")); + return new NasmAddress(new NasmLabel(oper.item.identif),'+',register); + } + + public NasmOperand visit(C3aFunction oper) + { + return new NasmLabel(oper.toString()); + } + + + + /*--------------------------------------------------------------------------------------------------------------*/ + + + public NasmOperand visit(C3aInstAdd inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmMov(label, inst.result.accept(this), inst.op1.accept(this), "")); + nasm.ajouteInst(new NasmAdd(null , inst.result.accept(this), inst.op2.accept(this), "")); + return null; + } + + public NasmOperand visit(C3aInstSub inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmMov(label, inst.result.accept(this), inst.op1.accept(this), "")); + nasm.ajouteInst(new NasmSub(null , inst.result.accept(this), inst.op2.accept(this), "")); + return null; +} + + public NasmOperand visit(C3aInstMult inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmMov(label, inst.result.accept(this), inst.op1.accept(this), "")); + nasm.ajouteInst(new NasmMul(null , inst.result.accept(this), inst.op2.accept(this), "")); + return null; +} + + public NasmOperand visit(C3aInstDiv inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmOperand op1 = inst.op1.accept(this); + NasmOperand op2 = inst.op2.accept(this); + + NasmRegister reg_eax = nasm.newRegister(); + reg_eax.colorRegister(Nasm.REG_EAX); + nasm.ajouteInst(new NasmMov(label, reg_eax,op1, "")); + + + + + + if (op2.isGeneralRegister()) + nasm.ajouteInst(new NasmDiv(null,inst.op2.accept(this),"")); + else { + + NasmRegister reg_ebx = nasm.newRegister(); + + nasm.ajouteInst(new NasmMov(null, reg_ebx,op2, "")); + nasm.ajouteInst(new NasmDiv(null,reg_ebx,"")); + + } + + NasmRegister reg_eax1 = nasm.newRegister(); + reg_eax1.colorRegister(Nasm.REG_EAX); + nasm.ajouteInst(new NasmMov(null,inst.result.accept(this),reg_eax1,"")); + + + + return null; +} + + + public NasmOperand visit(C3aInstCall inst) + { + + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmSub(label,esp,new NasmConstant(4),"allocation mémoire pour la valeur de retour")); + nasm.ajouteInst(new NasmCall(null,inst.op1.accept(this),"")); + NasmOperand reg_eax = inst.result.accept(this); + nasm.ajouteInst(new NasmPop(label,reg_eax,"récupération de la valeur de retour")); + + + if (inst.op1.val.nbArgs!=0) + nasm.ajouteInst(new NasmAdd(label,esp,new NasmConstant(4*(inst.op1.val.nbArgs)),"désallocation des arguments")); + + return null; +} + + public NasmOperand visit(C3aInstFBegin inst) + { + currentFct = inst.val; + NasmOperand label = new NasmLabel(inst.val.identif); + + nasm.ajouteInst(new NasmPush(label,ebp,"sauvegarde la valeur de ebp")); + nasm.ajouteInst(new NasmMov(null,ebp,esp,"nouvelle valeur de ebp")); + NasmRegister reg_eax = nasm.newRegister(); + reg_eax.colorRegister(Nasm.REG_EAX); - public NasmOperand visit(C3a c3a){return null;} - public NasmOperand visit(C3aInstAdd inst){return null;} - public NasmOperand visit(C3aInstCall inst){return null;} - public NasmOperand visit(C3aInstFBegin inst){return null;} - public NasmOperand visit(C3aInst inst){return null;} - public NasmOperand visit(C3aInstJumpIfLess inst){return null;} - public NasmOperand visit(C3aInstMult inst){return null;} - public NasmOperand visit(C3aInstRead inst){return null;} - public NasmOperand visit(C3aInstSub inst){return null;} - public NasmOperand visit(C3aInstAffect inst){return null;} - public NasmOperand visit(C3aInstDiv inst){return null;} - public NasmOperand visit(C3aInstFEnd inst){return null;} - public NasmOperand visit(C3aInstJumpIfEqual inst){return null;} - public NasmOperand visit(C3aInstJumpIfNotEqual inst){return null;} - public NasmOperand visit(C3aInstJump inst){return null;} - public NasmOperand visit(C3aInstParam inst){return null;} - public NasmOperand visit(C3aInstReturn inst){return null;} - public NasmOperand visit(C3aInstWrite inst){return null;} - public NasmOperand visit(C3aInstStop inst){return null;} - - public NasmOperand visit(C3aConstant oper){return null;} - public NasmOperand visit(C3aBooleanConstant oper){return null;} - public NasmOperand visit(C3aLabel oper){return null;} - public NasmOperand visit(C3aTemp oper){return null;} - public NasmOperand visit(C3aVar oper){return null;} - public NasmOperand visit(C3aFunction oper){return null;} + NasmRegister reg_ebx = nasm.newRegister(); + reg_ebx.colorRegister(Nasm.REG_EBX); + + NasmRegister reg_ecx = nasm.newRegister(); + reg_ecx.colorRegister(Nasm.REG_ECX); + + NasmRegister reg_edx = nasm.newRegister(); + reg_edx.colorRegister(Nasm.REG_EDX); + + + + nasm.ajouteInst(new NasmPush(null,reg_eax,"sauvegarde de eax")); + + nasm.ajouteInst(new NasmPush(null,reg_ebx,"sauvegarde de ebx")); + nasm.ajouteInst(new NasmPush(null,reg_ecx,"sauvegarde de ecx")); + nasm.ajouteInst(new NasmPush(null,reg_edx,"sauvegarde de edx")); + + + int nbVar = inst.val.saDecFonc.getVariable() == null?0:inst.val.saDecFonc.getVariable().length(); + nasm.ajouteInst(new NasmSub(null,esp,new NasmConstant(4*nbVar),"allocation des variables locales")); + return null; + } + + public NasmOperand visit(C3aInst inst) + { + inst.accept(this); + return null; + } + + public NasmOperand visit(C3aInstJumpIfLess inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmOperand op1 = inst.op1.accept(this); + if (op1.isGeneralRegister()) + nasm.ajouteInst(new NasmCmp(label,op1,inst.op2.accept(this),"JumpIfLess 1")); + else { + NasmRegister reg_eax = nasm.newRegister(); + nasm.ajouteInst(new NasmMov(label,reg_eax,op1,"JumpIfLess 1")); + nasm.ajouteInst(new NasmCmp(null,reg_eax,inst.op2.accept(this),"on passe par un registre temporaire")); + } + + nasm.ajouteInst(new NasmJl(null,inst.result.accept(this),"JumpIfLess 2")); + return null; + } + + public NasmOperand visit(C3aInstRead inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmRegister reg_eax = nasm.newRegister(); + reg_eax.colorRegister(Nasm.REG_EAX); + nasm.ajouteInst(new NasmMov(label,reg_eax,new NasmLabel("sinput"),"")); + nasm.ajouteInst(new NasmCall(label,new NasmLabel("readline"),"")); + nasm.ajouteInst(new NasmCall(label,new NasmLabel("atoi"),"")); + nasm.ajouteInst(new NasmMov(label,new NasmRegister(c3a.getTempCounter()),reg_eax,"")); + return null; + } + + public NasmOperand visit(C3aInstAffect inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmMov(label,inst.result.accept(this),inst.op1.accept(this),"Affect")); + return null; + } + + public NasmOperand visit(C3aInstFEnd inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + + + NasmRegister reg_eax = nasm.newRegister(); + reg_eax.colorRegister(Nasm.REG_EAX); + + NasmRegister reg_ebx = nasm.newRegister(); + reg_ebx.colorRegister(Nasm.REG_EBX); + + NasmRegister reg_ecx = nasm.newRegister(); + reg_ecx.colorRegister(Nasm.REG_ECX); + + NasmRegister reg_edx = nasm.newRegister(); + reg_edx.colorRegister(Nasm.REG_EDX); + + int nbrVar = currentFct.saDecFonc.getVariable()!=null ? currentFct.saDecFonc.getVariable().length() : 0; + nasm.ajouteInst(new NasmAdd(label,esp,new NasmConstant(nbrVar*4),"désallocation des variables locales")); + + + nasm.ajouteInst(new NasmPop(null,reg_edx,"restaure edx")); + nasm.ajouteInst(new NasmPop(null,reg_ecx,"restaure ecx")); + nasm.ajouteInst(new NasmPop(null,reg_ebx,"restaure ebx")); + nasm.ajouteInst(new NasmPop(null,reg_eax,"restaure eax")); + + + nasm.ajouteInst(new NasmPop(null,ebp,"restaure la valeur de ebp")); + nasm.ajouteInst(new NasmRet(null,"")); + return null; + } + + public NasmOperand visit(C3aInstJumpIfEqual inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmOperand op1 = inst.op1.accept(this); + if (op1.isGeneralRegister()) + nasm.ajouteInst(new NasmCmp(label,op1,inst.op2.accept(this),"JumpIfEqual 1")); + else { + NasmRegister reg_eax = nasm.newRegister(); + nasm.ajouteInst(new NasmMov(label,reg_eax,op1,"JumpIfEqual 1")); + nasm.ajouteInst(new NasmCmp(null,reg_eax,inst.op2.accept(this),"on passe par un registre temporaire")); + } + + nasm.ajouteInst(new NasmJe(null,inst.result.accept(this),"JumpIfEqual 2")); + return null; + } + + public NasmOperand visit(C3aInstJumpIfNotEqual inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmOperand op1 = inst.op1.accept(this); + if (op1.isGeneralRegister()) + nasm.ajouteInst(new NasmCmp(label,op1,inst.op2.accept(this),"jumpIfNotEqual 1")); + else { + NasmRegister reg_eax = nasm.newRegister(); + nasm.ajouteInst(new NasmMov(label,reg_eax,op1,"jumpIfNotEqual 1")); + nasm.ajouteInst(new NasmCmp(null,reg_eax,inst.op2.accept(this),"on passe par un registre temporaire")); + } + + nasm.ajouteInst(new NasmJne(null,inst.result.accept(this),"jumpIfNotEqual 2")); + return null; } + + public NasmOperand visit(C3aInstJump inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmJmp(label,inst.result.accept(this),"Jump")); + return null; + } + + public NasmOperand visit(C3aInstParam inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmPush(label,inst.op1.accept(this),"Param")); + return null; + } + + public NasmOperand visit(C3aInstReturn inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + nasm.ajouteInst(new NasmMov(null,new NasmAddress(ebp,'+',new NasmConstant(8)),inst.op1.accept(this),"ecriture de la valeur de retour")); + return null; + } + + public NasmOperand visit(C3aInstWrite inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmRegister reg_eax = nasm.newRegister(); + reg_eax.colorRegister(Nasm.REG_EAX); + nasm.ajouteInst(new NasmMov(label,reg_eax,inst.op1.accept(this),"Write 1")); + nasm.ajouteInst(new NasmCall(null,new NasmLabel("iprintLF"),"Write 2")); + return null; + } + + public NasmOperand visit(C3aInstStop inst) + { + NasmOperand label = (inst.label != null) ? inst.label.accept(this) : null; + NasmRegister reg_ebx = nasm.newRegister(); + reg_ebx.colorRegister(Nasm.REG_EBX); + nasm.ajouteInst(new NasmMov(label,reg_ebx,new NasmConstant(0)," valeur de retour du programme")); + NasmRegister reg_eax = nasm.newRegister(); + reg_eax.colorRegister(Nasm.REG_EAX); + nasm.ajouteInst(new NasmMov(label,reg_eax,new NasmConstant(1)," code de sortie")); + + nasm.ajouteInst(new NasmInt(label,"")); + return null; + } } diff --git a/src/nasm/LoadNasm.java b/src/nasm/LoadNasm.java deleted file mode 100644 index e68802c4e5f0b303877c33d8fc67a565c183b92a..0000000000000000000000000000000000000000 --- a/src/nasm/LoadNasm.java +++ /dev/null @@ -1,1117 +0,0 @@ -package nasm; -import nasmParser.analysis.DepthFirstAdapter; -import nasmParser.lexer.Lexer; -import nasmParser.lexer.LexerException; -import nasmParser.node.*; -import nasmParser.parser.Parser; -import nasmParser.parser.ParserException; -//import sc.analysis.DepthFirstAdapter; -import util.Error; - -import java.io.FileReader; -import java.io.IOException; -import java.io.PushbackReader; - -public class LoadNasm extends DepthFirstAdapter { - private Nasm nasm; - private NasmInst inst; - private NasmPseudoInst pseudoInst; - private NasmOperand operand; - private NasmLabel label; - private NasmExp exp; - private NasmSize size; - public LoadNasm(String nasmFileName) { - nasm = new Nasm(); - PushbackReader fileReader = null; - Parser parser = null; - Start root = null; - try { - fileReader = new PushbackReader(new FileReader(nasmFileName)); - } catch (IOException e) { - System.err.println("cannot open input file"); - e.printStackTrace(); - } - try { - parser = new Parser(new Lexer(fileReader)); - root = parser.parse(); - } catch (ParserException e) { - System.err.println("syntax error"); - e.printStackTrace(); - System.exit(Error.SYNT.code()); - } catch (LexerException e) { - System.err.println("lexical error"); - e.printStackTrace(); - System.exit(Error.LEX.code()); - } catch (IOException e) { - e.printStackTrace(); - } - root.apply(this); - } - - public void defaultIn(Node node) - { - // System.out.println("<" + node.getClass().getSimpleName() + ">"); - } - - public void defaultOut(Node node) - { - // System.out.println("</" + node.getClass().getSimpleName() + ">"); - } - - public Nasm getNasm(){return nasm;} - - - // prog = linclude secdata secbss sectext - @Override - public void caseAProg(AProg node) - { - inAProg(node); - if(node.getLinclude() != null) - { - node.getLinclude().apply(this); - } - if(node.getSecdata() != null) - { - node.getSecdata().apply(this); - } - if(node.getSecbss() != null) - { - node.getSecbss().apply(this); - } - if(node.getSectext() != null) - { - node.getSectext().apply(this); - } - outAProg(node); - } - - // linclude = {rec} include linclude - @Override - public void caseARecLinclude(ARecLinclude node) - { - inARecLinclude(node); - if(node.getInclude() != null) - { - node.getInclude().apply(this); - } - if(node.getLinclude() != null) - { - node.getLinclude().apply(this); - } - outARecLinclude(node); - } - - // linclude = {empty} - @Override - public void caseAEmptyLinclude(AEmptyLinclude node) - { - inAEmptyLinclude(node); - outAEmptyLinclude(node); - } - - // include = percentage inc [open]: quote filename [close]: quote - @Override - public void caseAInclude(AInclude node) - { - inAInclude(node); - if(node.getPercentage() != null) - { - node.getPercentage().apply(this); - } - if(node.getInc() != null) - { - node.getInc().apply(this); - } - if(node.getOpen() != null) - { - node.getOpen().apply(this); - } - if(node.getFilename() != null) - { - node.getFilename().apply(this); - } - if(node.getClose() != null) - { - node.getClose().apply(this); - } - outAInclude(node); - } - - // filename = {simple} label - @Override - public void caseASimpleFilename(ASimpleFilename node) - { - inASimpleFilename(node); - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - outASimpleFilename(node); - } - - // filename = {complex} [prefix]: label dot [suffix]: label - @Override - public void caseAComplexFilename(AComplexFilename node) - { - inAComplexFilename(node); - if(node.getPrefix() != null) - { - node.getPrefix().apply(this); - } - if(node.getDot() != null) - { - node.getDot().apply(this); - } - if(node.getSuffix() != null) - { - node.getSuffix().apply(this); - } - outAComplexFilename(node); - } - - // secdata = {nonempty} section data lconst - @Override - public void caseANonemptySecdata(ANonemptySecdata node) - { - inANonemptySecdata(node); - if(node.getSection() != null) - { - node.getSection().apply(this); - } - if(node.getData() != null) - { - node.getData().apply(this); - } - if(node.getLconst() != null) - { - node.getLconst().apply(this); - } - outANonemptySecdata(node); - } - - // secdata = {empty} - @Override - public void caseAEmptySecdata(AEmptySecdata node) - { - inAEmptySecdata(node); - outAEmptySecdata(node); - } - - // lconst = {rec} const lconst - @Override - public void caseARecLconst(ARecLconst node) - { - inARecLconst(node); - if(node.getConst() != null) - { - node.getConst().apply(this); - } - if(node.getLconst() != null) - { - node.getLconst().apply(this); - } - outARecLconst(node); - } - - - // lconst = {empty} - @Override - public void caseAEmptyLconst(AEmptyLconst node) - { - inAEmptyLconst(node); - outAEmptyLconst(node); - } - - // const = {db} label definebyte numconst - @Override - public void caseADbConst(ADbConst node) - { - inADbConst(node); - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - if(node.getDefinebyte() != null) - { - node.getDefinebyte().apply(this); - } - if(node.getNumconst() != null) - { - node.getNumconst().apply(this); - } - outADbConst(node); - } - - // const = {dw} label defineword numconst - @Override - public void caseADwConst(ADwConst node) - { - inADwConst(node); - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - if(node.getDefineword() != null) - { - node.getDefineword().apply(this); - } - if(node.getNumconst() != null) - { - node.getNumconst().apply(this); - } - outADwConst(node); - } - - // const = {dd} label definedoubleword numconst - @Override - public void caseADdConst(ADdConst node) - { - inADdConst(node); - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - if(node.getDefinedoubleword() != null) - { - node.getDefinedoubleword().apply(this); - } - if(node.getNumconst() != null) - { - node.getNumconst().apply(this); - } - outADdConst(node); - } - // const = {dq} label definequadword numconst - @Override - public void caseADqConst(ADqConst node) - { - inADqConst(node); - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - if(node.getDefinequadword() != null) - { - node.getDefinequadword().apply(this); - } - if(node.getNumconst() != null) - { - node.getNumconst().apply(this); - } - outADqConst(node); - } - // const = {dt} label definetenbytes numconst - @Override - public void caseADtConst(ADtConst node) - { - inADtConst(node); - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - if(node.getDefinetenbytes() != null) - { - node.getDefinetenbytes().apply(this); - } - if(node.getNumconst() != null) - { - node.getNumconst().apply(this); - } - outADtConst(node); - } - - - // secbss = {nonempty} section bss lvar - @Override - public void caseANonemptySecbss(ANonemptySecbss node) - { - inANonemptySecbss(node); - if(node.getSection() != null) - { - node.getSection().apply(this); - } - if(node.getBss() != null) - { - node.getBss().apply(this); - } - if(node.getLvar() != null) - { - node.getLvar().apply(this); - } - outANonemptySecbss(node); - } - // secbss = {empty} - @Override - public void caseAEmptySecbss(AEmptySecbss node) - { - inAEmptySecbss(node); - outAEmptySecbss(node); - } - - // lvar = {rec} var lvar - @Override - public void caseARecLvar(ARecLvar node) - { - inARecLvar(node); - node.getVar().apply(this); - nasm.ajoutePseudoInst(pseudoInst); - node.getLvar().apply(this); - outARecLvar(node); - } - // lvar = {empty} - @Override - public void caseAEmptyLvar(AEmptyLvar node) - { - inAEmptyLvar(node); - outAEmptyLvar(node); - } - - // var = {resb} label reservebyte number - @Override - public void caseAResbVar(AResbVar node) - { - inAResbVar(node); - node.getLabel().apply(this); - - int nb = Integer.parseInt(node.getNumber().getText()); - pseudoInst = new NasmResb(label,nb,""); - outAResbVar(node); - } - // var = {resw} label reserveword number - @Override - public void caseAReswVar(AReswVar node) - { - inAReswVar(node); - node.getLabel().apply(this); - int nb = Integer.parseInt(node.getNumber().getText()); - pseudoInst = new NasmResw(label,nb,""); - outAReswVar(node); - } - // var = {resd} label reservedoubleword number - @Override - public void caseAResdVar(AResdVar node) - { - inAResdVar(node); - node.getLabel().apply(this); - int nb = Integer.parseInt(node.getNumber().getText()); - pseudoInst = new NasmResd(label,nb,""); - outAResdVar(node); - } - // var = {resq} label reservequadword number - @Override - public void caseAResqVar(AResqVar node) - { - inAResqVar(node); - node.getLabel().apply(this); - int nb = Integer.parseInt(node.getNumber().getText()); - pseudoInst = new NasmResq(label,nb,""); - outAResqVar(node); - } - // var = {rest} label reservetenbytes number - @Override - public void caseARestVar(ARestVar node) - { - inARestVar(node); - node.getLabel().apply(this); - int nb = Integer.parseInt(node.getNumber().getText()); - pseudoInst = new NasmRest(label,nb,""); - outARestVar(node); - } - - // sectext = section text lglobal linst - ////////////////////// - @Override - public void caseASectext(ASectext node) - { - inASectext(node); - if(node.getSection() != null) - { - node.getSection().apply(this); - } - if(node.getText() != null) - { - node.getText().apply(this); - } - if(node.getLglobal() != null) - { - node.getLglobal().apply(this); - } - if(node.getLinst() != null) - { - node.getLinst().apply(this); - } - outASectext(node); - } - - // lglobal = {rec} global label lglobal - @Override - public void caseARecLglobal(ARecLglobal node) - { - inARecLglobal(node); - if(node.getGlobal() != null) - { - node.getGlobal().apply(this); - } - if(node.getLabel() != null) - { - node.getLabel().apply(this); - } - if(node.getLglobal() != null) - { - node.getLglobal().apply(this); - } - outARecLglobal(node); - } - // lglobal = {empty} - @Override - public void caseAEmptyLglobal(AEmptyLglobal node) - { - inAEmptyLglobal(node); - outAEmptyLglobal(node); - } - - - // linst = {rec} inst linst - @Override - public void caseARecLinst(ARecLinst node) - { - inARecLinst(node); - node.getInst().apply(this); - nasm.ajouteInst(inst); - label = null; - exp = null; - size = null; - operand = null; - - node.getLinst().apply(this); - outARecLinst(node); - } - - // linst = {last} inst - @Override - public void caseALastLinst(ALastLinst node) - { - inALastLinst(node); - node.getInst().apply(this); - nasm.ajouteInst(inst); - label = null; - exp = null; - size = null; - operand = null; - outALastLinst(node); - } - - - // inst = {mov} oplabel mov ar comma acr - @Override - public void caseAMovInst(AMovInst node) - { - inAMovInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - - node.getAcr().apply(this); - NasmOperand source = operand; - - inst = new NasmMov(lineLabel, destination, source, ""); - outAMovInst(node); - } - - // inst = {push} oplabel push acr - @Override - public void caseAPushInst(APushInst node) - { - inAPushInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmPush(lineLabel, source, ""); - outAPushInst(node); - } - - // inst = {pop} oplabel pop ar - @Override - public void caseAPopInst(APopInst node) - { - inAPopInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - - node.getAr().apply(this); - NasmOperand destination = operand; - inst = new NasmPop(lineLabel, destination, ""); - outAPopInst(node); - } - - // inst = {add} oplabel add ar comma acr - @Override - public void caseAAddInst(AAddInst node) - { - inAAddInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmAdd(lineLabel, destination, source, ""); - outAAddInst(node); - } - - // inst = {sub} oplabel sub ar comma acr - @Override - public void caseASubInst(ASubInst node) - { - inASubInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmSub(lineLabel, destination, source, ""); - outASubInst(node); - } - - // inst = {imul} oplabel imul ar comma acr - @Override - public void caseAImulInst(AImulInst node) - { - inAImulInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmMul(lineLabel, destination, source, ""); - outAImulInst(node); - } - - // inst = {idiv} oplabel idiv ar - @Override - public void caseAIdivInst(AIdivInst node) - { - inAIdivInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand source = operand; - inst = new NasmDiv(lineLabel, source, ""); - outAIdivInst(node); - } - - // inst = {and} oplabel and ar comma acr - @Override - public void caseAAndInst(AAndInst node) - { - inAAndInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = label; - inst = new NasmOr(lineLabel, destination, source, ""); - outAAndInst(node); - } - - // inst = {or} oplabel or ar comma acr - @Override - public void caseAOrInst(AOrInst node) - { - inAOrInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmOr(lineLabel, destination, source, ""); - outAOrInst(node); - } - - // inst = {xor} oplabel xor ar comma acr - @Override - public void caseAXorInst(AXorInst node) - { - inAXorInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmXor(lineLabel, destination, source, ""); - outAXorInst(node); - } - - // inst = {not} oplabel not ar - @Override - public void caseANotInst(ANotInst node) - { - inANotInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - inst = new NasmNot(lineLabel, destination, ""); - outANotInst(node); - } - - // inst = {cmp} oplabel cmp ar comma acr - @Override - public void caseACmpInst(ACmpInst node) - { - inACmpInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getAr().apply(this); - NasmOperand destination = operand; - node.getAcr().apply(this); - NasmOperand source = operand; - inst = new NasmCmp(lineLabel, destination, source, ""); - outACmpInst(node); - } - - // inst = {jmp} oplabel jmp label - @Override - public void caseAJmpInst(AJmpInst node) - { - inAJmpInst(node); - node.getOplabel().apply(this); - NasmOperand lineLabel = label; - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmJmp(lineLabel, jumpTo, ""); - outAJmpInst(node); - } - - // inst = {je} oplabel je label - @Override - public void caseAJeInst(AJeInst node) - { - inAJeInst(node); - node.getOplabel().apply(this); - NasmOperand lineLabel = label; - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmJe(lineLabel, jumpTo, ""); - outAJeInst(node); - } - - // inst = {jne} oplabel jne label - @Override - public void caseAJneInst(AJneInst node) - { - inAJneInst(node); - node.getOplabel().apply(this); - NasmOperand lineLabel = label; - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmJne(lineLabel, jumpTo, ""); - } - - // inst = {jg} oplabel jg label - @Override - public void caseAJgInst(AJgInst node) - { - inAJgInst(node); - node.getOplabel().apply(this); - NasmOperand lineLabel = label; - - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmJg(lineLabel, jumpTo, ""); - outAJgInst(node); - } - - // inst = {jge} oplabel jge label - @Override - public void caseAJgeInst(AJgeInst node) - { - inAJgeInst(node); - node.getOplabel().apply(this); - NasmOperand lineLabel = label; - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmJge(lineLabel, jumpTo, ""); - outAJgeInst(node); - } - - // inst = {jl} oplabel jl label - @Override - public void caseAJlInst(AJlInst node) - { - inAJlInst(node); - node.getOplabel().apply(this); - NasmOperand lineLabel = label; - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmJl(lineLabel, jumpTo, ""); - outAJlInst(node); - } - - // inst = {call} oplabel call label - @Override - public void caseACallInst(ACallInst node) - { - inACallInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - node.getLabel().apply(this); - NasmOperand jumpTo = label; - inst = new NasmCall(lineLabel, jumpTo, ""); - outACallInst(node); - } - - // inst = {ret} oplabel ret - @Override - public void caseARetInst(ARetInst node) - { - inARetInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - inst = new NasmRet(lineLabel, ""); - outARetInst(node); - } - - // inst = {inter} oplabel int - @Override - public void caseAInterInst(AInterInst node) - { - inAInterInst(node); - node.getOplabel().apply(this); - NasmLabel lineLabel = label; - inst = new NasmInt(lineLabel, ""); - outAInterInst(node); - } - - // acr = {address} address - @Override - public void caseAAddressAcr(AAddressAcr node) - { - inAAddressAcr(node); - if(node.getAddress() != null) - { - node.getAddress().apply(this); - } - outAAddressAcr(node); - } - - // acr = {numconst} numconst - @Override - public void caseANumconstAcr(ANumconstAcr node) - { - inANumconstAcr(node); - if(node.getNumconst() != null) - { - node.getNumconst().apply(this); - } - outANumconstAcr(node); - } - - // acr = {register} register - @Override - public void caseARegisterAcr(ARegisterAcr node) - { - inARegisterAcr(node); - if(node.getRegister() != null) - { - node.getRegister().apply(this); - } - outARegisterAcr(node); - } - - - // ar = {address} address - @Override - public void caseAAddressAr(AAddressAr node) - { - inAAddressAr(node); - if(node.getAddress() != null) - { - node.getAddress().apply(this); - } - outAAddressAr(node); - } - - // ar = {register} register - @Override - public void caseARegisterAr(ARegisterAr node) - { - inARegisterAr(node); - if(node.getRegister() != null) - { - node.getRegister().apply(this); - } - outARegisterAr(node); - } - - // address = opsizeof brackopen exp brackclose - @Override - public void caseAAddress(AAddress node) - { - inAAddress(node); - node.getOpsizeof().apply(this); - NasmSize sizeof = size; - node.getExp().apply(this); - NasmExp val = exp; - operand = new NasmAddress(val, sizeof); - outAAddress(node); - } - - - // opsizeof = {byte} byte - @Override - public void caseAByteOpsizeof(AByteOpsizeof node) - { - inAByteOpsizeof(node); - size = NasmSize.BYTE; - outAByteOpsizeof(node); - } - - // opsizeof = {word} word - @Override - public void caseAWordOpsizeof(AWordOpsizeof node) - { - inAWordOpsizeof(node); - size = NasmSize.WORD; - outAWordOpsizeof(node); - } - - // opsizeof = {dword} dword - @Override - public void caseADwordOpsizeof(ADwordOpsizeof node) - { - inADwordOpsizeof(node); - size = NasmSize.DWORD; - outADwordOpsizeof(node); - } - - // opsizeof = {empty} - @Override - public void caseAEmptyOpsizeof(AEmptyOpsizeof node) - { - inAEmptyOpsizeof(node); - size = NasmSize.UNDEFINED; - outAEmptyOpsizeof(node); - } - - // exp = {plus} exp plus exp1 - @Override - public void caseAPlusExp(APlusExp node) - { - inAPlusExp(node); - node.getExp().apply(this); - NasmExp op1 = exp; - node.getExp1().apply(this); - NasmExp op2 = exp; - exp = new NasmExpPlus(op1, op2); - outAPlusExp(node); - } - - // exp = {minus} exp minus exp1 - @Override - public void caseAMinusExp(AMinusExp node) - { - inAMinusExp(node); - node.getExp().apply(this); - NasmExp op1 = exp; - node.getExp1().apply(this); - NasmExp op2 = exp; - exp = new NasmExpMinus(op1, op2); - outAMinusExp(node); - } - - // exp = {next} exp1 - @Override - public void caseANextExp(ANextExp node) - { - inANextExp(node); - if(node.getExp1() != null) - { - node.getExp1().apply(this); - } - outANextExp(node); - } - - - // exp1 = {times} exp1 times exp2 - @Override - public void caseATimesExp1(ATimesExp1 node) - { - inATimesExp1(node); - node.getExp1().apply(this); - NasmExp op1 = exp; - node.getExp2().apply(this); - NasmExp op2 = exp; - exp = new NasmExpTimes(op1, op2); - outATimesExp1(node); - } - - // exp1 = {next} exp2 - @Override - public void caseANextExp1(ANextExp1 node) - { - inANextExp1(node); - if(node.getExp2() != null) - { - node.getExp2().apply(this); - } - outANextExp1(node); - } - - - // exp2 = {label} label - @Override - public void caseALabelExp2(ALabelExp2 node) - { - inALabelExp2(node); - node.getLabel().apply(this); - exp = label; - outALabelExp2(node); - } - - // exp2 = {numconst} numconst - @Override - public void caseANumconstExp2(ANumconstExp2 node) - { - inANumconstExp2(node); - node.getNumconst().apply(this); - exp = (NasmConstant)operand; - outANumconstExp2(node); - } - - // exp2 = {register} register - @Override - public void caseARegisterExp2(ARegisterExp2 node) - { - inARegisterExp2(node); - node.getRegister().apply(this); - exp = (NasmRegister) operand; - outARegisterExp2(node); - } - - // numconst = number - @Override - public void caseANumconst(ANumconst node) - { - inANumconst(node); - operand = new NasmConstant(Integer.parseInt(node.getNumber().getText())); - outANumconst(node); - } - - // register = {temp} prefix_register number - @Override - public void caseATempRegister(ATempRegister node) - { - inATempRegister(node); - int regNb = Integer.parseInt(node.getNumber().getText()); - if (regNb > nasm.getTempCounter()) - nasm.setTempCounter(regNb); - operand = new NasmRegister(regNb); - outATempRegister(node); - } - - // register = {eax} eax - @Override - public void caseAEaxRegister(AEaxRegister node) - { - inAEaxRegister(node); - NasmRegister reg = new NasmRegister(0); - reg.colorRegister(Nasm.REG_EAX); - operand = reg; - outAEaxRegister(node); - } - - // register = {ebx} ebx - @Override - public void caseAEbxRegister(AEbxRegister node) - { - inAEbxRegister(node); - NasmRegister reg = new NasmRegister(0); - reg.colorRegister(Nasm.REG_EBX); - operand = reg; - outAEbxRegister(node); - } - - // register = {ecx} ecx - @Override - public void caseAEcxRegister(AEcxRegister node) - { - inAEcxRegister(node); - NasmRegister reg = new NasmRegister(0); - reg.colorRegister(Nasm.REG_ECX); - operand = reg; - outAEcxRegister(node); - } - - // register = {edx} edx - @Override - public void caseAEdxRegister(AEdxRegister node) - { - inAEdxRegister(node); - NasmRegister reg = new NasmRegister(0); - reg.colorRegister(Nasm.REG_EDX); - operand = reg; - outAEdxRegister(node); - } - - // register = {ebp} ebp - @Override - public void caseAEbpRegister(AEbpRegister node) - { - inAEbpRegister(node); - NasmRegister reg = new NasmRegister(0); - reg.colorRegister(Nasm.REG_EBP); - operand = reg; - outAEbpRegister(node); - } - - // register = {esp} esp - @Override - public void caseAEspRegister(AEspRegister node) - { - inAEspRegister(node); - NasmRegister reg = new NasmRegister(0); - reg.colorRegister(Nasm.REG_ESP); - operand = reg; - outAEspRegister(node); - } - - - // oplabel = {label} label semicol - @Override - public void caseALabelOplabel(ALabelOplabel node) - { - inALabelOplabel(node); - node.getLabel().apply(this); - outALabelOplabel(node); - } - - // oplabel = {empty} - @Override - public void caseAEmptyOplabel(AEmptyOplabel node) - { - inAEmptyOplabel(node); - label = null; - outAEmptyOplabel(node); - } - - // label = id - @Override - public void caseALabel(ALabel node) - { - inALabel(node); - label = new NasmLabel(node.getId().getText()); - outALabel(node); - } -} - - - diff --git a/src/nasm/Memory.java b/src/nasm/Memory.java new file mode 100644 index 0000000000000000000000000000000000000000..68d5a2b0c19647511672ffca175372c7acffa872 --- /dev/null +++ b/src/nasm/Memory.java @@ -0,0 +1,136 @@ +package nasm; + +/* Big Endian */ + +public class Memory{ + /* stack segment */ + private int ss; + + /* data segment */ + private int ds; + + protected int ebp; + protected int esp; + private int memSize; + private int dataSize; + private int stackSize; + private byte[] mem; + + public Memory(int dataSize, int stackSize){ + this.dataSize = dataSize; + this.stackSize = stackSize; + this.memSize = dataSize + stackSize; + ss = memSize - 1; + esp = ss; + mem = new byte[memSize]; + ds = 0; + } + + public void printStack(){ + for(int adr = ss - 3; adr > esp; adr = adr - 4){ + // System.out.print("[" + adr + "] " + readInt(adr) + "\t"); + System.out.print(readInt(adr) + "\t"); + } + System.out.println(); + } + + public int readInt(int address){ + // System.out.println("read memory at address " + address); + if((address < 0) || (address + 3 > ss)) + throw new RuntimeException("segmentation fault"); + return bytesToInt(mem[address], mem[address + 1], mem[address + 2], mem[address + 3]); + } + + public void writeInt(int address, int value){ + if((address < 0) || (address + 3 > ss)) + throw new RuntimeException("segmentation fault"); + + byte[] fourBytes = intToBytes(value); + mem[address] = fourBytes[0]; + mem[address + 1] = fourBytes[1]; + mem[address + 2] = fourBytes[2]; + mem[address + 3] = fourBytes[3]; + } + + public void pushInt(int value){ + if(esp - 3 < dataSize) + throw new RuntimeException("stack overflow"); + + byte[] fourBytes = intToBytes(value); + esp--; + mem[esp] = fourBytes[3]; + esp--; + mem[esp] = fourBytes[2]; + esp--; + mem[esp] = fourBytes[1]; + esp--; + mem[esp] = fourBytes[0]; + /* mem[esp--] = fourBytes[3]; + mem[esp--] = fourBytes[2]; + mem[esp--] = fourBytes[1]; + mem[esp--] = fourBytes[0]; +*/ + + } + + public int popInt(){ + if(esp + 3 >= ss) + throw new RuntimeException("stack underflow"); + byte byte0 = mem[esp]; + esp++; + byte byte1 = mem[esp]; + esp++; + byte byte2 = mem[esp]; + esp++; + byte byte3 = mem[esp]; + esp++; + + /* byte byte0 = mem[++esp]; + byte byte1 = mem[++esp]; + byte byte2 = mem[++esp]; + byte byte3 = mem[++esp];*/ + + return bytesToInt(byte0, byte1, byte2, byte3); + } + + public int bytesToInt(byte byte0, byte byte1, byte byte2, byte byte3){ + return ((byte0 & 0xFF) << 24) | + ((byte1 & 0xFF) << 16) | + ((byte2 & 0xFF) << 8) | + ((byte3 & 0xFF) << 0); + } + + public byte[] intToBytes2( int data ) { + byte[] result = new byte[4]; + result[0] = (byte) ((data & 0xFF000000) >> 24); + result[1] = (byte) ((data & 0x00FF0000) >> 16); + result[2] = (byte) ((data & 0x0000FF00) >> 8); + result[3] = (byte) ((data & 0x000000FF) >> 0); + return result; +} + public byte[] intToBytes(int i) + { + byte[] result = new byte[4]; + + result[0] = (byte) (i >> 24); + result[1] = (byte) (i >> 16); + result[2] = (byte) (i >> 8); + result[3] = (byte) (i /*>> 0*/); + + return result; + } + + /* public static void main(String[] args){ + Memory mem = new Memory(100, 100); + mem.pushInt(3467); + int v = mem.popInt(); + System.out.println("val =" + v); + v = mem.popInt(); + + mem.writeInt(96, 234); + int val = mem.readInt(96); + System.out.println("val =" + val); + + }*/ + +} diff --git a/src/nasm/Nasm.java b/src/nasm/Nasm.java index 3bd34e4dffb1a3c4d05b5b030653882f6aee44da..912942c5d48cdfa49944e393e80e5e5a2fe27d1c 100644 --- a/src/nasm/Nasm.java +++ b/src/nasm/Nasm.java @@ -17,7 +17,6 @@ public class Nasm{ public static int REG_UNK = 6; // public static int NB_PREDEFINED_REG = 7; - public Nasm(Ts tableGlobale){ this.tableGlobale = tableGlobale; this.sectionBss = new ArrayList<NasmPseudoInst>(); @@ -44,25 +43,6 @@ public class Nasm{ this.sectionText.add(new NasmMov(null, inst.destination, newReg, "on passe par un registre temporaire")); return; } - if(inst instanceof NasmAdd && inst.destination instanceof NasmAddress && inst.source instanceof NasmAddress){ - NasmRegister newReg = newRegister(); - this.sectionText.add(new NasmMov(inst.label, newReg, inst.source, inst.comment)); - this.sectionText.add(new NasmAdd(null, inst.destination, newReg, "on passe par un registre temporaire")); - return; - } - if(inst instanceof NasmSub && inst.destination instanceof NasmAddress && inst.source instanceof NasmAddress){ - NasmRegister newReg = newRegister(); - this.sectionText.add(new NasmMov(inst.label, newReg, inst.source, inst.comment)); - this.sectionText.add(new NasmSub(null, inst.destination, newReg, "on passe par un registre temporaire")); - return; - } - if(inst instanceof NasmMul && inst.destination instanceof NasmAddress && inst.source instanceof NasmAddress){ - NasmRegister newReg = newRegister(); - this.sectionText.add(new NasmMov(inst.label, newReg, inst.source, inst.comment)); - this.sectionText.add(new NasmMul(null, inst.destination, newReg, "on passe par un registre temporaire")); - return; - } - // if(inst instanceof NasmCmp && inst.destination instanceof NasmConstant && inst.source instanceof NasmConstant){ if(inst instanceof NasmCmp @@ -87,11 +67,7 @@ public class Nasm{ for (Map.Entry< String, TsItemVar> me:st){ TsItemVar tsItem = me.getValue(); String identif = me.getKey(); - if(tsItem instanceof TsItemVarSimple) - ajoutePseudoInst(new NasmResd(new NasmLabel(identif), tsItem.type.taille(), "variable globale")); - if(tsItem instanceof TsItemVarTab) - ajoutePseudoInst(new NasmResd(new NasmLabel(identif), tsItem.type.taille() * ((TsItemVarTab)tsItem).taille, "variable globale")); - // ajoutePseudoInst(new NasmResd(new NasmLabel(identif), tsItem.taille*4, "variable globale")); + ajoutePseudoInst(new NasmResd(new NasmLabel(identif), tsItem.taille*4, "variable globale")); } } diff --git a/src/nasm/Nasm.old b/src/nasm/Nasm.old new file mode 100644 index 0000000000000000000000000000000000000000..69f060df5ece20dcfefb28d33d2331ed5b1afd75 --- /dev/null +++ b/src/nasm/Nasm.old @@ -0,0 +1,121 @@ +package nasm; +import java.util.*; +import java.io.*; +import ts.*; + +public class Nasm{ + public List<NasmInst> listeInst; + private int tempCounter; + Ts tableGlobale; + public static int REG_EAX = 0; + public static int REG_EBX = 1; + public static int REG_ECX = 2; + public static int REG_EDX = 3; + public static int REG_ESP = -1; + public static int REG_EBP = -2; + public static int REG_UNK = -3; + + + public Nasm(Ts tableGlobale){ + this.tableGlobale = tableGlobale; + this.listeInst = new ArrayList<NasmInst>(); + + } + + public int getTempCounter(){return this.tempCounter;} + public int setTempCounter(int c){return this.tempCounter = c;} + + + public void ajouteInst(NasmInst inst){ + if(inst instanceof NasmMov && inst.destination instanceof NasmAddress && inst.source instanceof NasmAddress){ + NasmRegister newReg = newRegister(); + this.listeInst.add(new NasmMov(inst.label, newReg, inst.source, inst.comment)); + this.listeInst.add(new NasmMov(null, inst.destination, newReg, "on passe par un registre temporaire")); + return; + } + + // if(inst instanceof NasmCmp && inst.destination instanceof NasmConstant && inst.source instanceof NasmConstant){ + if(inst instanceof NasmCmp + && (inst.destination instanceof NasmConstant + || (inst.destination instanceof NasmAddress && inst.source instanceof NasmAddress))){ + NasmRegister newReg = newRegister(); + this.listeInst.add(new NasmMov(inst.label, newReg, inst.destination, inst.comment)); + this.listeInst.add(new NasmCmp(null, newReg, inst.source, "on passe par un registre temporaire")); + return; + } + + this.listeInst.add(inst); + } + + public NasmRegister newRegister(){ + return new NasmRegister(tempCounter++); + } + + + public void affichePreambule(PrintStream out) + { + out.println("%include\t'io.asm'\n"); + /* Variables globales */ + out.println("section\t.bss"); + out.println("sinput:\tresb\t255\t;reserve a 255 byte space in memory for the users input string"); + + + Set< Map.Entry< String, TsItemVar> > st = tableGlobale.variables.entrySet(); + for (Map.Entry< String, TsItemVar> me:st){ + TsItemVar tsItem = me.getValue(); + String identif = me.getKey(); + out.println(identif + " :\tresd\t" + tsItem.taille * 4); + } + out.println("\nsection\t.text"); + out.println("global _start"); + out.println("_start:"); + } + + + + public void affichePre(String baseFileName){ + String fileName; + PrintStream out = System.out; + + if (baseFileName != null){ + try { + baseFileName = baseFileName; + fileName = baseFileName + ".pre-nasm"; + out = new PrintStream(fileName); + } + + catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + Iterator<NasmInst> iter = this.listeInst.iterator(); + while(iter.hasNext()){ + out.println(iter.next()); + } + } + + public void affiche(String baseFileName){ + String fileName; + PrintStream out = System.out; + + if (baseFileName != null){ + try { + baseFileName = baseFileName; + fileName = baseFileName + ".nasm"; + out = new PrintStream(fileName); + } + + catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + + this.affichePreambule(out); + + + Iterator<NasmInst> iter = this.listeInst.iterator(); + while(iter.hasNext()){ + out.println(iter.next()); + } + } +} diff --git a/src/nasm/NasmAdd.java b/src/nasm/NasmAdd.java index 340d0df41e5daa194a3f5124db85821edb4ac527..475f3701f5451bedda4b7a41d14c36ab35f1f7c5 100644 --- a/src/nasm/NasmAdd.java +++ b/src/nasm/NasmAdd.java @@ -3,7 +3,6 @@ package nasm; public class NasmAdd extends NasmInst { public NasmAdd(NasmOperand label, NasmOperand destination, NasmOperand source, String comment){ - destUse = true; destDef = true; srcUse = true; diff --git a/src/nasm/NasmAddress.java b/src/nasm/NasmAddress.java index f81e92aa623aae32aafa2b73d3d27660d3831913..66fb567799d1738a67540d57e33f0cd9d402f353 100644 --- a/src/nasm/NasmAddress.java +++ b/src/nasm/NasmAddress.java @@ -2,25 +2,60 @@ package nasm; public class NasmAddress extends NasmOperand { - public NasmExp val; - public NasmSize size; + public NasmOperand base; + public NasmOperand offset; + public char direction; + + public NasmAddress(NasmOperand base, char direction, NasmOperand offset){ + this.base = base; + this.direction = direction; + this.offset = offset; + } - public NasmAddress(NasmExp val, NasmSize size){ - this.val = val; - this.size = size; + public NasmAddress(NasmOperand base){ + this.base = base; + this.direction = '+'; + this.offset = new NasmConstant(0); } public String toString(){ - return this.size.toString() + " [" + this.val.toString() + "]"; + // return "address"; + if(this.offset != null) + // la multiplication par 4 pour passer en octets n'est effectuée que maintenant afin de + // traiter de la même façon les indices de tableaux et les adresses relatives + // c'est pas terrible ! + // return "" + this.base + this.direction + "4*" + this.offset; + return "" + this.base + this.direction + this.offset; + + // return "dword [" + this.base + this.direction + "4*" + this.offset + "]"; + return "" + this.base; + // return "dword [" + this.base + "]"; + } public boolean isGeneralRegister(){ return false; } + + /* + + + printf("dword ["); + nasm_affiche_operande(code_nasm, operande->u.address.base); + // la multiplication par 4 pour passer en octets n'est effectuée que maintenant afin de + // traiter de la même façon les indices de tableaux et les adresses relatives + // c'est pas terrible ! + if(operande->u.address.offset){ + printf(" %c 4 * ", operande->u.address.direction); + nasm_affiche_operande(code_nasm, operande->u.address.offset); + } + printf("]"); + */ + public <T> T accept(NasmVisitor <T> visitor) { return visitor.visit(this); - } + } } diff --git a/src/nasm/NasmConstant.java b/src/nasm/NasmConstant.java index 9f6a74991e9ae7c1ad6a9ec17c9c90225500aec6..3b28934e35760b604d25830a4b4625e1e0a57888 100644 --- a/src/nasm/NasmConstant.java +++ b/src/nasm/NasmConstant.java @@ -1,7 +1,6 @@ package nasm; -import java.util.ArrayList; -public class NasmConstant extends NasmOperand implements NasmExp{ +public class NasmConstant extends NasmOperand { public int val; public NasmConstant(int val){ this.val = val; @@ -14,15 +13,4 @@ public class NasmConstant extends NasmOperand implements NasmExp{ public <T> T accept(NasmVisitor <T> visitor) { return visitor.visit(this); } - - public ArrayList<NasmRegister> getRegisters() - { - ArrayList<NasmRegister> registerList = new ArrayList<NasmRegister>(); - this.getRegisters(registerList); - return registerList; - } - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList) - { - return registerList; - } } diff --git a/src/nasm/NasmEval.java b/src/nasm/NasmEval.java index 3178a3cc6673368d23b6d5b3b23dd2e7c003b9b9..00b33adb9cc96211a7eab216c3c3b21722f14a91 100644 --- a/src/nasm/NasmEval.java +++ b/src/nasm/NasmEval.java @@ -1,21 +1,21 @@ package nasm; + + import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.ArrayList; import java.util.HashMap; -import util.Memory; /* -This class emulates pre-nasm and nasm code for x86-64 architecture. +This class emulates pre-nasm for x86-64 architecture. It handles only integers on 4 bytes and have unlimited register. */ public class NasmEval implements NasmVisitor<Integer>{ private Nasm code; - private int dataSize = 0; - private int regNb; - private HashMap<String, Integer> labelToAddress; + private HashMap<String, Integer> labelToLine; + private HashMap<String, Integer> globalVariableToAddress; private Memory memory; private boolean stop; private ArrayList<Integer> output; @@ -23,13 +23,12 @@ public class NasmEval implements NasmVisitor<Integer>{ // registers private int[] registers; - private int ebp; private int eip = 0; private int eax = 0; private int ebx = 0; private int ecx = 0; private int edx = 0; - + //flags // Carry Flag -> not used private boolean CF = false; @@ -44,19 +43,32 @@ public class NasmEval implements NasmVisitor<Integer>{ private int verboseLevel; + public void PrintGlobalVariables(){ + for (HashMap.Entry<String, Integer> e : globalVariableToAddress.entrySet()) + System.out.println("[" + e.getValue() + "]\t" + e.getKey() + " = " + memory.readInt(e.getValue())); + + } public NasmEval(Nasm code, int stackSize, int verboseLevel){ this.code = code; this.verboseLevel = verboseLevel; regNb = this.code.getTempCounter(); - registers = new int[regNb+1]; + registers = new int[10*regNb]; eip = 0; stop = false; - output = new ArrayList<>(); - labelToAddress = new HashMap<>(); + labelToLine = associateLabelToLine(); + int dataSize = 0; + globalVariableToAddress = new HashMap<>(); + + // compute addresses of global variables + for(int i = 0; i < code.sectionBss.size(); i++){ + NasmPseudoInst pseudoInst = this.code.sectionBss.get(i); + globalVariableToAddress.put(pseudoInst.label.val, dataSize); + // System.out.println("var :" + pseudoInst.label.val + " address = " + dataSize); + dataSize += pseudoInst.nb * pseudoInst.sizeInBytes; + } - associateLabelToAddress(); - memory = new Memory(dataSize, stackSize); + memory = new Memory(dataSize, stackSize); while(!stop && eip < code.sectionText.size()){ NasmInst inst = this.code.sectionText.get(eip); @@ -64,12 +76,11 @@ public class NasmEval implements NasmVisitor<Integer>{ System.out.println("--------------------------------------"); PrintGlobalVariables(); - // System.out.println("eip = " + eip + "\tesp = " + memory.getTopInt() + "\t ebp = " + ebp); - System.out.println("eip = " + eip + "\tesp = " + memory.esp + "\t ebp = " + ebp); + System.out.println("eip = " + eip + "\tesp = " + memory.esp + "\t ebp = " + memory.ebp); System.out.println("eax = " + eax + "\tebx = " + ebx + "\tecx = " + ecx + "\tedx = " + edx); System.out.println("CF = " + CF + "\tPF = " + PF + "\tZF = " + ZF + "\tSF = " + SF + "\tOF = " + OF); printRegisters(); - System.out.print("PILE : \t"); + System.out.print("stack : \t"); memory.printStack(); System.out.println(inst); } @@ -78,14 +89,6 @@ public class NasmEval implements NasmVisitor<Integer>{ // displayOutput(); } - public void PrintGlobalVariables(){ - for (HashMap.Entry<String, Integer> e : labelToAddress.entrySet()) - - // System.out.println("[" + e.getValue() + "]\t" + e.getKey() + " = " + memory.readInt(e.getValue())); - System.out.println(e.getKey() + " = " + memory.readInt(e.getValue()) + " adr: " + e.getValue()); - - } - public void printRegisters(){ for(int i=0; i < regNb; i++){ System.out.print("r" + i + ":" + registers[i] + "\t"); @@ -103,89 +106,75 @@ public class NasmEval implements NasmVisitor<Integer>{ for(var val : output) out.println(val); } - - private void associateLabelToAddress(){ + + private HashMap<String, Integer> associateLabelToLine(){ + HashMap<String, Integer> labelToLine = new HashMap<>(); var instructions = code.sectionText; - // associate labels to line numbers - for(int lineNb = 0; lineNb <instructions.size(); lineNb++){ - if(instructions.get(lineNb).label != null) { - var label = (NasmLabel)instructions.get(lineNb).label; - labelToAddress.put(label.val, lineNb); + for(int i = 0; i <instructions.size(); i++){ + if(instructions.get(i).label != null) { + var label = (NasmLabel)instructions.get(i).label; + labelToLine.put(label.val, i); } } - // compute addresses of global variables and associate them to labels - for(int i = 0; i < code.sectionBss.size(); i++){ - NasmPseudoInst pseudoInst = this.code.sectionBss.get(i); - labelToAddress.put(pseudoInst.label.val, dataSize); - // System.out.println("var :" + pseudoInst.label.val + " address = " + dataSize); - dataSize += pseudoInst.nb * pseudoInst.sizeInBytes; - } - } - - /*------------------------------------------*/ - private void copy(NasmOperand dest, int value){ - if(dest instanceof NasmAddress) - copy((NasmAddress) dest, value); - else if(dest instanceof NasmRegister) - copy((NasmRegister) dest, value); + return labelToLine; } - - private void copy(NasmAddress dest, int value){ - int address = dest.val.accept(this); - memory.writeInt(address, value); - } - - private void copy(NasmRegister dest, int value){ - writeToRegister(dest, value); + private void affect(NasmOperand dest, int src){ + if(dest instanceof NasmRegister) + affect((NasmRegister) dest, src); + else if(dest instanceof NasmAddress) + affect((NasmAddress) dest, src); } - /*------------------------------------------*/ - - // return value stored in regiter - private int readFromRegister(NasmRegister reg){ - if(reg.color == Nasm.REG_EAX) - return eax; - if (reg.color == Nasm.REG_EBX) - return ebx; - if (reg.color == Nasm.REG_ECX) - return ecx; - if (reg.color == Nasm.REG_EDX) - return edx; - if (reg.color == Nasm.REG_ESP) - return memory.esp; - if (reg.color == Nasm.REG_EBP) - return ebp; - else - return registers[reg.val]; - - } // write in a register - private void writeToRegister(NasmRegister reg, int value){ - if(reg.color == Nasm.REG_EAX) - eax = value; - else if (reg.color == Nasm.REG_EBX) - ebx = value; - else if (reg.color == Nasm.REG_ECX) - ecx = value; - else if (reg.color == Nasm.REG_EDX) - edx = value; - else if (reg.color == Nasm.REG_ESP) - memory.esp = value; - else if (reg.color == Nasm.REG_EBP) - ebp = value; + private void affect(NasmRegister dest, int src){ + // System.out.println("affect value " + src + " to register"); + if(dest.color == Nasm.REG_EAX) + eax = src; + else if (dest.color == Nasm.REG_EBX) + ebx = src; + else if (dest.color == Nasm.REG_ECX) + ecx = src; + else if (dest.color == Nasm.REG_EDX) + edx = src; + else if (dest.color == Nasm.REG_ESP) + memory.esp = src; + else if (dest.color == Nasm.REG_EBP) + memory.ebp = src; else - registers[reg.val] = value; + registers[dest.val] = src; + } + + // write in memory + private void affect(NasmAddress dest, int src){ + if(dest.base instanceof NasmLabel){ + if(globalVariableToAddress.containsKey(((NasmLabel)dest.base).val)){ + int globalVarAddress = globalVariableToAddress.get(((NasmLabel)dest.base).val); + if(dest.direction == '+') + memory.writeInt(globalVarAddress + dest.offset.accept(this), src); + else + memory.writeInt(globalVarAddress - dest.offset.accept(this), src); + } + } + else{ + if(dest.direction == '+') + memory.writeInt(dest.base.accept(this) + dest.offset.accept(this), src); + else + memory.writeInt(dest.base.accept(this) - dest.offset.accept(this), src); + } } - /* visit address -> return the value stored at this address */ + /* visit operand -> return its value*/ @Override - public Integer visit(NasmAddress adr) { - return memory.readInt(adr.val.accept(this)); + public Integer visit(NasmAddress operand) { + if(operand.direction == '+') + return memory.readInt(operand.base.accept(this) + operand.offset.accept(this)); + else + return memory.readInt(operand.base.accept(this) - operand.offset.accept(this)); } - /* visit register -> return the value stored in the register */ + @Override public Integer visit(NasmRegister operand) { if(operand.color == Nasm.REG_EAX) @@ -199,45 +188,50 @@ public class NasmEval implements NasmVisitor<Integer>{ if (operand.color == Nasm.REG_ESP) return memory.esp; if (operand.color == Nasm.REG_EBP) - return ebp; + return memory.ebp; else return registers[operand.val]; } - /* visit constant -> return value of the constant */ @Override public Integer visit(NasmConstant operand) { + return operand.val; } - /* visit label -> return address corresponding to the label */ @Override public Integer visit(NasmLabel operand) { - if(labelToAddress.containsKey(operand.val)) - return labelToAddress.get(operand.val); - else - throw new RuntimeException("label " + operand.val + "does not correspond to address"); + // if label corresponds to a line of code, return the line number + if(labelToLine.containsKey(operand.val)) + return labelToLine.get(operand.val); + + // if label corresponds to a global variable, return it address + if(globalVariableToAddress.containsKey(operand.val)){ + int globalVarAddress = globalVariableToAddress.get(operand.val); + // System.out.println("-->var = " + operand.val + " address = " + globalVarAddress + " value = " + memory.readInt(globalVarAddress)); + return globalVarAddress; + // return memory.readInt(globalVarAddress); + } + throw new RuntimeException("label " + operand.val + "does not correspond to existing label or global variable"); } - - /* visiting an instruction returns new value of eip */ /* arithmetic operations */ @Override public Integer visit(NasmAdd inst) { - copy(inst.destination, inst.source.accept(this) + inst.destination.accept(this)); + affect(inst.destination, inst.source.accept(this) + inst.destination.accept(this)); return eip + 1; } @Override public Integer visit(NasmSub inst) { - copy(inst.destination, inst.destination.accept(this) - inst.source.accept(this)); + affect(inst.destination, inst.destination.accept(this) - inst.source.accept(this)); return eip + 1; } @Override public Integer visit(NasmMul inst) { - copy(inst.destination, inst.source.accept(this) * inst.destination.accept(this)); + affect(inst.destination, inst.source.accept(this) * inst.destination.accept(this)); return eip + 1; } @@ -253,25 +247,25 @@ public class NasmEval implements NasmVisitor<Integer>{ /* logical operations */ @Override public Integer visit(NasmOr inst) { - copy(inst.destination, inst.source.accept(this) | inst.destination.accept(this)); + affect(inst.destination, inst.source.accept(this) | inst.destination.accept(this)); return eip + 1; } @Override public Integer visit(NasmNot inst) { - copy(inst.destination, ~ inst.destination.accept(this)); + affect(inst.destination, ~ inst.destination.accept(this)); return eip + 1; } @Override public Integer visit(NasmXor inst) { - copy(inst.destination, inst.source.accept(this) ^ inst.destination.accept(this)); + affect(inst.destination, inst.source.accept(this) ^ inst.destination.accept(this)); return eip + 1; } @Override public Integer visit(NasmAnd inst) { - copy(inst.destination, inst.source.accept(this) & inst.destination.accept(this)); + affect(inst.destination, inst.source.accept(this) & inst.destination.accept(this)); return eip + 1; } @@ -309,6 +303,7 @@ public class NasmEval implements NasmVisitor<Integer>{ @Override public Integer visit(NasmJne inst) { + // return (!ZF && SF)? inst.address.accept(this) : eip + 1; return (!ZF)? inst.address.accept(this) : eip + 1; } @@ -334,7 +329,7 @@ public class NasmEval implements NasmVisitor<Integer>{ @Override public Integer visit(NasmPop inst) { - copy(inst.destination, memory.popInt()); + affect(inst.destination, memory.popInt()); return eip + 1; } @@ -351,7 +346,7 @@ public class NasmEval implements NasmVisitor<Integer>{ @Override public Integer visit(NasmMov inst) { - copy(inst.destination, inst.source.accept(this)); + affect(inst.destination, inst.source.accept(this)); return eip + 1; } @@ -378,33 +373,6 @@ public class NasmEval implements NasmVisitor<Integer>{ public Integer visit(NasmResq pseudoInst){return 0;} public Integer visit(NasmRest pseudoInst){return 0;} - /* visit expression -> returns an address */ - - public Integer visit(NasmExp exp) { /* c'est moche, il faudrait modifier ça !! */ - if(exp instanceof NasmLabel) - return ((NasmLabel)exp).accept(this); - - if(exp instanceof NasmRegister) - return ((NasmRegister)exp).accept(this); - - if(exp instanceof NasmLabel) - return ((NasmLabel)exp).accept(this); - - if(exp instanceof NasmConstant) - return ((NasmConstant)exp).accept(this); - - if(exp instanceof NasmExpPlus) - return ((NasmExpPlus)exp).accept(this); - - if(exp instanceof NasmExpMinus) - return ((NasmExpMinus)exp).accept(this); - - // if(exp instanceof NasmExpTimes) - return ((NasmExpTimes)exp).accept(this); - } - public Integer visit(NasmExpPlus exp) {return exp.op1.accept(this) + exp.op2.accept(this);} - public Integer visit(NasmExpMinus exp){return exp.op1.accept(this) - exp.op2.accept(this);} - public Integer visit(NasmExpTimes exp){return exp.op1.accept(this) * exp.op2.accept(this);} } diff --git a/src/nasm/NasmExp.java b/src/nasm/NasmExp.java deleted file mode 100644 index 6e51c1d1d92095a3dcdbd99ea4cb2831e32857bc..0000000000000000000000000000000000000000 --- a/src/nasm/NasmExp.java +++ /dev/null @@ -1,11 +0,0 @@ -package nasm; -import java.util.ArrayList; - -public interface NasmExp { - // public boolean isStackAddress(); - public ArrayList<NasmRegister> getRegisters(); - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList); - - - public <T> T accept(NasmVisitor <T> visitor); -} diff --git a/src/nasm/NasmExpMinus.java b/src/nasm/NasmExpMinus.java deleted file mode 100644 index 419c1c167e89e2cf0d1ed5a4236b8e9c160d0020..0000000000000000000000000000000000000000 --- a/src/nasm/NasmExpMinus.java +++ /dev/null @@ -1,34 +0,0 @@ -package nasm; -import java.util.ArrayList; - -public class NasmExpMinus implements NasmExp{ - public NasmExp op1; - public NasmExp op2; - - public NasmExpMinus(NasmExp op1, NasmExp op2){ - this.op1 = op1; - this.op2 = op2; - } - - @Override - public String toString() { - return op1.toString() + "-" + op2.toString(); - } - - public <T> T accept(NasmVisitor <T> visitor) { - return visitor.visit(this); - } - - public ArrayList<NasmRegister> getRegisters() - { - ArrayList<NasmRegister> registerList = new ArrayList<NasmRegister>(); - this.getRegisters(registerList); - return registerList; - } - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList) - { - this.op1.getRegisters(registerList); - this.op2.getRegisters(registerList); - return registerList; - } -} diff --git a/src/nasm/NasmExpPlus.java b/src/nasm/NasmExpPlus.java deleted file mode 100644 index 440d310d3fa1b3e8b46c6f9b06d01252eb9d7587..0000000000000000000000000000000000000000 --- a/src/nasm/NasmExpPlus.java +++ /dev/null @@ -1,34 +0,0 @@ -package nasm; -import java.util.ArrayList; - -public class NasmExpPlus implements NasmExp{ - public NasmExp op1; - public NasmExp op2; - - public NasmExpPlus(NasmExp op1, NasmExp op2){ - this.op1 = op1; - this.op2 = op2; - } - - @Override - public String toString() { - return op1.toString() + "+" + op2.toString(); - } - - public <T> T accept(NasmVisitor <T> visitor) { - return visitor.visit(this); - } - - public ArrayList<NasmRegister> getRegisters() - { - ArrayList<NasmRegister> registerList = new ArrayList<NasmRegister>(); - this.getRegisters(registerList); - return registerList; - } - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList) - { - this.op1.getRegisters(registerList); - this.op2.getRegisters(registerList); - return registerList; - } -} diff --git a/src/nasm/NasmExpTimes.java b/src/nasm/NasmExpTimes.java deleted file mode 100644 index efc07f3a498d2a90997e3f572916b83daa864394..0000000000000000000000000000000000000000 --- a/src/nasm/NasmExpTimes.java +++ /dev/null @@ -1,34 +0,0 @@ -package nasm; -import java.util.ArrayList; - -public class NasmExpTimes implements NasmExp{ - public NasmExp op1; - public NasmExp op2; - - public NasmExpTimes(NasmExp op1, NasmExp op2){ - this.op1 = op1; - this.op2 = op2; - } - - @Override - public String toString() { - return op1.toString() + "+" + op2.toString(); - } - - public <T> T accept(NasmVisitor <T> visitor) { - return visitor.visit(this); - } - - public ArrayList<NasmRegister> getRegisters() - { - ArrayList<NasmRegister> registerList = new ArrayList<NasmRegister>(); - this.getRegisters(registerList); - return registerList; - } - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList) - { - this.op1.getRegisters(registerList); - this.op2.getRegisters(registerList); - return registerList; - } -} diff --git a/src/nasm/NasmInst.java b/src/nasm/NasmInst.java index 5d81f8f999d766a2d0cf7bf6c766415b14e274a7..50c132159b7ade5265f1b40de080f68b0d89cff9 100644 --- a/src/nasm/NasmInst.java +++ b/src/nasm/NasmInst.java @@ -21,10 +21,16 @@ public abstract class NasmInst{ s = s + label + " :"; s = s + "\t" + opcode; if(arg1 != null) + if(arg1 instanceof NasmAddress) + s = s + "\tdword [" + arg1 + "]"; + else s = s + "\t" + arg1; if(arg2 != null) + if(arg2 instanceof NasmAddress) + s = s + ",\tdword [" + arg2 + "]"; + else s = s + ",\t" + arg2; - if(comment != null & comment != "") + if(comment != null) s = s + "\t;" + comment; return s; } diff --git a/src/nasm/NasmLabel.java b/src/nasm/NasmLabel.java index 85d49095fa53b78c098461e1fdd3c26810172051..9bab8ab06728888d757e3e125c250a0b83cc119a 100644 --- a/src/nasm/NasmLabel.java +++ b/src/nasm/NasmLabel.java @@ -1,7 +1,6 @@ package nasm; -import java.util.ArrayList; -public class NasmLabel extends NasmOperand implements NasmExp { +public class NasmLabel extends NasmOperand { public String val; public NasmLabel(String val){ @@ -13,16 +12,4 @@ public class NasmLabel extends NasmOperand implements NasmExp { public <T> T accept(NasmVisitor <T> visitor) { return visitor.visit(this); } - public boolean isStackAddress(){return false;} - - public ArrayList<NasmRegister> getRegisters() - { - ArrayList<NasmRegister> registerList = new ArrayList<NasmRegister>(); - this.getRegisters(registerList); - return registerList; - } - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList) - { - return registerList; - } } diff --git a/src/nasm/NasmOperand.java b/src/nasm/NasmOperand.java index 5fb05ba7c9194420c32219b93cdc0bb8fd1b1ea4..4659d25605250ea5e88819901dd3722437a883f6 100644 --- a/src/nasm/NasmOperand.java +++ b/src/nasm/NasmOperand.java @@ -1,6 +1,6 @@ package nasm; -public abstract class NasmOperand { +public abstract class NasmOperand{ public boolean isGeneralRegister(){ return false; } diff --git a/src/nasm/NasmParser.java b/src/nasm/NasmParser.java new file mode 100644 index 0000000000000000000000000000000000000000..af7822a4ea8f435004cd02cb86ded5cfe2b63d23 --- /dev/null +++ b/src/nasm/NasmParser.java @@ -0,0 +1,300 @@ +package nasm; + +import ts.Ts; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +public class NasmParser{ + + private Nasm code; + private String[] linesArgs; + private NasmInst currentInstr; + private NasmInst complementaryInstr; + private NasmLabel labelToNextInstr; + private int IAL = 0; // Indice after label; + private HashMap<String, NasmRegister> nameToReg; + + + /* (Map.of( + "eax", new NasmRegister(Nasm.REG_EAX), + "ebx", new NasmRegister(Nasm.REG_EBX), + "ecx", new NasmRegister(Nasm.REG_ECX), + "edx", new NasmRegister(Nasm.REG_EDX), + "esp", new NasmRegister(Nasm.REG_ESP), + "ebp", new NasmRegister(Nasm.REG_EBP), + "unk", new NasmRegister(Nasm.REG_UNK) + ));*/ + + public NasmParser(){ + code = new Nasm(); + + nameToReg = new HashMap<String, NasmRegister>(); + NasmRegister reg_eax = new NasmRegister(-1); + reg_eax.colorRegister(Nasm.REG_EAX); + nameToReg.put("eax", reg_eax); + + NasmRegister reg_ebx = new NasmRegister(-1); + reg_ebx.colorRegister(Nasm.REG_EBX); + nameToReg.put("ebx", reg_ebx); + + NasmRegister reg_ecx = new NasmRegister(-1); + reg_ecx.colorRegister(Nasm.REG_ECX); + nameToReg.put("ecx", reg_ecx); + + NasmRegister reg_edx = new NasmRegister(-1); + reg_edx.colorRegister(Nasm.REG_EDX); + nameToReg.put("edx", reg_edx); + + NasmRegister reg_esp = new NasmRegister(-1); + reg_esp.colorRegister(Nasm.REG_ESP); + nameToReg.put("esp", reg_esp); + + NasmRegister reg_ebp = new NasmRegister(-1); + reg_ebp.colorRegister(Nasm.REG_EBP); + nameToReg.put("ebp", reg_ebp); + + } + + public Nasm parse(String filename) throws IOException { + try(var linesStream = Files.lines(Paths.get(filename))) { + linesStream.forEachOrdered(this::processLine); + } + return code; + } + + private void processLine(String line){ + // System.out.println(line); + if(line.isEmpty()){return;} + if(line.startsWith("%include")) return; + if(line.startsWith("section")) return; + if(line.startsWith("global")) return; + if(line.startsWith("_start")) return; + + currentInstr = null; + complementaryInstr = null; + line = line.replace("dword", ""); + linesArgs = line.split("(,*([ ]|[\t]))+"); + labelToNextInstr = null; + IAL = 0; + registerLabel(); + if(line.contains("call")) + // currentInstr = new NasmCall(labelToNextInstr, new NasmAddress(new NasmLabel(linesArgs[IAL + 2])), ""); + currentInstr = new NasmCall(labelToNextInstr, new NasmLabel(linesArgs[IAL + 2]), ""); + else if(line.contains("mov")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmMov(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("push")){ + var rightOp = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmPush(labelToNextInstr, rightOp, ""); + } + else if(line.contains("pop")){ + var rightOp = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmPop(labelToNextInstr, rightOp, ""); + } + else if(line.contains("add")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmAdd(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("sub")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmSub(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("imul")) { + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmMul(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("idiv")){ + var rightOp = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmDiv(labelToNextInstr, rightOp, ""); + } + else if(line.contains("and")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmAnd(labelToNextInstr, leftOp, rightOp, ""); + } + else if(linesArgs[IAL + 1].contains("or")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmOr(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("xor")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmXor(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("jmp")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJmp(labelToNextInstr, address, ""); + } + else if(line.contains("je")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJe(labelToNextInstr, address, ""); + } + else if(line.contains("jne")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJne(labelToNextInstr, address, ""); + } + else if(line.contains("jg")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJg(labelToNextInstr, address, ""); + } + else if(line.contains("jge")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJge(labelToNextInstr, address, ""); + } + else if(line.contains("jl")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJl(labelToNextInstr, address, ""); + } + else if(line.contains("jle")){ + var address = getRightOperandType(linesArgs[IAL + 2]); + currentInstr = new NasmJle(labelToNextInstr, address, ""); + } + else if(line.contains("cmp")){ + var leftOp = getRightOperandType(linesArgs[IAL + 2]); + var rightOp = getRightOperandType(linesArgs[IAL + 3]); + currentInstr = new NasmCmp(labelToNextInstr, leftOp, rightOp, ""); + } + else if(line.contains("ret")) + currentInstr = new NasmRet(labelToNextInstr, ""); + + else if(line.contains("int 0x80")) + currentInstr = new NasmInt(labelToNextInstr, ""); + + else if(line.contains("resd")){ + int nb = Integer.parseInt(linesArgs[IAL + 2]); + code.ajoutePseudoInst(new NasmResd(labelToNextInstr, nb, "")); + } + else if(line.contains("resb")){ + int nb = Integer.parseInt(linesArgs[IAL + 2]); + code.ajoutePseudoInst(new NasmResb(labelToNextInstr, nb, "")); + } + /* else + currentInstr = new NasmEmpty(labelToNextInstr, ""); + */ + if(complementaryInstr != null) + code.ajouteInst(complementaryInstr); + if(currentInstr != null) + code.ajouteInst(currentInstr); + } + + private void registerLabel(){ + if(!linesArgs[0].isEmpty()) { + labelToNextInstr = new NasmLabel(linesArgs[0]); + IAL = 1; + } + } + + public NasmOperand getRightOperandType(String opName){ + if(isMemoryAccessOperand(opName)) { + return getRightMemoryOperand(opName); + } + else if (isRegister(opName)) + return getNasmRegister(opName); + else if(isNumber(opName)){ + var numValue = Integer.parseInt(opName); + return new NasmConstant(numValue); + } + else + return new NasmLabel(opName); + } + + private boolean isMemoryAccessOperand(String opName){ + return opName.contains("[") && opName.contains("]"); + } + + private NasmOperand getRightMemoryOperand(String opName){ + var simplifiedName = opName.replace("[", "").replace("]", ""); + if (isRelativeAddressing(simplifiedName)) { + var direction = '+'; + if (simplifiedName.contains("-")) + direction = '-'; + // on part d'une principe qu'un adresse relative est de la forme 'base {+| -} offset' + // offset est une constante numérique ou un registre + // base est ... + var baseName = simplifiedName.split("\\" + direction)[0]; + var offset = simplifiedName.split("\\" + direction)[1]; + var baseOp = getRightOperandType(baseName); + var offsetOp = (NasmOperand)null; + if(isNumber(offset)) + offsetOp = new NasmConstant(Integer.parseInt(offset)); + else { + offsetOp = getNasmRegister(offset); + } + return new NasmAddress(baseOp, direction, offsetOp); + } + else if (isRegister(simplifiedName)) + return new NasmAddress(getNasmRegister(simplifiedName)); + else + { + try { + var address = Integer.parseInt(simplifiedName); + return new NasmAddress(new NasmConstant(address)); + } catch(NumberFormatException e){ + return new NasmAddress(new NasmLabel(simplifiedName)); + } + } + } + + + private boolean isRelativeAddressing(String simplifiedOpName){ + return simplifiedOpName.contains("-") || simplifiedOpName.contains("+"); + } + + private boolean isNumber(String text){ + try{ + var res = Integer.parseInt(text); + return true; + }catch(NumberFormatException e){ + return false; + } + } + + private NasmRegister getNasmRegister(String registerName){ + if(nameToReg.containsKey(registerName)) + return nameToReg.get(registerName); + + StringBuilder sb = new StringBuilder(registerName); + sb.deleteCharAt(0); + int registerNb = Integer.parseInt(sb.toString()); + NasmRegister reg = new NasmRegister(registerNb); + code.tempCounter++; + /* if(registerName.equals("eax")) reg.colorRegister(Nasm.REG_EAX); + else if(registerName.equals("ebx")) reg.colorRegister(Nasm.REG_EBX); + else if(registerName.equals("ecx")) reg.colorRegister(Nasm.REG_ECX); + else if(registerName.equals("edx")) reg.colorRegister(Nasm.REG_EDX); + else if(registerName.equals("esp")) reg.colorRegister(Nasm.REG_ESP); + else if(registerName.equals("ebp")) reg.colorRegister(Nasm.REG_EBP);*/ + + nameToReg.put(registerName, reg); + return reg; + } + + private boolean isRegister(String opName){ + return (nameToReg.containsKey(opName) || opName.startsWith("r")); + } + + /* public static void main(String[] args){ + var parser = new NasmParser(); + try { + var stParser = new ts.TsParser(); + var res = parser.parse("fibo.pre-nasm", stParser.parse("fibo.ts")); + for(var instr : res.sectionText){ + System.out.println(instr); + } + }catch(IOException e){ + e.printStackTrace(); + } + + // System.out.println(fdf); + }*/ + +} diff --git a/src/nasm/NasmRegister.java b/src/nasm/NasmRegister.java index 9f00453fd70bb73d04c267f2f8008a4af0ca8ea6..76db6d385d22064f2b54353ea03497a9334f6914 100644 --- a/src/nasm/NasmRegister.java +++ b/src/nasm/NasmRegister.java @@ -1,7 +1,6 @@ package nasm; -import java.util.ArrayList; -public class NasmRegister extends NasmOperand implements NasmExp{ +public class NasmRegister extends NasmOperand { public int val; public int color = Nasm.REG_UNK; @@ -21,14 +20,9 @@ public class NasmRegister extends NasmOperand implements NasmExp{ if(this.color == Nasm.REG_ECX) return "ecx"; if(this.color == Nasm.REG_EDX) return "edx"; else - return "@" + this.val; + return "r" + this.val; } - public boolean isEbp(){ - if(this.color == Nasm.REG_EBP) return true; - return false; - } - public boolean isGeneralRegister(){ if(this.color == Nasm.REG_EAX) return true; if(this.color == Nasm.REG_EBX) return true; @@ -41,17 +35,4 @@ public class NasmRegister extends NasmOperand implements NasmExp{ public <T> T accept(NasmVisitor <T> visitor) { return visitor.visit(this); } - - public ArrayList<NasmRegister> getRegisters() - { - ArrayList<NasmRegister> registerList = new ArrayList<NasmRegister>(); - this.getRegisters(registerList); - return registerList; - } - public ArrayList<NasmRegister> getRegisters(ArrayList<NasmRegister> registerList) - { - registerList.add(this); - return registerList; - } - } diff --git a/src/nasm/NasmSize.java b/src/nasm/NasmSize.java deleted file mode 100644 index 3812007288c01ccb8ab2269b668ba9f5f5b80684..0000000000000000000000000000000000000000 --- a/src/nasm/NasmSize.java +++ /dev/null @@ -1,20 +0,0 @@ -package nasm; - -public enum NasmSize { - - BYTE(1, "byte"), - WORD(2, "word"), - DWORD(4, "dword"), - UNDEFINED(0, ""); - private final String name; - private final int value; - - NasmSize(int value, String name) { - this.value = value; - this.name = name; - } - - public String toString(){return name;} - public String getName(){return this.name;} - public int getValue(){return value;} -} \ No newline at end of file diff --git a/src/nasm/NasmVisitor.java b/src/nasm/NasmVisitor.java index 091f20e9470b925f46df3510421f5bdc643c595a..45530516b3ff35b6b2084dd6fd1707eec3195e06 100644 --- a/src/nasm/NasmVisitor.java +++ b/src/nasm/NasmVisitor.java @@ -37,11 +37,7 @@ public interface NasmVisitor <T> { public T visit(NasmResq pseudoInst); public T visit(NasmRest pseudoInst); - public T visit(NasmExp exp); - public T visit(NasmExpPlus exp); - public T visit(NasmExpMinus exp); - public T visit(NasmExpTimes exp); - + } diff --git a/src/sa.cfg b/src/sa.cfg deleted file mode 100644 index d8628151c95df95738b712398c5e699a17ec4bd6..0000000000000000000000000000000000000000 --- a/src/sa.cfg +++ /dev/null @@ -1,193 +0,0 @@ -Package sc; - -Helpers - -lettre = [['a' .. 'z'] + ['A' .. 'Z']]; -chiffre = ['0' .. '9']; -alpha = [lettre + ['_' + '$']]; -alphanum = [lettre + chiffre]; - -Tokens - -espaces = (' ' | 13 | 10)+; -commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); -virgule = ','; -divise = '/'; -point_virgule = ';'; -fois = '*'; -moins = '-'; -parenthese_ouvrante = '('; -parenthese_fermante = ')'; -crochet_ouvrant = '['; -crochet_fermant = ']'; -accolade_ouvrante = '{'; -accolade_fermante = '}'; -egal = '='; -inferieur = '<'; -et = '&'; -ou = '|'; -non = '!'; -plus = '+'; -nonnull = '?'; -si = 'si'; -alors = 'alors'; -sinon = 'sinon'; -tantque = 'tantque'; -faire = 'faire'; -entier = 'entier'; -retour = 'retour'; -lire = 'lire'; -ecrire = 'ecrire'; -nombre = chiffre+; -identif = alpha alphanum*; - -Ignored Tokens - -espaces, commentaire; - -Productions - -programme = -{decvarldecfonc} optdecvar listedecfonc | -{ldecfonc} listedecfonc; - -optdecvar = listedecvar point_virgule; - -listedecvar = -{decvarldecvar} decvar listedecvarbis | -{decvar} decvar; - - -listedecvarbis = -{decvarldecvar} virgule decvar listedecvarbis| -{decvar} virgule decvar ; - -decvar = -{decvarentier} entier identif | -{decvartableau} entier identif crochet_ouvrant nombre crochet_fermant ; - -listedecfonc = -{ldecfoncrec} decfonc listedecfonc | -{ldecfoncfinal} ; - -decfonc = -{decvarinstr} identif listeparam optdecvar instrbloc | -{instr} identif listeparam instrbloc ; - -listeparam = -{sansparam} parenthese_ouvrante parenthese_fermante | -{avecparam} parenthese_ouvrante listedecvar parenthese_fermante ; - -instr = -{instraffect} instraffect | -{instrbloc } instrbloc | -{instrsi } instrsi | -{instrtantque } instrtantque | -{instrappel } instrappel | -{instrretour } instrretour | -{instrecriture } instrecriture | -{instrvide} instrvide | -{instnonnull} instnonnull; - -instraffect = var egal exp point_virgule ; - -instrbloc = accolade_ouvrante listeinst accolade_fermante ; - -//listeinst = instr*; - -listeinst = -{linstrec} instr listeinst | -{linstfinal} ; - - - -instrsi = -{avecsinon} si exp alors instrbloc instrsinon | -{sanssinon} si exp alors instrbloc ; - -instopetern = -{sanssinon} si exp nonnull alors instrbloc instopetern | -{avecsinon} si exp2 alors instrbloc instnonnull; - - -instnonnull = nonnull instrbloc ; - -instrsinon = sinon instrbloc ; - -instrtantque = tantque exp faire instrbloc ; - -instrappel = appelfct point_virgule ; - -instrretour = retour exp point_virgule ; - -instrecriture = ecrire parenthese_ouvrante exp parenthese_fermante point_virgule ; - -instrvide = point_virgule ; - -//################################################################################ -// exp (booléennes, arithmétiques) avec implémentation des priorités. -// ordre croissant de priorités comme suit (le | a la plus petite priorité)= -// 7. | (ou) -// 6. & (et) -// 5. < = -// 4. + - -// 3. * / -// 2. ! (non) -// 1. (exp) appelfct var[exp] -//###############################################################################*/ - -exp = -{ou} exp ou exp1 | -{exp1} exp1; - -exp1 = -{et} exp1 et exp2 | -{exp2} exp2; - -exp2 = -{inf} exp2 inferieur exp3 | -{egal} exp2 egal exp3 | -{exp3} exp3; - -exp3 = -{plus} exp3 plus exp4 | -{moins} exp3 moins exp4 | -{exp4} exp4 ; - -exp4 = -{fois} exp4 fois exp5 | -{divise} exp4 divise exp5 | -{exp5} exp5 ; - -exp5 = -{non} non exp5 | -{exp6} exp6 ; - -exp6 = - {nonnull} nonnull exp6 | - {exp7} exp7 ; - -exp7 = - {nombre} nombre | - {appelfct} appelfct | - {var} var | - {parentheses} parenthese_ouvrante exp parenthese_fermante | - {lire} lire parenthese_ouvrante parenthese_fermante ; - - - -// accès à une variable, case d'un tableau ou appel à fonction - -var = -{vartab} identif crochet_ouvrant exp crochet_fermant | -{varsimple} identif ; - -listeexp = -{recursif} exp listeexpbis| -{final} ; - -listeexpbis = -{recursif} virgule exp listeexpbis | -{final} ; - -appelfct = identif parenthese_ouvrante listeexp parenthese_fermante ; \ No newline at end of file diff --git a/src/sa/ErrorException.java b/src/sa/ErrorException.java deleted file mode 100644 index 61963e600be7dc9fd5d631e3eae7f6a34990f16d..0000000000000000000000000000000000000000 --- a/src/sa/ErrorException.java +++ /dev/null @@ -1,23 +0,0 @@ -package sa; -import util.Error; - -public class ErrorException extends Exception{ - private Error error; - private String message; - - - public ErrorException(Error error, String message){ - this.error = error; - this.message = message; - } - - public String getMessage(){ - return message; - } - - public int getCode(){ - return error.code(); - } - - -} diff --git a/src/sa/LoadSa.java b/src/sa/LoadSa.java deleted file mode 100644 index 209de9c85c26193b813e1b9c8c4cdc4c544cf142..0000000000000000000000000000000000000000 --- a/src/sa/LoadSa.java +++ /dev/null @@ -1,547 +0,0 @@ -package sa; -import saParser.analysis.DepthFirstAdapter; -import saParser.lexer.Lexer; -import saParser.lexer.LexerException; -import saParser.node.*; -import saParser.parser.Parser; -import saParser.parser.ParserException; -import util.Error; -import util.Type; - -import java.io.FileReader; -import java.io.IOException; -import java.io.PushbackReader; - -public class LoadSa extends DepthFirstAdapter { - private SaProg root; - private SaNode returnValue; - private Type returnType; - - public LoadSa(String saFileName) { - PushbackReader fileReader = null; - Parser parser = null; - Start root = null; - try { - fileReader = new PushbackReader(new FileReader(saFileName)); - } catch (IOException e) { - System.err.println("cannot open input file"); - e.printStackTrace(); - } - try { - parser = new Parser(new Lexer(fileReader)); - root = parser.parse(); - } catch (ParserException e) { - System.err.println("syntax error"); - e.printStackTrace(); - System.exit(Error.SYNT.code()); - } catch (LexerException e) { - System.err.println("lexical error"); - e.printStackTrace(); - System.exit(Error.LEX.code()); - } catch (IOException e) { - e.printStackTrace(); - } - root.apply(this); - } - - public void defaultIn(Node node) - { - //System.out.println("<" + node.getClass().getSimpleName() + ">"); - } - - public void defaultOut(Node node) - { - //System.out.println("</" + node.getClass().getSimpleName() + ">"); - } - - public SaProg getRoot(){return root;} - - - - - -// prog = po saprog ldecvar ldecfonc pf - @Override - public void caseAProg(AProg node) - { - inAProg(node); - SaLDecVar ldecVar = null; - SaLDecFonc ldecFonc = null; - if(node.getLdecvar() != null) - { - node.getLdecvar().apply(this); - ldecVar = (SaLDecVar) returnValue; - } - if(node.getLdecfonc() != null) - { - node.getLdecfonc().apply(this); - ldecFonc = (SaLDecFonc) returnValue; - } - root = new SaProg(ldecVar, ldecFonc); - outAProg(node); - } - -// exp = {add} po saexpadd [op1]:exp [op2]:exp pf - @Override - public void caseAAddExp(AAddExp node) - { - inAAddExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpAdd(op1,op2); - outAAddExp(node); - } - -// exp = {and} po saexpand [op1]:exp [op2]:exp pf - @Override - public void caseAAndExp(AAndExp node) - { - inAAndExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpAnd(op1,op2); - outAAndExp(node); - } - -// exp = {div} po saexpdiv [op1]:exp [op2]:exp pf - @Override - public void caseADivExp(ADivExp node) - { - inADivExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpDiv(op1,op2); - outADivExp(node); - } - -// exp = {equal} po saexpequal [op1]:exp [op2]:exp pf - @Override - public void caseAEqualExp(AEqualExp node) - { - inAEqualExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpEqual(op1,op2); - outAEqualExp(node); - } - -// exp = {inf} po saexpinf [op1]:exp [op2]:exp pf - @Override - public void caseAInfExp(AInfExp node) - { - inAInfExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpInf(op1,op2); - outAInfExp(node); - } - -// exp = {mult} po saexpmult [op1]:exp [op2]:exp pf - @Override - public void caseAMultExp(AMultExp node) - { - inAMultExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpMult(op1,op2); - outAMultExp(node); - } - -// exp = {or} po saexpor [op1]:exp [op2]:exp pf - @Override - public void caseAOrExp(AOrExp node) - { - inAOrExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpOr(op1,op2); - } - -// exp = {sub} po saexpsub [op1]:exp [op2]:exp pf - @Override - public void caseASubExp(ASubExp node) - { - inASubExp(node); - node.getOp1().apply(this); - SaExp op1 = (SaExp) returnValue; - node.getOp2().apply(this); - SaExp op2 = (SaExp) returnValue; - returnValue = new SaExpSub(op1,op2); - outASubExp(node); - } - -// exp = {not} po saexpnot exp pf - @Override - public void caseANotExp(ANotExp node) - { - inANotExp(node); - node.getExp().apply(this); - SaExp exp = (SaExp) returnValue; - returnValue = new SaExpNot(exp); - outANotExp(node); - } - -// exp = {appel} po saexpappel appel pf - @Override - public void caseAAppelExp(AAppelExp node) - { - inAAppelExp(node); - node.getAppel().apply(this); - SaAppel appel = (SaAppel) returnValue; - returnValue = new SaExpAppel(appel); - outAAppelExp(node); - } - -// exp = {var} po saexpvar var pf - @Override - public void caseAVarExp(AVarExp node) - { - inAVarExp(node); - node.getVar().apply(this); - SaVar var = (SaVar) returnValue; - returnValue = new SaExpVar(var); - outAVarExp(node); - } - -// exp = {faux} faux - @Override - public void caseAFauxExp(AFauxExp node) - { - inAFauxExp(node); - returnValue = new SaExpFaux(); - outAFauxExp(node); - } - -// exp = {vrai} vrai - @Override - public void caseAVraiExp(AVraiExp node) - { - inAVraiExp(node); - returnValue = new SaExpVrai(); - outAVraiExp(node); - } - -// exp = {int} integer - @Override - public void caseAIntExp(AIntExp node) - { - inAIntExp(node); - int value = Integer.parseInt(node.getInteger().getText()); - returnValue = new SaExpInt(value); - outAIntExp(node); - } - -// exp = {lire} lire - @Override - public void caseALireExp(ALireExp node) - { - inALireExp(node); - returnValue = new SaExpLire(); - outALireExp(node); - } - -// inst = {affect} po sainstaffect var exp pf - @Override - public void caseAAffectInst(AAffectInst node) - { - inAAffectInst(node); - node.getVar().apply(this); - SaVar var = (SaVar) returnValue; - node.getExp().apply(this); - SaExp exp = (SaExp) returnValue; - returnValue = new SaInstAffect(var, exp); - outAAffectInst(node); - } - -// inst = {bloc} po sainstbloc linst pf - @Override - public void caseABlocInst(ABlocInst node) - { - inABlocInst(node); - node.getLinst().apply(this); - SaLInst linst = (SaLInst) returnValue; - returnValue = new SaInstBloc(linst); - outABlocInst(node); - } - -// inst = {ecriture} po sainstecriture exp pf - @Override - public void caseAEcritureInst(AEcritureInst node) - { - inAEcritureInst(node); - node.getExp().apply(this); - SaExp exp = (SaExp) returnValue; - returnValue = new SaInstEcriture(exp); - outAEcritureInst(node); - } - -// inst = {retour} po sainstretour exp pf - @Override - public void caseARetourInst(ARetourInst node) - { - inARetourInst(node); - node.getExp().apply(this); - SaExp exp = (SaExp) returnValue; - returnValue = new SaInstRetour(exp); - outARetourInst(node); - } - -// inst = {si} po sainstsi exp [alors]:inst [sinon]:inst pf - @Override - public void caseASiInst(ASiInst node) - { - inASiInst(node); - node.getExp().apply(this); - SaExp si = (SaExp) returnValue; - node.getAlors().apply(this); - SaInst alors = (SaInst) returnValue; - SaInst sinon = null; - if(node.getSinon() != null) - { - node.getSinon().apply(this); - sinon = (SaInst) returnValue; - } - returnValue = new SaInstSi(si, alors, sinon); - outASiInst(node); - } - - // inst = {si2} po sainstsi exp [alors]:inst null pf - - @Override - public void caseASi2Inst(ASi2Inst node) - { - inASi2Inst(node); - node.getExp().apply(this); - SaExp si = (SaExp) returnValue; - node.getAlors().apply(this); - SaInst alors = (SaInst) returnValue; - returnValue = new SaInstSi(si, alors, null); - outASi2Inst(node); - } - - - // inst = {tantque} po sainsttantque exp inst pf - @Override - public void caseATantqueInst(ATantqueInst node) - { - inATantqueInst(node); - node.getExp().apply(this); - SaExp test = (SaExp) returnValue; - node.getInst().apply(this); - SaInst bloc = (SaInst) returnValue; - returnValue = new SaInstTantQue(test, bloc); - outATantqueInst(node); - } - -// ldecfonc = {rec} po saldecfonc decfonc ldecfonc pf - @Override - public void caseARecLdecfonc(ARecLdecfonc node) - { - inARecLdecfonc(node); - node.getDecfonc().apply(this); - SaDecFonc dec = (SaDecFonc) returnValue; - node.getLdecfonc().apply(this); - SaLDecFonc ldec = (SaLDecFonc) returnValue; - returnValue = new SaLDecFonc(dec, ldec); - outARecLdecfonc(node); - } - -// ldecfonc = {fin} null - @Override - public void caseAFinLdecfonc(AFinLdecfonc node) - { - inAFinLdecfonc(node); - returnValue = null; - outAFinLdecfonc(node); - } - -// ldecvar = {rec} po saldecvar decvar ldecvar pf - @Override - public void caseARecLdecvar(ARecLdecvar node) - { - inARecLdecvar(node); - node.getDecvar().apply(this); - SaDecVar dec = (SaDecVar) returnValue; - node.getLdecvar().apply(this); - SaLDecVar ldec = (SaLDecVar) returnValue; - returnValue = new SaLDecVar(dec, ldec); - outARecLdecvar(node); - } - -// ldecvar = {fin} null - @Override - public void caseAFinLdecvar(AFinLdecvar node) - { - inAFinLdecvar(node); - returnValue = null; - outAFinLdecvar(node); - } - -// lexp = {rec} po salexp exp lexp pf - @Override - public void caseARecLexp(ARecLexp node) - { - inARecLexp(node); - node.getExp().apply(this); - SaExp exp = (SaExp) returnValue; - node.getLexp().apply(this); - SaLExp lexp = (SaLExp) returnValue; - returnValue = new SaLExp(exp, lexp); - outARecLexp(node); - } - -// lexp = {fin} null - @Override - public void caseAFinLexp(AFinLexp node) - { - inAFinLexp(node); - returnValue = null; - outAFinLexp(node); - } - -// linst = {rec} po salinst inst linst pf - @Override - public void caseARecLinst(ARecLinst node) - { - inARecLinst(node); - node.getInst().apply(this); - SaInst inst = (SaInst) returnValue; - node.getLinst().apply(this); - SaLInst linst = (SaLInst) returnValue; - returnValue = new SaLInst(inst, linst); - outARecLinst(node); - } - -// linst = {fin} null - @Override - public void caseAFinLinst(AFinLinst node) - { - inAFinLinst(node); - returnValue = null; - outAFinLinst(node); - } - -// decfonc = po sadecfonc id [param]:ldecvar [variables]:ldecvar inst type pf - @Override - public void caseADecfonc(ADecfonc node) - { - inADecfonc(node); - String foncName = node.getId().getText(); - node.getParam().apply(this); - SaLDecVar params = (SaLDecVar) returnValue; - node.getVariables().apply(this); - SaLDecVar variables = (SaLDecVar) returnValue; - node.getInst().apply(this); - SaInst corps = (SaInst) returnValue; - node.getType().apply(this); - Type type = returnType; - returnValue = new SaDecFonc(foncName, type, params, variables, corps); - outADecfonc(node); - } - -// decvar = {tab} po sadectab id integer type pf - @Override - public void caseATabDecvar(ATabDecvar node) - { - inATabDecvar(node); - String nom = node.getId().getText(); - int taille = Integer.parseInt(node.getInteger().getText()); - node.getType().apply(this); - Type type = returnType; - returnValue = new SaDecTab(nom, type, taille); - outATabDecvar(node); - } - -// decvar = {simple} po sadecvarsimple id type pf - @Override - public void caseASimpleDecvar(ASimpleDecvar node) - { - inASimpleDecvar(node); - String nom = node.getId().getText(); - node.getType().apply(this); - Type type = returnType; - returnValue = new SaDecVarSimple(nom, type); - outASimpleDecvar(node); - } - - // var = {indicee} po savarindicee id exp pf - @Override - public void caseAIndiceeVar(AIndiceeVar node) - { - inAIndiceeVar(node); - String nom = node.getId().getText(); - node.getExp().apply(this); - SaExp indice = (SaExp) returnValue; - returnValue = new SaVarIndicee(nom, indice); - outAIndiceeVar(node); - } - - // var = {simple} po savarsimple id pf - @Override - public void caseASimpleVar(ASimpleVar node) - { - inASimpleVar(node); - String nom = node.getId().getText(); - returnValue = new SaVarSimple(nom); - outASimpleVar(node); - } - -// appel = po saappel id lexp pf - @Override - public void caseAAppel(AAppel node) - { - inAAppel(node); - String nom = node.getId().getText(); - node.getLexp().apply(this); - SaLExp arguments = (SaLExp) returnValue; - returnValue = new SaAppel(nom, arguments); - outAAppel(node); - } - -// type = {entier} entier - @Override - public void caseAEntierType(AEntierType node) - { - inAEntierType(node); - returnType = Type.ENTIER; - outAEntierType(node); - } - -// type = {bool} bool - @Override - public void caseABoolType(ABoolType node) - { - inABoolType(node); - returnType = Type.BOOL; - outABoolType(node); - } - -// type = {null} nul - @Override - public void caseANullType(ANullType node) - { - inANullType(node); - returnType = Type.NUL; - outANullType(node); - } -} - - - - - - diff --git a/src/sa/Sa2Xml.java b/src/sa/Sa2Xml.java new file mode 100644 index 0000000000000000000000000000000000000000..3d832c0318a1fe046558a4cdb61ea4d23cb35ccc --- /dev/null +++ b/src/sa/Sa2Xml.java @@ -0,0 +1,468 @@ +package sa; +import java.io.*; + +public class Sa2Xml extends SaDepthFirstVisitor < Void > { + private int indentation = 0; + private String baseFileName; + private String fileName; + private PrintStream out; + private String childName; + + + public Sa2Xml(SaNode root, String baseFileName) + { + if (baseFileName == null){ + this.out = System.out; + } + else{ + try { + this.baseFileName = baseFileName; + this.fileName = baseFileName + ".sa"; + this.out = new PrintStream(this.fileName); + } + + catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + childName = "programme"; + root.accept(this); + } + + public void printOpenTag(String TagName){ + printOpenTag(TagName, null, null); + } + + public void printOpenTag(String TagName, SaNode node){ + printOpenTag(TagName, node, null); + } + + public void printOpenTag(String TagName, String attrValList){ + printOpenTag(TagName, null, attrValList); + } + + public void printOpenTag(String TagName, SaNode node, String attrValList){ + for(int i = 0; i < indentation; i++){this.out.print(" ");} + indentation++; + if(node != null) + this.out.print("<" + TagName + " type=" + "\"" + node.getClass().getSimpleName() + "\""); + else + this.out.print("<" + TagName); + if(attrValList != null) + this.out.print(attrValList); + this.out.println(">"); + } + + public void printCloseTag(String TagName) + { + indentation--; + for(int i = 0; i < indentation; i++){this.out.print(" ");} + this.out.println("</" + TagName + ">"); + } + + public void printOpenCloseTag(String TagName){ + printOpenTag(TagName, null, null); + } + + public void printOpenCloseTag(String TagName, SaNode node){ + printOpenCloseTag(TagName, node, null); + } + + public void printOpenCloseTag(String TagName, String attrValList){ + printOpenCloseTag(TagName, null, attrValList); + } + + public void printOpenCloseTag(String TagName, SaNode node, String attrValList){ + for(int i = 0; i < indentation; i++){this.out.print(" ");} + // indentation++; + if(node != null) + this.out.print("<" + TagName + " type=" + "\"" + node.getClass().getSimpleName() + "\""); + else + this.out.print("<" + TagName); + if(attrValList != null) + this.out.print(attrValList); + this.out.println("/>"); + } + + // P -> LDEC LDEC + public Void visit(SaProg node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + if(node.getVariables() != null){ + this.childName = "variables"; + node.getVariables().accept(this); + } + + if(node.getFonctions() != null){ + this.childName = "fonctions"; + node.getFonctions().accept(this); + } + printCloseTag(nodeName); + return null; + } + + + // DEC -> var id taille + public Void visit(SaDecTab node){ + String nodeName = this.childName; + String attrValList = " nom=\"" + node.getNom() + "\"" + " taille=\"" + node.getTaille() + "\""; + printOpenTag(nodeName, node, attrValList); + printCloseTag(nodeName); + return null; + } + + // EXP -> entier + public Void visit(SaExpInt node) + { + String nodeName = this.childName; + String attrValList = " val=\"" + node.getVal() + "\""; + printOpenCloseTag(nodeName, node, attrValList); + return null; + } + + public Void visit(SaExpVar node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "var"; + node.getVar().accept(this); + printCloseTag(nodeName); + return null; + } + + public Void visit(SaInstEcriture node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "arg"; + node.getArg().accept(this); + printCloseTag(nodeName); + return null; + } + + public Void visit(SaInstTantQue node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "test"; + node.getTest().accept(this); + if (node.getFaire() != null){ + childName = "faire"; + node.getFaire().accept(this); + } + printCloseTag(nodeName); + return null; + } + + public Void visit(SaLInst node) + { + if(node == null) return null; + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "tete"; + node.getTete().accept(this); + + if(node.getQueue() != null){ + childName = "queue"; + node.getQueue().accept(this); + } + printCloseTag(nodeName); + return null; + } + + // DEC -> fct id LDEC LDEC LINST + + public Void visit(SaDecFonc node) + { + String nodeName = this.childName; + String attrValList = " nom=\"" + node.getNom() + "\""; + + printOpenTag(nodeName, node, attrValList); + if(node.getParametres() != null){ + childName = "parametres"; + node.getParametres().accept(this); + } + + if(node.getVariable() != null){ + childName = "variables"; + node.getVariable().accept(this); + } + if (node.getCorps() != null){ + childName = "corps"; + node.getCorps().accept(this); + } + printCloseTag(nodeName); + return null; + } + + // DEC -> var id + public Void visit(SaDecVar node) + { + String nodeName = this.childName; + String attrValList = " nom=\"" + node.getNom() + "\""; + printOpenCloseTag(nodeName, node, attrValList); + return null; + } + + public Void visit(SaInstAffect node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + this.childName = "lhs"; + node.getLhs().accept(this); + this.childName = "rhs"; + node.getRhs().accept(this); + printCloseTag(nodeName); + return null; + } + + // LDEC -> DEC LDEC + // LDEC -> null + public Void visit(SaLDec node) + { + String nodeName = this.childName; + + printOpenTag(nodeName, node); + childName="tete"; + node.getTete().accept(this); + + if(node.getQueue() != null){ + childName="queue"; + node.getQueue().accept(this); + } + printCloseTag(nodeName); + + return null; + } + + + public Void visit(SaVarSimple node) + { + String nodeName = this.childName; + String attrValList = " nom=\"" + node.getNom() + "\""; + + printOpenCloseTag(nodeName, node, attrValList); + return null; + } + + + public Void visit(SaAppel node) + { + String nodeName = this.childName; + String attrValList = " nom=\"" + node.getNom() + "\""; + + printOpenTag(nodeName, node, attrValList); + if(node.getArguments() != null){ + childName = "arguments"; + node.getArguments().accept(this); + } + printCloseTag(nodeName); + return null; + } + + public Void visit(SaExpAppel node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "val"; + node.getVal().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> add EXP EXP + public Void visit(SaExpAdd node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> sub EXP EXP + public Void visit(SaExpSub node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + + } + + // EXP -> mult EXP EXP + public Void visit(SaExpMult node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> div EXP EXP + public Void visit(SaExpDiv node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> inf EXP EXP + public Void visit(SaExpInf node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> eq EXP EXP + public Void visit(SaExpEqual node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> and EXP EXP + public Void visit(SaExpAnd node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + + // EXP -> or EXP EXP + public Void visit(SaExpOr node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + childName = "op2"; + node.getOp2().accept(this); + printCloseTag(nodeName); + return null; + } + + // EXP -> not EXP + public Void visit(SaExpNot node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "op1"; + node.getOp1().accept(this); + printCloseTag(nodeName); + return null; + } + + + public Void visit(SaExpLire node) + { + String nodeName = this.childName; + printOpenCloseTag(nodeName, node); + return null; + } + + public Void visit(SaInstBloc node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "val"; + node.getVal().accept(this); + printCloseTag(nodeName); + return null; + } + + public Void visit(SaInstSi node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "test"; + node.getTest().accept(this); + if (node.getAlors() != null){ + childName = "alors"; + node.getAlors().accept(this); + } + if(node.getSinon() != null){ + childName = "sinon"; + node.getSinon().accept(this); + } + printCloseTag(nodeName); + return null; + } + +// INST -> ret EXP + public Void visit(SaInstRetour node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "val"; + node.getVal().accept(this); + printCloseTag(nodeName); + return null; + } + + + public Void visit(SaLExp node) + { + String nodeName = this.childName; + printOpenTag(nodeName, node); + childName = "tete"; + node.getTete().accept(this); + if(node.getQueue() != null){ + childName = "queue"; + node.getQueue().accept(this); + } + printCloseTag(nodeName); + return null; + } + public Void visit(SaVarIndicee node) + { + String nodeName = this.childName; + String attrValList = " nom=\"" + node.getNom() + "\""; + + printOpenTag(nodeName, node, attrValList); + childName = "indice"; + node.getIndice().accept(this); + printCloseTag(nodeName); + return null; + } + + + + + +} diff --git a/src/sa/SaAppel.java b/src/sa/SaAppel.java index 84a3f776e1a22e1576cef5ae7617683f99adf327..e7f9f6ddfff9e7f9a11c198b209647d32e0451cd 100644 --- a/src/sa/SaAppel.java +++ b/src/sa/SaAppel.java @@ -1,6 +1,5 @@ package sa; import ts.*; -import util.Type; public class SaAppel implements SaExp, SaInst{ @@ -16,18 +15,8 @@ public class SaAppel implements SaExp, SaInst{ public String getNom(){return this.nom;} public SaLExp getArguments(){return this.arguments;} - - - public Type getType(){ - return tsItem.typeRetour; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName()+ " " + nom + " " + arguments + ")"; - } } diff --git a/src/sa/SaCheckLinkage.java b/src/sa/SaCheckLinkage.java deleted file mode 100644 index f25f01789debecd89aea3c1023b5dac5e3b70e42..0000000000000000000000000000000000000000 --- a/src/sa/SaCheckLinkage.java +++ /dev/null @@ -1,42 +0,0 @@ -package sa; - -import util.Error; - -public class SaCheckLinkage extends SaDepthFirstVisitor <Void>{ - - public Void visit(SaDecFonc node) throws Exception { - defaultIn(node); - if (node.tsItem == null) throw new ErrorException(Error.TS, "linkage error in SaDecFonc"); - if(node.getParametres() != null) node.getParametres().accept(this); - if(node.getVariable() != null) node.getVariable().accept(this); - if(node.getCorps() != null) node.getCorps().accept(this); - defaultOut(node); - return null; - - } - - public Void visit(SaDecVarSimple node) throws ErrorException { - if (node.tsItem == null) throw new ErrorException(Error.TS, "linkage error in SaDecVarSimple"); - return null; - } - - public Void visit(SaDecTab node) throws ErrorException { - if(node.tsItem == null) throw new ErrorException(Error.TS, "linkage error in SaDecTab"); - return null; - } - - public Void visit(SaAppel node) throws ErrorException{ - if(node.tsItem == null) throw new ErrorException(Error.TS, "linkage error in SaAppel"); - return null; - } - - public Void visit(SaVarSimple node) throws ErrorException{ - if(node.tsItem == null) throw new ErrorException(Error.TS, "linkage error in SaVarSimple"); - return null; - } - public Void visit(SaVarIndicee node) throws ErrorException{ - if(node.tsItem == null) throw new ErrorException(Error.TS, "linkage error in SaVarIndicee"); - return null; - } -} - diff --git a/src/sa/SaDecFonc.java b/src/sa/SaDecFonc.java index 7f4b817756c74306030039cecf3df83db5c309de..d05115fe4c8e5030195cce02ea223428c5f32df7 100644 --- a/src/sa/SaDecFonc.java +++ b/src/sa/SaDecFonc.java @@ -1,34 +1,27 @@ package sa; import ts.*; -import util.Type; public class SaDecFonc implements SaDec{ - private String nom; - private SaLDecVar parametres; - private SaLDecVar variables; - private SaInst corps; - private Type typeRetour; - public TsItemFct tsItem; + private String nom; + private SaLDec parametres; + private SaLDec variables; + private SaInst corps; + public TsItemFct tsItem; - public SaDecFonc(String nom, Type typeRetour, SaLDecVar parametres, SaLDecVar variables, SaInst corps){ + public SaDecFonc(String nom, SaLDec parametres, SaLDec variables, SaInst corps){ this.nom = nom; - this.typeRetour = typeRetour; this.parametres = parametres; this.variables = variables; this.corps = corps; this.tsItem = null; } - public String getNom(){return this.nom;} - public Type getTypeRetour(){return this.typeRetour;} - public SaLDecVar getParametres(){return this.parametres;} - public SaLDecVar getVariable(){return this.variables;} - public SaInst getCorps(){return this.corps;} + public String getNom(){return this.nom;} + public SaLDec getParametres(){return this.parametres;} + public SaLDec getVariable(){return this.variables;} + public SaInst getCorps(){return this.corps;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - public String toString(){ - return "(" + this.getClass().getSimpleName() + " " + nom + " " + typeRetour + " " + parametres + " " + variables + " " + corps + ")"; - } } diff --git a/src/sa/SaDecTab.java b/src/sa/SaDecTab.java index 8eaf2094c4e567fb0fa25e14eb2390c2ebe5090c..628ee88e5f7be5dc2b9ae678acacc6c34f1ce1c7 100644 --- a/src/sa/SaDecTab.java +++ b/src/sa/SaDecTab.java @@ -1,31 +1,22 @@ package sa; import ts.*; -import util.Type; -public class SaDecTab implements SaDecVar{ - private String nom; - private int taille; - private Type type; - public TsItemVar tsItem; +public class SaDecTab implements SaDec{ + private String nom; + private int taille; + public TsItemVar tsItem; - public SaDecTab(String nom, Type type, int taille){ + public SaDecTab(String nom, int taille){ this.nom = nom; - this.type = type; this.taille = taille; this.tsItem = null; } - public String getNom(){return this.nom;} - public int getTaille(){return this.taille;} - public Type getType(){return this.type;} - public TsItemVar getTsItem(){return this.tsItem;} - public void setTsItem(TsItemVar tsItem){this.tsItem = tsItem;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public String getNom(){return this.nom;} + public int getTaille(){return this.taille;} + + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + nom + " " + type + " " + taille + ")"; - } } diff --git a/src/sa/SaDecVar.java b/src/sa/SaDecVar.java index 9cc6f02a87b83e5a3692d4c9fbfab6533acb5386..b526a1753365f06512452d1bfe27b1dc0199e826 100644 --- a/src/sa/SaDecVar.java +++ b/src/sa/SaDecVar.java @@ -1,11 +1,18 @@ package sa; -import util.Type; import ts.*; -public interface SaDecVar extends SaNode { - public String getNom(); - public Type getType(); - public TsItemVar getTsItem(); - public void setTsItem(TsItemVar tsItem); +public class SaDecVar implements SaDec{ + private String nom; + public TsItemVar tsItem; + public SaDecVar(String nom){ + this.nom = nom; + this.tsItem = null; + } + + public String getNom(){return this.nom;} + + public <T> T accept(SaVisitor <T> visitor) { + return visitor.visit(this); + } } diff --git a/src/sa/SaDecVarSimple.java b/src/sa/SaDecVarSimple.java deleted file mode 100644 index 557cf28b32d934981c05104457e587a433767a00..0000000000000000000000000000000000000000 --- a/src/sa/SaDecVarSimple.java +++ /dev/null @@ -1,29 +0,0 @@ -package sa; -import ts.*; -import util.Type; - -public class SaDecVarSimple implements SaDecVar{ - private String nom; - private Type type; - public TsItemVar tsItem; - - public SaDecVarSimple(String nom, Type type){ - this.nom = nom; - this.type = type; - this.tsItem = null; - } - - public String getNom(){return this.nom;} - public Type getType(){return this.type;} - public TsItemVar getTsItem(){return this.tsItem;} - public void setTsItem(TsItemVar tsItem){this.tsItem = tsItem;} - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ - return visitor.visit(this); - } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + nom + " " + type + ")"; - } -} diff --git a/src/sa/SaDepthFirstVisitor.java b/src/sa/SaDepthFirstVisitor.java index ded93ad194c4d1bc1f81c6f76a48c900262ce527..07ba24d68987f4dc7c4faa7e746dfcdbc14f497a 100644 --- a/src/sa/SaDepthFirstVisitor.java +++ b/src/sa/SaDepthFirstVisitor.java @@ -74,7 +74,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // P -> LDEC LDEC - public T visit(SaProg node) throws Exception + public T visit(SaProg node) { defaultIn(node); if(node.getVariables() != null) @@ -86,13 +86,13 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // DEC -> var id taille - public T visit(SaDecTab node) throws Exception{ + public T visit(SaDecTab node){ defaultIn(node); defaultOut(node); return null; } - public T visit(SaExp node) throws Exception + public T visit(SaExp node) { defaultIn(node); defaultOut(node); @@ -100,30 +100,13 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> entier - public T visit(SaExpInt node) throws Exception + public T visit(SaExpInt node) { defaultIn(node); defaultOut(node); return null; } - - // EXP -> vrai - public T visit(SaExpVrai node) throws Exception - { - defaultIn(node); - defaultOut(node); - return null; - } - - // EXP -> faux - public T visit(SaExpFaux node) throws Exception - { - defaultIn(node); - defaultOut(node); - return null; - } - - public T visit(SaExpVar node) throws Exception + public T visit(SaExpVar node) { defaultIn(node); node.getVar().accept(this); @@ -131,7 +114,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ return null; } - public T visit(SaInstEcriture node) throws Exception + public T visit(SaInstEcriture node) { defaultIn(node); node.getArg().accept(this); @@ -139,7 +122,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ return null; } - public T visit(SaInstTantQue node) throws Exception + public T visit(SaInstTantQue node) { defaultIn(node); node.getTest().accept(this); @@ -148,7 +131,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ defaultOut(node); return null; } - public T visit(SaLInst node) throws Exception + public T visit(SaLInst node) { defaultIn(node); if(node != null){ @@ -160,7 +143,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // DEC -> fct id LDEC LDEC LINST - public T visit(SaDecFonc node) throws Exception + public T visit(SaDecFonc node) { defaultIn(node); if(node.getParametres() != null) node.getParametres().accept(this); @@ -171,14 +154,14 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // DEC -> var id - public T visit(SaDecVar node) throws Exception + public T visit(SaDecVar node) { defaultIn(node); defaultOut(node); return null; } - public T visit(SaInstAffect node) throws Exception + public T visit(SaInstAffect node) { defaultIn(node); node.getLhs().accept(this); @@ -189,25 +172,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ // LDEC -> DEC LDEC // LDEC -> null - /* public T visit(SaLDec node) throws Exception - { - defaultIn(node); - node.getTete().accept(this); - if(node.getQueue() != null) node.getQueue().accept(this); - defaultOut(node); - return null; - }*/ - - public T visit(SaLDecVar node) throws Exception - { - defaultIn(node); - node.getTete().accept(this); - if(node.getQueue() != null) node.getQueue().accept(this); - defaultOut(node); - return null; - } - - public T visit(SaLDecFonc node) throws Exception + public T visit(SaLDec node) { defaultIn(node); node.getTete().accept(this); @@ -216,14 +181,14 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ return null; } - public T visit(SaVarSimple node) throws Exception + public T visit(SaVarSimple node) { defaultIn(node); defaultOut(node); return null; } - public T visit(SaAppel node) throws Exception + public T visit(SaAppel node) { defaultIn(node); if(node.getArguments() != null) node.getArguments().accept(this); @@ -231,7 +196,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ return null; } - public T visit(SaExpAppel node) throws Exception + public T visit(SaExpAppel node) { defaultIn(node); node.getVal().accept(this); @@ -240,7 +205,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> add EXP EXP - public T visit(SaExpAdd node) throws Exception + public T visit(SaExpAdd node) { defaultIn(node); node.getOp1().accept(this); @@ -250,7 +215,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> sub EXP EXP - public T visit(SaExpSub node) throws Exception + public T visit(SaExpSub node) { defaultIn(node); node.getOp1().accept(this); @@ -260,7 +225,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> mult EXP EXP - public T visit(SaExpMult node) throws Exception + public T visit(SaExpMult node) { defaultIn(node); node.getOp1().accept(this); @@ -270,7 +235,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> div EXP EXP - public T visit(SaExpDiv node) throws Exception + public T visit(SaExpDiv node) { defaultIn(node); node.getOp1().accept(this); @@ -280,7 +245,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> inf EXP EXP - public T visit(SaExpInf node) throws Exception + public T visit(SaExpInf node) { defaultIn(node); node.getOp1().accept(this); @@ -290,7 +255,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> eq EXP EXP - public T visit(SaExpEqual node) throws Exception + public T visit(SaExpEqual node) { defaultIn(node); node.getOp1().accept(this); @@ -300,7 +265,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> and EXP EXP - public T visit(SaExpAnd node) throws Exception + public T visit(SaExpAnd node) { defaultIn(node); node.getOp1().accept(this); @@ -311,7 +276,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ // EXP -> or EXP EXP - public T visit(SaExpOr node) throws Exception + public T visit(SaExpOr node) { defaultIn(node); node.getOp1().accept(this); @@ -321,7 +286,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // EXP -> not EXP - public T visit(SaExpNot node) throws Exception + public T visit(SaExpNot node) { defaultIn(node); node.getOp1().accept(this); @@ -330,14 +295,14 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } - public T visit(SaExpLire node) throws Exception + public T visit(SaExpLire node) { defaultIn(node); defaultOut(node); return null; } - public T visit(SaInstBloc node) throws Exception + public T visit(SaInstBloc node) { defaultIn(node); node.getVal().accept(this); @@ -345,7 +310,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ return null; } - public T visit(SaInstSi node) throws Exception + public T visit(SaInstSi node) { defaultIn(node); node.getTest().accept(this); @@ -357,7 +322,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } // INST -> ret EXP - public T visit(SaInstRetour node) throws Exception + public T visit(SaInstRetour node) { defaultIn(node); node.getVal().accept(this); @@ -366,7 +331,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ } - public T visit(SaLExp node) throws Exception + public T visit(SaLExp node) { defaultIn(node); node.getTete().accept(this); @@ -375,7 +340,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{ defaultOut(node); return null; } - public T visit(SaVarIndicee node) throws Exception + public T visit(SaVarIndicee node) { defaultIn(node); node.getIndice().accept(this); diff --git a/src/sa/SaEnvironment.java b/src/sa/SaEnvironment.java index 1c85759e6227e50911e0e656b6835235672e5483..d7cb56c056711c9e66c77f869e08dac7e5a65101 100644 --- a/src/sa/SaEnvironment.java +++ b/src/sa/SaEnvironment.java @@ -1,12 +1,11 @@ package sa; import java.util.*; import ts.*; -import util.Memory; public class SaEnvironment { - public Memory vars; - public Memory args; - public TypeVal returnValue; + private int[] vars; + private int[] args; + private int returnValue; public SaEnvironment (TsItemFct fct) { @@ -14,20 +13,21 @@ public class SaEnvironment { Ts localTable = fct.getTable(); int i = 0; - args = new Memory(localTable.getAdrArgCourante(), 0); - vars = new Memory(localTable.getAdrVarCourante(), 0); - - // args = new Memory(200, 0); - // vars = new Memory(200, 0); - - returnValue = null; - // System.out.println("allocation d'un nouvel environnement, fonction " + fct.getIdentif()); - // System.out.println("dim var = " + localTable.getAdrVarCourante()); - // System.out.println("dim arg = " + localTable.getAdrArgCourante()); + args = new int[localTable.nbArg()]; + vars = new int[localTable.nbVar()]; + returnValue = 0; + // System.out.println("allocation d'un nouvel environnement"); + // System.out.println("nb var = " + localTable.nbVar()); + // System.out.println("nb arg = " + localTable.nbArg()); } - - public TypeVal getReturnValue(){return returnValue;} - public void setReturnValue(TypeVal typeVal){returnValue = typeVal;} + public int getVar(int adr){return vars[adr/4];} + public void setVar(int adr, int val){vars[adr/4] = val;} + + public int getArg(int adr){return args[adr/4];} + public void setArg(int adr, int val){args[adr/4] = val;} + + public int getReturnValue(){return returnValue;} + public void setReturnValue(int val){returnValue = val;} } diff --git a/src/sa/SaEval.java b/src/sa/SaEval.java index 434054b497c7cd4b84c1836258258fa210d7cb4a..099c48e27bd0831575aa846e0ae2634a539af614 100644 --- a/src/sa/SaEval.java +++ b/src/sa/SaEval.java @@ -2,103 +2,63 @@ package sa; import java.util.*; import java.io.*; import ts.*; -import util.Memory; -import util.Type; - -public class SaEval extends SaDepthFirstVisitor <TypeVal> { +public class SaEval extends SaDepthFirstVisitor <Integer> { private Ts tableGlobale; private SaEnvironment curEnv; - private Memory varGlob; + private int[] varGlob; private ArrayList<String> programOutput = new ArrayList<String>(); private boolean stop; - - public SaEval(SaNode root, Ts tableGlobale){ - this.tableGlobale = tableGlobale; - curEnv = null; - varGlob = new Memory(tableGlobale.getAdrVarCourante(), 0); - stop = false; - SaAppel appelMain = new SaAppel("main", null); - appelMain.tsItem = tableGlobale.getFct("main"); - - try{ - appelMain.accept(this); - } catch(Exception e){ - e.printStackTrace() - } - } - - public TypeVal getVar(SaVarSimple saVar){ - TsItemVarSimple tsItem = saVar.getTsItem(); - return getVar(tsItem); - } - - public TypeVal getVar(TsItemVarSimple tsItem){ - Memory container = null; - if(tsItem.portee == this.tableGlobale) // variable globale - container = varGlob; - else - container = (tsItem.isParam)? curEnv.args : curEnv.vars; - if(tsItem.type == Type.ENTIER) - return new TypeVal(container.readInt(tsItem.adresse)); - // if(tsItem.type == Type.BOOL) - return new TypeVal(container.readBoolean(tsItem.adresse)); - } - - public void setVar(SaVarSimple saVar, TypeVal typeVal){ - TsItemVarSimple tsItem = saVar.getTsItem(); - setVar(tsItem, typeVal); - } - - - public void setVar(TsItemVarSimple tsItem, TypeVal typeVal){ - Memory container = null; - // trois cas possibles : une variable locale, une variable globale ou un argument - if(tsItem.portee == this.tableGlobale) // variable globale - container = varGlob; - else if (tsItem.isParam) - container = curEnv.args; - else - container = curEnv.vars; - - if(tsItem.type == Type.ENTIER) - container.writeInt(tsItem.adresse, typeVal.valInt); - if(tsItem.type == Type.BOOL) - container.writeBoolean(tsItem.adresse, typeVal.valBool); - } - - private TypeVal getVarGlobIndicee(SaVarIndicee saVarIndicee, TypeVal indice){ - TsItemVar tsItem = saVarIndicee.getTsItem(); - if(tsItem.type == Type.ENTIER) - return new TypeVal(varGlob.readInt(tsItem.adresse + tsItem.type.taille() * indice.valInt)); - // if(tsItem.type == Type.BOOL) - return new TypeVal(varGlob.readBoolean(tsItem.adresse + tsItem.type.taille() * indice.valInt)); - } - - private void setVarGlobIndicee(SaVarIndicee saVarIndicee, TypeVal indice, TypeVal typeVal){ - TsItemVar tsItem = saVarIndicee.getTsItem(); - if(tsItem.type == Type.ENTIER) - varGlob.writeInt(tsItem.adresse + tsItem.type.taille() * indice.valInt, typeVal.valInt); - if(tsItem.type == Type.BOOL) - varGlob.writeBoolean(tsItem.adresse + tsItem.type.taille() * indice.valInt , typeVal.valBool); - } - - - public void affiche(String baseFileName){ - String fileName; - PrintStream out = System.out; - - if (baseFileName != null){ - try { - baseFileName = baseFileName; - fileName = baseFileName + ".saout"; - out = new PrintStream(fileName); - } catch (IOException e) { - System.err.println("Error: " + e.getMessage()); - } - } - for (String line : programOutput) - out.println(line); + private static final int SIZEOF_ENTIER = 4; + private int getVarGlob(TsItemVar tsItem){ + // les adresses sont en octets, mais varGlob est un tableau d'entiers + return varGlob[tsItem.adresse / SIZEOF_ENTIER]; + } + + private int getVarGlobIndicee(TsItemVar tsItem, int indice){ + // les adresses sont en octets, mais varGlob est un tableau d'entiers + return varGlob[tsItem.adresse / SIZEOF_ENTIER + indice]; + } + + private void setVarGlob(TsItemVar tsItem, int val){ + // les adresses sont en octets, mais varGlob est un tableau d'entiers + varGlob[tsItem.adresse / SIZEOF_ENTIER] = val; + } + + private void setVarGlobIndicee(TsItemVar tsItem, int indice, int val){ + // les adresses sont en octets, mais varGlob est un tableau d'entiers + varGlob[tsItem.adresse / SIZEOF_ENTIER + indice] = val; + } + + public SaEval(SaNode root, Ts tableGlobale){ + this.tableGlobale = tableGlobale; + curEnv = null; + varGlob = new int[tableGlobale.nbVar()]; + stop = false; + + SaAppel appelMain = new SaAppel("main", null); + appelMain.tsItem = tableGlobale.getFct("main"); + + appelMain.accept(this); + } + + public void affiche(String baseFileName){ + String fileName; + PrintStream out = System.out; + + if (baseFileName != null){ + try { + baseFileName = baseFileName; + fileName = baseFileName + ".saout"; + out = new PrintStream(fileName); + } + + catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + } + } + for (String line : programOutput) + out.println(line); } @@ -112,356 +72,354 @@ public class SaEval extends SaDepthFirstVisitor <TypeVal> { } // P -> LDEC LDEC - public TypeVal visit(SaProg node) throws Exception + public Integer visit(SaProg node) { - defaultIn(node); - System.out.println("dans prog"); - if(node.getVariables() != null) - node.getVariables().accept(this); - if(node.getFonctions() != null) - node.getFonctions().accept(this); - defaultOut(node); - return null; + defaultIn(node); + if(node.getVariables() != null) + node.getVariables().accept(this); + if(node.getFonctions() != null) + node.getFonctions().accept(this); + defaultOut(node); + return 1; } // DEC -> var id taille - public TypeVal visit(SaDecTab node) throws Exception{ - defaultIn(node); - defaultOut(node); - return null; + public Integer visit(SaDecTab node){ + defaultIn(node); + defaultOut(node); + return 1; } - public TypeVal visit(SaExp node) throws Exception + public Integer visit(SaExp node) { - defaultIn(node); - defaultOut(node); - return null; + defaultIn(node); + defaultOut(node); + return 1; } // EXP -> entier - public TypeVal visit(SaExpInt node) throws Exception + public Integer visit(SaExpInt node) { - defaultIn(node); - defaultOut(node); - return new TypeVal(node.getVal()); - } - - - // EXP -> vrai - public TypeVal visit(SaExpVrai node) throws Exception - { - defaultIn(node); - defaultOut(node); - return new TypeVal(true); - } - - // EXP -> faux - public TypeVal visit(SaExpFaux node) throws Exception - { - defaultIn(node); - defaultOut(node); - return new TypeVal(false); + defaultIn(node); + defaultOut(node); + return node.getVal(); } - - public TypeVal visit(SaExpVar node) throws Exception + public Integer visit(SaExpVar node) { - defaultIn(node); - TypeVal typeVal = node.getVar().accept(this); - defaultOut(node); - return typeVal; + defaultIn(node); + int val = node.getVar().accept(this); + defaultOut(node); + return val; } - public TypeVal visit(SaInstEcriture node) throws Exception + public Integer visit(SaInstEcriture node) { - defaultIn(node); - TypeVal arg = node.getArg().accept(this); - if(arg.type == Type.ENTIER) - programOutput.add(String.valueOf(arg.valInt)); - else if(arg.type == Type.BOOL){ - if(arg.valBool == true) - programOutput.add(String.valueOf(1)); - else - programOutput.add(String.valueOf(0)); - } - defaultOut(node); - return null; + defaultIn(node); + int arg = node.getArg().accept(this); + programOutput.add(String.valueOf(arg)); + defaultOut(node); + return 1; } - public TypeVal visit(SaInstTantQue node) throws Exception + public Integer visit(SaInstTantQue node) { - defaultIn(node); - TypeVal test = node.getTest().accept(this); - while (test.valBool == true){ - if (node.getFaire() != null) - node.getFaire().accept(this); - else{ - System.out.println("Infinite loop detected, breaking out"); - break; - } - test = node.getTest().accept(this); - } - defaultOut(node); - return null; + defaultIn(node); + int test = node.getTest().accept(this); + while (test != 0){ + if (node.getFaire() != null) + node.getFaire().accept(this); + else + { + System.out.println("Infinite loop detected, breaking out"); + break; + } + test = node.getTest().accept(this); + } + defaultOut(node); + return 1; } - - public TypeVal visit(SaLInst node) throws Exception + public Integer visit(SaLInst node) { - defaultIn(node); - stop = false; - TypeVal valRet = node.getTete().accept(this); - if(!stop && node.getQueue() != null) node.getQueue().accept(this); - defaultOut(node); - return null; + + defaultIn(node); + stop = false; + int valRet = node.getTete().accept(this); + if(!stop && node.getQueue() != null) node.getQueue().accept(this); + defaultOut(node); + return 1; } // DEC -> fct id LDEC LDEC LINST - public TypeVal visit(SaDecFonc node) throws Exception + public Integer visit(SaDecFonc node) { - defaultIn(node); - if(node.getParametres() != null) node.getParametres().accept(this); - if(node.getVariable() != null) node.getVariable().accept(this); - node.getCorps().accept(this); - defaultOut(node); - return null; + defaultIn(node); + if(node.getParametres() != null) node.getParametres().accept(this); + if(node.getVariable() != null) node.getVariable().accept(this); + node.getCorps().accept(this); + defaultOut(node); + return 1; } // DEC -> var id - public TypeVal visit(SaDecVar node) throws Exception + public Integer visit(SaDecVar node) { - defaultIn(node); - defaultOut(node); - return null; + defaultIn(node); + defaultOut(node); + return 1; } - public TypeVal visit(SaInstAffect node) throws Exception + public Integer visit(SaInstAffect node) { - defaultIn(node); - TypeVal typeVal = node.getRhs().accept(this); - if(node.getLhs() instanceof SaVarIndicee){ // c'est une case de tableau, donc forcément globale - SaVarIndicee lhsIndicee = (SaVarIndicee) node.getLhs(); - TypeVal indice = lhsIndicee.getIndice().accept(this); - setVarGlobIndicee(lhsIndicee, indice, typeVal); - } else{ - setVar((SaVarSimple) node.getLhs(), typeVal); - } - - defaultOut(node); - return null; + defaultIn(node); + int val = node.getRhs().accept(this); + + + if(node.getLhs() instanceof SaVarIndicee){ // c'est une case de tableau, donc forcément globale + SaVarIndicee lhsIndicee = (SaVarIndicee) node.getLhs(); + int indice = lhsIndicee.getIndice().accept(this); + /*int base = lhsIndicee.tsItem.adresse; + varGlob[base + indice] = val;*/ + setVarGlobIndicee(lhsIndicee.tsItem, indice, val); + + } + else{// lhs est une variable simple, trois cas possibles : une variable locale, une variable globale ou un argument + SaVarSimple lhsSimple = (SaVarSimple) node.getLhs(); + if(lhsSimple.tsItem.portee == this.tableGlobale){ // variable globale + setVarGlob(lhsSimple.tsItem, val); + // varGlob[lhsSimple.tsItem.adresse] = val; + } + else if(lhsSimple.tsItem.isParam){ // parametre + curEnv.setArg(lhsSimple.tsItem.adresse, val); + } + else { // variable locale + curEnv.setVar(lhsSimple.tsItem.adresse, val); + } + } + defaultOut(node); + return 1; } // LDEC -> DEC LDEC // LDEC -> null - /* public TypeVal visit(SaLDec node) throws Exception + public Integer visit(SaLDec node) { defaultIn(node); node.getTete().accept(this); if(node.getQueue() != null) node.getQueue().accept(this); defaultOut(node); - return null; - }*/ + return 1; + } - public TypeVal visit(SaVarSimple node) throws Exception + public Integer visit(SaVarSimple node) { - defaultIn(node); - TypeVal typeVal = getVar(node); - defaultOut(node); - return typeVal; + defaultIn(node); + int val = 0; + + if(node.tsItem.portee == this.tableGlobale){ // variable globale + // val = varGlob[node.tsItem.adresse]; + val = getVarGlob(node.tsItem); + } + else if(node.tsItem.isParam){ // parametre + val = curEnv.getArg(node.tsItem.adresse); + } + else { // variable locale + val = curEnv.getVar(node.tsItem.adresse); + } + + defaultOut(node); + return val; } - public TypeVal visit(SaAppel node) throws Exception + public Integer visit(SaAppel node) { - defaultIn(node); - TsItemFct fct = node.tsItem; - SaLExp lArgs = null; - SaLDecVar lParam = null; - Ts localTable = fct.getTable(); - // on construit la liste des arguments d'appel de la fonction - ArrayList<TypeVal> listeArguments = new ArrayList<TypeVal>(); - for(lArgs = node.getArguments(); lArgs != null; lArgs = lArgs.getQueue()){ - listeArguments.add(lArgs.getTete().accept(this)); - } - - //on sauvegarde de l'environnement courant pour le restaurer après l'appel - SaEnvironment oldEnv = curEnv; - // on crée un nouvel environnement pour la fonction appelée - // le nouvel environnement est l'environnement courant - curEnv = new SaEnvironment(fct); - - // on stocke les valeurs des arguments dans l'environnement - int n = 0; - for(lParam = fct.saDecFonc.getParametres(); lParam != null; lParam = lParam.getQueue()){ - setVar((TsItemVarSimple)((SaDecVar)lParam.getTete()).getTsItem(), listeArguments.get(n)); - n++; - } - // on exécute le corps de la fonction - if(fct.saDecFonc.getCorps() != null) - fct.saDecFonc.getCorps().accept(this); - - // on récupère la valeur de retour - TypeVal returnValue = curEnv.getReturnValue(); - - //restauration de l'environnement d'avant appel - curEnv = oldEnv; - defaultOut(node); - return returnValue; + defaultIn(node); + TsItemFct fct = node.tsItem; + SaLExp lArgs = null; + SaLExp l; + Ts localTable = fct.getTable(); + int adr = 0; + SaEnvironment newEnv = new SaEnvironment(node.tsItem); + + // localTable.affiche(System.out); + + for(lArgs = node.getArguments(); lArgs != null; lArgs = lArgs.getQueue()){ + int val = lArgs.getTete().accept(this); + newEnv.setArg(adr, val); + // les adresses sont en octets et les paramètres sont des entiers stockés sur 4 octets + adr += SIZEOF_ENTIER; + } + //sauvegarde de l'environnement courant pour le restaurer après l'appel + SaEnvironment oldEnv = curEnv; + // le nouvel environnement devient l'environnement courant + curEnv = newEnv; + // on exécute le corps de la fonction + if(fct.saDecFonc.getCorps() != null) + fct.saDecFonc.getCorps().accept(this); + + int returnValue = curEnv.getReturnValue(); + + //restauration de l'environnement d'avant appel + curEnv = oldEnv; + defaultOut(node); + return returnValue; } - public TypeVal visit(SaExpAppel node) throws Exception + public Integer visit(SaExpAppel node) { - defaultIn(node); - TypeVal typeVal = node.getVal().accept(this); - defaultOut(node); - return typeVal; + defaultIn(node); + int val = node.getVal().accept(this); + defaultOut(node); + return val; } // EXP -> add EXP EXP - public TypeVal visit(SaExpAdd node) throws Exception + public Integer visit(SaExpAdd node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal(op1.valInt + op2.valInt); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return op1 + op2; } // EXP -> sub EXP EXP - public TypeVal visit(SaExpSub node) throws Exception + public Integer visit(SaExpSub node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal(op1.valInt - op2.valInt); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return op1 - op2; } // EXP -> mult EXP EXP - public TypeVal visit(SaExpMult node) throws Exception + public Integer visit(SaExpMult node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal(op1.valInt * op2.valInt); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return op1 * op2; } // EXP -> div EXP EXP - public TypeVal visit(SaExpDiv node) throws Exception + public Integer visit(SaExpDiv node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal((int) op1.valInt / op2.valInt); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return (int)(op1 / op2); } // EXP -> inf EXP EXP - public TypeVal visit(SaExpInf node) throws Exception + public Integer visit(SaExpInf node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal((op1.valInt < op2.valInt)? true : false); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return (op1 < op2)? 1 : 0; } // EXP -> eq EXP EXP - public TypeVal visit(SaExpEqual node) throws Exception + public Integer visit(SaExpEqual node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - if(op1.type == Type.ENTIER) - return new TypeVal((op1.valInt == op2.valInt)? true : false); - else - return new TypeVal((op1.valBool == op2.valBool)? true : false); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return (op1 == op2)? 1 : 0; } // EXP -> and EXP EXP - public TypeVal visit(SaExpAnd node) throws Exception + public Integer visit(SaExpAnd node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal(op1.valBool && op2.valBool); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return (op1 != 0 && op2 != 0) ? 1 : 0; } + // EXP -> or EXP EXP - public TypeVal visit(SaExpOr node) throws Exception + public Integer visit(SaExpOr node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - TypeVal op2 = node.getOp2().accept(this); - defaultOut(node); - return new TypeVal(op1.valBool || op2.valBool); + defaultIn(node); + int op1 = node.getOp1().accept(this); + int op2 = node.getOp2().accept(this); + defaultOut(node); + return (op1 != 0 || op2 !=0)? 1 : 0; } // EXP -> not EXP - public TypeVal visit(SaExpNot node) throws Exception + public Integer visit(SaExpNot node) { - defaultIn(node); - TypeVal op1 = node.getOp1().accept(this); - defaultOut(node); - return new TypeVal(!op1.valBool); + defaultIn(node); + int op1 = node.getOp1().accept(this); + defaultOut(node); + return (op1 == 0) ? 1 : 0; } - public TypeVal visit(SaExpLire node) throws Exception + public Integer visit(SaExpLire node) { - defaultIn(node); - defaultOut(node); - return null; + defaultIn(node); + defaultOut(node); + return 1; } - public TypeVal visit(SaInstBloc node) throws Exception + public Integer visit(SaInstBloc node) { - defaultIn(node); - node.getVal().accept(this); - defaultOut(node); - return null; + defaultIn(node); + node.getVal().accept(this); + defaultOut(node); + return 1; } - public TypeVal visit(SaInstSi node) throws Exception + public Integer visit(SaInstSi node) { - defaultIn(node); - TypeVal test = node.getTest().accept(this); - if(test.valBool && node.getAlors() != null) - node.getAlors().accept(this); - if(!test.valBool && node.getSinon() != null) - node.getSinon().accept(this); - defaultOut(node); - return null; + defaultIn(node); + int test = node.getTest().accept(this); + if(test != 0 && node.getAlors() != null) + node.getAlors().accept(this); + if(test == 0 && node.getSinon() != null) + node.getSinon().accept(this); + defaultOut(node); + return 1; } // INST -> ret EXP - public TypeVal visit(SaInstRetour node) throws Exception + public Integer visit(SaInstRetour node) { - defaultIn(node); - curEnv.setReturnValue(node.getVal().accept(this)); - stop = true; - defaultOut(node); - return null; + defaultIn(node); + curEnv.setReturnValue(node.getVal().accept(this)); + stop = true; + defaultOut(node); + return 1; } - public TypeVal visit(SaLExp node) throws Exception + public Integer visit(SaLExp node) { - defaultIn(node); - node.getTete().accept(this); - if(node.getQueue() != null) - node.getQueue().accept(this); - defaultOut(node); - return null; + defaultIn(node); + node.getTete().accept(this); + if(node.getQueue() != null) + node.getQueue().accept(this); + defaultOut(node); + return 1; } - public TypeVal visit(SaVarIndicee node) throws Exception + public Integer visit(SaVarIndicee node) { - defaultIn(node); - node.getIndice().accept(this); - TypeVal indice = node.getIndice().accept(this); - defaultOut(node); - return getVarGlobIndicee(node, indice); + defaultIn(node); + node.getIndice().accept(this); + int indice = node.getIndice().accept(this); + // int base = node.tsItem.adresse; + defaultOut(node); + // return varGlob[base + indice]; + return getVarGlobIndicee(node.tsItem, indice); } } diff --git a/src/sa/SaExp.java b/src/sa/SaExp.java index 81cbf3cd71f316298250651539dfb8addb9f692c..6f33072fe0a3091b8d20236b9513d59f2ce8307f 100644 --- a/src/sa/SaExp.java +++ b/src/sa/SaExp.java @@ -1,6 +1,5 @@ package sa; -import util.Type; public interface SaExp extends SaNode { - public Type getType(); + } diff --git a/src/sa/SaExpAdd.java b/src/sa/SaExpAdd.java index 0041eed4950087de222de4c9739a438e40b3d301..4c0997e5052a2182a2a9e51ac7d540da86043748 100644 --- a/src/sa/SaExpAdd.java +++ b/src/sa/SaExpAdd.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpAdd implements SaExp{ private SaExp op1; @@ -13,14 +12,7 @@ public class SaExpAdd implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.ENTIER; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - public String toString(){ - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpAnd.java b/src/sa/SaExpAnd.java index df94c5b74eddbefb67adfd2fa7b3f0eb1357c057..b02c052c9bb3bf89b38ca8d8d530cf04afdba3e1 100644 --- a/src/sa/SaExpAnd.java +++ b/src/sa/SaExpAnd.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpAnd implements SaExp{ private SaExp op1; @@ -13,14 +12,7 @@ public class SaExpAnd implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.BOOL; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpAppel.java b/src/sa/SaExpAppel.java index 611aa6a106ea92f6dd2198b5706294cf127dd00d..d321270de9bdb87922db78e620748228feedcf2e 100644 --- a/src/sa/SaExpAppel.java +++ b/src/sa/SaExpAppel.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpAppel implements SaExp{ private SaAppel val; @@ -10,16 +9,7 @@ public class SaExpAppel implements SaExp{ public SaAppel getVal(){return this.val;} - public Type getType(){ - return val.getType(); - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + val + ")"; - } } diff --git a/src/sa/SaExpDiv.java b/src/sa/SaExpDiv.java index cc2db6e65ad14122a34b40d2b79f5ba9a6abe3c0..3b020331733aae8c9fe54e3cb5b96dc6e14afc5f 100644 --- a/src/sa/SaExpDiv.java +++ b/src/sa/SaExpDiv.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpDiv implements SaExp{ private SaExp op1; @@ -13,15 +12,7 @@ public class SaExpDiv implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.ENTIER; - } - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpEqual.java b/src/sa/SaExpEqual.java index 01eeb010443570e08ce02b43b5af0834c8df4bef..940e56c77332df4312bb93f7b4a04d6255b43b71 100644 --- a/src/sa/SaExpEqual.java +++ b/src/sa/SaExpEqual.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpEqual implements SaExp{ private SaExp op1; @@ -13,15 +12,7 @@ public class SaExpEqual implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.BOOL; - } - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpFaux.java b/src/sa/SaExpFaux.java deleted file mode 100644 index 125956f06d4a0c057364ef77e4ad44034b31eb01..0000000000000000000000000000000000000000 --- a/src/sa/SaExpFaux.java +++ /dev/null @@ -1,28 +0,0 @@ -package sa; -import util.Type; - -public class SaExpFaux implements SaExp{ - private final boolean val; - - public SaExpFaux(){ - this.val = false; - } - - public boolean getVal(){ - return this.val; - } - - public Type getType(){ - return Type.BOOL; - } - - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ - return visitor.visit(this); - } - - @Override - public String toString() { - return "faux"; - } -} diff --git a/src/sa/SaExpInf.java b/src/sa/SaExpInf.java index 1f7c54a50048cd9745749d5c9dec52b6c89522a1..3da1f688ef8a7ebc83a67c0e2570df56216486bd 100644 --- a/src/sa/SaExpInf.java +++ b/src/sa/SaExpInf.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpInf implements SaExp{ private SaExp op1; @@ -13,16 +12,7 @@ public class SaExpInf implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.BOOL; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception { + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpInt.java b/src/sa/SaExpInt.java index 10bd6d6b6b674fed031f384502667ffc3c1d6717..b16158a206ce6f8f0846da6ce34eedac6afdc919 100644 --- a/src/sa/SaExpInt.java +++ b/src/sa/SaExpInt.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpInt implements SaExp{ private int val; @@ -12,15 +11,7 @@ public class SaExpInt implements SaExp{ return this.val; } - public Type getType(){ - return Type.ENTIER; - } - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return Integer.toString(val); - } } diff --git a/src/sa/SaExpLire.java b/src/sa/SaExpLire.java index 53d8520143f187cf397e344a70f19a3fd72d26b6..9ff57e37e75e6996e4ecf4c38052b77824c1d316 100644 --- a/src/sa/SaExpLire.java +++ b/src/sa/SaExpLire.java @@ -1,21 +1,11 @@ package sa; -import util.Type; public class SaExpLire implements SaExp{ public SaExpLire(){ } - public Type getType(){ - return Type.ENTIER; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } } diff --git a/src/sa/SaExpMult.java b/src/sa/SaExpMult.java index 597038dc0fdade0639bdf52e2eb622dbf347055a..9a2fa8cf95703a1e2b9bcd9d32d745800c3deed8 100644 --- a/src/sa/SaExpMult.java +++ b/src/sa/SaExpMult.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpMult implements SaExp{ private SaExp op1; @@ -13,15 +12,7 @@ public class SaExpMult implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.ENTIER; - } - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpNot.java b/src/sa/SaExpNot.java index 60a1c08aa6cc3097f205d3f51cb159117946666a..2084e05321fa36bc9d3fc88e075ff1c53aea3423 100644 --- a/src/sa/SaExpNot.java +++ b/src/sa/SaExpNot.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpNot implements SaExp{ private SaExp op1; @@ -11,16 +10,7 @@ public class SaExpNot implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return null;} - public Type getType(){ - return Type.BOOL; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + ")"; - } } diff --git a/src/sa/SaExpOr.java b/src/sa/SaExpOr.java index ec9807d3a9f600483df235ebd151d6f356e9dcfb..455af1d151800541ad52ba563b6ae2393d479287 100644 --- a/src/sa/SaExpOr.java +++ b/src/sa/SaExpOr.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpOr implements SaExp{ private SaExp op1; @@ -13,16 +12,7 @@ public class SaExpOr implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.BOOL; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpSub.java b/src/sa/SaExpSub.java index bf02733028e29275798694ded4d36faf7591da3c..1dbcd6c119112f18a7ccd961136e427db12f7b38 100644 --- a/src/sa/SaExpSub.java +++ b/src/sa/SaExpSub.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpSub implements SaExp{ private SaExp op1; @@ -13,16 +12,7 @@ public class SaExpSub implements SaExp{ public SaExp getOp1(){return this.op1;} public SaExp getOp2(){return this.op2;} - public Type getType(){ - return Type.ENTIER; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")"; - } } diff --git a/src/sa/SaExpVar.java b/src/sa/SaExpVar.java index f983c1fdb0e37ee2bf0ab8cd1242f7f596f5023f..52f753d4961149e9f0cc81e1b19530c7a57997d0 100644 --- a/src/sa/SaExpVar.java +++ b/src/sa/SaExpVar.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaExpVar implements SaExp{ private SaVar var; @@ -10,15 +9,7 @@ public class SaExpVar implements SaExp{ public SaVar getVar(){return this.var;} - public Type getType(){ - return this.var.getTsItem().getType(); - } - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + var + ")"; - } } diff --git a/src/sa/SaExpVrai.java b/src/sa/SaExpVrai.java deleted file mode 100644 index ef992113637d8e746629cfdb508d8d6e817dfe5f..0000000000000000000000000000000000000000 --- a/src/sa/SaExpVrai.java +++ /dev/null @@ -1,27 +0,0 @@ -package sa; -import util.Type; - -public class SaExpVrai implements SaExp{ - private final boolean val; - - public SaExpVrai(){ - this.val = true; - } - - public boolean getVal(){ - return this.val; - } - - public Type getType(){ - return Type.BOOL; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ - return visitor.visit(this); - } - - @Override - public String toString() { - return "vrai"; - } -} diff --git a/src/sa/SaInstAffect.java b/src/sa/SaInstAffect.java index 126f741d3e900f468a368ad089faaf9c18c83e0d..96259625d7477e41f177cab0f4077276b720ed45 100644 --- a/src/sa/SaInstAffect.java +++ b/src/sa/SaInstAffect.java @@ -11,12 +11,8 @@ public class SaInstAffect implements SaInst{ public SaVar getLhs(){return this.lhs;} public SaExp getRhs(){return this.rhs;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName()+ " " + lhs + " " + rhs + ")"; - } } diff --git a/src/sa/SaInstBloc.java b/src/sa/SaInstBloc.java index 8f13f49c6bccdc48b6fc4bda8cdbe9e8a417ffc1..efa0db416aa0456d524b0f6cbdf31511c8ece3a6 100644 --- a/src/sa/SaInstBloc.java +++ b/src/sa/SaInstBloc.java @@ -8,12 +8,8 @@ public class SaInstBloc implements SaInst{ } public SaLInst getVal(){return this.val;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + val + ")"; - } } diff --git a/src/sa/SaInstEcriture.java b/src/sa/SaInstEcriture.java index 4ba2af340865b3579f6a28de66f28ce3b8797700..de4d3b470b791efb82a849fe8b76c72eeb86b797 100644 --- a/src/sa/SaInstEcriture.java +++ b/src/sa/SaInstEcriture.java @@ -9,12 +9,8 @@ public class SaInstEcriture implements SaInst{ public SaExp getArg(){return this.arg;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + arg + ")"; - } } diff --git a/src/sa/SaInstRetour.java b/src/sa/SaInstRetour.java index c3993e88ee81b9f5584e2a3da6dff5911d50f718..6d7239411e6ddc1280195edcd5cbf93c8a403a9e 100644 --- a/src/sa/SaInstRetour.java +++ b/src/sa/SaInstRetour.java @@ -1,5 +1,4 @@ package sa; -import util.Type; public class SaInstRetour implements SaInst{ private SaExp val; @@ -7,18 +6,10 @@ public class SaInstRetour implements SaInst{ public SaInstRetour(SaExp val){ this.val = val; } - - public Type getType(){ - return val.getType(); - } public SaExp getVal(){return this.val;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + val + ")"; - } } diff --git a/src/sa/SaInstSi.java b/src/sa/SaInstSi.java index fc8c1d7a1c02b1da58a2e8dcaec1d2b9f2b1cd11..c5d2f90cc5c0efc1549278d4bc0c1d15056375f5 100644 --- a/src/sa/SaInstSi.java +++ b/src/sa/SaInstSi.java @@ -15,12 +15,8 @@ public class SaInstSi implements SaInst{ public SaInst getAlors(){return this.alors;} public SaInst getSinon(){return this.sinon;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + test + " " + alors + " " + sinon + ")"; - } } diff --git a/src/sa/SaInstTantQue.java b/src/sa/SaInstTantQue.java index dfc87e1b053b28b22281134d6dc8756108cf2dff..a31ba7a036ee75a08eded73ba1f307cd87331907 100644 --- a/src/sa/SaInstTantQue.java +++ b/src/sa/SaInstTantQue.java @@ -12,12 +12,7 @@ public class SaInstTantQue implements SaInst{ public SaExp getTest(){return this.test;} public SaInst getFaire(){return this.faire;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + test + " " + faire + ")"; - } } diff --git a/src/sa/SaLDec.java b/src/sa/SaLDec.java new file mode 100644 index 0000000000000000000000000000000000000000..739d24acdf88cfa8b1ac05cf050a693fcc22993f --- /dev/null +++ b/src/sa/SaLDec.java @@ -0,0 +1,25 @@ +package sa; + +public class SaLDec implements SaNode{ + private SaDec tete; + private SaLDec queue; + + public SaLDec(SaDec tete, SaLDec queue){ + this.tete = tete; + this.queue = queue; + } + + public SaDec getTete(){return this.tete;} + public SaLDec getQueue(){return this.queue;} + + public int length(){ + + if(this.queue == null) return 1; + return 1 + this.queue.length() ; + } + + public <T> T accept(SaVisitor <T> visitor) { + return visitor.visit(this); + } + +} diff --git a/src/sa/SaLDecFonc.java b/src/sa/SaLDecFonc.java deleted file mode 100644 index 73135aeaf1b30f4684851bd6f0dc90f0f97dbe73..0000000000000000000000000000000000000000 --- a/src/sa/SaLDecFonc.java +++ /dev/null @@ -1,28 +0,0 @@ -package sa; - -public class SaLDecFonc implements SaNode{ - private SaDecFonc tete; - private SaLDecFonc queue; - - public SaLDecFonc(SaDecFonc tete, SaLDecFonc queue){ - this.tete = tete; - this.queue = queue; - } - - public SaDecFonc getTete(){return this.tete;} - public SaLDecFonc getQueue(){return this.queue;} - - public int length(){ - if(this.queue == null) return 1; - return 1 + this.queue.length() ; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception{ - return visitor.visit(this); - } - - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + tete + " " + queue + ")"; - } - -} diff --git a/src/sa/SaLDecVar.java b/src/sa/SaLDecVar.java deleted file mode 100644 index 9f69dc3ed20db5c58d68cdff7dc21d20a1883d7d..0000000000000000000000000000000000000000 --- a/src/sa/SaLDecVar.java +++ /dev/null @@ -1,27 +0,0 @@ -package sa; - -public class SaLDecVar implements SaNode{ - private SaDecVar tete; - private SaLDecVar queue; - - public SaLDecVar(SaDecVar tete, SaLDecVar queue){ - this.tete = tete; - this.queue = queue; - } - - public SaDecVar getTete(){return this.tete;} - public SaLDecVar getQueue(){return this.queue;} - - public int length(){ - if(this.queue == null) return 1; - return 1 + this.queue.length() ; - } - - public <T> T accept(SaVisitor <T> visitor) throws Exception { - return visitor.visit(this); - } - public String toString(){ - return "(" + this.getClass().getSimpleName() + " " + tete + " " + queue + ")"; - } - -} diff --git a/src/sa/SaLExp.java b/src/sa/SaLExp.java index a6e489fd7262d334388bd399ff5e793e5718675f..c28ab02d98f66e1ee202ee8b21b92b82b4fca0f5 100644 --- a/src/sa/SaLExp.java +++ b/src/sa/SaLExp.java @@ -19,12 +19,8 @@ public class SaLExp implements SaNode{ - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + tete + " " + queue + ")"; - } } diff --git a/src/sa/SaLInst.java b/src/sa/SaLInst.java index 29c7cd06d8a6c5a810b0b0750485f7e455ea08ff..846a266ba7177591f4036aef9330c17e5caa05f7 100644 --- a/src/sa/SaLInst.java +++ b/src/sa/SaLInst.java @@ -12,12 +12,8 @@ public class SaLInst implements SaNode{ public SaInst getTete(){return this.tete;} public SaLInst getQueue(){return this.queue;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - public String toString(){ - return "(" + this.getClass().getSimpleName() + " " + tete + " " + queue +")"; - } - } diff --git a/src/sa/SaNode.java b/src/sa/SaNode.java index cd65a017106d6bc8e3da3cc141677127b2d6a18e..af95d49d1d9ee6ef2e01a1b2724b0019764f3ec9 100644 --- a/src/sa/SaNode.java +++ b/src/sa/SaNode.java @@ -1,6 +1,6 @@ package sa; public interface SaNode{ - public <T> T accept(SaVisitor <T> visitor) throws Exception; + public <T> T accept(SaVisitor <T> visitor); } diff --git a/src/sa/SaProg.java b/src/sa/SaProg.java index f0081db250d89a1d48a676f1f13f987192b056e3..12ffbe14baf7749b159f9a1647e27acb8d193eed 100644 --- a/src/sa/SaProg.java +++ b/src/sa/SaProg.java @@ -1,21 +1,19 @@ package sa; public class SaProg implements SaNode{ - private SaLDecVar variables; - private SaLDecFonc fonctions; + private SaLDec variables; + private SaLDec fonctions; - public SaProg(SaLDecVar variables, SaLDecFonc fonctions){ + public SaProg(SaLDec variables, SaLDec fonctions){ this.variables = variables; this.fonctions = fonctions; } - public SaLDecVar getVariables(){return this.variables;} - public SaLDecFonc getFonctions(){return this.fonctions;} + public SaLDec getVariables(){return this.variables;} + public SaLDec getFonctions(){return this.fonctions;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - public String toString(){ - return "(" + this.getClass().getSimpleName() + " " + variables + " " + fonctions +")"; - } + } diff --git a/src/sa/SaTypeCheck.java b/src/sa/SaTypeCheck.java deleted file mode 100644 index 60e71efec1cba615a2f3bb32f6c710652f1f5086..0000000000000000000000000000000000000000 --- a/src/sa/SaTypeCheck.java +++ /dev/null @@ -1,32 +0,0 @@ -package sa; -import util.Type; -import util.Error; -import ts.*; - -public class SaTypeCheck extends SaDepthFirstVisitor <Void>{ - private TsItemFct fonctionCourante; - - public SaTypeCheck(SaNode root) - { - try{ - root.accept(this); - } catch(ErrorException e){ - System.err.print("ERREUR DE TYPAGE : "); - System.err.println(e.getMessage()); - System.exit(e.getCode()); - } catch(Exception e){} - } - - public void defaultIn(SaNode node) - { - // System.out.println("<" + node.getClass().getSimpleName() + ">"); - } - - public void defaultOut(SaNode node) - { - // System.out.println("</" + node.getClass().getSimpleName() + ">"); - } - - - -} diff --git a/src/sa/SaVar.java b/src/sa/SaVar.java index 8e5536ed3b3374d9272e3a86b79caf0410852638..867cc81a184fae787c81c977bc0e4106fdbdad7c 100644 --- a/src/sa/SaVar.java +++ b/src/sa/SaVar.java @@ -1,6 +1,5 @@ package sa; -import ts.*; public interface SaVar extends SaNode { - TsItemVar getTsItem(); + } diff --git a/src/sa/SaVarIndicee.java b/src/sa/SaVarIndicee.java index d125b11b4d0488fd44e0fe18b0c340835ff9dbd6..7564ac05a57ccc96266f6f4aba9256613ec7a346 100644 --- a/src/sa/SaVarIndicee.java +++ b/src/sa/SaVarIndicee.java @@ -12,16 +12,11 @@ public class SaVarIndicee implements SaVar{ this.tsItem = null; } - public TsItemVar getTsItem(){return this.tsItem;} public String getNom(){return this.nom;} public SaExp getIndice(){return this.indice;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName() + " " + nom + " " + indice +")"; - } } diff --git a/src/sa/SaVarSimple.java b/src/sa/SaVarSimple.java index d496e74ac0ab58ec1cc908cb8e0fe2331e13976f..2fe918671e72894b4ccdc1407c547cfcb5983b79 100644 --- a/src/sa/SaVarSimple.java +++ b/src/sa/SaVarSimple.java @@ -3,7 +3,7 @@ import ts.*; public class SaVarSimple implements SaVar{ public String nom; - public TsItemVarSimple tsItem; + public TsItemVar tsItem; public SaVarSimple(String nom){ this.nom = nom; @@ -11,14 +11,9 @@ public class SaVarSimple implements SaVar{ } public String getNom(){return this.nom;} - public TsItemVarSimple getTsItem(){return this.tsItem;} - public <T> T accept(SaVisitor <T> visitor) throws Exception{ + public <T> T accept(SaVisitor <T> visitor) { return visitor.visit(this); } - @Override - public String toString() { - return "(" + this.getClass().getSimpleName()+ " " + nom + ")"; - } } diff --git a/src/sa/SaVisitor.java b/src/sa/SaVisitor.java index 3d28bb7870f422fa6caa7a50066a819b40fa6c11..d027b82661cd4e6eabeb89072e3b1dbe77354c16 100644 --- a/src/sa/SaVisitor.java +++ b/src/sa/SaVisitor.java @@ -1,38 +1,34 @@ package sa; interface SaVisitor <T> { - public T visit(SaProg node) throws Exception; - public T visit(SaInstEcriture node) throws Exception; - public T visit(SaInstTantQue node) throws Exception; - public T visit(SaInstBloc node) throws Exception; - public T visit(SaInstSi node) throws Exception; - public T visit(SaInstAffect node) throws Exception; - public T visit(SaInstRetour node) throws Exception; - public T visit(SaLInst node) throws Exception; - public T visit(SaDecFonc node) throws Exception; - public T visit(SaDecVar node) throws Exception; - public T visit(SaDecTab node) throws Exception; - // public T visit(SaLDec node) throws Exception; - public T visit(SaLDecVar node) throws Exception; - public T visit(SaLDecFonc node) throws Exception; - public T visit(SaVarSimple node) throws Exception; - public T visit(SaVarIndicee node) throws Exception; - public T visit(SaAppel node) throws Exception; - public T visit(SaExp node) throws Exception; - public T visit(SaExpLire node) throws Exception; - public T visit(SaExpInt node) throws Exception; - public T visit(SaExpVrai node) throws Exception; - public T visit(SaExpFaux node) throws Exception; - public T visit(SaExpVar node) throws Exception; - public T visit(SaExpAppel node) throws Exception; - public T visit(SaExpAdd node) throws Exception; - public T visit(SaExpSub node) throws Exception; - public T visit(SaExpMult node) throws Exception; - public T visit(SaExpDiv node) throws Exception; - public T visit(SaExpInf node) throws Exception; - public T visit(SaExpEqual node) throws Exception; - public T visit(SaExpAnd node) throws Exception; - public T visit(SaExpOr node) throws Exception; - public T visit(SaExpNot node) throws Exception; - public T visit(SaLExp node) throws Exception; + public T visit(SaLInst node); + public T visit(SaDecTab node); + public T visit(SaInstEcriture node); + public T visit(SaInstTantQue node); + public T visit(SaInstBloc node); + public T visit(SaInstSi node); + public T visit(SaInstAffect node); + public T visit(SaInstRetour node); + public T visit(SaDecFonc node); + public T visit(SaDecVar node); + public T visit(SaLDec node); + public T visit(SaProg node); + public T visit(SaVarSimple node); + public T visit(SaAppel node); + public T visit(SaExp node); + public T visit(SaExpLire node); + public T visit(SaExpInt node); + public T visit(SaExpVar node); + public T visit(SaExpAppel node); + public T visit(SaExpAdd node); + public T visit(SaExpSub node); + public T visit(SaExpMult node); + public T visit(SaExpDiv node); + public T visit(SaExpInf node); + public T visit(SaExpEqual node); + public T visit(SaExpAnd node); + public T visit(SaExpOr node); + public T visit(SaExpNot node); + public T visit(SaLExp node); + public T visit(SaVarIndicee node); } diff --git a/src/sa/Sc2sa.java b/src/sa/Sc2sa.java deleted file mode 100644 index 0bc4abd6ec52633b975ecfb731e2db8b18e8f1e5..0000000000000000000000000000000000000000 --- a/src/sa/Sc2sa.java +++ /dev/null @@ -1,43 +0,0 @@ -package sa; -import lParser.analysis.*; -import lParser.node.*; -import util.Type; - -public class Sc2sa extends DepthFirstAdapter -{ - private SaNode returnValue; - private Type returnType; - private SaProg saRoot = null; - - public void defaultIn(@SuppressWarnings("unused") Node node) - { - //System.out.println("<" + node.getClass().getSimpleName() + ">"); - } - - public void defaultOut(@SuppressWarnings("unused") Node node) - { - //System.out.println("</" + node.getClass().getSimpleName() + ">"); - } - - public SaProg getRoot() - { - return this.saRoot; - } - - - // exp3 = {plus} exp3 plus exp4 - /* @Override - public void caseAPlusExp3(APlusExp3 node) - { - SaExp op1 = null; - SaExp op2 = null; - inAPlusExp3(node); - node.getExp3().apply(this); - op1 = (SaExp) this.returnValue; - node.getExp4().apply(this); - op2 = (SaExp) this.returnValue; - this.returnValue = new SaExpAdd(op1, op2); - outAPlusExp3(node); - }*/ -} - diff --git a/src/sa/TypeVal.java b/src/sa/TypeVal.java deleted file mode 100644 index 54cf58ba35f3d0aa29407d82b6b81f1a0f8aab77..0000000000000000000000000000000000000000 --- a/src/sa/TypeVal.java +++ /dev/null @@ -1,31 +0,0 @@ -package sa; -import util.Type; - -public class TypeVal{ - public Type type; - public boolean valBool; - public int valInt; - - public TypeVal(int val) - { - type = Type.ENTIER; - valInt = val; - } - - public TypeVal(boolean val) - { - type = Type.BOOL; - valBool = val; - } - - public String toString(){ - if(type == Type.BOOL){ - return (valBool == true)? String.valueOf(1): String.valueOf(0); - } - else{ - return String.valueOf(valInt); - } - } - - -} diff --git a/src/sc/analysis/Analysis.java b/src/sc/analysis/Analysis.java new file mode 100644 index 0000000000000000000000000000000000000000..82af0dc4c5f9added6ecf7f7239021d541cefe8a --- /dev/null +++ b/src/sc/analysis/Analysis.java @@ -0,0 +1,104 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.analysis; + +import sc.node.*; + +public interface Analysis extends Switch +{ + Object getIn(Node node); + void setIn(Node node, Object o); + Object getOut(Node node); + void setOut(Node node, Object o); + + void caseStart(Start node); + void caseAProgramProgram(AProgramProgram node); + void caseALdvoLdvo(ALdvoLdvo node); + void caseAEpsilonLdvo(AEpsilonLdvo node); + void caseALDvLdv(ALDvLdv node); + void caseAEpsilonLdv(AEpsilonLdv node); + void caseADecVarDv(ADecVarDv node); + void caseADecVar2Dv(ADecVar2Dv node); + void caseALDvbLdvb(ALDvbLdvb node); + void caseAEpsilonLdvb(AEpsilonLdvb node); + void caseALdfLdf(ALdfLdf node); + void caseAEpsilonLdf(AEpsilonLdf node); + void caseADfDf(ADfDf node); + void caseAParamsLparam(AParamsLparam node); + void caseAIblocIb(AIblocIb node); + void caseAListeILi(AListeILi node); + void caseAEpsilonLi(AEpsilonLi node); + void caseAIAffI(AIAffI node); + void caseAISiI(AISiI node); + void caseAITqI(AITqI node); + void caseAIRetI(AIRetI node); + void caseAIAppI(AIAppI node); + void caseAIEcrI(AIEcrI node); + void caseAAffectationIaffectation(AAffectationIaffectation node); + void caseAIdV(AIdV node); + void caseAIdtabV(AIdtabV node); + void caseAT1Expression(AT1Expression node); + void caseAOuExpression(AOuExpression node); + void caseAT2T1(AT2T1 node); + void caseAEtT1(AEtT1 node); + void caseAT3T2(AT3T2 node); + void caseAEgalT2(AEgalT2 node); + void caseAInferieurT2(AInferieurT2 node); + void caseAT4T3(AT4T3 node); + void caseAPlusT3(APlusT3 node); + void caseAMoinsT3(AMoinsT3 node); + void caseAT5T4(AT5T4 node); + void caseAMultiplicationT4(AMultiplicationT4 node); + void caseADivisionT4(ADivisionT4 node); + void caseAT6T5(AT6T5 node); + void caseANonT5(ANonT5 node); + void caseAExpressionT6(AExpressionT6 node); + void caseAX1T6(AX1T6 node); + void caseAX2T6(AX2T6 node); + void caseAAppT6(AAppT6 node); + void caseAAppel(AAppel node); + void caseAListeExpLe(AListeExpLe node); + void caseAEpsilonLe(AEpsilonLe node); + void caseAListeExpBLeb(AListeExpBLeb node); + void caseAEpsilonLeb(AEpsilonLeb node); + void caseASiIsi(ASiIsi node); + void caseASisinonIsi(ASisinonIsi node); + void caseATantqueItantque(ATantqueItantque node); + void caseARetournerIret(ARetournerIret node); + void caseAIappelIappel(AIappelIappel node); + void caseAIecrireIecrire(AIecrireIecrire node); + + void caseTEspaces(TEspaces node); + void caseTCommentaire(TCommentaire node); + void caseTParentheseFermante(TParentheseFermante node); + void caseTAccoladeOuvrante(TAccoladeOuvrante node); + void caseTAccoladeFermante(TAccoladeFermante node); + void caseTCrochetOuvrant(TCrochetOuvrant node); + void caseTCrochetFermant(TCrochetFermant node); + void caseTVirgule(TVirgule node); + void caseTPVirgule(TPVirgule node); + void caseTNombre(TNombre node); + void caseTEntier(TEntier node); + void caseTParentheseOuvrante(TParentheseOuvrante node); + void caseTOu(TOu node); + void caseTEt(TEt node); + void caseTPlus(TPlus node); + void caseTMoins(TMoins node); + void caseTDivision(TDivision node); + void caseTMultiplication(TMultiplication node); + void caseTEgal(TEgal node); + void caseTInferieur(TInferieur node); + void caseTNon(TNon node); + void caseTSi(TSi node); + void caseTAlors(TAlors node); + void caseTSinon(TSinon node); + void caseTTantque(TTantque node); + void caseTFaire(TFaire node); + void caseTRetour(TRetour node); + void caseTEcrire(TEcrire node); + void caseTLire(TLire node); + void caseTEpsilon(TEpsilon node); + void caseTIdentif(TIdentif node); + void caseEOF(EOF node); + void caseInvalidToken(InvalidToken node); +} diff --git a/src/sc/analysis/AnalysisAdapter.java b/src/sc/analysis/AnalysisAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..e0f8d0c749bbbdf2d23a9d9bffbe5cdf34e902c7 --- /dev/null +++ b/src/sc/analysis/AnalysisAdapter.java @@ -0,0 +1,609 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.analysis; + +import java.util.*; +import sc.node.*; + +public class AnalysisAdapter implements Analysis +{ + private Hashtable<Node,Object> in; + private Hashtable<Node,Object> out; + + @Override + public Object getIn(Node node) + { + if(this.in == null) + { + return null; + } + + return this.in.get(node); + } + + @Override + public void setIn(Node node, Object o) + { + if(this.in == null) + { + this.in = new Hashtable<Node,Object>(1); + } + + if(o != null) + { + this.in.put(node, o); + } + else + { + this.in.remove(node); + } + } + + @Override + public Object getOut(Node node) + { + if(this.out == null) + { + return null; + } + + return this.out.get(node); + } + + @Override + public void setOut(Node node, Object o) + { + if(this.out == null) + { + this.out = new Hashtable<Node,Object>(1); + } + + if(o != null) + { + this.out.put(node, o); + } + else + { + this.out.remove(node); + } + } + + @Override + public void caseStart(Start node) + { + defaultCase(node); + } + + @Override + public void caseAProgramProgram(AProgramProgram node) + { + defaultCase(node); + } + + @Override + public void caseALdvoLdvo(ALdvoLdvo node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLdvo(AEpsilonLdvo node) + { + defaultCase(node); + } + + @Override + public void caseALDvLdv(ALDvLdv node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLdv(AEpsilonLdv node) + { + defaultCase(node); + } + + @Override + public void caseADecVarDv(ADecVarDv node) + { + defaultCase(node); + } + + @Override + public void caseADecVar2Dv(ADecVar2Dv node) + { + defaultCase(node); + } + + @Override + public void caseALDvbLdvb(ALDvbLdvb node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLdvb(AEpsilonLdvb node) + { + defaultCase(node); + } + + @Override + public void caseALdfLdf(ALdfLdf node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLdf(AEpsilonLdf node) + { + defaultCase(node); + } + + @Override + public void caseADfDf(ADfDf node) + { + defaultCase(node); + } + + @Override + public void caseAParamsLparam(AParamsLparam node) + { + defaultCase(node); + } + + @Override + public void caseAIblocIb(AIblocIb node) + { + defaultCase(node); + } + + @Override + public void caseAListeILi(AListeILi node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLi(AEpsilonLi node) + { + defaultCase(node); + } + + @Override + public void caseAIAffI(AIAffI node) + { + defaultCase(node); + } + + @Override + public void caseAISiI(AISiI node) + { + defaultCase(node); + } + + @Override + public void caseAITqI(AITqI node) + { + defaultCase(node); + } + + @Override + public void caseAIRetI(AIRetI node) + { + defaultCase(node); + } + + @Override + public void caseAIAppI(AIAppI node) + { + defaultCase(node); + } + + @Override + public void caseAIEcrI(AIEcrI node) + { + defaultCase(node); + } + + @Override + public void caseAAffectationIaffectation(AAffectationIaffectation node) + { + defaultCase(node); + } + + @Override + public void caseAIdV(AIdV node) + { + defaultCase(node); + } + + @Override + public void caseAIdtabV(AIdtabV node) + { + defaultCase(node); + } + + @Override + public void caseAT1Expression(AT1Expression node) + { + defaultCase(node); + } + + @Override + public void caseAOuExpression(AOuExpression node) + { + defaultCase(node); + } + + @Override + public void caseAT2T1(AT2T1 node) + { + defaultCase(node); + } + + @Override + public void caseAEtT1(AEtT1 node) + { + defaultCase(node); + } + + @Override + public void caseAT3T2(AT3T2 node) + { + defaultCase(node); + } + + @Override + public void caseAEgalT2(AEgalT2 node) + { + defaultCase(node); + } + + @Override + public void caseAInferieurT2(AInferieurT2 node) + { + defaultCase(node); + } + + @Override + public void caseAT4T3(AT4T3 node) + { + defaultCase(node); + } + + @Override + public void caseAPlusT3(APlusT3 node) + { + defaultCase(node); + } + + @Override + public void caseAMoinsT3(AMoinsT3 node) + { + defaultCase(node); + } + + @Override + public void caseAT5T4(AT5T4 node) + { + defaultCase(node); + } + + @Override + public void caseAMultiplicationT4(AMultiplicationT4 node) + { + defaultCase(node); + } + + @Override + public void caseADivisionT4(ADivisionT4 node) + { + defaultCase(node); + } + + @Override + public void caseAT6T5(AT6T5 node) + { + defaultCase(node); + } + + @Override + public void caseANonT5(ANonT5 node) + { + defaultCase(node); + } + + @Override + public void caseAExpressionT6(AExpressionT6 node) + { + defaultCase(node); + } + + @Override + public void caseAX1T6(AX1T6 node) + { + defaultCase(node); + } + + @Override + public void caseAX2T6(AX2T6 node) + { + defaultCase(node); + } + + @Override + public void caseAAppT6(AAppT6 node) + { + defaultCase(node); + } + + @Override + public void caseAAppel(AAppel node) + { + defaultCase(node); + } + + @Override + public void caseAListeExpLe(AListeExpLe node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLe(AEpsilonLe node) + { + defaultCase(node); + } + + @Override + public void caseAListeExpBLeb(AListeExpBLeb node) + { + defaultCase(node); + } + + @Override + public void caseAEpsilonLeb(AEpsilonLeb node) + { + defaultCase(node); + } + + @Override + public void caseASiIsi(ASiIsi node) + { + defaultCase(node); + } + + @Override + public void caseASisinonIsi(ASisinonIsi node) + { + defaultCase(node); + } + + @Override + public void caseATantqueItantque(ATantqueItantque node) + { + defaultCase(node); + } + + @Override + public void caseARetournerIret(ARetournerIret node) + { + defaultCase(node); + } + + @Override + public void caseAIappelIappel(AIappelIappel node) + { + defaultCase(node); + } + + @Override + public void caseAIecrireIecrire(AIecrireIecrire node) + { + defaultCase(node); + } + + @Override + public void caseTEspaces(TEspaces node) + { + defaultCase(node); + } + + @Override + public void caseTCommentaire(TCommentaire node) + { + defaultCase(node); + } + + @Override + public void caseTParentheseFermante(TParentheseFermante node) + { + defaultCase(node); + } + + @Override + public void caseTAccoladeOuvrante(TAccoladeOuvrante node) + { + defaultCase(node); + } + + @Override + public void caseTAccoladeFermante(TAccoladeFermante node) + { + defaultCase(node); + } + + @Override + public void caseTCrochetOuvrant(TCrochetOuvrant node) + { + defaultCase(node); + } + + @Override + public void caseTCrochetFermant(TCrochetFermant node) + { + defaultCase(node); + } + + @Override + public void caseTVirgule(TVirgule node) + { + defaultCase(node); + } + + @Override + public void caseTPVirgule(TPVirgule node) + { + defaultCase(node); + } + + @Override + public void caseTNombre(TNombre node) + { + defaultCase(node); + } + + @Override + public void caseTEntier(TEntier node) + { + defaultCase(node); + } + + @Override + public void caseTParentheseOuvrante(TParentheseOuvrante node) + { + defaultCase(node); + } + + @Override + public void caseTOu(TOu node) + { + defaultCase(node); + } + + @Override + public void caseTEt(TEt node) + { + defaultCase(node); + } + + @Override + public void caseTPlus(TPlus node) + { + defaultCase(node); + } + + @Override + public void caseTMoins(TMoins node) + { + defaultCase(node); + } + + @Override + public void caseTDivision(TDivision node) + { + defaultCase(node); + } + + @Override + public void caseTMultiplication(TMultiplication node) + { + defaultCase(node); + } + + @Override + public void caseTEgal(TEgal node) + { + defaultCase(node); + } + + @Override + public void caseTInferieur(TInferieur node) + { + defaultCase(node); + } + + @Override + public void caseTNon(TNon node) + { + defaultCase(node); + } + + @Override + public void caseTSi(TSi node) + { + defaultCase(node); + } + + @Override + public void caseTAlors(TAlors node) + { + defaultCase(node); + } + + @Override + public void caseTSinon(TSinon node) + { + defaultCase(node); + } + + @Override + public void caseTTantque(TTantque node) + { + defaultCase(node); + } + + @Override + public void caseTFaire(TFaire node) + { + defaultCase(node); + } + + @Override + public void caseTRetour(TRetour node) + { + defaultCase(node); + } + + @Override + public void caseTEcrire(TEcrire node) + { + defaultCase(node); + } + + @Override + public void caseTLire(TLire node) + { + defaultCase(node); + } + + @Override + public void caseTEpsilon(TEpsilon node) + { + defaultCase(node); + } + + @Override + public void caseTIdentif(TIdentif node) + { + defaultCase(node); + } + + @Override + public void caseEOF(EOF node) + { + defaultCase(node); + } + + @Override + public void caseInvalidToken(InvalidToken node) + { + defaultCase(node); + } + + public void defaultCase(@SuppressWarnings("unused") Node node) + { + // do nothing + } +} diff --git a/src/sc/analysis/DepthFirstAdapter.java b/src/sc/analysis/DepthFirstAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..95048731bbb78bbcd3536957f02120f0e725f374 --- /dev/null +++ b/src/sc/analysis/DepthFirstAdapter.java @@ -0,0 +1,1437 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.analysis; + +import java.util.*; +import sc.node.*; + +public class DepthFirstAdapter extends AnalysisAdapter +{ + public void inStart(Start node) + { + defaultIn(node); + } + + public void outStart(Start node) + { + defaultOut(node); + } + + public void defaultIn(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + public void defaultOut(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + @Override + public void caseStart(Start node) + { + inStart(node); + node.getPProgram().apply(this); + node.getEOF().apply(this); + outStart(node); + } + + public void inAProgramProgram(AProgramProgram node) + { + defaultIn(node); + } + + public void outAProgramProgram(AProgramProgram node) + { + defaultOut(node); + } + + @Override + public void caseAProgramProgram(AProgramProgram node) + { + inAProgramProgram(node); + if(node.getLdvo() != null) + { + node.getLdvo().apply(this); + } + if(node.getLdf() != null) + { + node.getLdf().apply(this); + } + outAProgramProgram(node); + } + + public void inALdvoLdvo(ALdvoLdvo node) + { + defaultIn(node); + } + + public void outALdvoLdvo(ALdvoLdvo node) + { + defaultOut(node); + } + + @Override + public void caseALdvoLdvo(ALdvoLdvo node) + { + inALdvoLdvo(node); + if(node.getLdv() != null) + { + node.getLdv().apply(this); + } + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + outALdvoLdvo(node); + } + + public void inAEpsilonLdvo(AEpsilonLdvo node) + { + defaultIn(node); + } + + public void outAEpsilonLdvo(AEpsilonLdvo node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdvo(AEpsilonLdvo node) + { + inAEpsilonLdvo(node); + outAEpsilonLdvo(node); + } + + public void inALDvLdv(ALDvLdv node) + { + defaultIn(node); + } + + public void outALDvLdv(ALDvLdv node) + { + defaultOut(node); + } + + @Override + public void caseALDvLdv(ALDvLdv node) + { + inALDvLdv(node); + if(node.getDv() != null) + { + node.getDv().apply(this); + } + if(node.getLdvb() != null) + { + node.getLdvb().apply(this); + } + outALDvLdv(node); + } + + public void inAEpsilonLdv(AEpsilonLdv node) + { + defaultIn(node); + } + + public void outAEpsilonLdv(AEpsilonLdv node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdv(AEpsilonLdv node) + { + inAEpsilonLdv(node); + outAEpsilonLdv(node); + } + + public void inADecVarDv(ADecVarDv node) + { + defaultIn(node); + } + + public void outADecVarDv(ADecVarDv node) + { + defaultOut(node); + } + + @Override + public void caseADecVarDv(ADecVarDv node) + { + inADecVarDv(node); + if(node.getEntier() != null) + { + node.getEntier().apply(this); + } + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + outADecVarDv(node); + } + + public void inADecVar2Dv(ADecVar2Dv node) + { + defaultIn(node); + } + + public void outADecVar2Dv(ADecVar2Dv node) + { + defaultOut(node); + } + + @Override + public void caseADecVar2Dv(ADecVar2Dv node) + { + inADecVar2Dv(node); + if(node.getEntier() != null) + { + node.getEntier().apply(this); + } + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + if(node.getCrochetOuvrant() != null) + { + node.getCrochetOuvrant().apply(this); + } + if(node.getNombre() != null) + { + node.getNombre().apply(this); + } + if(node.getCrochetFermant() != null) + { + node.getCrochetFermant().apply(this); + } + outADecVar2Dv(node); + } + + public void inALDvbLdvb(ALDvbLdvb node) + { + defaultIn(node); + } + + public void outALDvbLdvb(ALDvbLdvb node) + { + defaultOut(node); + } + + @Override + public void caseALDvbLdvb(ALDvbLdvb node) + { + inALDvbLdvb(node); + if(node.getVirgule() != null) + { + node.getVirgule().apply(this); + } + if(node.getDv() != null) + { + node.getDv().apply(this); + } + if(node.getLdvb() != null) + { + node.getLdvb().apply(this); + } + outALDvbLdvb(node); + } + + public void inAEpsilonLdvb(AEpsilonLdvb node) + { + defaultIn(node); + } + + public void outAEpsilonLdvb(AEpsilonLdvb node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdvb(AEpsilonLdvb node) + { + inAEpsilonLdvb(node); + outAEpsilonLdvb(node); + } + + public void inALdfLdf(ALdfLdf node) + { + defaultIn(node); + } + + public void outALdfLdf(ALdfLdf node) + { + defaultOut(node); + } + + @Override + public void caseALdfLdf(ALdfLdf node) + { + inALdfLdf(node); + if(node.getDf() != null) + { + node.getDf().apply(this); + } + if(node.getLdf() != null) + { + node.getLdf().apply(this); + } + outALdfLdf(node); + } + + public void inAEpsilonLdf(AEpsilonLdf node) + { + defaultIn(node); + } + + public void outAEpsilonLdf(AEpsilonLdf node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdf(AEpsilonLdf node) + { + inAEpsilonLdf(node); + outAEpsilonLdf(node); + } + + public void inADfDf(ADfDf node) + { + defaultIn(node); + } + + public void outADfDf(ADfDf node) + { + defaultOut(node); + } + + @Override + public void caseADfDf(ADfDf node) + { + inADfDf(node); + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + if(node.getLparam() != null) + { + node.getLparam().apply(this); + } + if(node.getLdvo() != null) + { + node.getLdvo().apply(this); + } + if(node.getIb() != null) + { + node.getIb().apply(this); + } + outADfDf(node); + } + + public void inAParamsLparam(AParamsLparam node) + { + defaultIn(node); + } + + public void outAParamsLparam(AParamsLparam node) + { + defaultOut(node); + } + + @Override + public void caseAParamsLparam(AParamsLparam node) + { + inAParamsLparam(node); + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + if(node.getLdv() != null) + { + node.getLdv().apply(this); + } + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + outAParamsLparam(node); + } + + public void inAIblocIb(AIblocIb node) + { + defaultIn(node); + } + + public void outAIblocIb(AIblocIb node) + { + defaultOut(node); + } + + @Override + public void caseAIblocIb(AIblocIb node) + { + inAIblocIb(node); + if(node.getAccoladeOuvrante() != null) + { + node.getAccoladeOuvrante().apply(this); + } + if(node.getLi() != null) + { + node.getLi().apply(this); + } + if(node.getAccoladeFermante() != null) + { + node.getAccoladeFermante().apply(this); + } + outAIblocIb(node); + } + + public void inAListeILi(AListeILi node) + { + defaultIn(node); + } + + public void outAListeILi(AListeILi node) + { + defaultOut(node); + } + + @Override + public void caseAListeILi(AListeILi node) + { + inAListeILi(node); + if(node.getI() != null) + { + node.getI().apply(this); + } + if(node.getLi() != null) + { + node.getLi().apply(this); + } + outAListeILi(node); + } + + public void inAEpsilonLi(AEpsilonLi node) + { + defaultIn(node); + } + + public void outAEpsilonLi(AEpsilonLi node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLi(AEpsilonLi node) + { + inAEpsilonLi(node); + outAEpsilonLi(node); + } + + public void inAIAffI(AIAffI node) + { + defaultIn(node); + } + + public void outAIAffI(AIAffI node) + { + defaultOut(node); + } + + @Override + public void caseAIAffI(AIAffI node) + { + inAIAffI(node); + if(node.getIaffectation() != null) + { + node.getIaffectation().apply(this); + } + outAIAffI(node); + } + + public void inAISiI(AISiI node) + { + defaultIn(node); + } + + public void outAISiI(AISiI node) + { + defaultOut(node); + } + + @Override + public void caseAISiI(AISiI node) + { + inAISiI(node); + if(node.getIsi() != null) + { + node.getIsi().apply(this); + } + outAISiI(node); + } + + public void inAITqI(AITqI node) + { + defaultIn(node); + } + + public void outAITqI(AITqI node) + { + defaultOut(node); + } + + @Override + public void caseAITqI(AITqI node) + { + inAITqI(node); + if(node.getItantque() != null) + { + node.getItantque().apply(this); + } + outAITqI(node); + } + + public void inAIRetI(AIRetI node) + { + defaultIn(node); + } + + public void outAIRetI(AIRetI node) + { + defaultOut(node); + } + + @Override + public void caseAIRetI(AIRetI node) + { + inAIRetI(node); + if(node.getIret() != null) + { + node.getIret().apply(this); + } + outAIRetI(node); + } + + public void inAIAppI(AIAppI node) + { + defaultIn(node); + } + + public void outAIAppI(AIAppI node) + { + defaultOut(node); + } + + @Override + public void caseAIAppI(AIAppI node) + { + inAIAppI(node); + if(node.getIappel() != null) + { + node.getIappel().apply(this); + } + outAIAppI(node); + } + + public void inAIEcrI(AIEcrI node) + { + defaultIn(node); + } + + public void outAIEcrI(AIEcrI node) + { + defaultOut(node); + } + + @Override + public void caseAIEcrI(AIEcrI node) + { + inAIEcrI(node); + if(node.getIecrire() != null) + { + node.getIecrire().apply(this); + } + outAIEcrI(node); + } + + public void inAAffectationIaffectation(AAffectationIaffectation node) + { + defaultIn(node); + } + + public void outAAffectationIaffectation(AAffectationIaffectation node) + { + defaultOut(node); + } + + @Override + public void caseAAffectationIaffectation(AAffectationIaffectation node) + { + inAAffectationIaffectation(node); + if(node.getV() != null) + { + node.getV().apply(this); + } + if(node.getEgal() != null) + { + node.getEgal().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + outAAffectationIaffectation(node); + } + + public void inAIdV(AIdV node) + { + defaultIn(node); + } + + public void outAIdV(AIdV node) + { + defaultOut(node); + } + + @Override + public void caseAIdV(AIdV node) + { + inAIdV(node); + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + outAIdV(node); + } + + public void inAIdtabV(AIdtabV node) + { + defaultIn(node); + } + + public void outAIdtabV(AIdtabV node) + { + defaultOut(node); + } + + @Override + public void caseAIdtabV(AIdtabV node) + { + inAIdtabV(node); + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + if(node.getCrochetOuvrant() != null) + { + node.getCrochetOuvrant().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getCrochetFermant() != null) + { + node.getCrochetFermant().apply(this); + } + outAIdtabV(node); + } + + public void inAT1Expression(AT1Expression node) + { + defaultIn(node); + } + + public void outAT1Expression(AT1Expression node) + { + defaultOut(node); + } + + @Override + public void caseAT1Expression(AT1Expression node) + { + inAT1Expression(node); + if(node.getT1() != null) + { + node.getT1().apply(this); + } + outAT1Expression(node); + } + + public void inAOuExpression(AOuExpression node) + { + defaultIn(node); + } + + public void outAOuExpression(AOuExpression node) + { + defaultOut(node); + } + + @Override + public void caseAOuExpression(AOuExpression node) + { + inAOuExpression(node); + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getOu() != null) + { + node.getOu().apply(this); + } + if(node.getT1() != null) + { + node.getT1().apply(this); + } + outAOuExpression(node); + } + + public void inAT2T1(AT2T1 node) + { + defaultIn(node); + } + + public void outAT2T1(AT2T1 node) + { + defaultOut(node); + } + + @Override + public void caseAT2T1(AT2T1 node) + { + inAT2T1(node); + if(node.getT2() != null) + { + node.getT2().apply(this); + } + outAT2T1(node); + } + + public void inAEtT1(AEtT1 node) + { + defaultIn(node); + } + + public void outAEtT1(AEtT1 node) + { + defaultOut(node); + } + + @Override + public void caseAEtT1(AEtT1 node) + { + inAEtT1(node); + if(node.getT1() != null) + { + node.getT1().apply(this); + } + if(node.getEt() != null) + { + node.getEt().apply(this); + } + if(node.getT2() != null) + { + node.getT2().apply(this); + } + outAEtT1(node); + } + + public void inAT3T2(AT3T2 node) + { + defaultIn(node); + } + + public void outAT3T2(AT3T2 node) + { + defaultOut(node); + } + + @Override + public void caseAT3T2(AT3T2 node) + { + inAT3T2(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAT3T2(node); + } + + public void inAEgalT2(AEgalT2 node) + { + defaultIn(node); + } + + public void outAEgalT2(AEgalT2 node) + { + defaultOut(node); + } + + @Override + public void caseAEgalT2(AEgalT2 node) + { + inAEgalT2(node); + if(node.getT2() != null) + { + node.getT2().apply(this); + } + if(node.getEgal() != null) + { + node.getEgal().apply(this); + } + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAEgalT2(node); + } + + public void inAInferieurT2(AInferieurT2 node) + { + defaultIn(node); + } + + public void outAInferieurT2(AInferieurT2 node) + { + defaultOut(node); + } + + @Override + public void caseAInferieurT2(AInferieurT2 node) + { + inAInferieurT2(node); + if(node.getT2() != null) + { + node.getT2().apply(this); + } + if(node.getInferieur() != null) + { + node.getInferieur().apply(this); + } + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAInferieurT2(node); + } + + public void inAT4T3(AT4T3 node) + { + defaultIn(node); + } + + public void outAT4T3(AT4T3 node) + { + defaultOut(node); + } + + @Override + public void caseAT4T3(AT4T3 node) + { + inAT4T3(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outAT4T3(node); + } + + public void inAPlusT3(APlusT3 node) + { + defaultIn(node); + } + + public void outAPlusT3(APlusT3 node) + { + defaultOut(node); + } + + @Override + public void caseAPlusT3(APlusT3 node) + { + inAPlusT3(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + if(node.getPlus() != null) + { + node.getPlus().apply(this); + } + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outAPlusT3(node); + } + + public void inAMoinsT3(AMoinsT3 node) + { + defaultIn(node); + } + + public void outAMoinsT3(AMoinsT3 node) + { + defaultOut(node); + } + + @Override + public void caseAMoinsT3(AMoinsT3 node) + { + inAMoinsT3(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + if(node.getMoins() != null) + { + node.getMoins().apply(this); + } + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outAMoinsT3(node); + } + + public void inAT5T4(AT5T4 node) + { + defaultIn(node); + } + + public void outAT5T4(AT5T4 node) + { + defaultOut(node); + } + + @Override + public void caseAT5T4(AT5T4 node) + { + inAT5T4(node); + if(node.getT5() != null) + { + node.getT5().apply(this); + } + outAT5T4(node); + } + + public void inAMultiplicationT4(AMultiplicationT4 node) + { + defaultIn(node); + } + + public void outAMultiplicationT4(AMultiplicationT4 node) + { + defaultOut(node); + } + + @Override + public void caseAMultiplicationT4(AMultiplicationT4 node) + { + inAMultiplicationT4(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + if(node.getMultiplication() != null) + { + node.getMultiplication().apply(this); + } + if(node.getT5() != null) + { + node.getT5().apply(this); + } + outAMultiplicationT4(node); + } + + public void inADivisionT4(ADivisionT4 node) + { + defaultIn(node); + } + + public void outADivisionT4(ADivisionT4 node) + { + defaultOut(node); + } + + @Override + public void caseADivisionT4(ADivisionT4 node) + { + inADivisionT4(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + if(node.getDivision() != null) + { + node.getDivision().apply(this); + } + if(node.getT5() != null) + { + node.getT5().apply(this); + } + outADivisionT4(node); + } + + public void inAT6T5(AT6T5 node) + { + defaultIn(node); + } + + public void outAT6T5(AT6T5 node) + { + defaultOut(node); + } + + @Override + public void caseAT6T5(AT6T5 node) + { + inAT6T5(node); + if(node.getT6() != null) + { + node.getT6().apply(this); + } + outAT6T5(node); + } + + public void inANonT5(ANonT5 node) + { + defaultIn(node); + } + + public void outANonT5(ANonT5 node) + { + defaultOut(node); + } + + @Override + public void caseANonT5(ANonT5 node) + { + inANonT5(node); + if(node.getNon() != null) + { + node.getNon().apply(this); + } + if(node.getT5() != null) + { + node.getT5().apply(this); + } + outANonT5(node); + } + + public void inAExpressionT6(AExpressionT6 node) + { + defaultIn(node); + } + + public void outAExpressionT6(AExpressionT6 node) + { + defaultOut(node); + } + + @Override + public void caseAExpressionT6(AExpressionT6 node) + { + inAExpressionT6(node); + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + outAExpressionT6(node); + } + + public void inAX1T6(AX1T6 node) + { + defaultIn(node); + } + + public void outAX1T6(AX1T6 node) + { + defaultOut(node); + } + + @Override + public void caseAX1T6(AX1T6 node) + { + inAX1T6(node); + if(node.getNombre() != null) + { + node.getNombre().apply(this); + } + outAX1T6(node); + } + + public void inAX2T6(AX2T6 node) + { + defaultIn(node); + } + + public void outAX2T6(AX2T6 node) + { + defaultOut(node); + } + + @Override + public void caseAX2T6(AX2T6 node) + { + inAX2T6(node); + if(node.getV() != null) + { + node.getV().apply(this); + } + outAX2T6(node); + } + + public void inAAppT6(AAppT6 node) + { + defaultIn(node); + } + + public void outAAppT6(AAppT6 node) + { + defaultOut(node); + } + + @Override + public void caseAAppT6(AAppT6 node) + { + inAAppT6(node); + if(node.getAppel() != null) + { + node.getAppel().apply(this); + } + outAAppT6(node); + } + + public void inAAppel(AAppel node) + { + defaultIn(node); + } + + public void outAAppel(AAppel node) + { + defaultOut(node); + } + + @Override + public void caseAAppel(AAppel node) + { + inAAppel(node); + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + if(node.getLe() != null) + { + node.getLe().apply(this); + } + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + outAAppel(node); + } + + public void inAListeExpLe(AListeExpLe node) + { + defaultIn(node); + } + + public void outAListeExpLe(AListeExpLe node) + { + defaultOut(node); + } + + @Override + public void caseAListeExpLe(AListeExpLe node) + { + inAListeExpLe(node); + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getLeb() != null) + { + node.getLeb().apply(this); + } + outAListeExpLe(node); + } + + public void inAEpsilonLe(AEpsilonLe node) + { + defaultIn(node); + } + + public void outAEpsilonLe(AEpsilonLe node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLe(AEpsilonLe node) + { + inAEpsilonLe(node); + outAEpsilonLe(node); + } + + public void inAListeExpBLeb(AListeExpBLeb node) + { + defaultIn(node); + } + + public void outAListeExpBLeb(AListeExpBLeb node) + { + defaultOut(node); + } + + @Override + public void caseAListeExpBLeb(AListeExpBLeb node) + { + inAListeExpBLeb(node); + if(node.getVirgule() != null) + { + node.getVirgule().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getLeb() != null) + { + node.getLeb().apply(this); + } + outAListeExpBLeb(node); + } + + public void inAEpsilonLeb(AEpsilonLeb node) + { + defaultIn(node); + } + + public void outAEpsilonLeb(AEpsilonLeb node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLeb(AEpsilonLeb node) + { + inAEpsilonLeb(node); + outAEpsilonLeb(node); + } + + public void inASiIsi(ASiIsi node) + { + defaultIn(node); + } + + public void outASiIsi(ASiIsi node) + { + defaultOut(node); + } + + @Override + public void caseASiIsi(ASiIsi node) + { + inASiIsi(node); + if(node.getSi() != null) + { + node.getSi().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getAlors() != null) + { + node.getAlors().apply(this); + } + if(node.getIb() != null) + { + node.getIb().apply(this); + } + outASiIsi(node); + } + + public void inASisinonIsi(ASisinonIsi node) + { + defaultIn(node); + } + + public void outASisinonIsi(ASisinonIsi node) + { + defaultOut(node); + } + + @Override + public void caseASisinonIsi(ASisinonIsi node) + { + inASisinonIsi(node); + if(node.getSi() != null) + { + node.getSi().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getAlors() != null) + { + node.getAlors().apply(this); + } + if(node.getCas1() != null) + { + node.getCas1().apply(this); + } + if(node.getSinon() != null) + { + node.getSinon().apply(this); + } + if(node.getCas2() != null) + { + node.getCas2().apply(this); + } + outASisinonIsi(node); + } + + public void inATantqueItantque(ATantqueItantque node) + { + defaultIn(node); + } + + public void outATantqueItantque(ATantqueItantque node) + { + defaultOut(node); + } + + @Override + public void caseATantqueItantque(ATantqueItantque node) + { + inATantqueItantque(node); + if(node.getTantque() != null) + { + node.getTantque().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getFaire() != null) + { + node.getFaire().apply(this); + } + if(node.getIb() != null) + { + node.getIb().apply(this); + } + outATantqueItantque(node); + } + + public void inARetournerIret(ARetournerIret node) + { + defaultIn(node); + } + + public void outARetournerIret(ARetournerIret node) + { + defaultOut(node); + } + + @Override + public void caseARetournerIret(ARetournerIret node) + { + inARetournerIret(node); + if(node.getRetour() != null) + { + node.getRetour().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + outARetournerIret(node); + } + + public void inAIappelIappel(AIappelIappel node) + { + defaultIn(node); + } + + public void outAIappelIappel(AIappelIappel node) + { + defaultOut(node); + } + + @Override + public void caseAIappelIappel(AIappelIappel node) + { + inAIappelIappel(node); + if(node.getAppel() != null) + { + node.getAppel().apply(this); + } + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + outAIappelIappel(node); + } + + public void inAIecrireIecrire(AIecrireIecrire node) + { + defaultIn(node); + } + + public void outAIecrireIecrire(AIecrireIecrire node) + { + defaultOut(node); + } + + @Override + public void caseAIecrireIecrire(AIecrireIecrire node) + { + inAIecrireIecrire(node); + if(node.getEcrire() != null) + { + node.getEcrire().apply(this); + } + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + outAIecrireIecrire(node); + } +} diff --git a/src/sc/analysis/ReversedDepthFirstAdapter.java b/src/sc/analysis/ReversedDepthFirstAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..97b83ffb43e39921cd1bde7947d1bceba16151f3 --- /dev/null +++ b/src/sc/analysis/ReversedDepthFirstAdapter.java @@ -0,0 +1,1437 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.analysis; + +import java.util.*; +import sc.node.*; + +public class ReversedDepthFirstAdapter extends AnalysisAdapter +{ + public void inStart(Start node) + { + defaultIn(node); + } + + public void outStart(Start node) + { + defaultOut(node); + } + + public void defaultIn(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + public void defaultOut(@SuppressWarnings("unused") Node node) + { + // Do nothing + } + + @Override + public void caseStart(Start node) + { + inStart(node); + node.getEOF().apply(this); + node.getPProgram().apply(this); + outStart(node); + } + + public void inAProgramProgram(AProgramProgram node) + { + defaultIn(node); + } + + public void outAProgramProgram(AProgramProgram node) + { + defaultOut(node); + } + + @Override + public void caseAProgramProgram(AProgramProgram node) + { + inAProgramProgram(node); + if(node.getLdf() != null) + { + node.getLdf().apply(this); + } + if(node.getLdvo() != null) + { + node.getLdvo().apply(this); + } + outAProgramProgram(node); + } + + public void inALdvoLdvo(ALdvoLdvo node) + { + defaultIn(node); + } + + public void outALdvoLdvo(ALdvoLdvo node) + { + defaultOut(node); + } + + @Override + public void caseALdvoLdvo(ALdvoLdvo node) + { + inALdvoLdvo(node); + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + if(node.getLdv() != null) + { + node.getLdv().apply(this); + } + outALdvoLdvo(node); + } + + public void inAEpsilonLdvo(AEpsilonLdvo node) + { + defaultIn(node); + } + + public void outAEpsilonLdvo(AEpsilonLdvo node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdvo(AEpsilonLdvo node) + { + inAEpsilonLdvo(node); + outAEpsilonLdvo(node); + } + + public void inALDvLdv(ALDvLdv node) + { + defaultIn(node); + } + + public void outALDvLdv(ALDvLdv node) + { + defaultOut(node); + } + + @Override + public void caseALDvLdv(ALDvLdv node) + { + inALDvLdv(node); + if(node.getLdvb() != null) + { + node.getLdvb().apply(this); + } + if(node.getDv() != null) + { + node.getDv().apply(this); + } + outALDvLdv(node); + } + + public void inAEpsilonLdv(AEpsilonLdv node) + { + defaultIn(node); + } + + public void outAEpsilonLdv(AEpsilonLdv node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdv(AEpsilonLdv node) + { + inAEpsilonLdv(node); + outAEpsilonLdv(node); + } + + public void inADecVarDv(ADecVarDv node) + { + defaultIn(node); + } + + public void outADecVarDv(ADecVarDv node) + { + defaultOut(node); + } + + @Override + public void caseADecVarDv(ADecVarDv node) + { + inADecVarDv(node); + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + if(node.getEntier() != null) + { + node.getEntier().apply(this); + } + outADecVarDv(node); + } + + public void inADecVar2Dv(ADecVar2Dv node) + { + defaultIn(node); + } + + public void outADecVar2Dv(ADecVar2Dv node) + { + defaultOut(node); + } + + @Override + public void caseADecVar2Dv(ADecVar2Dv node) + { + inADecVar2Dv(node); + if(node.getCrochetFermant() != null) + { + node.getCrochetFermant().apply(this); + } + if(node.getNombre() != null) + { + node.getNombre().apply(this); + } + if(node.getCrochetOuvrant() != null) + { + node.getCrochetOuvrant().apply(this); + } + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + if(node.getEntier() != null) + { + node.getEntier().apply(this); + } + outADecVar2Dv(node); + } + + public void inALDvbLdvb(ALDvbLdvb node) + { + defaultIn(node); + } + + public void outALDvbLdvb(ALDvbLdvb node) + { + defaultOut(node); + } + + @Override + public void caseALDvbLdvb(ALDvbLdvb node) + { + inALDvbLdvb(node); + if(node.getLdvb() != null) + { + node.getLdvb().apply(this); + } + if(node.getDv() != null) + { + node.getDv().apply(this); + } + if(node.getVirgule() != null) + { + node.getVirgule().apply(this); + } + outALDvbLdvb(node); + } + + public void inAEpsilonLdvb(AEpsilonLdvb node) + { + defaultIn(node); + } + + public void outAEpsilonLdvb(AEpsilonLdvb node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdvb(AEpsilonLdvb node) + { + inAEpsilonLdvb(node); + outAEpsilonLdvb(node); + } + + public void inALdfLdf(ALdfLdf node) + { + defaultIn(node); + } + + public void outALdfLdf(ALdfLdf node) + { + defaultOut(node); + } + + @Override + public void caseALdfLdf(ALdfLdf node) + { + inALdfLdf(node); + if(node.getLdf() != null) + { + node.getLdf().apply(this); + } + if(node.getDf() != null) + { + node.getDf().apply(this); + } + outALdfLdf(node); + } + + public void inAEpsilonLdf(AEpsilonLdf node) + { + defaultIn(node); + } + + public void outAEpsilonLdf(AEpsilonLdf node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLdf(AEpsilonLdf node) + { + inAEpsilonLdf(node); + outAEpsilonLdf(node); + } + + public void inADfDf(ADfDf node) + { + defaultIn(node); + } + + public void outADfDf(ADfDf node) + { + defaultOut(node); + } + + @Override + public void caseADfDf(ADfDf node) + { + inADfDf(node); + if(node.getIb() != null) + { + node.getIb().apply(this); + } + if(node.getLdvo() != null) + { + node.getLdvo().apply(this); + } + if(node.getLparam() != null) + { + node.getLparam().apply(this); + } + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + outADfDf(node); + } + + public void inAParamsLparam(AParamsLparam node) + { + defaultIn(node); + } + + public void outAParamsLparam(AParamsLparam node) + { + defaultOut(node); + } + + @Override + public void caseAParamsLparam(AParamsLparam node) + { + inAParamsLparam(node); + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + if(node.getLdv() != null) + { + node.getLdv().apply(this); + } + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + outAParamsLparam(node); + } + + public void inAIblocIb(AIblocIb node) + { + defaultIn(node); + } + + public void outAIblocIb(AIblocIb node) + { + defaultOut(node); + } + + @Override + public void caseAIblocIb(AIblocIb node) + { + inAIblocIb(node); + if(node.getAccoladeFermante() != null) + { + node.getAccoladeFermante().apply(this); + } + if(node.getLi() != null) + { + node.getLi().apply(this); + } + if(node.getAccoladeOuvrante() != null) + { + node.getAccoladeOuvrante().apply(this); + } + outAIblocIb(node); + } + + public void inAListeILi(AListeILi node) + { + defaultIn(node); + } + + public void outAListeILi(AListeILi node) + { + defaultOut(node); + } + + @Override + public void caseAListeILi(AListeILi node) + { + inAListeILi(node); + if(node.getLi() != null) + { + node.getLi().apply(this); + } + if(node.getI() != null) + { + node.getI().apply(this); + } + outAListeILi(node); + } + + public void inAEpsilonLi(AEpsilonLi node) + { + defaultIn(node); + } + + public void outAEpsilonLi(AEpsilonLi node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLi(AEpsilonLi node) + { + inAEpsilonLi(node); + outAEpsilonLi(node); + } + + public void inAIAffI(AIAffI node) + { + defaultIn(node); + } + + public void outAIAffI(AIAffI node) + { + defaultOut(node); + } + + @Override + public void caseAIAffI(AIAffI node) + { + inAIAffI(node); + if(node.getIaffectation() != null) + { + node.getIaffectation().apply(this); + } + outAIAffI(node); + } + + public void inAISiI(AISiI node) + { + defaultIn(node); + } + + public void outAISiI(AISiI node) + { + defaultOut(node); + } + + @Override + public void caseAISiI(AISiI node) + { + inAISiI(node); + if(node.getIsi() != null) + { + node.getIsi().apply(this); + } + outAISiI(node); + } + + public void inAITqI(AITqI node) + { + defaultIn(node); + } + + public void outAITqI(AITqI node) + { + defaultOut(node); + } + + @Override + public void caseAITqI(AITqI node) + { + inAITqI(node); + if(node.getItantque() != null) + { + node.getItantque().apply(this); + } + outAITqI(node); + } + + public void inAIRetI(AIRetI node) + { + defaultIn(node); + } + + public void outAIRetI(AIRetI node) + { + defaultOut(node); + } + + @Override + public void caseAIRetI(AIRetI node) + { + inAIRetI(node); + if(node.getIret() != null) + { + node.getIret().apply(this); + } + outAIRetI(node); + } + + public void inAIAppI(AIAppI node) + { + defaultIn(node); + } + + public void outAIAppI(AIAppI node) + { + defaultOut(node); + } + + @Override + public void caseAIAppI(AIAppI node) + { + inAIAppI(node); + if(node.getIappel() != null) + { + node.getIappel().apply(this); + } + outAIAppI(node); + } + + public void inAIEcrI(AIEcrI node) + { + defaultIn(node); + } + + public void outAIEcrI(AIEcrI node) + { + defaultOut(node); + } + + @Override + public void caseAIEcrI(AIEcrI node) + { + inAIEcrI(node); + if(node.getIecrire() != null) + { + node.getIecrire().apply(this); + } + outAIEcrI(node); + } + + public void inAAffectationIaffectation(AAffectationIaffectation node) + { + defaultIn(node); + } + + public void outAAffectationIaffectation(AAffectationIaffectation node) + { + defaultOut(node); + } + + @Override + public void caseAAffectationIaffectation(AAffectationIaffectation node) + { + inAAffectationIaffectation(node); + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getEgal() != null) + { + node.getEgal().apply(this); + } + if(node.getV() != null) + { + node.getV().apply(this); + } + outAAffectationIaffectation(node); + } + + public void inAIdV(AIdV node) + { + defaultIn(node); + } + + public void outAIdV(AIdV node) + { + defaultOut(node); + } + + @Override + public void caseAIdV(AIdV node) + { + inAIdV(node); + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + outAIdV(node); + } + + public void inAIdtabV(AIdtabV node) + { + defaultIn(node); + } + + public void outAIdtabV(AIdtabV node) + { + defaultOut(node); + } + + @Override + public void caseAIdtabV(AIdtabV node) + { + inAIdtabV(node); + if(node.getCrochetFermant() != null) + { + node.getCrochetFermant().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getCrochetOuvrant() != null) + { + node.getCrochetOuvrant().apply(this); + } + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + outAIdtabV(node); + } + + public void inAT1Expression(AT1Expression node) + { + defaultIn(node); + } + + public void outAT1Expression(AT1Expression node) + { + defaultOut(node); + } + + @Override + public void caseAT1Expression(AT1Expression node) + { + inAT1Expression(node); + if(node.getT1() != null) + { + node.getT1().apply(this); + } + outAT1Expression(node); + } + + public void inAOuExpression(AOuExpression node) + { + defaultIn(node); + } + + public void outAOuExpression(AOuExpression node) + { + defaultOut(node); + } + + @Override + public void caseAOuExpression(AOuExpression node) + { + inAOuExpression(node); + if(node.getT1() != null) + { + node.getT1().apply(this); + } + if(node.getOu() != null) + { + node.getOu().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + outAOuExpression(node); + } + + public void inAT2T1(AT2T1 node) + { + defaultIn(node); + } + + public void outAT2T1(AT2T1 node) + { + defaultOut(node); + } + + @Override + public void caseAT2T1(AT2T1 node) + { + inAT2T1(node); + if(node.getT2() != null) + { + node.getT2().apply(this); + } + outAT2T1(node); + } + + public void inAEtT1(AEtT1 node) + { + defaultIn(node); + } + + public void outAEtT1(AEtT1 node) + { + defaultOut(node); + } + + @Override + public void caseAEtT1(AEtT1 node) + { + inAEtT1(node); + if(node.getT2() != null) + { + node.getT2().apply(this); + } + if(node.getEt() != null) + { + node.getEt().apply(this); + } + if(node.getT1() != null) + { + node.getT1().apply(this); + } + outAEtT1(node); + } + + public void inAT3T2(AT3T2 node) + { + defaultIn(node); + } + + public void outAT3T2(AT3T2 node) + { + defaultOut(node); + } + + @Override + public void caseAT3T2(AT3T2 node) + { + inAT3T2(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAT3T2(node); + } + + public void inAEgalT2(AEgalT2 node) + { + defaultIn(node); + } + + public void outAEgalT2(AEgalT2 node) + { + defaultOut(node); + } + + @Override + public void caseAEgalT2(AEgalT2 node) + { + inAEgalT2(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + if(node.getEgal() != null) + { + node.getEgal().apply(this); + } + if(node.getT2() != null) + { + node.getT2().apply(this); + } + outAEgalT2(node); + } + + public void inAInferieurT2(AInferieurT2 node) + { + defaultIn(node); + } + + public void outAInferieurT2(AInferieurT2 node) + { + defaultOut(node); + } + + @Override + public void caseAInferieurT2(AInferieurT2 node) + { + inAInferieurT2(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + if(node.getInferieur() != null) + { + node.getInferieur().apply(this); + } + if(node.getT2() != null) + { + node.getT2().apply(this); + } + outAInferieurT2(node); + } + + public void inAT4T3(AT4T3 node) + { + defaultIn(node); + } + + public void outAT4T3(AT4T3 node) + { + defaultOut(node); + } + + @Override + public void caseAT4T3(AT4T3 node) + { + inAT4T3(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outAT4T3(node); + } + + public void inAPlusT3(APlusT3 node) + { + defaultIn(node); + } + + public void outAPlusT3(APlusT3 node) + { + defaultOut(node); + } + + @Override + public void caseAPlusT3(APlusT3 node) + { + inAPlusT3(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + if(node.getPlus() != null) + { + node.getPlus().apply(this); + } + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAPlusT3(node); + } + + public void inAMoinsT3(AMoinsT3 node) + { + defaultIn(node); + } + + public void outAMoinsT3(AMoinsT3 node) + { + defaultOut(node); + } + + @Override + public void caseAMoinsT3(AMoinsT3 node) + { + inAMoinsT3(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + if(node.getMoins() != null) + { + node.getMoins().apply(this); + } + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAMoinsT3(node); + } + + public void inAT5T4(AT5T4 node) + { + defaultIn(node); + } + + public void outAT5T4(AT5T4 node) + { + defaultOut(node); + } + + @Override + public void caseAT5T4(AT5T4 node) + { + inAT5T4(node); + if(node.getT5() != null) + { + node.getT5().apply(this); + } + outAT5T4(node); + } + + public void inAMultiplicationT4(AMultiplicationT4 node) + { + defaultIn(node); + } + + public void outAMultiplicationT4(AMultiplicationT4 node) + { + defaultOut(node); + } + + @Override + public void caseAMultiplicationT4(AMultiplicationT4 node) + { + inAMultiplicationT4(node); + if(node.getT5() != null) + { + node.getT5().apply(this); + } + if(node.getMultiplication() != null) + { + node.getMultiplication().apply(this); + } + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outAMultiplicationT4(node); + } + + public void inADivisionT4(ADivisionT4 node) + { + defaultIn(node); + } + + public void outADivisionT4(ADivisionT4 node) + { + defaultOut(node); + } + + @Override + public void caseADivisionT4(ADivisionT4 node) + { + inADivisionT4(node); + if(node.getT5() != null) + { + node.getT5().apply(this); + } + if(node.getDivision() != null) + { + node.getDivision().apply(this); + } + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outADivisionT4(node); + } + + public void inAT6T5(AT6T5 node) + { + defaultIn(node); + } + + public void outAT6T5(AT6T5 node) + { + defaultOut(node); + } + + @Override + public void caseAT6T5(AT6T5 node) + { + inAT6T5(node); + if(node.getT6() != null) + { + node.getT6().apply(this); + } + outAT6T5(node); + } + + public void inANonT5(ANonT5 node) + { + defaultIn(node); + } + + public void outANonT5(ANonT5 node) + { + defaultOut(node); + } + + @Override + public void caseANonT5(ANonT5 node) + { + inANonT5(node); + if(node.getT5() != null) + { + node.getT5().apply(this); + } + if(node.getNon() != null) + { + node.getNon().apply(this); + } + outANonT5(node); + } + + public void inAExpressionT6(AExpressionT6 node) + { + defaultIn(node); + } + + public void outAExpressionT6(AExpressionT6 node) + { + defaultOut(node); + } + + @Override + public void caseAExpressionT6(AExpressionT6 node) + { + inAExpressionT6(node); + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + outAExpressionT6(node); + } + + public void inAX1T6(AX1T6 node) + { + defaultIn(node); + } + + public void outAX1T6(AX1T6 node) + { + defaultOut(node); + } + + @Override + public void caseAX1T6(AX1T6 node) + { + inAX1T6(node); + if(node.getNombre() != null) + { + node.getNombre().apply(this); + } + outAX1T6(node); + } + + public void inAX2T6(AX2T6 node) + { + defaultIn(node); + } + + public void outAX2T6(AX2T6 node) + { + defaultOut(node); + } + + @Override + public void caseAX2T6(AX2T6 node) + { + inAX2T6(node); + if(node.getV() != null) + { + node.getV().apply(this); + } + outAX2T6(node); + } + + public void inAAppT6(AAppT6 node) + { + defaultIn(node); + } + + public void outAAppT6(AAppT6 node) + { + defaultOut(node); + } + + @Override + public void caseAAppT6(AAppT6 node) + { + inAAppT6(node); + if(node.getAppel() != null) + { + node.getAppel().apply(this); + } + outAAppT6(node); + } + + public void inAAppel(AAppel node) + { + defaultIn(node); + } + + public void outAAppel(AAppel node) + { + defaultOut(node); + } + + @Override + public void caseAAppel(AAppel node) + { + inAAppel(node); + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + if(node.getLe() != null) + { + node.getLe().apply(this); + } + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + if(node.getIdentif() != null) + { + node.getIdentif().apply(this); + } + outAAppel(node); + } + + public void inAListeExpLe(AListeExpLe node) + { + defaultIn(node); + } + + public void outAListeExpLe(AListeExpLe node) + { + defaultOut(node); + } + + @Override + public void caseAListeExpLe(AListeExpLe node) + { + inAListeExpLe(node); + if(node.getLeb() != null) + { + node.getLeb().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + outAListeExpLe(node); + } + + public void inAEpsilonLe(AEpsilonLe node) + { + defaultIn(node); + } + + public void outAEpsilonLe(AEpsilonLe node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLe(AEpsilonLe node) + { + inAEpsilonLe(node); + outAEpsilonLe(node); + } + + public void inAListeExpBLeb(AListeExpBLeb node) + { + defaultIn(node); + } + + public void outAListeExpBLeb(AListeExpBLeb node) + { + defaultOut(node); + } + + @Override + public void caseAListeExpBLeb(AListeExpBLeb node) + { + inAListeExpBLeb(node); + if(node.getLeb() != null) + { + node.getLeb().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getVirgule() != null) + { + node.getVirgule().apply(this); + } + outAListeExpBLeb(node); + } + + public void inAEpsilonLeb(AEpsilonLeb node) + { + defaultIn(node); + } + + public void outAEpsilonLeb(AEpsilonLeb node) + { + defaultOut(node); + } + + @Override + public void caseAEpsilonLeb(AEpsilonLeb node) + { + inAEpsilonLeb(node); + outAEpsilonLeb(node); + } + + public void inASiIsi(ASiIsi node) + { + defaultIn(node); + } + + public void outASiIsi(ASiIsi node) + { + defaultOut(node); + } + + @Override + public void caseASiIsi(ASiIsi node) + { + inASiIsi(node); + if(node.getIb() != null) + { + node.getIb().apply(this); + } + if(node.getAlors() != null) + { + node.getAlors().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getSi() != null) + { + node.getSi().apply(this); + } + outASiIsi(node); + } + + public void inASisinonIsi(ASisinonIsi node) + { + defaultIn(node); + } + + public void outASisinonIsi(ASisinonIsi node) + { + defaultOut(node); + } + + @Override + public void caseASisinonIsi(ASisinonIsi node) + { + inASisinonIsi(node); + if(node.getCas2() != null) + { + node.getCas2().apply(this); + } + if(node.getSinon() != null) + { + node.getSinon().apply(this); + } + if(node.getCas1() != null) + { + node.getCas1().apply(this); + } + if(node.getAlors() != null) + { + node.getAlors().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getSi() != null) + { + node.getSi().apply(this); + } + outASisinonIsi(node); + } + + public void inATantqueItantque(ATantqueItantque node) + { + defaultIn(node); + } + + public void outATantqueItantque(ATantqueItantque node) + { + defaultOut(node); + } + + @Override + public void caseATantqueItantque(ATantqueItantque node) + { + inATantqueItantque(node); + if(node.getIb() != null) + { + node.getIb().apply(this); + } + if(node.getFaire() != null) + { + node.getFaire().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getTantque() != null) + { + node.getTantque().apply(this); + } + outATantqueItantque(node); + } + + public void inARetournerIret(ARetournerIret node) + { + defaultIn(node); + } + + public void outARetournerIret(ARetournerIret node) + { + defaultOut(node); + } + + @Override + public void caseARetournerIret(ARetournerIret node) + { + inARetournerIret(node); + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getRetour() != null) + { + node.getRetour().apply(this); + } + outARetournerIret(node); + } + + public void inAIappelIappel(AIappelIappel node) + { + defaultIn(node); + } + + public void outAIappelIappel(AIappelIappel node) + { + defaultOut(node); + } + + @Override + public void caseAIappelIappel(AIappelIappel node) + { + inAIappelIappel(node); + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + if(node.getAppel() != null) + { + node.getAppel().apply(this); + } + outAIappelIappel(node); + } + + public void inAIecrireIecrire(AIecrireIecrire node) + { + defaultIn(node); + } + + public void outAIecrireIecrire(AIecrireIecrire node) + { + defaultOut(node); + } + + @Override + public void caseAIecrireIecrire(AIecrireIecrire node) + { + inAIecrireIecrire(node); + if(node.getPVirgule() != null) + { + node.getPVirgule().apply(this); + } + if(node.getParentheseFermante() != null) + { + node.getParentheseFermante().apply(this); + } + if(node.getExpression() != null) + { + node.getExpression().apply(this); + } + if(node.getParentheseOuvrante() != null) + { + node.getParentheseOuvrante().apply(this); + } + if(node.getEcrire() != null) + { + node.getEcrire().apply(this); + } + outAIecrireIecrire(node); + } +} diff --git a/src/sc/analysis/Sc2sa.java b/src/sc/analysis/Sc2sa.java new file mode 100644 index 0000000000000000000000000000000000000000..48da69a2cdca99299df4bbc7126d25267fd24a1b --- /dev/null +++ b/src/sc/analysis/Sc2sa.java @@ -0,0 +1,981 @@ +package sc.analysis; + +import sa.*; +import sa.SaNode; +import sc.node.*; + +public class Sc2sa extends DepthFirstAdapter{ + + private SaNode returnValue; + + public void inStart(Start node) + { + defaultIn(node); + } + + public void outStart(Start node) + { + defaultOut(node); + } + + public void defaultIn(@SuppressWarnings("unused") Node node) + { + System.out.println("<" + node.getClass().getSimpleName() + ">"); + } + + public void defaultOut(@SuppressWarnings("unused") Node node) + { + System.out.println("</" + node.getClass().getSimpleName() + ">"); + } + + @Override + public void caseStart(Start node) + { + + inStart(node); + node.getPProgram().apply(this); + node.getEOF().apply(this); + outStart(node); + } + + public void inAProgramProgram(AProgramProgram node) + { + defaultIn(node); + } + + public void outAProgramProgram(AProgramProgram node) + { + defaultOut(node); + } + + @Override + public void caseAProgramProgram(AProgramProgram node) + { + SaLDec lvar = null; + SaLDec lfonc = null; + inAProgramProgram(node); + if(node.getLdvo() != null) + { + node.getLdvo().apply(this); + lvar = (SaLDec) returnValue; + } + if(node.getLdf() != null) + { + node.getLdf().apply(this); + lfonc = (SaLDec) returnValue; + } + returnValue = new SaProg(lvar,lfonc); + outAProgramProgram(node); + } + + @Override + public void caseALdvoLdvo(ALdvoLdvo node) + { + SaLDec lvar = null; + inALdvoLdvo(node); + if(node.getLdv() != null) + { + node.getLdv().apply(this); + lvar = (SaLDec) returnValue; + } + returnValue = lvar; + outALdvoLdvo(node); + } + + @Override + public void caseAEpsilonLdvo(AEpsilonLdvo node) + { + inAEpsilonLdvo(node); + returnValue = null; + outAEpsilonLdvo(node); + } + + @Override + public void caseALDvLdv(ALDvLdv node) + { + SaDec tete = null; + SaLDec queu = null; + inALDvLdv(node); + if(node.getDv() != null) + { + node.getDv().apply(this); + tete = (SaDec) returnValue; + } + if(node.getLdvb() != null) + { + node.getLdvb().apply(this); + queu = (SaLDec) returnValue; + } + returnValue = new SaLDec(tete,queu); + outALDvLdv(node); + } + @Override + public void caseAEpsilonLdv(AEpsilonLdv node) + { + inAEpsilonLdv(node); + returnValue = null; + outAEpsilonLdv(node); + } + + @Override + public void caseADecVarDv(ADecVarDv node) + { + String idendif = null; + inADecVarDv(node); + if(node.getEntier() != null) + + if(node.getIdentif() != null) + { + idendif = node.getIdentif().getText(); + + } + returnValue = new SaDecVar(idendif); + outADecVarDv(node); + } + + + + @Override + public void caseADecVar2Dv(ADecVar2Dv node) + { + inADecVar2Dv(node); + String nom = null; + Integer index = null; + if(node.getIdentif() != null) + { + nom = node.getIdentif().getText(); + } + + if(node.getNombre() != null) + { + index = Integer.parseInt(node.getNombre().getText()); + } + returnValue = new SaDecTab(nom,index); + + outADecVar2Dv(node); + } + + @Override + public void caseALDvbLdvb(ALDvbLdvb node) + { + SaDec tete = null; + SaLDec queue = null; + inALDvbLdvb(node); + + if(node.getDv() != null) + { + node.getDv().apply(this); + tete = (SaDec) returnValue; + } + if(node.getLdvb() != null) + { + node.getLdvb().apply(this); + queue = (SaLDec) returnValue; + } + returnValue = new SaLDec(tete,queue); + outALDvbLdvb(node); + } + @Override + public void caseAEpsilonLdvb(AEpsilonLdvb node) + { + inAEpsilonLdvb(node); + returnValue = null; + outAEpsilonLdvb(node); + } + + @Override + public void caseALdfLdf(ALdfLdf node) + { + SaDecFonc fonc = null; + SaLDec listFonct = null; + inALdfLdf(node); + if(node.getDf() != null) + { + node.getDf().apply(this); + fonc = (SaDecFonc) returnValue; + } + if(node.getLdf() != null) + { + node.getLdf().apply(this); + listFonct = (SaLDec) returnValue; + } + returnValue = new SaLDec(fonc,listFonct); + outALdfLdf(node); + } + @Override + public void caseAEpsilonLdf(AEpsilonLdf node) + { + inAEpsilonLdf(node); + returnValue = null; + outAEpsilonLdf(node); + } + + + @Override + public void caseADfDf(ADfDf node) + { + inADfDf(node); + String foncName = null; + SaLDec param = null; + SaInstBloc bloc = null; + SaLDec variablesLocales = null; + if(node.getIdentif() != null) + { + foncName = node.getIdentif().getText(); + } + if(node.getLparam() != null) + { + node.getLparam().apply(this); + param = (SaLDec) returnValue; + } + if(node.getLdvo() != null) + { + node.getLdvo().apply(this); + variablesLocales = (SaLDec) returnValue; + } + if(node.getIb() != null) + { + node.getIb().apply(this); + bloc = (SaInstBloc) returnValue; + } + returnValue = new SaDecFonc(foncName,param,variablesLocales, bloc); + outADfDf(node); + } + + @Override + public void caseAParamsLparam(AParamsLparam node) + { + inAParamsLparam(node); + SaLDec variable = null; + if(node.getLdv() != null) + { + node.getLdv().apply(this); + variable = (SaLDec) returnValue; + } + returnValue = variable; + + outAParamsLparam(node); + } + + @Override + public void caseAIblocIb(AIblocIb node) + { + inAIblocIb(node); + + SaLInst listInst = null; + + if(node.getLi() != null) + { + node.getLi().apply(this); + listInst = (SaLInst) returnValue; + } + returnValue = new SaInstBloc(listInst); + + outAIblocIb(node); + } + + @Override + public void caseAListeILi(AListeILi node) + { + inAListeILi(node); + SaInst tete = null; + SaLInst queue = null; + + if(node.getI() != null) + { + node.getI().apply(this); + tete = (SaInst) returnValue; + } + if(node.getLi() != null) + { + node.getLi().apply(this); + queue = (SaLInst) returnValue; + } + returnValue = new SaLInst(tete,queue); + outAListeILi(node); + } + + @Override + public void caseAEpsilonLi(AEpsilonLi node) + { + inAEpsilonLi(node); + returnValue = null; + outAEpsilonLi(node); + } + + + @Override + public void caseAIAffI(AIAffI node) + { + inAIAffI(node); + SaInst affect = null; + if(node.getIaffectation() != null) + { + node.getIaffectation().apply(this); + affect = (SaInst) returnValue; + } + returnValue = affect; + outAIAffI(node); + } + + @Override + public void caseAISiI(AISiI node) + { + inAISiI(node); + SaInst si = null; + if(node.getIsi() != null) + { + node.getIsi().apply(this); + si = (SaInst) returnValue; + } + returnValue = si; + outAISiI(node); + } + + + @Override + public void caseAITqI(AITqI node) + { + inAITqI(node); + SaInst tq = null; + if(node.getItantque() != null) + { + node.getItantque().apply(this); + tq = (SaInst) returnValue; + } + returnValue = tq; + outAITqI(node); + } + + @Override + public void caseAIRetI(AIRetI node) + { + inAIRetI(node); + SaInst ret = null; + if(node.getIret() != null) + { + node.getIret().apply(this); + ret = (SaInst) returnValue; + } + returnValue = ret; + outAIRetI(node); + } + + @Override + public void caseAIAppI(AIAppI node) + { + inAIAppI(node); + SaInst app = null; + if(node.getIappel() != null) + { + node.getIappel().apply(this); + app = (SaInst) returnValue; + } + returnValue = app; + outAIAppI(node); + } + + + @Override + public void caseAIEcrI(AIEcrI node) + { + inAIEcrI(node); + SaInst ecrire = null; + if(node.getIecrire() != null) + { + node.getIecrire().apply(this); + ecrire = (SaInst) returnValue; + } + returnValue = ecrire; + outAIEcrI(node); + } + + + @Override + public void caseAAffectationIaffectation(AAffectationIaffectation node) + { + inAAffectationIaffectation(node); + SaVar var = null; + SaExp result = null; + if(node.getV() != null) + { + node.getV().apply(this); + var = (SaVar) returnValue; + } + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + result = (SaExp) returnValue; + } + returnValue = new SaInstAffect(var,result); + + outAAffectationIaffectation(node); + } + + @Override + public void caseAIdV(AIdV node) + { + inAIdV(node); + String nomVariable = null; + if(node.getIdentif() != null) + { + nomVariable = node.getIdentif().getText(); + } + returnValue = new SaVarSimple(nomVariable); + outAIdV(node); + } + + + @Override + public void caseAIdtabV(AIdtabV node) + { + inAIdtabV(node); + String nomVar =null; + SaExp Indice = null; + if(node.getIdentif() != null) + { + nomVar = node.getIdentif().getText(); + + } + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + Indice = (SaExp) returnValue; + } + returnValue = new SaVarIndicee(nomVar,Indice); + + outAIdtabV(node); + } + + @Override + public void caseAT1Expression(AT1Expression node) + { + inAT1Expression(node); + if(node.getT1() != null) + { + node.getT1().apply(this); + } + outAT1Expression(node); + } + + + @Override + public void caseAOuExpression(AOuExpression node) + { + inAOuExpression(node); + SaExp op1 = null; + SaExp op2 = null; + if(node.getExpression() != null) + { + node.getExpression().apply(this); + op1 = (SaExp) returnValue; + } + + if(node.getT1() != null) + { + node.getT1().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpOr(op1,op2); + outAOuExpression(node); + } + + @Override + public void caseAT2T1(AT2T1 node) + { + inAT2T1(node); + if(node.getT2() != null) + { + node.getT2().apply(this); + } + outAT2T1(node); + } + + + @Override + public void caseAEtT1(AEtT1 node) + { + inAEtT1(node); + SaExp op1 = null; + SaExp op2 = null; + if(node.getT1() != null) + { + node.getT1().apply(this); + op1 = (SaExp) returnValue; + + } + + if(node.getT2() != null) + { + node.getT2().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpAnd(op1,op2); + outAEtT1(node); + } + + public void caseAT3T2(AT3T2 node) + { + inAT3T2(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + } + outAT3T2(node); + } + + @Override + public void caseAEgalT2(AEgalT2 node) + { + inAEgalT2(node); + SaExp op1 = null; + SaExp op2 = null; + if(node.getT2() != null) + { + node.getT2().apply(this); + op1 = (SaExp) returnValue; + } + + if(node.getT3() != null) + { + node.getT3().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpEqual(op1,op2); + outAEgalT2(node); + } + + + + @Override + public void caseAInferieurT2(AInferieurT2 node) + { + inAInferieurT2(node); + SaExp op1 = null; + SaExp op2 = null; + if(node.getT2() != null) + { + node.getT2().apply(this); + op1 = (SaExp) returnValue; + } + + if(node.getT3() != null) + { + node.getT3().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpInf(op1,op2); + outAInferieurT2(node); + } + + @Override + public void caseAT4T3(AT4T3 node) + { + inAT4T3(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + } + outAT4T3(node); + } + + + + + + + + @Override + public void caseAPlusT3(APlusT3 node) + { + SaExp op1 = null; + SaExp op2 = null; + inAPlusT3(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + op1 = (SaExp) returnValue; + } + + if(node.getT4() != null) + { + node.getT4().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpAdd(op1,op2); + outAPlusT3(node); + } + + @Override + public void caseAMoinsT3(AMoinsT3 node) + { + SaExp t3 = null; + SaExp t4 = null; + inAMoinsT3(node); + if(node.getT3() != null) + { + node.getT3().apply(this); + t3 = (SaExp) returnValue; + } + + if(node.getT4() != null) + { + node.getT4().apply(this); + t4 = (SaExp) returnValue; + } + returnValue = new SaExpSub(t3,t4); + outAMoinsT3(node); + } + + @Override + public void caseAT5T4(AT5T4 node) + { + inAT5T4(node); + if(node.getT5() != null) + { + node.getT5().apply(this); + } + outAT5T4(node); + } + + @Override + public void caseAMultiplicationT4(AMultiplicationT4 node) + { + SaExp op1 = null; + SaExp op2 = null; + inAMultiplicationT4(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + op1 = (SaExp) returnValue; + } + + if(node.getT5() != null) + { + node.getT5().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpMult(op1,op2); + outAMultiplicationT4(node); + } + + + @Override + public void caseADivisionT4(ADivisionT4 node) + { + SaExp op1 = null; + SaExp op2 = null; + inADivisionT4(node); + if(node.getT4() != null) + { + node.getT4().apply(this); + op1 = (SaExp) returnValue; + } + + if(node.getT5() != null) + { + node.getT5().apply(this); + op2 = (SaExp) returnValue; + } + returnValue = new SaExpDiv(op1,op2); + outADivisionT4(node); + } + + @Override + public void caseAT6T5(AT6T5 node) + { + inAT6T5(node); + if(node.getT6() != null) + { + node.getT6().apply(this); + } + outAT6T5(node); + } + + + @Override + public void caseANonT5(ANonT5 node) + { + SaExp t5 = null; + inANonT5(node); + + if(node.getT5() != null) + { + node.getT5().apply(this); + t5 = (SaExp) returnValue; + } + returnValue = new SaExpNot(t5); + outANonT5(node); + } + + @Override + public void caseAExpressionT6(AExpressionT6 node) + { + SaExp t6 = null; + inAExpressionT6(node); + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + t6 = (SaExp) returnValue; + } + returnValue = t6; + outAExpressionT6(node); + + } + + + @Override + public void caseAX1T6(AX1T6 node) + { + inAX1T6(node); + Integer nbr = null; + if(node.getNombre() != null) + { + nbr = Integer.parseInt(node.getNombre().getText()); + } + returnValue = new SaExpInt(nbr); + outAX1T6(node); + } + + @Override + public void caseAX2T6(AX2T6 node) + { + inAX2T6(node); + SaVar var = null; + if(node.getV() != null) + { + node.getV().apply(this); + var = (SaVar) returnValue; + } + returnValue = new SaExpVar(var); + outAX2T6(node); + } + + @Override + public void caseAAppT6(AAppT6 node) + { + inAAppT6(node); + SaAppel app = null; + + if(node.getAppel() != null) + { + node.getAppel().apply(this); + app = (SaAppel) returnValue; + } + returnValue = new SaExpAppel(app); + outAAppT6(node); + } + + + + + + + @Override + public void caseAAppel(AAppel node) + { + inAAppel(node); + String nomFonc = null; + SaLExp args = null; + + if(node.getIdentif() != null) + { + nomFonc = node.getIdentif().getText(); + } + + if(node.getLe() != null) + { + node.getLe().apply(this); + args = (SaLExp) returnValue; + } + returnValue = new SaAppel(nomFonc,args); + + outAAppel(node); + } + + @Override + public void caseAListeExpLe(AListeExpLe node) + { + inAListeExpLe(node); + SaExp exp = null; + SaLExp listExp = null; + if(node.getExpression() != null) + { + node.getExpression().apply(this); + exp = (SaExp) returnValue; + } + if(node.getLeb() != null) + { + node.getLeb().apply(this); + listExp = (SaLExp) returnValue; + } + returnValue = new SaLExp(exp,listExp); + outAListeExpLe(node); + } + + + @Override + public void caseAEpsilonLe(AEpsilonLe node) + { + inAEpsilonLe(node); + returnValue = null; + outAEpsilonLe(node); + } + + + @Override + public void caseAListeExpBLeb(AListeExpBLeb node) + { + inAListeExpBLeb(node); + SaExp exp = null; + SaLExp listExp = null; + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + exp = (SaExp) returnValue; + } + if(node.getLeb() != null) + { + node.getLeb().apply(this); + listExp = (SaLExp) returnValue; + } + returnValue = new SaLExp(exp,listExp); + outAListeExpBLeb(node); + } + + @Override + public void caseAEpsilonLeb(AEpsilonLeb node) + { + inAEpsilonLeb(node); + returnValue = null; + outAEpsilonLeb(node); + } + + @Override + public void caseASiIsi(ASiIsi node) + { + inASiIsi(node); + SaExp test = null; + SaInst alors = null; + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + test = (SaExp) returnValue; + + } + + if(node.getIb() != null) + { + node.getIb().apply(this); + alors = (SaInst) returnValue; + } + returnValue = new SaInstSi(test,alors,null); + outASiIsi(node); + } + + + @Override + public void caseASisinonIsi(ASisinonIsi node) + { + inASisinonIsi(node); + SaExp test = null; + SaInst alors = null; + SaInst sinon = null; + if(node.getExpression() != null) + { + node.getExpression().apply(this); + test = (SaExp) returnValue; + } + + if(node.getCas1() != null) + { + node.getCas1().apply(this); + alors = (SaInst) returnValue; + } + + if(node.getCas2() != null) + { + node.getCas2().apply(this); + sinon = (SaInst) returnValue; + } + returnValue = new SaInstSi(test,alors,sinon); + outASisinonIsi(node); + } + + + + + + + public void caseATantqueItantque(ATantqueItantque node) + { + SaExp test = null; + SaInst bloc = null; + inATantqueItantque(node); + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + test = (SaExp) returnValue; + } + if(node.getIb() != null) + { + node.getIb().apply(this); + bloc = (SaInst) returnValue; + } + returnValue = new SaInstTantQue(test, bloc); + outATantqueItantque(node); + } + + + @Override + public void caseARetournerIret(ARetournerIret node) + { + SaExp exp = null; + inARetournerIret(node); + + if(node.getExpression() != null) + { + node.getExpression().apply(this); + exp = (SaExp) returnValue; + } + returnValue = new SaInstRetour(exp); + outARetournerIret(node); + } + + @Override + public void caseAIappelIappel(AIappelIappel node) + { + SaAppel app = null; + inAIappelIappel(node); + if(node.getAppel() != null) + { + node.getAppel().apply(this); + app = (SaAppel) returnValue; + } + returnValue = app; + outAIappelIappel(node); + } + + @Override + public void caseAIecrireIecrire(AIecrireIecrire node) + { + SaExp arg = null; + if(node.getExpression() != null) + { + node.getExpression().apply(this); + arg = (SaExp) returnValue; + } + returnValue = new SaInstEcriture(arg); + outAIecrireIecrire(node); + } + + public SaNode getReturnValue() { + return returnValue; + } +} diff --git a/src/sc/lexer/IPushbackReader.java b/src/sc/lexer/IPushbackReader.java new file mode 100644 index 0000000000000000000000000000000000000000..050ba753bd4e0dd742d84eb17d9f39cf855bb5b0 --- /dev/null +++ b/src/sc/lexer/IPushbackReader.java @@ -0,0 +1,12 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.lexer; + +import java.io.*; + +@SuppressWarnings("serial") +public interface IPushbackReader +{ + public int read() throws IOException; + public void unread(int c) throws IOException; +} diff --git a/src/sc/lexer/Lexer.java b/src/sc/lexer/Lexer.java new file mode 100644 index 0000000000000000000000000000000000000000..203939fde46e119a5a4cf3255377f9e5bdeeb112 --- /dev/null +++ b/src/sc/lexer/Lexer.java @@ -0,0 +1,752 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.lexer; + +import java.io.*; +import sc.node.*; + +@SuppressWarnings("nls") +public class Lexer +{ + protected Token token; + protected State state = State.INITIAL; + + private IPushbackReader in; + private int line; + private int pos; + private boolean cr; + private boolean eof; + private final StringBuffer text = new StringBuffer(); + + @SuppressWarnings("unused") + protected void filter() throws LexerException, IOException + { + // Do nothing + } + + public Lexer(@SuppressWarnings("hiding") final PushbackReader in) + { + this.in = new IPushbackReader() { + + private PushbackReader pushbackReader = in; + + @Override + public void unread(int c) throws IOException { + pushbackReader.unread(c); + } + + @Override + public int read() throws IOException { + return pushbackReader.read(); + } + }; + } + + public Lexer(@SuppressWarnings("hiding") IPushbackReader in) + { + this.in = in; + } + + public Token peek() throws LexerException, IOException + { + while(this.token == null) + { + this.token = getToken(); + filter(); + } + + return this.token; + } + + public Token next() throws LexerException, IOException + { + while(this.token == null) + { + this.token = getToken(); + filter(); + } + + Token result = this.token; + this.token = null; + return result; + } + + protected Token getToken() throws IOException, LexerException + { + int dfa_state = 0; + + int start_pos = this.pos; + int start_line = this.line; + + int accept_state = -1; + int accept_token = -1; + int accept_length = -1; + int accept_pos = -1; + int accept_line = -1; + + @SuppressWarnings("hiding") int[][][] gotoTable = Lexer.gotoTable[this.state.id()]; + @SuppressWarnings("hiding") int[] accept = Lexer.accept[this.state.id()]; + this.text.setLength(0); + + while(true) + { + int c = getChar(); + + if(c != -1) + { + switch(c) + { + case 10: + if(this.cr) + { + this.cr = false; + } + else + { + this.line++; + this.pos = 0; + } + break; + case 13: + this.line++; + this.pos = 0; + this.cr = true; + break; + default: + this.pos++; + this.cr = false; + break; + } + + this.text.append((char) c); + + do + { + int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state; + + dfa_state = -1; + + int[][] tmp1 = gotoTable[oldState]; + int low = 0; + int high = tmp1.length - 1; + + while(low <= high) + { + // int middle = (low + high) / 2; + int middle = (low + high) >>> 1; + int[] tmp2 = tmp1[middle]; + + if(c < tmp2[0]) + { + high = middle - 1; + } + else if(c > tmp2[1]) + { + low = middle + 1; + } + else + { + dfa_state = tmp2[2]; + break; + } + } + }while(dfa_state < -1); + } + else + { + dfa_state = -1; + } + + if(dfa_state >= 0) + { + if(accept[dfa_state] != -1) + { + accept_state = dfa_state; + accept_token = accept[dfa_state]; + accept_length = this.text.length(); + accept_pos = this.pos; + accept_line = this.line; + } + } + else + { + if(accept_state != -1) + { + switch(accept_token) + { + case 0: + { + @SuppressWarnings("hiding") Token token = new0( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 1: + { + @SuppressWarnings("hiding") Token token = new1( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 2: + { + @SuppressWarnings("hiding") Token token = new2( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 3: + { + @SuppressWarnings("hiding") Token token = new3( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 4: + { + @SuppressWarnings("hiding") Token token = new4( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 5: + { + @SuppressWarnings("hiding") Token token = new5( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 6: + { + @SuppressWarnings("hiding") Token token = new6( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 7: + { + @SuppressWarnings("hiding") Token token = new7( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 8: + { + @SuppressWarnings("hiding") Token token = new8( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 9: + { + @SuppressWarnings("hiding") Token token = new9( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 10: + { + @SuppressWarnings("hiding") Token token = new10( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 11: + { + @SuppressWarnings("hiding") Token token = new11( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 12: + { + @SuppressWarnings("hiding") Token token = new12( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 13: + { + @SuppressWarnings("hiding") Token token = new13( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 14: + { + @SuppressWarnings("hiding") Token token = new14( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 15: + { + @SuppressWarnings("hiding") Token token = new15( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 16: + { + @SuppressWarnings("hiding") Token token = new16( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 17: + { + @SuppressWarnings("hiding") Token token = new17( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 18: + { + @SuppressWarnings("hiding") Token token = new18( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 19: + { + @SuppressWarnings("hiding") Token token = new19( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 20: + { + @SuppressWarnings("hiding") Token token = new20( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 21: + { + @SuppressWarnings("hiding") Token token = new21( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 22: + { + @SuppressWarnings("hiding") Token token = new22( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 23: + { + @SuppressWarnings("hiding") Token token = new23( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 24: + { + @SuppressWarnings("hiding") Token token = new24( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 25: + { + @SuppressWarnings("hiding") Token token = new25( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 26: + { + @SuppressWarnings("hiding") Token token = new26( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 27: + { + @SuppressWarnings("hiding") Token token = new27( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 28: + { + @SuppressWarnings("hiding") Token token = new28( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 29: + { + @SuppressWarnings("hiding") Token token = new29( + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + case 30: + { + @SuppressWarnings("hiding") Token token = new30( + getText(accept_length), + start_line + 1, + start_pos + 1); + pushBack(accept_length); + this.pos = accept_pos; + this.line = accept_line; + return token; + } + } + } + else + { + if(this.text.length() > 0) + { + throw new LexerException( + new InvalidToken(this.text.substring(0, 1), start_line + 1, start_pos + 1), + "[" + (start_line + 1) + "," + (start_pos + 1) + "]" + + " Unknown token: " + this.text); + } + + @SuppressWarnings("hiding") EOF token = new EOF( + start_line + 1, + start_pos + 1); + return token; + } + } + } + } + + Token new0(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEspaces(text, line, pos); } + Token new1(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TCommentaire(text, line, pos); } + Token new2(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TParentheseFermante(line, pos); } + Token new3(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAccoladeOuvrante(line, pos); } + Token new4(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAccoladeFermante(line, pos); } + Token new5(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TCrochetOuvrant(line, pos); } + Token new6(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TCrochetFermant(line, pos); } + Token new7(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TVirgule(line, pos); } + Token new8(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TPVirgule(line, pos); } + Token new9(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNombre(text, line, pos); } + Token new10(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEntier(line, pos); } + Token new11(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TParentheseOuvrante(line, pos); } + Token new12(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TOu(line, pos); } + Token new13(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEt(line, pos); } + Token new14(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TPlus(line, pos); } + Token new15(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMoins(line, pos); } + Token new16(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TDivision(line, pos); } + Token new17(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TMultiplication(line, pos); } + Token new18(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEgal(line, pos); } + Token new19(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TInferieur(line, pos); } + Token new20(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TNon(line, pos); } + Token new21(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TSi(line, pos); } + Token new22(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TAlors(line, pos); } + Token new23(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TSinon(line, pos); } + Token new24(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTantque(line, pos); } + Token new25(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TFaire(line, pos); } + Token new26(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TRetour(line, pos); } + Token new27(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEcrire(line, pos); } + Token new28(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLire(line, pos); } + Token new29(@SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TEpsilon(line, pos); } + Token new30(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TIdentif(text, line, pos); } + + private int getChar() throws IOException + { + if(this.eof) + { + return -1; + } + + int result = this.in.read(); + + if(result == -1) + { + this.eof = true; + } + + return result; + } + + private void pushBack(int acceptLength) throws IOException + { + int length = this.text.length(); + for(int i = length - 1; i >= acceptLength; i--) + { + this.eof = false; + + this.in.unread(this.text.charAt(i)); + } + } + + protected void unread(@SuppressWarnings("hiding") Token token) throws IOException + { + @SuppressWarnings("hiding") String text = token.getText(); + int length = text.length(); + + for(int i = length - 1; i >= 0; i--) + { + this.eof = false; + + this.in.unread(text.charAt(i)); + } + + this.pos = token.getPos() - 1; + this.line = token.getLine() - 1; + } + + private String getText(int acceptLength) + { + StringBuffer s = new StringBuffer(acceptLength); + for(int i = 0; i < acceptLength; i++) + { + s.append(this.text.charAt(i)); + } + + return s.toString(); + } + + private static int[][][][] gotoTable; +/* { + { // INITIAL + {{10, 10, 1}, {13, 13, 2}, {32, 32, 3}, {33, 33, 4}, {35, 35, 5}, {38, 38, 6}, {40, 40, 7}, {41, 41, 8}, {42, 42, 9}, {43, 43, 10}, {44, 44, 11}, {45, 45, 12}, {47, 47, 13}, {48, 57, 14}, {59, 59, 15}, {60, 60, 16}, {61, 61, 17}, {65, 90, 18}, {91, 91, 19}, {93, 93, 20}, {97, 97, 21}, {98, 100, 18}, {101, 101, 22}, {102, 102, 23}, {103, 107, 18}, {108, 108, 24}, {109, 113, 18}, {114, 114, 25}, {115, 115, 26}, {116, 116, 27}, {117, 122, 18}, {123, 123, 28}, {124, 124, 29}, {125, 125, 30}, }, + {{10, 13, -2}, {32, 32, 31}, }, + {{10, 32, -3}, }, + {{10, 32, -3}, }, + {}, + {{0, 9, 32}, {10, 10, 33}, {11, 12, 32}, {13, 13, 34}, {14, 65535, 32}, }, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {{48, 57, 14}, }, + {}, + {}, + {}, + {{48, 57, 35}, {65, 90, 36}, {97, 122, 36}, }, + {}, + {}, + {{48, 90, -20}, {97, 107, 36}, {108, 108, 37}, {109, 122, 36}, }, + {{48, 90, -20}, {97, 98, 36}, {99, 99, 38}, {100, 109, 36}, {110, 110, 39}, {111, 122, 36}, }, + {{48, 90, -20}, {97, 97, 40}, {98, 122, 36}, }, + {{48, 90, -20}, {97, 104, 36}, {105, 105, 41}, {106, 122, 36}, }, + {{48, 90, -20}, {97, 100, 36}, {101, 101, 42}, {102, 122, 36}, }, + {{48, 104, -26}, {105, 105, 43}, {106, 122, 36}, }, + {{48, 90, -20}, {97, 97, 44}, {98, 122, 36}, }, + {}, + {}, + {}, + {{10, 32, -3}, }, + {{0, 65535, -7}, }, + {{13, 13, 45}, }, + {}, + {{48, 122, -20}, }, + {{48, 122, -20}, }, + {{48, 90, -20}, {97, 110, 36}, {111, 111, 46}, {112, 122, 36}, }, + {{48, 90, -20}, {97, 113, 36}, {114, 114, 47}, {115, 122, 36}, }, + {{48, 90, -20}, {97, 115, 36}, {116, 116, 48}, {117, 122, 36}, }, + {{48, 104, -26}, {105, 105, 49}, {106, 122, 36}, }, + {{48, 113, -40}, {114, 114, 50}, {115, 122, 36}, }, + {{48, 115, -41}, {116, 116, 51}, {117, 122, 36}, }, + {{48, 90, -20}, {97, 109, 36}, {110, 110, 52}, {111, 122, 36}, }, + {{48, 109, -45}, {110, 110, 53}, {111, 122, 36}, }, + {}, + {{48, 113, -40}, {114, 114, 54}, {115, 122, 36}, }, + {{48, 104, -26}, {105, 105, 55}, {106, 122, 36}, }, + {{48, 104, -26}, {105, 105, 56}, {106, 122, 36}, }, + {{48, 113, -40}, {114, 114, 57}, {115, 122, 36}, }, + {{48, 100, -27}, {101, 101, 58}, {102, 122, 36}, }, + {{48, 110, -39}, {111, 111, 59}, {112, 122, 36}, }, + {{48, 110, -39}, {111, 111, 60}, {112, 122, 36}, }, + {{48, 115, -41}, {116, 116, 61}, {117, 122, 36}, }, + {{48, 90, -20}, {97, 114, 36}, {115, 115, 62}, {116, 122, 36}, }, + {{48, 113, -40}, {114, 114, 63}, {115, 122, 36}, }, + {{48, 100, -27}, {101, 101, 64}, {102, 122, 36}, }, + {{48, 100, -27}, {101, 101, 65}, {102, 122, 36}, }, + {{48, 122, -20}, }, + {{48, 90, -20}, {97, 116, 36}, {117, 117, 66}, {118, 122, 36}, }, + {{48, 109, -45}, {110, 110, 67}, {111, 122, 36}, }, + {{48, 90, -20}, {97, 112, 36}, {113, 113, 68}, {114, 122, 36}, }, + {{48, 122, -20}, }, + {{48, 100, -27}, {101, 101, 69}, {102, 122, 36}, }, + {{48, 113, -40}, {114, 114, 70}, {115, 122, 36}, }, + {{48, 122, -20}, }, + {{48, 113, -40}, {114, 114, 71}, {115, 122, 36}, }, + {{48, 122, -20}, }, + {{48, 116, -61}, {117, 117, 72}, {118, 122, 36}, }, + {{48, 122, -20}, }, + {{48, 122, -20}, }, + {{48, 122, -20}, }, + {{48, 100, -27}, {101, 101, 73}, {102, 122, 36}, }, + {{48, 122, -20}, }, + } + };*/ + + private static int[][] accept; +/* { + // INITIAL + {-1, 0, 0, 0, 20, -1, 13, 11, 2, 17, 14, 7, 15, 16, 9, 8, 19, 18, 30, 5, 6, 30, 30, 30, 30, 30, 30, 30, 3, 12, 4, 0, -1, 1, 1, 30, 30, 30, 30, 30, 30, 30, 30, 21, 30, 1, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 28, 30, 30, 30, 22, 30, 30, 25, 30, 23, 30, 27, 10, 26, 30, 24, }, + + };*/ + + public static class State + { + public final static State INITIAL = new State(0); + + private int id; + + private State(@SuppressWarnings("hiding") int id) + { + this.id = id; + } + + public int id() + { + return this.id; + } + } + + static + { + try + { + DataInputStream s = new DataInputStream( + new BufferedInputStream( + Lexer.class.getResourceAsStream("lexer.dat"))); + + // read gotoTable + int length = s.readInt(); + gotoTable = new int[length][][][]; + for(int i = 0; i < gotoTable.length; i++) + { + length = s.readInt(); + gotoTable[i] = new int[length][][]; + for(int j = 0; j < gotoTable[i].length; j++) + { + length = s.readInt(); + gotoTable[i][j] = new int[length][3]; + for(int k = 0; k < gotoTable[i][j].length; k++) + { + for(int l = 0; l < 3; l++) + { + gotoTable[i][j][k][l] = s.readInt(); + } + } + } + } + + // read accept + length = s.readInt(); + accept = new int[length][]; + for(int i = 0; i < accept.length; i++) + { + length = s.readInt(); + accept[i] = new int[length]; + for(int j = 0; j < accept[i].length; j++) + { + accept[i][j] = s.readInt(); + } + } + + s.close(); + } + catch(Exception e) + { + throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted."); + } + } +} diff --git a/src/sc/lexer/LexerException.java b/src/sc/lexer/LexerException.java new file mode 100644 index 0000000000000000000000000000000000000000..f9a70b65050282c067010f647476c1d452d0ac5b --- /dev/null +++ b/src/sc/lexer/LexerException.java @@ -0,0 +1,22 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.lexer; + +import sc.node.*; + +@SuppressWarnings("serial") +public class LexerException extends Exception +{ + private InvalidToken invalidToken; + + public LexerException(@SuppressWarnings("hiding") InvalidToken invalidToken, String message) + { + super(message); + this.invalidToken = invalidToken; + } + + public InvalidToken getToken() + { + return this.invalidToken; + } +} diff --git a/src/sc/lexer/lexer.dat b/src/sc/lexer/lexer.dat new file mode 100644 index 0000000000000000000000000000000000000000..b70d7b04255a5a7418125bb9806e96ff844c4b27 Binary files /dev/null and b/src/sc/lexer/lexer.dat differ diff --git a/src/sc/node/AAffectationIaffectation.java b/src/sc/node/AAffectationIaffectation.java new file mode 100644 index 0000000000000000000000000000000000000000..df75d02d43eb8ac63d03c9f0bdf659b03747663f --- /dev/null +++ b/src/sc/node/AAffectationIaffectation.java @@ -0,0 +1,224 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AAffectationIaffectation extends PIaffectation +{ + private PV _v_; + private TEgal _egal_; + private PExpression _expression_; + private TPVirgule _pVirgule_; + + public AAffectationIaffectation() + { + // Constructor + } + + public AAffectationIaffectation( + @SuppressWarnings("hiding") PV _v_, + @SuppressWarnings("hiding") TEgal _egal_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TPVirgule _pVirgule_) + { + // Constructor + setV(_v_); + + setEgal(_egal_); + + setExpression(_expression_); + + setPVirgule(_pVirgule_); + + } + + @Override + public Object clone() + { + return new AAffectationIaffectation( + cloneNode(this._v_), + cloneNode(this._egal_), + cloneNode(this._expression_), + cloneNode(this._pVirgule_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAAffectationIaffectation(this); + } + + public PV getV() + { + return this._v_; + } + + public void setV(PV node) + { + if(this._v_ != null) + { + this._v_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._v_ = node; + } + + public TEgal getEgal() + { + return this._egal_; + } + + public void setEgal(TEgal node) + { + if(this._egal_ != null) + { + this._egal_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._egal_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TPVirgule getPVirgule() + { + return this._pVirgule_; + } + + public void setPVirgule(TPVirgule node) + { + if(this._pVirgule_ != null) + { + this._pVirgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pVirgule_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._v_) + + toString(this._egal_) + + toString(this._expression_) + + toString(this._pVirgule_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._v_ == child) + { + this._v_ = null; + return; + } + + if(this._egal_ == child) + { + this._egal_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._pVirgule_ == child) + { + this._pVirgule_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._v_ == oldChild) + { + setV((PV) newChild); + return; + } + + if(this._egal_ == oldChild) + { + setEgal((TEgal) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._pVirgule_ == oldChild) + { + setPVirgule((TPVirgule) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AAppT6.java b/src/sc/node/AAppT6.java new file mode 100644 index 0000000000000000000000000000000000000000..906261a977b2cdfac6f247c9695b235c67cc3a8d --- /dev/null +++ b/src/sc/node/AAppT6.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AAppT6 extends PT6 +{ + private PAppel _appel_; + + public AAppT6() + { + // Constructor + } + + public AAppT6( + @SuppressWarnings("hiding") PAppel _appel_) + { + // Constructor + setAppel(_appel_); + + } + + @Override + public Object clone() + { + return new AAppT6( + cloneNode(this._appel_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAAppT6(this); + } + + public PAppel getAppel() + { + return this._appel_; + } + + public void setAppel(PAppel node) + { + if(this._appel_ != null) + { + this._appel_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._appel_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._appel_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._appel_ == child) + { + this._appel_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._appel_ == oldChild) + { + setAppel((PAppel) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AAppel.java b/src/sc/node/AAppel.java new file mode 100644 index 0000000000000000000000000000000000000000..43f30f134543bccd2fd8a59d98365e3a3d488a13 --- /dev/null +++ b/src/sc/node/AAppel.java @@ -0,0 +1,224 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AAppel extends PAppel +{ + private TIdentif _identif_; + private TParentheseOuvrante _parentheseOuvrante_; + private PLe _le_; + private TParentheseFermante _parentheseFermante_; + + public AAppel() + { + // Constructor + } + + public AAppel( + @SuppressWarnings("hiding") TIdentif _identif_, + @SuppressWarnings("hiding") TParentheseOuvrante _parentheseOuvrante_, + @SuppressWarnings("hiding") PLe _le_, + @SuppressWarnings("hiding") TParentheseFermante _parentheseFermante_) + { + // Constructor + setIdentif(_identif_); + + setParentheseOuvrante(_parentheseOuvrante_); + + setLe(_le_); + + setParentheseFermante(_parentheseFermante_); + + } + + @Override + public Object clone() + { + return new AAppel( + cloneNode(this._identif_), + cloneNode(this._parentheseOuvrante_), + cloneNode(this._le_), + cloneNode(this._parentheseFermante_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAAppel(this); + } + + public TIdentif getIdentif() + { + return this._identif_; + } + + public void setIdentif(TIdentif node) + { + if(this._identif_ != null) + { + this._identif_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._identif_ = node; + } + + public TParentheseOuvrante getParentheseOuvrante() + { + return this._parentheseOuvrante_; + } + + public void setParentheseOuvrante(TParentheseOuvrante node) + { + if(this._parentheseOuvrante_ != null) + { + this._parentheseOuvrante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseOuvrante_ = node; + } + + public PLe getLe() + { + return this._le_; + } + + public void setLe(PLe node) + { + if(this._le_ != null) + { + this._le_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._le_ = node; + } + + public TParentheseFermante getParentheseFermante() + { + return this._parentheseFermante_; + } + + public void setParentheseFermante(TParentheseFermante node) + { + if(this._parentheseFermante_ != null) + { + this._parentheseFermante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseFermante_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._identif_) + + toString(this._parentheseOuvrante_) + + toString(this._le_) + + toString(this._parentheseFermante_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._identif_ == child) + { + this._identif_ = null; + return; + } + + if(this._parentheseOuvrante_ == child) + { + this._parentheseOuvrante_ = null; + return; + } + + if(this._le_ == child) + { + this._le_ = null; + return; + } + + if(this._parentheseFermante_ == child) + { + this._parentheseFermante_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._identif_ == oldChild) + { + setIdentif((TIdentif) newChild); + return; + } + + if(this._parentheseOuvrante_ == oldChild) + { + setParentheseOuvrante((TParentheseOuvrante) newChild); + return; + } + + if(this._le_ == oldChild) + { + setLe((PLe) newChild); + return; + } + + if(this._parentheseFermante_ == oldChild) + { + setParentheseFermante((TParentheseFermante) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ADecVar2Dv.java b/src/sc/node/ADecVar2Dv.java new file mode 100644 index 0000000000000000000000000000000000000000..d4a7edefaa7bae622c7187d6b4ce1dc3438f51f0 --- /dev/null +++ b/src/sc/node/ADecVar2Dv.java @@ -0,0 +1,267 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ADecVar2Dv extends PDv +{ + private TEntier _entier_; + private TIdentif _identif_; + private TCrochetOuvrant _crochetOuvrant_; + private TNombre _nombre_; + private TCrochetFermant _crochetFermant_; + + public ADecVar2Dv() + { + // Constructor + } + + public ADecVar2Dv( + @SuppressWarnings("hiding") TEntier _entier_, + @SuppressWarnings("hiding") TIdentif _identif_, + @SuppressWarnings("hiding") TCrochetOuvrant _crochetOuvrant_, + @SuppressWarnings("hiding") TNombre _nombre_, + @SuppressWarnings("hiding") TCrochetFermant _crochetFermant_) + { + // Constructor + setEntier(_entier_); + + setIdentif(_identif_); + + setCrochetOuvrant(_crochetOuvrant_); + + setNombre(_nombre_); + + setCrochetFermant(_crochetFermant_); + + } + + @Override + public Object clone() + { + return new ADecVar2Dv( + cloneNode(this._entier_), + cloneNode(this._identif_), + cloneNode(this._crochetOuvrant_), + cloneNode(this._nombre_), + cloneNode(this._crochetFermant_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseADecVar2Dv(this); + } + + public TEntier getEntier() + { + return this._entier_; + } + + public void setEntier(TEntier node) + { + if(this._entier_ != null) + { + this._entier_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._entier_ = node; + } + + public TIdentif getIdentif() + { + return this._identif_; + } + + public void setIdentif(TIdentif node) + { + if(this._identif_ != null) + { + this._identif_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._identif_ = node; + } + + public TCrochetOuvrant getCrochetOuvrant() + { + return this._crochetOuvrant_; + } + + public void setCrochetOuvrant(TCrochetOuvrant node) + { + if(this._crochetOuvrant_ != null) + { + this._crochetOuvrant_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._crochetOuvrant_ = node; + } + + public TNombre getNombre() + { + return this._nombre_; + } + + public void setNombre(TNombre node) + { + if(this._nombre_ != null) + { + this._nombre_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._nombre_ = node; + } + + public TCrochetFermant getCrochetFermant() + { + return this._crochetFermant_; + } + + public void setCrochetFermant(TCrochetFermant node) + { + if(this._crochetFermant_ != null) + { + this._crochetFermant_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._crochetFermant_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._entier_) + + toString(this._identif_) + + toString(this._crochetOuvrant_) + + toString(this._nombre_) + + toString(this._crochetFermant_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._entier_ == child) + { + this._entier_ = null; + return; + } + + if(this._identif_ == child) + { + this._identif_ = null; + return; + } + + if(this._crochetOuvrant_ == child) + { + this._crochetOuvrant_ = null; + return; + } + + if(this._nombre_ == child) + { + this._nombre_ = null; + return; + } + + if(this._crochetFermant_ == child) + { + this._crochetFermant_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._entier_ == oldChild) + { + setEntier((TEntier) newChild); + return; + } + + if(this._identif_ == oldChild) + { + setIdentif((TIdentif) newChild); + return; + } + + if(this._crochetOuvrant_ == oldChild) + { + setCrochetOuvrant((TCrochetOuvrant) newChild); + return; + } + + if(this._nombre_ == oldChild) + { + setNombre((TNombre) newChild); + return; + } + + if(this._crochetFermant_ == oldChild) + { + setCrochetFermant((TCrochetFermant) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ADecVarDv.java b/src/sc/node/ADecVarDv.java new file mode 100644 index 0000000000000000000000000000000000000000..2f9462a23bce28c16db27f4ddfccbf4f375a5ee5 --- /dev/null +++ b/src/sc/node/ADecVarDv.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ADecVarDv extends PDv +{ + private TEntier _entier_; + private TIdentif _identif_; + + public ADecVarDv() + { + // Constructor + } + + public ADecVarDv( + @SuppressWarnings("hiding") TEntier _entier_, + @SuppressWarnings("hiding") TIdentif _identif_) + { + // Constructor + setEntier(_entier_); + + setIdentif(_identif_); + + } + + @Override + public Object clone() + { + return new ADecVarDv( + cloneNode(this._entier_), + cloneNode(this._identif_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseADecVarDv(this); + } + + public TEntier getEntier() + { + return this._entier_; + } + + public void setEntier(TEntier node) + { + if(this._entier_ != null) + { + this._entier_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._entier_ = node; + } + + public TIdentif getIdentif() + { + return this._identif_; + } + + public void setIdentif(TIdentif node) + { + if(this._identif_ != null) + { + this._identif_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._identif_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._entier_) + + toString(this._identif_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._entier_ == child) + { + this._entier_ = null; + return; + } + + if(this._identif_ == child) + { + this._identif_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._entier_ == oldChild) + { + setEntier((TEntier) newChild); + return; + } + + if(this._identif_ == oldChild) + { + setIdentif((TIdentif) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ADfDf.java b/src/sc/node/ADfDf.java new file mode 100644 index 0000000000000000000000000000000000000000..a38a3688059f7f39cf1b9141d1fbd65d71cc9db8 --- /dev/null +++ b/src/sc/node/ADfDf.java @@ -0,0 +1,224 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ADfDf extends PDf +{ + private TIdentif _identif_; + private PLparam _lparam_; + private PLdvo _ldvo_; + private PIb _ib_; + + public ADfDf() + { + // Constructor + } + + public ADfDf( + @SuppressWarnings("hiding") TIdentif _identif_, + @SuppressWarnings("hiding") PLparam _lparam_, + @SuppressWarnings("hiding") PLdvo _ldvo_, + @SuppressWarnings("hiding") PIb _ib_) + { + // Constructor + setIdentif(_identif_); + + setLparam(_lparam_); + + setLdvo(_ldvo_); + + setIb(_ib_); + + } + + @Override + public Object clone() + { + return new ADfDf( + cloneNode(this._identif_), + cloneNode(this._lparam_), + cloneNode(this._ldvo_), + cloneNode(this._ib_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseADfDf(this); + } + + public TIdentif getIdentif() + { + return this._identif_; + } + + public void setIdentif(TIdentif node) + { + if(this._identif_ != null) + { + this._identif_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._identif_ = node; + } + + public PLparam getLparam() + { + return this._lparam_; + } + + public void setLparam(PLparam node) + { + if(this._lparam_ != null) + { + this._lparam_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._lparam_ = node; + } + + public PLdvo getLdvo() + { + return this._ldvo_; + } + + public void setLdvo(PLdvo node) + { + if(this._ldvo_ != null) + { + this._ldvo_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldvo_ = node; + } + + public PIb getIb() + { + return this._ib_; + } + + public void setIb(PIb node) + { + if(this._ib_ != null) + { + this._ib_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ib_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._identif_) + + toString(this._lparam_) + + toString(this._ldvo_) + + toString(this._ib_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._identif_ == child) + { + this._identif_ = null; + return; + } + + if(this._lparam_ == child) + { + this._lparam_ = null; + return; + } + + if(this._ldvo_ == child) + { + this._ldvo_ = null; + return; + } + + if(this._ib_ == child) + { + this._ib_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._identif_ == oldChild) + { + setIdentif((TIdentif) newChild); + return; + } + + if(this._lparam_ == oldChild) + { + setLparam((PLparam) newChild); + return; + } + + if(this._ldvo_ == oldChild) + { + setLdvo((PLdvo) newChild); + return; + } + + if(this._ib_ == oldChild) + { + setIb((PIb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ADivisionT4.java b/src/sc/node/ADivisionT4.java new file mode 100644 index 0000000000000000000000000000000000000000..4f022397d4ed05fa99182fffb7c2febb633312c9 --- /dev/null +++ b/src/sc/node/ADivisionT4.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ADivisionT4 extends PT4 +{ + private PT4 _t4_; + private TDivision _division_; + private PT5 _t5_; + + public ADivisionT4() + { + // Constructor + } + + public ADivisionT4( + @SuppressWarnings("hiding") PT4 _t4_, + @SuppressWarnings("hiding") TDivision _division_, + @SuppressWarnings("hiding") PT5 _t5_) + { + // Constructor + setT4(_t4_); + + setDivision(_division_); + + setT5(_t5_); + + } + + @Override + public Object clone() + { + return new ADivisionT4( + cloneNode(this._t4_), + cloneNode(this._division_), + cloneNode(this._t5_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseADivisionT4(this); + } + + public PT4 getT4() + { + return this._t4_; + } + + public void setT4(PT4 node) + { + if(this._t4_ != null) + { + this._t4_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t4_ = node; + } + + public TDivision getDivision() + { + return this._division_; + } + + public void setDivision(TDivision node) + { + if(this._division_ != null) + { + this._division_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._division_ = node; + } + + public PT5 getT5() + { + return this._t5_; + } + + public void setT5(PT5 node) + { + if(this._t5_ != null) + { + this._t5_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t5_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t4_) + + toString(this._division_) + + toString(this._t5_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t4_ == child) + { + this._t4_ = null; + return; + } + + if(this._division_ == child) + { + this._division_ = null; + return; + } + + if(this._t5_ == child) + { + this._t5_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t4_ == oldChild) + { + setT4((PT4) newChild); + return; + } + + if(this._division_ == oldChild) + { + setDivision((TDivision) newChild); + return; + } + + if(this._t5_ == oldChild) + { + setT5((PT5) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEgalT2.java b/src/sc/node/AEgalT2.java new file mode 100644 index 0000000000000000000000000000000000000000..c0f1373281f47808f891712ddb0c499d548b6e44 --- /dev/null +++ b/src/sc/node/AEgalT2.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEgalT2 extends PT2 +{ + private PT2 _t2_; + private TEgal _egal_; + private PT3 _t3_; + + public AEgalT2() + { + // Constructor + } + + public AEgalT2( + @SuppressWarnings("hiding") PT2 _t2_, + @SuppressWarnings("hiding") TEgal _egal_, + @SuppressWarnings("hiding") PT3 _t3_) + { + // Constructor + setT2(_t2_); + + setEgal(_egal_); + + setT3(_t3_); + + } + + @Override + public Object clone() + { + return new AEgalT2( + cloneNode(this._t2_), + cloneNode(this._egal_), + cloneNode(this._t3_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEgalT2(this); + } + + public PT2 getT2() + { + return this._t2_; + } + + public void setT2(PT2 node) + { + if(this._t2_ != null) + { + this._t2_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t2_ = node; + } + + public TEgal getEgal() + { + return this._egal_; + } + + public void setEgal(TEgal node) + { + if(this._egal_ != null) + { + this._egal_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._egal_ = node; + } + + public PT3 getT3() + { + return this._t3_; + } + + public void setT3(PT3 node) + { + if(this._t3_ != null) + { + this._t3_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t3_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t2_) + + toString(this._egal_) + + toString(this._t3_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t2_ == child) + { + this._t2_ = null; + return; + } + + if(this._egal_ == child) + { + this._egal_ = null; + return; + } + + if(this._t3_ == child) + { + this._t3_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t2_ == oldChild) + { + setT2((PT2) newChild); + return; + } + + if(this._egal_ == oldChild) + { + setEgal((TEgal) newChild); + return; + } + + if(this._t3_ == oldChild) + { + setT3((PT3) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLdf.java b/src/sc/node/AEpsilonLdf.java new file mode 100644 index 0000000000000000000000000000000000000000..2841dbe9af5536a730c45604189169e2763e6a47 --- /dev/null +++ b/src/sc/node/AEpsilonLdf.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLdf extends PLdf +{ + + public AEpsilonLdf() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLdf(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLdf(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLdv.java b/src/sc/node/AEpsilonLdv.java new file mode 100644 index 0000000000000000000000000000000000000000..2379bf6633bfd5a7a071568c9555909c9e3fda74 --- /dev/null +++ b/src/sc/node/AEpsilonLdv.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLdv extends PLdv +{ + + public AEpsilonLdv() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLdv(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLdv(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLdvb.java b/src/sc/node/AEpsilonLdvb.java new file mode 100644 index 0000000000000000000000000000000000000000..204a3d32289fcceaea4b6e237d076af9b9daad1e --- /dev/null +++ b/src/sc/node/AEpsilonLdvb.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLdvb extends PLdvb +{ + + public AEpsilonLdvb() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLdvb(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLdvb(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLdvo.java b/src/sc/node/AEpsilonLdvo.java new file mode 100644 index 0000000000000000000000000000000000000000..7a071ae8fa16f42aa4119c0c7717b88965b9aeb8 --- /dev/null +++ b/src/sc/node/AEpsilonLdvo.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLdvo extends PLdvo +{ + + public AEpsilonLdvo() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLdvo(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLdvo(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLe.java b/src/sc/node/AEpsilonLe.java new file mode 100644 index 0000000000000000000000000000000000000000..f3430a47f638a716bc85b1053303475fb4958e24 --- /dev/null +++ b/src/sc/node/AEpsilonLe.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLe extends PLe +{ + + public AEpsilonLe() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLe(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLe(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLeb.java b/src/sc/node/AEpsilonLeb.java new file mode 100644 index 0000000000000000000000000000000000000000..5869e2a4a52c358ed0161e0cae77e2f8793d0b9d --- /dev/null +++ b/src/sc/node/AEpsilonLeb.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLeb extends PLeb +{ + + public AEpsilonLeb() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLeb(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLeb(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEpsilonLi.java b/src/sc/node/AEpsilonLi.java new file mode 100644 index 0000000000000000000000000000000000000000..60d909c15260179cb3ab0e107c14aeac56ad7a1b --- /dev/null +++ b/src/sc/node/AEpsilonLi.java @@ -0,0 +1,47 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEpsilonLi extends PLi +{ + + public AEpsilonLi() + { + // Constructor + } + + @Override + public Object clone() + { + return new AEpsilonLi(); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEpsilonLi(this); + } + + @Override + public String toString() + { + return ""; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AEtT1.java b/src/sc/node/AEtT1.java new file mode 100644 index 0000000000000000000000000000000000000000..13c6c075c9a2e158ebb80abb7953b40416ea41bd --- /dev/null +++ b/src/sc/node/AEtT1.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AEtT1 extends PT1 +{ + private PT1 _t1_; + private TEt _et_; + private PT2 _t2_; + + public AEtT1() + { + // Constructor + } + + public AEtT1( + @SuppressWarnings("hiding") PT1 _t1_, + @SuppressWarnings("hiding") TEt _et_, + @SuppressWarnings("hiding") PT2 _t2_) + { + // Constructor + setT1(_t1_); + + setEt(_et_); + + setT2(_t2_); + + } + + @Override + public Object clone() + { + return new AEtT1( + cloneNode(this._t1_), + cloneNode(this._et_), + cloneNode(this._t2_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEtT1(this); + } + + public PT1 getT1() + { + return this._t1_; + } + + public void setT1(PT1 node) + { + if(this._t1_ != null) + { + this._t1_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t1_ = node; + } + + public TEt getEt() + { + return this._et_; + } + + public void setEt(TEt node) + { + if(this._et_ != null) + { + this._et_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._et_ = node; + } + + public PT2 getT2() + { + return this._t2_; + } + + public void setT2(PT2 node) + { + if(this._t2_ != null) + { + this._t2_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t2_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t1_) + + toString(this._et_) + + toString(this._t2_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t1_ == child) + { + this._t1_ = null; + return; + } + + if(this._et_ == child) + { + this._et_ = null; + return; + } + + if(this._t2_ == child) + { + this._t2_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t1_ == oldChild) + { + setT1((PT1) newChild); + return; + } + + if(this._et_ == oldChild) + { + setEt((TEt) newChild); + return; + } + + if(this._t2_ == oldChild) + { + setT2((PT2) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AExpressionT6.java b/src/sc/node/AExpressionT6.java new file mode 100644 index 0000000000000000000000000000000000000000..d4829d22eaa8919f3bea06af64b5b15d3a4c17c1 --- /dev/null +++ b/src/sc/node/AExpressionT6.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AExpressionT6 extends PT6 +{ + private TParentheseOuvrante _parentheseOuvrante_; + private PExpression _expression_; + private TParentheseFermante _parentheseFermante_; + + public AExpressionT6() + { + // Constructor + } + + public AExpressionT6( + @SuppressWarnings("hiding") TParentheseOuvrante _parentheseOuvrante_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TParentheseFermante _parentheseFermante_) + { + // Constructor + setParentheseOuvrante(_parentheseOuvrante_); + + setExpression(_expression_); + + setParentheseFermante(_parentheseFermante_); + + } + + @Override + public Object clone() + { + return new AExpressionT6( + cloneNode(this._parentheseOuvrante_), + cloneNode(this._expression_), + cloneNode(this._parentheseFermante_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAExpressionT6(this); + } + + public TParentheseOuvrante getParentheseOuvrante() + { + return this._parentheseOuvrante_; + } + + public void setParentheseOuvrante(TParentheseOuvrante node) + { + if(this._parentheseOuvrante_ != null) + { + this._parentheseOuvrante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseOuvrante_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TParentheseFermante getParentheseFermante() + { + return this._parentheseFermante_; + } + + public void setParentheseFermante(TParentheseFermante node) + { + if(this._parentheseFermante_ != null) + { + this._parentheseFermante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseFermante_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._parentheseOuvrante_) + + toString(this._expression_) + + toString(this._parentheseFermante_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._parentheseOuvrante_ == child) + { + this._parentheseOuvrante_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._parentheseFermante_ == child) + { + this._parentheseFermante_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._parentheseOuvrante_ == oldChild) + { + setParentheseOuvrante((TParentheseOuvrante) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._parentheseFermante_ == oldChild) + { + setParentheseFermante((TParentheseFermante) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIAffI.java b/src/sc/node/AIAffI.java new file mode 100644 index 0000000000000000000000000000000000000000..c51a7dadd3820e3c0a282b39d7725c16eba3c46a --- /dev/null +++ b/src/sc/node/AIAffI.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIAffI extends PI +{ + private PIaffectation _iaffectation_; + + public AIAffI() + { + // Constructor + } + + public AIAffI( + @SuppressWarnings("hiding") PIaffectation _iaffectation_) + { + // Constructor + setIaffectation(_iaffectation_); + + } + + @Override + public Object clone() + { + return new AIAffI( + cloneNode(this._iaffectation_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIAffI(this); + } + + public PIaffectation getIaffectation() + { + return this._iaffectation_; + } + + public void setIaffectation(PIaffectation node) + { + if(this._iaffectation_ != null) + { + this._iaffectation_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._iaffectation_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._iaffectation_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._iaffectation_ == child) + { + this._iaffectation_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._iaffectation_ == oldChild) + { + setIaffectation((PIaffectation) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIAppI.java b/src/sc/node/AIAppI.java new file mode 100644 index 0000000000000000000000000000000000000000..874b65a9ba5e8b4d9257cd60d206b4793920923c --- /dev/null +++ b/src/sc/node/AIAppI.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIAppI extends PI +{ + private PIappel _iappel_; + + public AIAppI() + { + // Constructor + } + + public AIAppI( + @SuppressWarnings("hiding") PIappel _iappel_) + { + // Constructor + setIappel(_iappel_); + + } + + @Override + public Object clone() + { + return new AIAppI( + cloneNode(this._iappel_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIAppI(this); + } + + public PIappel getIappel() + { + return this._iappel_; + } + + public void setIappel(PIappel node) + { + if(this._iappel_ != null) + { + this._iappel_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._iappel_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._iappel_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._iappel_ == child) + { + this._iappel_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._iappel_ == oldChild) + { + setIappel((PIappel) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIEcrI.java b/src/sc/node/AIEcrI.java new file mode 100644 index 0000000000000000000000000000000000000000..5f4b026f08c1ce3c8df3364fbe81eb3f031f77c5 --- /dev/null +++ b/src/sc/node/AIEcrI.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIEcrI extends PI +{ + private PIecrire _iecrire_; + + public AIEcrI() + { + // Constructor + } + + public AIEcrI( + @SuppressWarnings("hiding") PIecrire _iecrire_) + { + // Constructor + setIecrire(_iecrire_); + + } + + @Override + public Object clone() + { + return new AIEcrI( + cloneNode(this._iecrire_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIEcrI(this); + } + + public PIecrire getIecrire() + { + return this._iecrire_; + } + + public void setIecrire(PIecrire node) + { + if(this._iecrire_ != null) + { + this._iecrire_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._iecrire_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._iecrire_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._iecrire_ == child) + { + this._iecrire_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._iecrire_ == oldChild) + { + setIecrire((PIecrire) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIRetI.java b/src/sc/node/AIRetI.java new file mode 100644 index 0000000000000000000000000000000000000000..d4fd4a32d8e4f8ae98b3480bb183467867e5ad2d --- /dev/null +++ b/src/sc/node/AIRetI.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIRetI extends PI +{ + private PIret _iret_; + + public AIRetI() + { + // Constructor + } + + public AIRetI( + @SuppressWarnings("hiding") PIret _iret_) + { + // Constructor + setIret(_iret_); + + } + + @Override + public Object clone() + { + return new AIRetI( + cloneNode(this._iret_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIRetI(this); + } + + public PIret getIret() + { + return this._iret_; + } + + public void setIret(PIret node) + { + if(this._iret_ != null) + { + this._iret_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._iret_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._iret_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._iret_ == child) + { + this._iret_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._iret_ == oldChild) + { + setIret((PIret) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AISiI.java b/src/sc/node/AISiI.java new file mode 100644 index 0000000000000000000000000000000000000000..7a10ab093082de3d2c17a513be10bd3fbca91326 --- /dev/null +++ b/src/sc/node/AISiI.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AISiI extends PI +{ + private PIsi _isi_; + + public AISiI() + { + // Constructor + } + + public AISiI( + @SuppressWarnings("hiding") PIsi _isi_) + { + // Constructor + setIsi(_isi_); + + } + + @Override + public Object clone() + { + return new AISiI( + cloneNode(this._isi_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAISiI(this); + } + + public PIsi getIsi() + { + return this._isi_; + } + + public void setIsi(PIsi node) + { + if(this._isi_ != null) + { + this._isi_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._isi_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._isi_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._isi_ == child) + { + this._isi_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._isi_ == oldChild) + { + setIsi((PIsi) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AITqI.java b/src/sc/node/AITqI.java new file mode 100644 index 0000000000000000000000000000000000000000..c11c7546168ce4e6f46b7891b3fe6e76b8aa90ae --- /dev/null +++ b/src/sc/node/AITqI.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AITqI extends PI +{ + private PItantque _itantque_; + + public AITqI() + { + // Constructor + } + + public AITqI( + @SuppressWarnings("hiding") PItantque _itantque_) + { + // Constructor + setItantque(_itantque_); + + } + + @Override + public Object clone() + { + return new AITqI( + cloneNode(this._itantque_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAITqI(this); + } + + public PItantque getItantque() + { + return this._itantque_; + } + + public void setItantque(PItantque node) + { + if(this._itantque_ != null) + { + this._itantque_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._itantque_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._itantque_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._itantque_ == child) + { + this._itantque_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._itantque_ == oldChild) + { + setItantque((PItantque) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIappelIappel.java b/src/sc/node/AIappelIappel.java new file mode 100644 index 0000000000000000000000000000000000000000..8f921359dd8978a2002f4542f9381b19f00e7656 --- /dev/null +++ b/src/sc/node/AIappelIappel.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIappelIappel extends PIappel +{ + private PAppel _appel_; + private TPVirgule _pVirgule_; + + public AIappelIappel() + { + // Constructor + } + + public AIappelIappel( + @SuppressWarnings("hiding") PAppel _appel_, + @SuppressWarnings("hiding") TPVirgule _pVirgule_) + { + // Constructor + setAppel(_appel_); + + setPVirgule(_pVirgule_); + + } + + @Override + public Object clone() + { + return new AIappelIappel( + cloneNode(this._appel_), + cloneNode(this._pVirgule_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIappelIappel(this); + } + + public PAppel getAppel() + { + return this._appel_; + } + + public void setAppel(PAppel node) + { + if(this._appel_ != null) + { + this._appel_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._appel_ = node; + } + + public TPVirgule getPVirgule() + { + return this._pVirgule_; + } + + public void setPVirgule(TPVirgule node) + { + if(this._pVirgule_ != null) + { + this._pVirgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pVirgule_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._appel_) + + toString(this._pVirgule_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._appel_ == child) + { + this._appel_ = null; + return; + } + + if(this._pVirgule_ == child) + { + this._pVirgule_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._appel_ == oldChild) + { + setAppel((PAppel) newChild); + return; + } + + if(this._pVirgule_ == oldChild) + { + setPVirgule((TPVirgule) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIblocIb.java b/src/sc/node/AIblocIb.java new file mode 100644 index 0000000000000000000000000000000000000000..e4bd0b759ac0f8ebde645f491ae1a522115c4668 --- /dev/null +++ b/src/sc/node/AIblocIb.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIblocIb extends PIb +{ + private TAccoladeOuvrante _accoladeOuvrante_; + private PLi _li_; + private TAccoladeFermante _accoladeFermante_; + + public AIblocIb() + { + // Constructor + } + + public AIblocIb( + @SuppressWarnings("hiding") TAccoladeOuvrante _accoladeOuvrante_, + @SuppressWarnings("hiding") PLi _li_, + @SuppressWarnings("hiding") TAccoladeFermante _accoladeFermante_) + { + // Constructor + setAccoladeOuvrante(_accoladeOuvrante_); + + setLi(_li_); + + setAccoladeFermante(_accoladeFermante_); + + } + + @Override + public Object clone() + { + return new AIblocIb( + cloneNode(this._accoladeOuvrante_), + cloneNode(this._li_), + cloneNode(this._accoladeFermante_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIblocIb(this); + } + + public TAccoladeOuvrante getAccoladeOuvrante() + { + return this._accoladeOuvrante_; + } + + public void setAccoladeOuvrante(TAccoladeOuvrante node) + { + if(this._accoladeOuvrante_ != null) + { + this._accoladeOuvrante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._accoladeOuvrante_ = node; + } + + public PLi getLi() + { + return this._li_; + } + + public void setLi(PLi node) + { + if(this._li_ != null) + { + this._li_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._li_ = node; + } + + public TAccoladeFermante getAccoladeFermante() + { + return this._accoladeFermante_; + } + + public void setAccoladeFermante(TAccoladeFermante node) + { + if(this._accoladeFermante_ != null) + { + this._accoladeFermante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._accoladeFermante_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._accoladeOuvrante_) + + toString(this._li_) + + toString(this._accoladeFermante_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._accoladeOuvrante_ == child) + { + this._accoladeOuvrante_ = null; + return; + } + + if(this._li_ == child) + { + this._li_ = null; + return; + } + + if(this._accoladeFermante_ == child) + { + this._accoladeFermante_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._accoladeOuvrante_ == oldChild) + { + setAccoladeOuvrante((TAccoladeOuvrante) newChild); + return; + } + + if(this._li_ == oldChild) + { + setLi((PLi) newChild); + return; + } + + if(this._accoladeFermante_ == oldChild) + { + setAccoladeFermante((TAccoladeFermante) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIdV.java b/src/sc/node/AIdV.java new file mode 100644 index 0000000000000000000000000000000000000000..7b4cb0ca285aa20a0aa8789cfb0e69b87d9d83bf --- /dev/null +++ b/src/sc/node/AIdV.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIdV extends PV +{ + private TIdentif _identif_; + + public AIdV() + { + // Constructor + } + + public AIdV( + @SuppressWarnings("hiding") TIdentif _identif_) + { + // Constructor + setIdentif(_identif_); + + } + + @Override + public Object clone() + { + return new AIdV( + cloneNode(this._identif_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIdV(this); + } + + public TIdentif getIdentif() + { + return this._identif_; + } + + public void setIdentif(TIdentif node) + { + if(this._identif_ != null) + { + this._identif_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._identif_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._identif_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._identif_ == child) + { + this._identif_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._identif_ == oldChild) + { + setIdentif((TIdentif) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIdtabV.java b/src/sc/node/AIdtabV.java new file mode 100644 index 0000000000000000000000000000000000000000..7ac6382a33ad3a70c68f42e69bffe0a68de94525 --- /dev/null +++ b/src/sc/node/AIdtabV.java @@ -0,0 +1,224 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIdtabV extends PV +{ + private TIdentif _identif_; + private TCrochetOuvrant _crochetOuvrant_; + private PExpression _expression_; + private TCrochetFermant _crochetFermant_; + + public AIdtabV() + { + // Constructor + } + + public AIdtabV( + @SuppressWarnings("hiding") TIdentif _identif_, + @SuppressWarnings("hiding") TCrochetOuvrant _crochetOuvrant_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TCrochetFermant _crochetFermant_) + { + // Constructor + setIdentif(_identif_); + + setCrochetOuvrant(_crochetOuvrant_); + + setExpression(_expression_); + + setCrochetFermant(_crochetFermant_); + + } + + @Override + public Object clone() + { + return new AIdtabV( + cloneNode(this._identif_), + cloneNode(this._crochetOuvrant_), + cloneNode(this._expression_), + cloneNode(this._crochetFermant_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIdtabV(this); + } + + public TIdentif getIdentif() + { + return this._identif_; + } + + public void setIdentif(TIdentif node) + { + if(this._identif_ != null) + { + this._identif_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._identif_ = node; + } + + public TCrochetOuvrant getCrochetOuvrant() + { + return this._crochetOuvrant_; + } + + public void setCrochetOuvrant(TCrochetOuvrant node) + { + if(this._crochetOuvrant_ != null) + { + this._crochetOuvrant_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._crochetOuvrant_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TCrochetFermant getCrochetFermant() + { + return this._crochetFermant_; + } + + public void setCrochetFermant(TCrochetFermant node) + { + if(this._crochetFermant_ != null) + { + this._crochetFermant_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._crochetFermant_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._identif_) + + toString(this._crochetOuvrant_) + + toString(this._expression_) + + toString(this._crochetFermant_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._identif_ == child) + { + this._identif_ = null; + return; + } + + if(this._crochetOuvrant_ == child) + { + this._crochetOuvrant_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._crochetFermant_ == child) + { + this._crochetFermant_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._identif_ == oldChild) + { + setIdentif((TIdentif) newChild); + return; + } + + if(this._crochetOuvrant_ == oldChild) + { + setCrochetOuvrant((TCrochetOuvrant) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._crochetFermant_ == oldChild) + { + setCrochetFermant((TCrochetFermant) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AIecrireIecrire.java b/src/sc/node/AIecrireIecrire.java new file mode 100644 index 0000000000000000000000000000000000000000..1670cd6f519ffe3b26785081f9a3ec4c09646ce5 --- /dev/null +++ b/src/sc/node/AIecrireIecrire.java @@ -0,0 +1,267 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AIecrireIecrire extends PIecrire +{ + private TEcrire _ecrire_; + private TParentheseOuvrante _parentheseOuvrante_; + private PExpression _expression_; + private TParentheseFermante _parentheseFermante_; + private TPVirgule _pVirgule_; + + public AIecrireIecrire() + { + // Constructor + } + + public AIecrireIecrire( + @SuppressWarnings("hiding") TEcrire _ecrire_, + @SuppressWarnings("hiding") TParentheseOuvrante _parentheseOuvrante_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TParentheseFermante _parentheseFermante_, + @SuppressWarnings("hiding") TPVirgule _pVirgule_) + { + // Constructor + setEcrire(_ecrire_); + + setParentheseOuvrante(_parentheseOuvrante_); + + setExpression(_expression_); + + setParentheseFermante(_parentheseFermante_); + + setPVirgule(_pVirgule_); + + } + + @Override + public Object clone() + { + return new AIecrireIecrire( + cloneNode(this._ecrire_), + cloneNode(this._parentheseOuvrante_), + cloneNode(this._expression_), + cloneNode(this._parentheseFermante_), + cloneNode(this._pVirgule_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAIecrireIecrire(this); + } + + public TEcrire getEcrire() + { + return this._ecrire_; + } + + public void setEcrire(TEcrire node) + { + if(this._ecrire_ != null) + { + this._ecrire_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ecrire_ = node; + } + + public TParentheseOuvrante getParentheseOuvrante() + { + return this._parentheseOuvrante_; + } + + public void setParentheseOuvrante(TParentheseOuvrante node) + { + if(this._parentheseOuvrante_ != null) + { + this._parentheseOuvrante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseOuvrante_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TParentheseFermante getParentheseFermante() + { + return this._parentheseFermante_; + } + + public void setParentheseFermante(TParentheseFermante node) + { + if(this._parentheseFermante_ != null) + { + this._parentheseFermante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseFermante_ = node; + } + + public TPVirgule getPVirgule() + { + return this._pVirgule_; + } + + public void setPVirgule(TPVirgule node) + { + if(this._pVirgule_ != null) + { + this._pVirgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pVirgule_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._ecrire_) + + toString(this._parentheseOuvrante_) + + toString(this._expression_) + + toString(this._parentheseFermante_) + + toString(this._pVirgule_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._ecrire_ == child) + { + this._ecrire_ = null; + return; + } + + if(this._parentheseOuvrante_ == child) + { + this._parentheseOuvrante_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._parentheseFermante_ == child) + { + this._parentheseFermante_ = null; + return; + } + + if(this._pVirgule_ == child) + { + this._pVirgule_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._ecrire_ == oldChild) + { + setEcrire((TEcrire) newChild); + return; + } + + if(this._parentheseOuvrante_ == oldChild) + { + setParentheseOuvrante((TParentheseOuvrante) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._parentheseFermante_ == oldChild) + { + setParentheseFermante((TParentheseFermante) newChild); + return; + } + + if(this._pVirgule_ == oldChild) + { + setPVirgule((TPVirgule) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AInferieurT2.java b/src/sc/node/AInferieurT2.java new file mode 100644 index 0000000000000000000000000000000000000000..7b8e7e22cda8baa1b6079b09b0556cb0c6ea10c8 --- /dev/null +++ b/src/sc/node/AInferieurT2.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AInferieurT2 extends PT2 +{ + private PT2 _t2_; + private TInferieur _inferieur_; + private PT3 _t3_; + + public AInferieurT2() + { + // Constructor + } + + public AInferieurT2( + @SuppressWarnings("hiding") PT2 _t2_, + @SuppressWarnings("hiding") TInferieur _inferieur_, + @SuppressWarnings("hiding") PT3 _t3_) + { + // Constructor + setT2(_t2_); + + setInferieur(_inferieur_); + + setT3(_t3_); + + } + + @Override + public Object clone() + { + return new AInferieurT2( + cloneNode(this._t2_), + cloneNode(this._inferieur_), + cloneNode(this._t3_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAInferieurT2(this); + } + + public PT2 getT2() + { + return this._t2_; + } + + public void setT2(PT2 node) + { + if(this._t2_ != null) + { + this._t2_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t2_ = node; + } + + public TInferieur getInferieur() + { + return this._inferieur_; + } + + public void setInferieur(TInferieur node) + { + if(this._inferieur_ != null) + { + this._inferieur_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._inferieur_ = node; + } + + public PT3 getT3() + { + return this._t3_; + } + + public void setT3(PT3 node) + { + if(this._t3_ != null) + { + this._t3_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t3_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t2_) + + toString(this._inferieur_) + + toString(this._t3_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t2_ == child) + { + this._t2_ = null; + return; + } + + if(this._inferieur_ == child) + { + this._inferieur_ = null; + return; + } + + if(this._t3_ == child) + { + this._t3_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t2_ == oldChild) + { + setT2((PT2) newChild); + return; + } + + if(this._inferieur_ == oldChild) + { + setInferieur((TInferieur) newChild); + return; + } + + if(this._t3_ == oldChild) + { + setT3((PT3) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ALDvLdv.java b/src/sc/node/ALDvLdv.java new file mode 100644 index 0000000000000000000000000000000000000000..d5989725396457c2f66bda2c05e795dea10a6dd7 --- /dev/null +++ b/src/sc/node/ALDvLdv.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ALDvLdv extends PLdv +{ + private PDv _dv_; + private PLdvb _ldvb_; + + public ALDvLdv() + { + // Constructor + } + + public ALDvLdv( + @SuppressWarnings("hiding") PDv _dv_, + @SuppressWarnings("hiding") PLdvb _ldvb_) + { + // Constructor + setDv(_dv_); + + setLdvb(_ldvb_); + + } + + @Override + public Object clone() + { + return new ALDvLdv( + cloneNode(this._dv_), + cloneNode(this._ldvb_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseALDvLdv(this); + } + + public PDv getDv() + { + return this._dv_; + } + + public void setDv(PDv node) + { + if(this._dv_ != null) + { + this._dv_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._dv_ = node; + } + + public PLdvb getLdvb() + { + return this._ldvb_; + } + + public void setLdvb(PLdvb node) + { + if(this._ldvb_ != null) + { + this._ldvb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldvb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._dv_) + + toString(this._ldvb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._dv_ == child) + { + this._dv_ = null; + return; + } + + if(this._ldvb_ == child) + { + this._ldvb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._dv_ == oldChild) + { + setDv((PDv) newChild); + return; + } + + if(this._ldvb_ == oldChild) + { + setLdvb((PLdvb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ALDvbLdvb.java b/src/sc/node/ALDvbLdvb.java new file mode 100644 index 0000000000000000000000000000000000000000..9c5360ddc0e6ae186eea9842cc3154b59f3899a2 --- /dev/null +++ b/src/sc/node/ALDvbLdvb.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ALDvbLdvb extends PLdvb +{ + private TVirgule _virgule_; + private PDv _dv_; + private PLdvb _ldvb_; + + public ALDvbLdvb() + { + // Constructor + } + + public ALDvbLdvb( + @SuppressWarnings("hiding") TVirgule _virgule_, + @SuppressWarnings("hiding") PDv _dv_, + @SuppressWarnings("hiding") PLdvb _ldvb_) + { + // Constructor + setVirgule(_virgule_); + + setDv(_dv_); + + setLdvb(_ldvb_); + + } + + @Override + public Object clone() + { + return new ALDvbLdvb( + cloneNode(this._virgule_), + cloneNode(this._dv_), + cloneNode(this._ldvb_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseALDvbLdvb(this); + } + + public TVirgule getVirgule() + { + return this._virgule_; + } + + public void setVirgule(TVirgule node) + { + if(this._virgule_ != null) + { + this._virgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._virgule_ = node; + } + + public PDv getDv() + { + return this._dv_; + } + + public void setDv(PDv node) + { + if(this._dv_ != null) + { + this._dv_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._dv_ = node; + } + + public PLdvb getLdvb() + { + return this._ldvb_; + } + + public void setLdvb(PLdvb node) + { + if(this._ldvb_ != null) + { + this._ldvb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldvb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._virgule_) + + toString(this._dv_) + + toString(this._ldvb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._virgule_ == child) + { + this._virgule_ = null; + return; + } + + if(this._dv_ == child) + { + this._dv_ = null; + return; + } + + if(this._ldvb_ == child) + { + this._ldvb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._virgule_ == oldChild) + { + setVirgule((TVirgule) newChild); + return; + } + + if(this._dv_ == oldChild) + { + setDv((PDv) newChild); + return; + } + + if(this._ldvb_ == oldChild) + { + setLdvb((PLdvb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ALdfLdf.java b/src/sc/node/ALdfLdf.java new file mode 100644 index 0000000000000000000000000000000000000000..9ebf78884b4575a6014e08d25fdaa0b8c07a9c17 --- /dev/null +++ b/src/sc/node/ALdfLdf.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ALdfLdf extends PLdf +{ + private PDf _df_; + private PLdf _ldf_; + + public ALdfLdf() + { + // Constructor + } + + public ALdfLdf( + @SuppressWarnings("hiding") PDf _df_, + @SuppressWarnings("hiding") PLdf _ldf_) + { + // Constructor + setDf(_df_); + + setLdf(_ldf_); + + } + + @Override + public Object clone() + { + return new ALdfLdf( + cloneNode(this._df_), + cloneNode(this._ldf_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseALdfLdf(this); + } + + public PDf getDf() + { + return this._df_; + } + + public void setDf(PDf node) + { + if(this._df_ != null) + { + this._df_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._df_ = node; + } + + public PLdf getLdf() + { + return this._ldf_; + } + + public void setLdf(PLdf node) + { + if(this._ldf_ != null) + { + this._ldf_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldf_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._df_) + + toString(this._ldf_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._df_ == child) + { + this._df_ = null; + return; + } + + if(this._ldf_ == child) + { + this._ldf_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._df_ == oldChild) + { + setDf((PDf) newChild); + return; + } + + if(this._ldf_ == oldChild) + { + setLdf((PLdf) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ALdvoLdvo.java b/src/sc/node/ALdvoLdvo.java new file mode 100644 index 0000000000000000000000000000000000000000..5bf926754ce0c604f530bd725e015eecbf810720 --- /dev/null +++ b/src/sc/node/ALdvoLdvo.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ALdvoLdvo extends PLdvo +{ + private PLdv _ldv_; + private TPVirgule _pVirgule_; + + public ALdvoLdvo() + { + // Constructor + } + + public ALdvoLdvo( + @SuppressWarnings("hiding") PLdv _ldv_, + @SuppressWarnings("hiding") TPVirgule _pVirgule_) + { + // Constructor + setLdv(_ldv_); + + setPVirgule(_pVirgule_); + + } + + @Override + public Object clone() + { + return new ALdvoLdvo( + cloneNode(this._ldv_), + cloneNode(this._pVirgule_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseALdvoLdvo(this); + } + + public PLdv getLdv() + { + return this._ldv_; + } + + public void setLdv(PLdv node) + { + if(this._ldv_ != null) + { + this._ldv_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldv_ = node; + } + + public TPVirgule getPVirgule() + { + return this._pVirgule_; + } + + public void setPVirgule(TPVirgule node) + { + if(this._pVirgule_ != null) + { + this._pVirgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pVirgule_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._ldv_) + + toString(this._pVirgule_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._ldv_ == child) + { + this._ldv_ = null; + return; + } + + if(this._pVirgule_ == child) + { + this._pVirgule_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._ldv_ == oldChild) + { + setLdv((PLdv) newChild); + return; + } + + if(this._pVirgule_ == oldChild) + { + setPVirgule((TPVirgule) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AListeExpBLeb.java b/src/sc/node/AListeExpBLeb.java new file mode 100644 index 0000000000000000000000000000000000000000..4478630db67b2e71b17c767a046ccdad6ba702d4 --- /dev/null +++ b/src/sc/node/AListeExpBLeb.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AListeExpBLeb extends PLeb +{ + private TVirgule _virgule_; + private PExpression _expression_; + private PLeb _leb_; + + public AListeExpBLeb() + { + // Constructor + } + + public AListeExpBLeb( + @SuppressWarnings("hiding") TVirgule _virgule_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") PLeb _leb_) + { + // Constructor + setVirgule(_virgule_); + + setExpression(_expression_); + + setLeb(_leb_); + + } + + @Override + public Object clone() + { + return new AListeExpBLeb( + cloneNode(this._virgule_), + cloneNode(this._expression_), + cloneNode(this._leb_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAListeExpBLeb(this); + } + + public TVirgule getVirgule() + { + return this._virgule_; + } + + public void setVirgule(TVirgule node) + { + if(this._virgule_ != null) + { + this._virgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._virgule_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public PLeb getLeb() + { + return this._leb_; + } + + public void setLeb(PLeb node) + { + if(this._leb_ != null) + { + this._leb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._leb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._virgule_) + + toString(this._expression_) + + toString(this._leb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._virgule_ == child) + { + this._virgule_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._leb_ == child) + { + this._leb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._virgule_ == oldChild) + { + setVirgule((TVirgule) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._leb_ == oldChild) + { + setLeb((PLeb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AListeExpLe.java b/src/sc/node/AListeExpLe.java new file mode 100644 index 0000000000000000000000000000000000000000..2f37066796a67637f85ee01b99460c05061a4902 --- /dev/null +++ b/src/sc/node/AListeExpLe.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AListeExpLe extends PLe +{ + private PExpression _expression_; + private PLeb _leb_; + + public AListeExpLe() + { + // Constructor + } + + public AListeExpLe( + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") PLeb _leb_) + { + // Constructor + setExpression(_expression_); + + setLeb(_leb_); + + } + + @Override + public Object clone() + { + return new AListeExpLe( + cloneNode(this._expression_), + cloneNode(this._leb_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAListeExpLe(this); + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public PLeb getLeb() + { + return this._leb_; + } + + public void setLeb(PLeb node) + { + if(this._leb_ != null) + { + this._leb_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._leb_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._expression_) + + toString(this._leb_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._leb_ == child) + { + this._leb_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._leb_ == oldChild) + { + setLeb((PLeb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AListeILi.java b/src/sc/node/AListeILi.java new file mode 100644 index 0000000000000000000000000000000000000000..c1288a5a3289475965eaede48b2b996af7ee13c8 --- /dev/null +++ b/src/sc/node/AListeILi.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AListeILi extends PLi +{ + private PI _i_; + private PLi _li_; + + public AListeILi() + { + // Constructor + } + + public AListeILi( + @SuppressWarnings("hiding") PI _i_, + @SuppressWarnings("hiding") PLi _li_) + { + // Constructor + setI(_i_); + + setLi(_li_); + + } + + @Override + public Object clone() + { + return new AListeILi( + cloneNode(this._i_), + cloneNode(this._li_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAListeILi(this); + } + + public PI getI() + { + return this._i_; + } + + public void setI(PI node) + { + if(this._i_ != null) + { + this._i_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._i_ = node; + } + + public PLi getLi() + { + return this._li_; + } + + public void setLi(PLi node) + { + if(this._li_ != null) + { + this._li_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._li_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._i_) + + toString(this._li_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._i_ == child) + { + this._i_ = null; + return; + } + + if(this._li_ == child) + { + this._li_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._i_ == oldChild) + { + setI((PI) newChild); + return; + } + + if(this._li_ == oldChild) + { + setLi((PLi) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AMoinsT3.java b/src/sc/node/AMoinsT3.java new file mode 100644 index 0000000000000000000000000000000000000000..51b56eaa45d675a010791c30d978d58a8978769f --- /dev/null +++ b/src/sc/node/AMoinsT3.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AMoinsT3 extends PT3 +{ + private PT3 _t3_; + private TMoins _moins_; + private PT4 _t4_; + + public AMoinsT3() + { + // Constructor + } + + public AMoinsT3( + @SuppressWarnings("hiding") PT3 _t3_, + @SuppressWarnings("hiding") TMoins _moins_, + @SuppressWarnings("hiding") PT4 _t4_) + { + // Constructor + setT3(_t3_); + + setMoins(_moins_); + + setT4(_t4_); + + } + + @Override + public Object clone() + { + return new AMoinsT3( + cloneNode(this._t3_), + cloneNode(this._moins_), + cloneNode(this._t4_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAMoinsT3(this); + } + + public PT3 getT3() + { + return this._t3_; + } + + public void setT3(PT3 node) + { + if(this._t3_ != null) + { + this._t3_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t3_ = node; + } + + public TMoins getMoins() + { + return this._moins_; + } + + public void setMoins(TMoins node) + { + if(this._moins_ != null) + { + this._moins_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._moins_ = node; + } + + public PT4 getT4() + { + return this._t4_; + } + + public void setT4(PT4 node) + { + if(this._t4_ != null) + { + this._t4_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t4_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t3_) + + toString(this._moins_) + + toString(this._t4_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t3_ == child) + { + this._t3_ = null; + return; + } + + if(this._moins_ == child) + { + this._moins_ = null; + return; + } + + if(this._t4_ == child) + { + this._t4_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t3_ == oldChild) + { + setT3((PT3) newChild); + return; + } + + if(this._moins_ == oldChild) + { + setMoins((TMoins) newChild); + return; + } + + if(this._t4_ == oldChild) + { + setT4((PT4) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AMultiplicationT4.java b/src/sc/node/AMultiplicationT4.java new file mode 100644 index 0000000000000000000000000000000000000000..1293ff2831a9fdbc6c182fedf3c02454d0ee1e75 --- /dev/null +++ b/src/sc/node/AMultiplicationT4.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AMultiplicationT4 extends PT4 +{ + private PT4 _t4_; + private TMultiplication _multiplication_; + private PT5 _t5_; + + public AMultiplicationT4() + { + // Constructor + } + + public AMultiplicationT4( + @SuppressWarnings("hiding") PT4 _t4_, + @SuppressWarnings("hiding") TMultiplication _multiplication_, + @SuppressWarnings("hiding") PT5 _t5_) + { + // Constructor + setT4(_t4_); + + setMultiplication(_multiplication_); + + setT5(_t5_); + + } + + @Override + public Object clone() + { + return new AMultiplicationT4( + cloneNode(this._t4_), + cloneNode(this._multiplication_), + cloneNode(this._t5_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAMultiplicationT4(this); + } + + public PT4 getT4() + { + return this._t4_; + } + + public void setT4(PT4 node) + { + if(this._t4_ != null) + { + this._t4_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t4_ = node; + } + + public TMultiplication getMultiplication() + { + return this._multiplication_; + } + + public void setMultiplication(TMultiplication node) + { + if(this._multiplication_ != null) + { + this._multiplication_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._multiplication_ = node; + } + + public PT5 getT5() + { + return this._t5_; + } + + public void setT5(PT5 node) + { + if(this._t5_ != null) + { + this._t5_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t5_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t4_) + + toString(this._multiplication_) + + toString(this._t5_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t4_ == child) + { + this._t4_ = null; + return; + } + + if(this._multiplication_ == child) + { + this._multiplication_ = null; + return; + } + + if(this._t5_ == child) + { + this._t5_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t4_ == oldChild) + { + setT4((PT4) newChild); + return; + } + + if(this._multiplication_ == oldChild) + { + setMultiplication((TMultiplication) newChild); + return; + } + + if(this._t5_ == oldChild) + { + setT5((PT5) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ANonT5.java b/src/sc/node/ANonT5.java new file mode 100644 index 0000000000000000000000000000000000000000..3242df4b712a349de984620a6f667f5d71dc35b7 --- /dev/null +++ b/src/sc/node/ANonT5.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ANonT5 extends PT5 +{ + private TNon _non_; + private PT5 _t5_; + + public ANonT5() + { + // Constructor + } + + public ANonT5( + @SuppressWarnings("hiding") TNon _non_, + @SuppressWarnings("hiding") PT5 _t5_) + { + // Constructor + setNon(_non_); + + setT5(_t5_); + + } + + @Override + public Object clone() + { + return new ANonT5( + cloneNode(this._non_), + cloneNode(this._t5_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseANonT5(this); + } + + public TNon getNon() + { + return this._non_; + } + + public void setNon(TNon node) + { + if(this._non_ != null) + { + this._non_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._non_ = node; + } + + public PT5 getT5() + { + return this._t5_; + } + + public void setT5(PT5 node) + { + if(this._t5_ != null) + { + this._t5_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t5_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._non_) + + toString(this._t5_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._non_ == child) + { + this._non_ = null; + return; + } + + if(this._t5_ == child) + { + this._t5_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._non_ == oldChild) + { + setNon((TNon) newChild); + return; + } + + if(this._t5_ == oldChild) + { + setT5((PT5) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AOuExpression.java b/src/sc/node/AOuExpression.java new file mode 100644 index 0000000000000000000000000000000000000000..03ea7df9b00b8cda42573b14e575033bd7e3e819 --- /dev/null +++ b/src/sc/node/AOuExpression.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AOuExpression extends PExpression +{ + private PExpression _expression_; + private TOu _ou_; + private PT1 _t1_; + + public AOuExpression() + { + // Constructor + } + + public AOuExpression( + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TOu _ou_, + @SuppressWarnings("hiding") PT1 _t1_) + { + // Constructor + setExpression(_expression_); + + setOu(_ou_); + + setT1(_t1_); + + } + + @Override + public Object clone() + { + return new AOuExpression( + cloneNode(this._expression_), + cloneNode(this._ou_), + cloneNode(this._t1_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAOuExpression(this); + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TOu getOu() + { + return this._ou_; + } + + public void setOu(TOu node) + { + if(this._ou_ != null) + { + this._ou_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ou_ = node; + } + + public PT1 getT1() + { + return this._t1_; + } + + public void setT1(PT1 node) + { + if(this._t1_ != null) + { + this._t1_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t1_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._expression_) + + toString(this._ou_) + + toString(this._t1_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._ou_ == child) + { + this._ou_ = null; + return; + } + + if(this._t1_ == child) + { + this._t1_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._ou_ == oldChild) + { + setOu((TOu) newChild); + return; + } + + if(this._t1_ == oldChild) + { + setT1((PT1) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AParamsLparam.java b/src/sc/node/AParamsLparam.java new file mode 100644 index 0000000000000000000000000000000000000000..1ef8008573076448ecab6395ef2671720bc5d8e4 --- /dev/null +++ b/src/sc/node/AParamsLparam.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AParamsLparam extends PLparam +{ + private TParentheseOuvrante _parentheseOuvrante_; + private PLdv _ldv_; + private TParentheseFermante _parentheseFermante_; + + public AParamsLparam() + { + // Constructor + } + + public AParamsLparam( + @SuppressWarnings("hiding") TParentheseOuvrante _parentheseOuvrante_, + @SuppressWarnings("hiding") PLdv _ldv_, + @SuppressWarnings("hiding") TParentheseFermante _parentheseFermante_) + { + // Constructor + setParentheseOuvrante(_parentheseOuvrante_); + + setLdv(_ldv_); + + setParentheseFermante(_parentheseFermante_); + + } + + @Override + public Object clone() + { + return new AParamsLparam( + cloneNode(this._parentheseOuvrante_), + cloneNode(this._ldv_), + cloneNode(this._parentheseFermante_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAParamsLparam(this); + } + + public TParentheseOuvrante getParentheseOuvrante() + { + return this._parentheseOuvrante_; + } + + public void setParentheseOuvrante(TParentheseOuvrante node) + { + if(this._parentheseOuvrante_ != null) + { + this._parentheseOuvrante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseOuvrante_ = node; + } + + public PLdv getLdv() + { + return this._ldv_; + } + + public void setLdv(PLdv node) + { + if(this._ldv_ != null) + { + this._ldv_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldv_ = node; + } + + public TParentheseFermante getParentheseFermante() + { + return this._parentheseFermante_; + } + + public void setParentheseFermante(TParentheseFermante node) + { + if(this._parentheseFermante_ != null) + { + this._parentheseFermante_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._parentheseFermante_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._parentheseOuvrante_) + + toString(this._ldv_) + + toString(this._parentheseFermante_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._parentheseOuvrante_ == child) + { + this._parentheseOuvrante_ = null; + return; + } + + if(this._ldv_ == child) + { + this._ldv_ = null; + return; + } + + if(this._parentheseFermante_ == child) + { + this._parentheseFermante_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._parentheseOuvrante_ == oldChild) + { + setParentheseOuvrante((TParentheseOuvrante) newChild); + return; + } + + if(this._ldv_ == oldChild) + { + setLdv((PLdv) newChild); + return; + } + + if(this._parentheseFermante_ == oldChild) + { + setParentheseFermante((TParentheseFermante) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/APlusT3.java b/src/sc/node/APlusT3.java new file mode 100644 index 0000000000000000000000000000000000000000..febb15ca9869a729bd97f3169bb29b3d69ea4149 --- /dev/null +++ b/src/sc/node/APlusT3.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class APlusT3 extends PT3 +{ + private PT3 _t3_; + private TPlus _plus_; + private PT4 _t4_; + + public APlusT3() + { + // Constructor + } + + public APlusT3( + @SuppressWarnings("hiding") PT3 _t3_, + @SuppressWarnings("hiding") TPlus _plus_, + @SuppressWarnings("hiding") PT4 _t4_) + { + // Constructor + setT3(_t3_); + + setPlus(_plus_); + + setT4(_t4_); + + } + + @Override + public Object clone() + { + return new APlusT3( + cloneNode(this._t3_), + cloneNode(this._plus_), + cloneNode(this._t4_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAPlusT3(this); + } + + public PT3 getT3() + { + return this._t3_; + } + + public void setT3(PT3 node) + { + if(this._t3_ != null) + { + this._t3_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t3_ = node; + } + + public TPlus getPlus() + { + return this._plus_; + } + + public void setPlus(TPlus node) + { + if(this._plus_ != null) + { + this._plus_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._plus_ = node; + } + + public PT4 getT4() + { + return this._t4_; + } + + public void setT4(PT4 node) + { + if(this._t4_ != null) + { + this._t4_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t4_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t3_) + + toString(this._plus_) + + toString(this._t4_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t3_ == child) + { + this._t3_ = null; + return; + } + + if(this._plus_ == child) + { + this._plus_ = null; + return; + } + + if(this._t4_ == child) + { + this._t4_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t3_ == oldChild) + { + setT3((PT3) newChild); + return; + } + + if(this._plus_ == oldChild) + { + setPlus((TPlus) newChild); + return; + } + + if(this._t4_ == oldChild) + { + setT4((PT4) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AProgramProgram.java b/src/sc/node/AProgramProgram.java new file mode 100644 index 0000000000000000000000000000000000000000..3930b5d42504e827f8f8ccb4d50ca59e81ade050 --- /dev/null +++ b/src/sc/node/AProgramProgram.java @@ -0,0 +1,138 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AProgramProgram extends PProgram +{ + private PLdvo _ldvo_; + private PLdf _ldf_; + + public AProgramProgram() + { + // Constructor + } + + public AProgramProgram( + @SuppressWarnings("hiding") PLdvo _ldvo_, + @SuppressWarnings("hiding") PLdf _ldf_) + { + // Constructor + setLdvo(_ldvo_); + + setLdf(_ldf_); + + } + + @Override + public Object clone() + { + return new AProgramProgram( + cloneNode(this._ldvo_), + cloneNode(this._ldf_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAProgramProgram(this); + } + + public PLdvo getLdvo() + { + return this._ldvo_; + } + + public void setLdvo(PLdvo node) + { + if(this._ldvo_ != null) + { + this._ldvo_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldvo_ = node; + } + + public PLdf getLdf() + { + return this._ldf_; + } + + public void setLdf(PLdf node) + { + if(this._ldf_ != null) + { + this._ldf_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ldf_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._ldvo_) + + toString(this._ldf_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._ldvo_ == child) + { + this._ldvo_ = null; + return; + } + + if(this._ldf_ == child) + { + this._ldf_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._ldvo_ == oldChild) + { + setLdvo((PLdvo) newChild); + return; + } + + if(this._ldf_ == oldChild) + { + setLdf((PLdf) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ARetournerIret.java b/src/sc/node/ARetournerIret.java new file mode 100644 index 0000000000000000000000000000000000000000..4568e1b05bb19a5f0dc43f9f0aeeacd57f9ad739 --- /dev/null +++ b/src/sc/node/ARetournerIret.java @@ -0,0 +1,181 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ARetournerIret extends PIret +{ + private TRetour _retour_; + private PExpression _expression_; + private TPVirgule _pVirgule_; + + public ARetournerIret() + { + // Constructor + } + + public ARetournerIret( + @SuppressWarnings("hiding") TRetour _retour_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TPVirgule _pVirgule_) + { + // Constructor + setRetour(_retour_); + + setExpression(_expression_); + + setPVirgule(_pVirgule_); + + } + + @Override + public Object clone() + { + return new ARetournerIret( + cloneNode(this._retour_), + cloneNode(this._expression_), + cloneNode(this._pVirgule_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseARetournerIret(this); + } + + public TRetour getRetour() + { + return this._retour_; + } + + public void setRetour(TRetour node) + { + if(this._retour_ != null) + { + this._retour_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._retour_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TPVirgule getPVirgule() + { + return this._pVirgule_; + } + + public void setPVirgule(TPVirgule node) + { + if(this._pVirgule_ != null) + { + this._pVirgule_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pVirgule_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._retour_) + + toString(this._expression_) + + toString(this._pVirgule_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._retour_ == child) + { + this._retour_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._pVirgule_ == child) + { + this._pVirgule_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._retour_ == oldChild) + { + setRetour((TRetour) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._pVirgule_ == oldChild) + { + setPVirgule((TPVirgule) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ASiIsi.java b/src/sc/node/ASiIsi.java new file mode 100644 index 0000000000000000000000000000000000000000..9eff63a376f84b604b99a5f49df7424b974dbc47 --- /dev/null +++ b/src/sc/node/ASiIsi.java @@ -0,0 +1,224 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ASiIsi extends PIsi +{ + private TSi _si_; + private PExpression _expression_; + private TAlors _alors_; + private PIb _ib_; + + public ASiIsi() + { + // Constructor + } + + public ASiIsi( + @SuppressWarnings("hiding") TSi _si_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TAlors _alors_, + @SuppressWarnings("hiding") PIb _ib_) + { + // Constructor + setSi(_si_); + + setExpression(_expression_); + + setAlors(_alors_); + + setIb(_ib_); + + } + + @Override + public Object clone() + { + return new ASiIsi( + cloneNode(this._si_), + cloneNode(this._expression_), + cloneNode(this._alors_), + cloneNode(this._ib_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseASiIsi(this); + } + + public TSi getSi() + { + return this._si_; + } + + public void setSi(TSi node) + { + if(this._si_ != null) + { + this._si_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._si_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TAlors getAlors() + { + return this._alors_; + } + + public void setAlors(TAlors node) + { + if(this._alors_ != null) + { + this._alors_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._alors_ = node; + } + + public PIb getIb() + { + return this._ib_; + } + + public void setIb(PIb node) + { + if(this._ib_ != null) + { + this._ib_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ib_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._si_) + + toString(this._expression_) + + toString(this._alors_) + + toString(this._ib_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._si_ == child) + { + this._si_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._alors_ == child) + { + this._alors_ = null; + return; + } + + if(this._ib_ == child) + { + this._ib_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._si_ == oldChild) + { + setSi((TSi) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._alors_ == oldChild) + { + setAlors((TAlors) newChild); + return; + } + + if(this._ib_ == oldChild) + { + setIb((PIb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ASisinonIsi.java b/src/sc/node/ASisinonIsi.java new file mode 100644 index 0000000000000000000000000000000000000000..f97b9bcdd9de3ebc84205b2320d31a952c078001 --- /dev/null +++ b/src/sc/node/ASisinonIsi.java @@ -0,0 +1,310 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ASisinonIsi extends PIsi +{ + private TSi _si_; + private PExpression _expression_; + private TAlors _alors_; + private PIb _cas1_; + private TSinon _sinon_; + private PIb _cas2_; + + public ASisinonIsi() + { + // Constructor + } + + public ASisinonIsi( + @SuppressWarnings("hiding") TSi _si_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TAlors _alors_, + @SuppressWarnings("hiding") PIb _cas1_, + @SuppressWarnings("hiding") TSinon _sinon_, + @SuppressWarnings("hiding") PIb _cas2_) + { + // Constructor + setSi(_si_); + + setExpression(_expression_); + + setAlors(_alors_); + + setCas1(_cas1_); + + setSinon(_sinon_); + + setCas2(_cas2_); + + } + + @Override + public Object clone() + { + return new ASisinonIsi( + cloneNode(this._si_), + cloneNode(this._expression_), + cloneNode(this._alors_), + cloneNode(this._cas1_), + cloneNode(this._sinon_), + cloneNode(this._cas2_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseASisinonIsi(this); + } + + public TSi getSi() + { + return this._si_; + } + + public void setSi(TSi node) + { + if(this._si_ != null) + { + this._si_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._si_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TAlors getAlors() + { + return this._alors_; + } + + public void setAlors(TAlors node) + { + if(this._alors_ != null) + { + this._alors_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._alors_ = node; + } + + public PIb getCas1() + { + return this._cas1_; + } + + public void setCas1(PIb node) + { + if(this._cas1_ != null) + { + this._cas1_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._cas1_ = node; + } + + public TSinon getSinon() + { + return this._sinon_; + } + + public void setSinon(TSinon node) + { + if(this._sinon_ != null) + { + this._sinon_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._sinon_ = node; + } + + public PIb getCas2() + { + return this._cas2_; + } + + public void setCas2(PIb node) + { + if(this._cas2_ != null) + { + this._cas2_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._cas2_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._si_) + + toString(this._expression_) + + toString(this._alors_) + + toString(this._cas1_) + + toString(this._sinon_) + + toString(this._cas2_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._si_ == child) + { + this._si_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._alors_ == child) + { + this._alors_ = null; + return; + } + + if(this._cas1_ == child) + { + this._cas1_ = null; + return; + } + + if(this._sinon_ == child) + { + this._sinon_ = null; + return; + } + + if(this._cas2_ == child) + { + this._cas2_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._si_ == oldChild) + { + setSi((TSi) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._alors_ == oldChild) + { + setAlors((TAlors) newChild); + return; + } + + if(this._cas1_ == oldChild) + { + setCas1((PIb) newChild); + return; + } + + if(this._sinon_ == oldChild) + { + setSinon((TSinon) newChild); + return; + } + + if(this._cas2_ == oldChild) + { + setCas2((PIb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AT1Expression.java b/src/sc/node/AT1Expression.java new file mode 100644 index 0000000000000000000000000000000000000000..1b3b681904454cda83645bfa5ea09d5be0681a4e --- /dev/null +++ b/src/sc/node/AT1Expression.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AT1Expression extends PExpression +{ + private PT1 _t1_; + + public AT1Expression() + { + // Constructor + } + + public AT1Expression( + @SuppressWarnings("hiding") PT1 _t1_) + { + // Constructor + setT1(_t1_); + + } + + @Override + public Object clone() + { + return new AT1Expression( + cloneNode(this._t1_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAT1Expression(this); + } + + public PT1 getT1() + { + return this._t1_; + } + + public void setT1(PT1 node) + { + if(this._t1_ != null) + { + this._t1_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t1_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t1_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t1_ == child) + { + this._t1_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t1_ == oldChild) + { + setT1((PT1) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AT2T1.java b/src/sc/node/AT2T1.java new file mode 100644 index 0000000000000000000000000000000000000000..c6ce045fcd62de10ea0ec4e4f8744aba20827a63 --- /dev/null +++ b/src/sc/node/AT2T1.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AT2T1 extends PT1 +{ + private PT2 _t2_; + + public AT2T1() + { + // Constructor + } + + public AT2T1( + @SuppressWarnings("hiding") PT2 _t2_) + { + // Constructor + setT2(_t2_); + + } + + @Override + public Object clone() + { + return new AT2T1( + cloneNode(this._t2_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAT2T1(this); + } + + public PT2 getT2() + { + return this._t2_; + } + + public void setT2(PT2 node) + { + if(this._t2_ != null) + { + this._t2_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t2_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t2_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t2_ == child) + { + this._t2_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t2_ == oldChild) + { + setT2((PT2) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AT3T2.java b/src/sc/node/AT3T2.java new file mode 100644 index 0000000000000000000000000000000000000000..78e1a12a922c60d5c3045a29172eeee06a7d5170 --- /dev/null +++ b/src/sc/node/AT3T2.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AT3T2 extends PT2 +{ + private PT3 _t3_; + + public AT3T2() + { + // Constructor + } + + public AT3T2( + @SuppressWarnings("hiding") PT3 _t3_) + { + // Constructor + setT3(_t3_); + + } + + @Override + public Object clone() + { + return new AT3T2( + cloneNode(this._t3_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAT3T2(this); + } + + public PT3 getT3() + { + return this._t3_; + } + + public void setT3(PT3 node) + { + if(this._t3_ != null) + { + this._t3_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t3_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t3_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t3_ == child) + { + this._t3_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t3_ == oldChild) + { + setT3((PT3) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AT4T3.java b/src/sc/node/AT4T3.java new file mode 100644 index 0000000000000000000000000000000000000000..f3e156d2346440e40b0f4ddd303b1c9df3d2d7e8 --- /dev/null +++ b/src/sc/node/AT4T3.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AT4T3 extends PT3 +{ + private PT4 _t4_; + + public AT4T3() + { + // Constructor + } + + public AT4T3( + @SuppressWarnings("hiding") PT4 _t4_) + { + // Constructor + setT4(_t4_); + + } + + @Override + public Object clone() + { + return new AT4T3( + cloneNode(this._t4_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAT4T3(this); + } + + public PT4 getT4() + { + return this._t4_; + } + + public void setT4(PT4 node) + { + if(this._t4_ != null) + { + this._t4_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t4_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t4_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t4_ == child) + { + this._t4_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t4_ == oldChild) + { + setT4((PT4) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AT5T4.java b/src/sc/node/AT5T4.java new file mode 100644 index 0000000000000000000000000000000000000000..fa58ba7401bec6f8c647ba9778b5dac05ba2b521 --- /dev/null +++ b/src/sc/node/AT5T4.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AT5T4 extends PT4 +{ + private PT5 _t5_; + + public AT5T4() + { + // Constructor + } + + public AT5T4( + @SuppressWarnings("hiding") PT5 _t5_) + { + // Constructor + setT5(_t5_); + + } + + @Override + public Object clone() + { + return new AT5T4( + cloneNode(this._t5_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAT5T4(this); + } + + public PT5 getT5() + { + return this._t5_; + } + + public void setT5(PT5 node) + { + if(this._t5_ != null) + { + this._t5_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t5_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t5_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t5_ == child) + { + this._t5_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t5_ == oldChild) + { + setT5((PT5) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AT6T5.java b/src/sc/node/AT6T5.java new file mode 100644 index 0000000000000000000000000000000000000000..a8a8f73b8066c02ee6a0b5ae3166ea56971d2064 --- /dev/null +++ b/src/sc/node/AT6T5.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AT6T5 extends PT5 +{ + private PT6 _t6_; + + public AT6T5() + { + // Constructor + } + + public AT6T5( + @SuppressWarnings("hiding") PT6 _t6_) + { + // Constructor + setT6(_t6_); + + } + + @Override + public Object clone() + { + return new AT6T5( + cloneNode(this._t6_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAT6T5(this); + } + + public PT6 getT6() + { + return this._t6_; + } + + public void setT6(PT6 node) + { + if(this._t6_ != null) + { + this._t6_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._t6_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._t6_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._t6_ == child) + { + this._t6_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._t6_ == oldChild) + { + setT6((PT6) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/ATantqueItantque.java b/src/sc/node/ATantqueItantque.java new file mode 100644 index 0000000000000000000000000000000000000000..2ef37c1913915d5885fba47cf300a38295d6aab6 --- /dev/null +++ b/src/sc/node/ATantqueItantque.java @@ -0,0 +1,224 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class ATantqueItantque extends PItantque +{ + private TTantque _tantque_; + private PExpression _expression_; + private TFaire _faire_; + private PIb _ib_; + + public ATantqueItantque() + { + // Constructor + } + + public ATantqueItantque( + @SuppressWarnings("hiding") TTantque _tantque_, + @SuppressWarnings("hiding") PExpression _expression_, + @SuppressWarnings("hiding") TFaire _faire_, + @SuppressWarnings("hiding") PIb _ib_) + { + // Constructor + setTantque(_tantque_); + + setExpression(_expression_); + + setFaire(_faire_); + + setIb(_ib_); + + } + + @Override + public Object clone() + { + return new ATantqueItantque( + cloneNode(this._tantque_), + cloneNode(this._expression_), + cloneNode(this._faire_), + cloneNode(this._ib_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseATantqueItantque(this); + } + + public TTantque getTantque() + { + return this._tantque_; + } + + public void setTantque(TTantque node) + { + if(this._tantque_ != null) + { + this._tantque_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._tantque_ = node; + } + + public PExpression getExpression() + { + return this._expression_; + } + + public void setExpression(PExpression node) + { + if(this._expression_ != null) + { + this._expression_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._expression_ = node; + } + + public TFaire getFaire() + { + return this._faire_; + } + + public void setFaire(TFaire node) + { + if(this._faire_ != null) + { + this._faire_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._faire_ = node; + } + + public PIb getIb() + { + return this._ib_; + } + + public void setIb(PIb node) + { + if(this._ib_ != null) + { + this._ib_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._ib_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._tantque_) + + toString(this._expression_) + + toString(this._faire_) + + toString(this._ib_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._tantque_ == child) + { + this._tantque_ = null; + return; + } + + if(this._expression_ == child) + { + this._expression_ = null; + return; + } + + if(this._faire_ == child) + { + this._faire_ = null; + return; + } + + if(this._ib_ == child) + { + this._ib_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._tantque_ == oldChild) + { + setTantque((TTantque) newChild); + return; + } + + if(this._expression_ == oldChild) + { + setExpression((PExpression) newChild); + return; + } + + if(this._faire_ == oldChild) + { + setFaire((TFaire) newChild); + return; + } + + if(this._ib_ == oldChild) + { + setIb((PIb) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AX1T6.java b/src/sc/node/AX1T6.java new file mode 100644 index 0000000000000000000000000000000000000000..34e34d3e5d17fdf915850e4b8aac4e1c6a24844e --- /dev/null +++ b/src/sc/node/AX1T6.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AX1T6 extends PT6 +{ + private TNombre _nombre_; + + public AX1T6() + { + // Constructor + } + + public AX1T6( + @SuppressWarnings("hiding") TNombre _nombre_) + { + // Constructor + setNombre(_nombre_); + + } + + @Override + public Object clone() + { + return new AX1T6( + cloneNode(this._nombre_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAX1T6(this); + } + + public TNombre getNombre() + { + return this._nombre_; + } + + public void setNombre(TNombre node) + { + if(this._nombre_ != null) + { + this._nombre_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._nombre_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._nombre_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._nombre_ == child) + { + this._nombre_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._nombre_ == oldChild) + { + setNombre((TNombre) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/AX2T6.java b/src/sc/node/AX2T6.java new file mode 100644 index 0000000000000000000000000000000000000000..82ea95e8482e2161c25452cc4521ad62cbf533aa --- /dev/null +++ b/src/sc/node/AX2T6.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class AX2T6 extends PT6 +{ + private PV _v_; + + public AX2T6() + { + // Constructor + } + + public AX2T6( + @SuppressWarnings("hiding") PV _v_) + { + // Constructor + setV(_v_); + + } + + @Override + public Object clone() + { + return new AX2T6( + cloneNode(this._v_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAX2T6(this); + } + + public PV getV() + { + return this._v_; + } + + public void setV(PV node) + { + if(this._v_ != null) + { + this._v_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._v_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._v_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._v_ == child) + { + this._v_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._v_ == oldChild) + { + setV((PV) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/node/EOF.java b/src/sc/node/EOF.java new file mode 100644 index 0000000000000000000000000000000000000000..52f53cc225774e7be06cb3ba1e7be338c05bc1fe --- /dev/null +++ b/src/sc/node/EOF.java @@ -0,0 +1,33 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class EOF extends Token +{ + public EOF() + { + setText(""); + } + + public EOF(int line, int pos) + { + setText(""); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new EOF(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseEOF(this); + } +} diff --git a/src/sc/node/InvalidToken.java b/src/sc/node/InvalidToken.java new file mode 100644 index 0000000000000000000000000000000000000000..e088b68340cc65789fb5c9a54dbf069cfa66edcc --- /dev/null +++ b/src/sc/node/InvalidToken.java @@ -0,0 +1,33 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class InvalidToken extends Token +{ + public InvalidToken(String text) + { + setText(text); + } + + public InvalidToken(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new InvalidToken(getText(), getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseInvalidToken(this); + } +} diff --git a/src/sc/node/Node.java b/src/sc/node/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..7c26108737af9783138c37639837b47c33502b4f --- /dev/null +++ b/src/sc/node/Node.java @@ -0,0 +1,78 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import java.util.*; + +@SuppressWarnings("nls") +public abstract class Node implements Switchable, Cloneable +{ + private Node parent; + + @Override + public abstract Object clone(); + + public Node parent() + { + return this.parent; + } + + void parent(@SuppressWarnings("hiding") Node parent) + { + this.parent = parent; + } + + abstract void removeChild(Node child); + abstract void replaceChild(Node oldChild, Node newChild); + + public void replaceBy(Node node) + { + this.parent.replaceChild(this, node); + } + + protected String toString(Node node) + { + if(node != null) + { + return node.toString(); + } + + return ""; + } + + protected String toString(List<?> list) + { + StringBuffer s = new StringBuffer(); + + for(Iterator<?> i = list.iterator(); i.hasNext();) + { + s.append(i.next()); + } + + return s.toString(); + } + + @SuppressWarnings("unchecked") + protected <T extends Node> T cloneNode(T node) + { + if(node != null) + { + return (T) node.clone(); + } + + return null; + } + + @SuppressWarnings("unchecked") + protected <T extends Node> List<T> cloneList(List<T> list) + { + List<T> clone = new LinkedList<T>(); + + for(T n : list) + { + clone.add((T) n.clone()); + } + + return clone; + } +} diff --git a/src/sc/node/PAppel.java b/src/sc/node/PAppel.java new file mode 100644 index 0000000000000000000000000000000000000000..b3206e20fe1fac0ea73203e8de0d3272c41a4fe0 --- /dev/null +++ b/src/sc/node/PAppel.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PAppel extends Node +{ + // Empty body +} diff --git a/src/sc/node/PDf.java b/src/sc/node/PDf.java new file mode 100644 index 0000000000000000000000000000000000000000..9a68c33cac5728e7ae5e885c138d3bacf4eefbcd --- /dev/null +++ b/src/sc/node/PDf.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PDf extends Node +{ + // Empty body +} diff --git a/src/sc/node/PDv.java b/src/sc/node/PDv.java new file mode 100644 index 0000000000000000000000000000000000000000..708faf2f8b2c3e34bfa96dc7e62aad957cc48cec --- /dev/null +++ b/src/sc/node/PDv.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PDv extends Node +{ + // Empty body +} diff --git a/src/sc/node/PExpression.java b/src/sc/node/PExpression.java new file mode 100644 index 0000000000000000000000000000000000000000..3f742fbee204406919fb71bd991feabebc78f293 --- /dev/null +++ b/src/sc/node/PExpression.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PExpression extends Node +{ + // Empty body +} diff --git a/src/sc/node/PI.java b/src/sc/node/PI.java new file mode 100644 index 0000000000000000000000000000000000000000..8a9270dd434ad1cf15017003ed8dadb585d59839 --- /dev/null +++ b/src/sc/node/PI.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PI extends Node +{ + // Empty body +} diff --git a/src/sc/node/PIaffectation.java b/src/sc/node/PIaffectation.java new file mode 100644 index 0000000000000000000000000000000000000000..c2370c3f3673cb0cb08b94e42e8c9d46f6d22abf --- /dev/null +++ b/src/sc/node/PIaffectation.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PIaffectation extends Node +{ + // Empty body +} diff --git a/src/sc/node/PIappel.java b/src/sc/node/PIappel.java new file mode 100644 index 0000000000000000000000000000000000000000..490d9bd07fa890040dee584cd5616ce4704faf12 --- /dev/null +++ b/src/sc/node/PIappel.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PIappel extends Node +{ + // Empty body +} diff --git a/src/sc/node/PIb.java b/src/sc/node/PIb.java new file mode 100644 index 0000000000000000000000000000000000000000..46e357c6a10f1b7aec85f5b39aebc916b086723e --- /dev/null +++ b/src/sc/node/PIb.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PIb extends Node +{ + // Empty body +} diff --git a/src/sc/node/PIecrire.java b/src/sc/node/PIecrire.java new file mode 100644 index 0000000000000000000000000000000000000000..45984a6cd64f7b3fdf1f4c2271759f33e35bb732 --- /dev/null +++ b/src/sc/node/PIecrire.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PIecrire extends Node +{ + // Empty body +} diff --git a/src/sc/node/PIret.java b/src/sc/node/PIret.java new file mode 100644 index 0000000000000000000000000000000000000000..f725ed3d25c6c02f79ddf112c814f2b9c821777e --- /dev/null +++ b/src/sc/node/PIret.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PIret extends Node +{ + // Empty body +} diff --git a/src/sc/node/PIsi.java b/src/sc/node/PIsi.java new file mode 100644 index 0000000000000000000000000000000000000000..5cc8785b0c2e7fddb41c1e5d2862131d8a383bbd --- /dev/null +++ b/src/sc/node/PIsi.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PIsi extends Node +{ + // Empty body +} diff --git a/src/sc/node/PItantque.java b/src/sc/node/PItantque.java new file mode 100644 index 0000000000000000000000000000000000000000..44b309e01e7de75e2c32725748b932eba0a31ad1 --- /dev/null +++ b/src/sc/node/PItantque.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PItantque extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLdf.java b/src/sc/node/PLdf.java new file mode 100644 index 0000000000000000000000000000000000000000..6804da2c015e08abc0902f784f771a8a466b05af --- /dev/null +++ b/src/sc/node/PLdf.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLdf extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLdv.java b/src/sc/node/PLdv.java new file mode 100644 index 0000000000000000000000000000000000000000..fe43d013e2f8895a0a26fb8d93bd0420376d9111 --- /dev/null +++ b/src/sc/node/PLdv.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLdv extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLdvb.java b/src/sc/node/PLdvb.java new file mode 100644 index 0000000000000000000000000000000000000000..7bc2e63fcab4cfacbcb1322b2899290e3d114f2f --- /dev/null +++ b/src/sc/node/PLdvb.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLdvb extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLdvo.java b/src/sc/node/PLdvo.java new file mode 100644 index 0000000000000000000000000000000000000000..5febcb3764159a18d33a103cb3525d9da19f1385 --- /dev/null +++ b/src/sc/node/PLdvo.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLdvo extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLe.java b/src/sc/node/PLe.java new file mode 100644 index 0000000000000000000000000000000000000000..dcd2b7dc3e0cb890be774fc8b343066b70a8671d --- /dev/null +++ b/src/sc/node/PLe.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLe extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLeb.java b/src/sc/node/PLeb.java new file mode 100644 index 0000000000000000000000000000000000000000..8c1872a7736a2919130fc81c88c01b8c8132fbfc --- /dev/null +++ b/src/sc/node/PLeb.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLeb extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLi.java b/src/sc/node/PLi.java new file mode 100644 index 0000000000000000000000000000000000000000..2cdedc3033971d61a7dd275a85a3bb451da0d43e --- /dev/null +++ b/src/sc/node/PLi.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLi extends Node +{ + // Empty body +} diff --git a/src/sc/node/PLparam.java b/src/sc/node/PLparam.java new file mode 100644 index 0000000000000000000000000000000000000000..9f7ed599522c6edc7b11e2c9bdc1f26e62c4e834 --- /dev/null +++ b/src/sc/node/PLparam.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PLparam extends Node +{ + // Empty body +} diff --git a/src/sc/node/PProgram.java b/src/sc/node/PProgram.java new file mode 100644 index 0000000000000000000000000000000000000000..e6981a37f317cd53977205f63ca724764f59fcfa --- /dev/null +++ b/src/sc/node/PProgram.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PProgram extends Node +{ + // Empty body +} diff --git a/src/sc/node/PT1.java b/src/sc/node/PT1.java new file mode 100644 index 0000000000000000000000000000000000000000..b5a8ca8076b6082650a821499390ef2cc4c6c9d6 --- /dev/null +++ b/src/sc/node/PT1.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PT1 extends Node +{ + // Empty body +} diff --git a/src/sc/node/PT2.java b/src/sc/node/PT2.java new file mode 100644 index 0000000000000000000000000000000000000000..c6a401d60e244c14687844dd611cd4e9430f7971 --- /dev/null +++ b/src/sc/node/PT2.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PT2 extends Node +{ + // Empty body +} diff --git a/src/sc/node/PT3.java b/src/sc/node/PT3.java new file mode 100644 index 0000000000000000000000000000000000000000..b10f281cdffcb9710285a6e8555ec8e033dd516c --- /dev/null +++ b/src/sc/node/PT3.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PT3 extends Node +{ + // Empty body +} diff --git a/src/sc/node/PT4.java b/src/sc/node/PT4.java new file mode 100644 index 0000000000000000000000000000000000000000..492aae3c3f323099dbd0bc597a99777742a89846 --- /dev/null +++ b/src/sc/node/PT4.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PT4 extends Node +{ + // Empty body +} diff --git a/src/sc/node/PT5.java b/src/sc/node/PT5.java new file mode 100644 index 0000000000000000000000000000000000000000..e4fe580a55d7f37b9c1fbf9b8c30168854df8fbe --- /dev/null +++ b/src/sc/node/PT5.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PT5 extends Node +{ + // Empty body +} diff --git a/src/sc/node/PT6.java b/src/sc/node/PT6.java new file mode 100644 index 0000000000000000000000000000000000000000..8d6ab3cef9cccf828d375668fcdd53190f101325 --- /dev/null +++ b/src/sc/node/PT6.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PT6 extends Node +{ + // Empty body +} diff --git a/src/sc/node/PV.java b/src/sc/node/PV.java new file mode 100644 index 0000000000000000000000000000000000000000..9b043530a06b5815540bee05d876bfebb4b39c32 --- /dev/null +++ b/src/sc/node/PV.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public abstract class PV extends Node +{ + // Empty body +} diff --git a/src/sc/node/Start.java b/src/sc/node/Start.java new file mode 100644 index 0000000000000000000000000000000000000000..9383e1d55713156d387a5c25a308ab0a8b16fd8b --- /dev/null +++ b/src/sc/node/Start.java @@ -0,0 +1,133 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class Start extends Node +{ + private PProgram _pProgram_; + private EOF _eof_; + + public Start() + { + // Empty body + } + + public Start( + @SuppressWarnings("hiding") PProgram _pProgram_, + @SuppressWarnings("hiding") EOF _eof_) + { + setPProgram(_pProgram_); + setEOF(_eof_); + } + + @Override + public Object clone() + { + return new Start( + cloneNode(this._pProgram_), + cloneNode(this._eof_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseStart(this); + } + + public PProgram getPProgram() + { + return this._pProgram_; + } + + public void setPProgram(PProgram node) + { + if(this._pProgram_ != null) + { + this._pProgram_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._pProgram_ = node; + } + + public EOF getEOF() + { + return this._eof_; + } + + public void setEOF(EOF node) + { + if(this._eof_ != null) + { + this._eof_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._eof_ = node; + } + + @Override + void removeChild(Node child) + { + if(this._pProgram_ == child) + { + this._pProgram_ = null; + return; + } + + if(this._eof_ == child) + { + this._eof_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(Node oldChild, Node newChild) + { + if(this._pProgram_ == oldChild) + { + setPProgram((PProgram) newChild); + return; + } + + if(this._eof_ == oldChild) + { + setEOF((EOF) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + public String toString() + { + return "" + + toString(this._pProgram_) + + toString(this._eof_); + } +} diff --git a/src/sc/node/Switch.java b/src/sc/node/Switch.java new file mode 100644 index 0000000000000000000000000000000000000000..2930f2485296a6f10657f345cb9217d6a3e882a1 --- /dev/null +++ b/src/sc/node/Switch.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public interface Switch +{ + // Empty body +} diff --git a/src/sc/node/Switchable.java b/src/sc/node/Switchable.java new file mode 100644 index 0000000000000000000000000000000000000000..77de9130c39b04334369a4fa6518e958d039b4d1 --- /dev/null +++ b/src/sc/node/Switchable.java @@ -0,0 +1,8 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +public interface Switchable +{ + void apply(Switch sw); +} diff --git a/src/sc/node/TAccoladeFermante.java b/src/sc/node/TAccoladeFermante.java new file mode 100644 index 0000000000000000000000000000000000000000..68cdcb91c2a220a54bb0dadbbbcc728f88156b96 --- /dev/null +++ b/src/sc/node/TAccoladeFermante.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TAccoladeFermante extends Token +{ + public TAccoladeFermante() + { + super.setText("}"); + } + + public TAccoladeFermante(int line, int pos) + { + super.setText("}"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TAccoladeFermante(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTAccoladeFermante(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TAccoladeFermante text."); + } +} diff --git a/src/sc/node/TAccoladeOuvrante.java b/src/sc/node/TAccoladeOuvrante.java new file mode 100644 index 0000000000000000000000000000000000000000..06f811a7f89ddaf60c4c40c7e8edff224ceea0b0 --- /dev/null +++ b/src/sc/node/TAccoladeOuvrante.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TAccoladeOuvrante extends Token +{ + public TAccoladeOuvrante() + { + super.setText("{"); + } + + public TAccoladeOuvrante(int line, int pos) + { + super.setText("{"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TAccoladeOuvrante(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTAccoladeOuvrante(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TAccoladeOuvrante text."); + } +} diff --git a/src/sc/node/TAlors.java b/src/sc/node/TAlors.java new file mode 100644 index 0000000000000000000000000000000000000000..4a52dde073f93a198726817f13061975a3451c89 --- /dev/null +++ b/src/sc/node/TAlors.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TAlors extends Token +{ + public TAlors() + { + super.setText("alors"); + } + + public TAlors(int line, int pos) + { + super.setText("alors"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TAlors(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTAlors(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TAlors text."); + } +} diff --git a/src/sc/node/TCommentaire.java b/src/sc/node/TCommentaire.java new file mode 100644 index 0000000000000000000000000000000000000000..8f3f09f4722d72150a3f7e220c3bb98db72b26fb --- /dev/null +++ b/src/sc/node/TCommentaire.java @@ -0,0 +1,33 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TCommentaire extends Token +{ + public TCommentaire(String text) + { + setText(text); + } + + public TCommentaire(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TCommentaire(getText(), getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTCommentaire(this); + } +} diff --git a/src/sc/node/TCrochetFermant.java b/src/sc/node/TCrochetFermant.java new file mode 100644 index 0000000000000000000000000000000000000000..b17849f42d21ed52143cb3e89fbf3478ac51cfdb --- /dev/null +++ b/src/sc/node/TCrochetFermant.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TCrochetFermant extends Token +{ + public TCrochetFermant() + { + super.setText("]"); + } + + public TCrochetFermant(int line, int pos) + { + super.setText("]"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TCrochetFermant(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTCrochetFermant(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TCrochetFermant text."); + } +} diff --git a/src/sc/node/TCrochetOuvrant.java b/src/sc/node/TCrochetOuvrant.java new file mode 100644 index 0000000000000000000000000000000000000000..2dc362ead5ff89c7d53396851fa95e0245fe6cfc --- /dev/null +++ b/src/sc/node/TCrochetOuvrant.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TCrochetOuvrant extends Token +{ + public TCrochetOuvrant() + { + super.setText("["); + } + + public TCrochetOuvrant(int line, int pos) + { + super.setText("["); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TCrochetOuvrant(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTCrochetOuvrant(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TCrochetOuvrant text."); + } +} diff --git a/src/sc/node/TDivision.java b/src/sc/node/TDivision.java new file mode 100644 index 0000000000000000000000000000000000000000..c07b88c47bd370f00653a7ad9b9d8e7e234ff272 --- /dev/null +++ b/src/sc/node/TDivision.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TDivision extends Token +{ + public TDivision() + { + super.setText("/"); + } + + public TDivision(int line, int pos) + { + super.setText("/"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TDivision(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTDivision(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TDivision text."); + } +} diff --git a/src/sc/node/TEcrire.java b/src/sc/node/TEcrire.java new file mode 100644 index 0000000000000000000000000000000000000000..dbc474f2c1753c0195d8e776fefa2ac6a4e3070f --- /dev/null +++ b/src/sc/node/TEcrire.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TEcrire extends Token +{ + public TEcrire() + { + super.setText("ecrire"); + } + + public TEcrire(int line, int pos) + { + super.setText("ecrire"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TEcrire(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTEcrire(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TEcrire text."); + } +} diff --git a/src/sc/node/TEgal.java b/src/sc/node/TEgal.java new file mode 100644 index 0000000000000000000000000000000000000000..3bf24b2fb77d8485c9a2adfb66f599fedaa5cb17 --- /dev/null +++ b/src/sc/node/TEgal.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TEgal extends Token +{ + public TEgal() + { + super.setText("="); + } + + public TEgal(int line, int pos) + { + super.setText("="); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TEgal(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTEgal(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TEgal text."); + } +} diff --git a/src/sc/node/TEntier.java b/src/sc/node/TEntier.java new file mode 100644 index 0000000000000000000000000000000000000000..5ad70e46ece00b1ec2c46e8ed36ee2bfdc8828be --- /dev/null +++ b/src/sc/node/TEntier.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TEntier extends Token +{ + public TEntier() + { + super.setText("entier"); + } + + public TEntier(int line, int pos) + { + super.setText("entier"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TEntier(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTEntier(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TEntier text."); + } +} diff --git a/src/sc/node/TEpsilon.java b/src/sc/node/TEpsilon.java new file mode 100644 index 0000000000000000000000000000000000000000..6bde488e2c7dd1746d4e38a444b6d0f0a6c4da98 --- /dev/null +++ b/src/sc/node/TEpsilon.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TEpsilon extends Token +{ + public TEpsilon() + { + super.setText(" "); + } + + public TEpsilon(int line, int pos) + { + super.setText(" "); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TEpsilon(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTEpsilon(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TEpsilon text."); + } +} diff --git a/src/sc/node/TEspaces.java b/src/sc/node/TEspaces.java new file mode 100644 index 0000000000000000000000000000000000000000..409be0cea5c038bc63822c8f36ab783f6e3bff51 --- /dev/null +++ b/src/sc/node/TEspaces.java @@ -0,0 +1,33 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TEspaces extends Token +{ + public TEspaces(String text) + { + setText(text); + } + + public TEspaces(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TEspaces(getText(), getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTEspaces(this); + } +} diff --git a/src/sc/node/TEt.java b/src/sc/node/TEt.java new file mode 100644 index 0000000000000000000000000000000000000000..5fb644396c1d6996075e8a9e98e46f5863e2a71c --- /dev/null +++ b/src/sc/node/TEt.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TEt extends Token +{ + public TEt() + { + super.setText("&"); + } + + public TEt(int line, int pos) + { + super.setText("&"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TEt(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTEt(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TEt text."); + } +} diff --git a/src/sc/node/TFaire.java b/src/sc/node/TFaire.java new file mode 100644 index 0000000000000000000000000000000000000000..afb73feab39b3c981082635918c6a29b7f916459 --- /dev/null +++ b/src/sc/node/TFaire.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TFaire extends Token +{ + public TFaire() + { + super.setText("faire"); + } + + public TFaire(int line, int pos) + { + super.setText("faire"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TFaire(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTFaire(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TFaire text."); + } +} diff --git a/src/sc/node/TIdentif.java b/src/sc/node/TIdentif.java new file mode 100644 index 0000000000000000000000000000000000000000..e224f95f70beff531e1de99c8f748aee3429ae06 --- /dev/null +++ b/src/sc/node/TIdentif.java @@ -0,0 +1,33 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TIdentif extends Token +{ + public TIdentif(String text) + { + setText(text); + } + + public TIdentif(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TIdentif(getText(), getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTIdentif(this); + } +} diff --git a/src/sc/node/TInferieur.java b/src/sc/node/TInferieur.java new file mode 100644 index 0000000000000000000000000000000000000000..2fda2103613a889463b9603c9b2c0886e0b7549a --- /dev/null +++ b/src/sc/node/TInferieur.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TInferieur extends Token +{ + public TInferieur() + { + super.setText("<"); + } + + public TInferieur(int line, int pos) + { + super.setText("<"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TInferieur(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTInferieur(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TInferieur text."); + } +} diff --git a/src/sc/node/TLire.java b/src/sc/node/TLire.java new file mode 100644 index 0000000000000000000000000000000000000000..d945895b09f1a207aa2dbb85d942549f9fcfcfb9 --- /dev/null +++ b/src/sc/node/TLire.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TLire extends Token +{ + public TLire() + { + super.setText("lire"); + } + + public TLire(int line, int pos) + { + super.setText("lire"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TLire(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTLire(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TLire text."); + } +} diff --git a/src/sc/node/TMoins.java b/src/sc/node/TMoins.java new file mode 100644 index 0000000000000000000000000000000000000000..a923ad801677c2ba4dce6adf46d448eb4aa01ba7 --- /dev/null +++ b/src/sc/node/TMoins.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TMoins extends Token +{ + public TMoins() + { + super.setText("-"); + } + + public TMoins(int line, int pos) + { + super.setText("-"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TMoins(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTMoins(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TMoins text."); + } +} diff --git a/src/sc/node/TMultiplication.java b/src/sc/node/TMultiplication.java new file mode 100644 index 0000000000000000000000000000000000000000..9b272a8c171e2646c36144bef186f83444588253 --- /dev/null +++ b/src/sc/node/TMultiplication.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TMultiplication extends Token +{ + public TMultiplication() + { + super.setText("*"); + } + + public TMultiplication(int line, int pos) + { + super.setText("*"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TMultiplication(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTMultiplication(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TMultiplication text."); + } +} diff --git a/src/sc/node/TNombre.java b/src/sc/node/TNombre.java new file mode 100644 index 0000000000000000000000000000000000000000..e9ae42cf44a10e7d6389d024cccd2c693936a394 --- /dev/null +++ b/src/sc/node/TNombre.java @@ -0,0 +1,33 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TNombre extends Token +{ + public TNombre(String text) + { + setText(text); + } + + public TNombre(String text, int line, int pos) + { + setText(text); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TNombre(getText(), getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTNombre(this); + } +} diff --git a/src/sc/node/TNon.java b/src/sc/node/TNon.java new file mode 100644 index 0000000000000000000000000000000000000000..e4bf33d70877ee96b09f0d5ffc979bf1c8247f2f --- /dev/null +++ b/src/sc/node/TNon.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TNon extends Token +{ + public TNon() + { + super.setText("!"); + } + + public TNon(int line, int pos) + { + super.setText("!"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TNon(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTNon(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TNon text."); + } +} diff --git a/src/sc/node/TOu.java b/src/sc/node/TOu.java new file mode 100644 index 0000000000000000000000000000000000000000..b7cf8fb865f52b7edd81df2d00a6613d38512859 --- /dev/null +++ b/src/sc/node/TOu.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TOu extends Token +{ + public TOu() + { + super.setText("|"); + } + + public TOu(int line, int pos) + { + super.setText("|"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TOu(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTOu(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TOu text."); + } +} diff --git a/src/sc/node/TPVirgule.java b/src/sc/node/TPVirgule.java new file mode 100644 index 0000000000000000000000000000000000000000..fe4959fdefd0dfa0264a7fbfe30b001ccde21216 --- /dev/null +++ b/src/sc/node/TPVirgule.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TPVirgule extends Token +{ + public TPVirgule() + { + super.setText(";"); + } + + public TPVirgule(int line, int pos) + { + super.setText(";"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TPVirgule(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTPVirgule(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TPVirgule text."); + } +} diff --git a/src/sc/node/TParentheseFermante.java b/src/sc/node/TParentheseFermante.java new file mode 100644 index 0000000000000000000000000000000000000000..21a59993bad024cafd2fcf1a981ccc778a56e1f5 --- /dev/null +++ b/src/sc/node/TParentheseFermante.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TParentheseFermante extends Token +{ + public TParentheseFermante() + { + super.setText(")"); + } + + public TParentheseFermante(int line, int pos) + { + super.setText(")"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TParentheseFermante(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTParentheseFermante(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TParentheseFermante text."); + } +} diff --git a/src/sc/node/TParentheseOuvrante.java b/src/sc/node/TParentheseOuvrante.java new file mode 100644 index 0000000000000000000000000000000000000000..fe01b93193ff0863df3f3073cb8bd0beedc730f2 --- /dev/null +++ b/src/sc/node/TParentheseOuvrante.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TParentheseOuvrante extends Token +{ + public TParentheseOuvrante() + { + super.setText("("); + } + + public TParentheseOuvrante(int line, int pos) + { + super.setText("("); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TParentheseOuvrante(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTParentheseOuvrante(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TParentheseOuvrante text."); + } +} diff --git a/src/sc/node/TPlus.java b/src/sc/node/TPlus.java new file mode 100644 index 0000000000000000000000000000000000000000..3eed3bd535d79f6bc0e5f82a3fbd9b61473b5bde --- /dev/null +++ b/src/sc/node/TPlus.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TPlus extends Token +{ + public TPlus() + { + super.setText("+"); + } + + public TPlus(int line, int pos) + { + super.setText("+"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TPlus(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTPlus(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TPlus text."); + } +} diff --git a/src/sc/node/TRetour.java b/src/sc/node/TRetour.java new file mode 100644 index 0000000000000000000000000000000000000000..4a411eced9373ba142fadd5867896a0674cd0da0 --- /dev/null +++ b/src/sc/node/TRetour.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TRetour extends Token +{ + public TRetour() + { + super.setText("retour"); + } + + public TRetour(int line, int pos) + { + super.setText("retour"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TRetour(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTRetour(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TRetour text."); + } +} diff --git a/src/sc/node/TSi.java b/src/sc/node/TSi.java new file mode 100644 index 0000000000000000000000000000000000000000..f505335f63824ce25dcdcb297a86e37ab340f036 --- /dev/null +++ b/src/sc/node/TSi.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TSi extends Token +{ + public TSi() + { + super.setText("si"); + } + + public TSi(int line, int pos) + { + super.setText("si"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TSi(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTSi(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TSi text."); + } +} diff --git a/src/sc/node/TSinon.java b/src/sc/node/TSinon.java new file mode 100644 index 0000000000000000000000000000000000000000..07c38e977a96af688cb51aa8ab730b88cbefcba3 --- /dev/null +++ b/src/sc/node/TSinon.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TSinon extends Token +{ + public TSinon() + { + super.setText("sinon"); + } + + public TSinon(int line, int pos) + { + super.setText("sinon"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TSinon(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTSinon(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TSinon text."); + } +} diff --git a/src/sc/node/TTantque.java b/src/sc/node/TTantque.java new file mode 100644 index 0000000000000000000000000000000000000000..db81842e68753e23c94363d987cf5e3c766ed137 --- /dev/null +++ b/src/sc/node/TTantque.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TTantque extends Token +{ + public TTantque() + { + super.setText("tantque"); + } + + public TTantque(int line, int pos) + { + super.setText("tantque"); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TTantque(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTTantque(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TTantque text."); + } +} diff --git a/src/sc/node/TVirgule.java b/src/sc/node/TVirgule.java new file mode 100644 index 0000000000000000000000000000000000000000..dfa69cc130c5dd9a512290abb1f068f358e4ab7d --- /dev/null +++ b/src/sc/node/TVirgule.java @@ -0,0 +1,39 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +import sc.analysis.*; + +@SuppressWarnings("nls") +public final class TVirgule extends Token +{ + public TVirgule() + { + super.setText(","); + } + + public TVirgule(int line, int pos) + { + super.setText(","); + setLine(line); + setPos(pos); + } + + @Override + public Object clone() + { + return new TVirgule(getLine(), getPos()); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseTVirgule(this); + } + + @Override + public void setText(@SuppressWarnings("unused") String text) + { + throw new RuntimeException("Cannot change TVirgule text."); + } +} diff --git a/src/sc/node/Token.java b/src/sc/node/Token.java new file mode 100644 index 0000000000000000000000000000000000000000..153b75080a4b842650bc80e6597ab9dcad50a6c5 --- /dev/null +++ b/src/sc/node/Token.java @@ -0,0 +1,59 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.node; + +@SuppressWarnings("nls") +public abstract class Token extends Node +{ + private String text; + private int line; + private int pos; + + public String getText() + { + return this.text; + } + + public void setText(@SuppressWarnings("hiding") String text) + { + this.text = text; + } + + public int getLine() + { + return this.line; + } + + public void setLine(@SuppressWarnings("hiding") int line) + { + this.line = line; + } + + public int getPos() + { + return this.pos; + } + + public void setPos(@SuppressWarnings("hiding") int pos) + { + this.pos = pos; + } + + @Override + public String toString() + { + return this.text + " "; + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + throw new RuntimeException("Not a child."); + } +} diff --git a/src/sc/parser/Parser.java b/src/sc/parser/Parser.java new file mode 100644 index 0000000000000000000000000000000000000000..8b7fabdeeb6b8a0f9c661d9450e635fd9fa85667 --- /dev/null +++ b/src/sc/parser/Parser.java @@ -0,0 +1,2068 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.parser; + +import sc.lexer.*; +import sc.node.*; +import sc.analysis.*; +import java.util.*; + +import java.io.DataInputStream; +import java.io.BufferedInputStream; +import java.io.IOException; + +@SuppressWarnings("nls") +public class Parser +{ + public final Analysis ignoredTokens = new AnalysisAdapter(); + + protected ArrayList<Object> nodeList; + + private final Lexer lexer; + private final ListIterator<Object> stack = new LinkedList<Object>().listIterator(); + private int last_pos; + private int last_line; + private Token last_token; + private final TokenIndex converter = new TokenIndex(); + private final int[] action = new int[2]; + + private final static int SHIFT = 0; + private final static int REDUCE = 1; + private final static int ACCEPT = 2; + private final static int ERROR = 3; + + public Parser(@SuppressWarnings("hiding") Lexer lexer) + { + this.lexer = lexer; + } + + protected void filter() throws ParserException, LexerException, IOException + { + // Empty body + } + + private void push(int numstate, ArrayList<Object> listNode, boolean hidden) throws ParserException, LexerException, IOException + { + this.nodeList = listNode; + + if(!hidden) + { + filter(); + } + + if(!this.stack.hasNext()) + { + this.stack.add(new State(numstate, this.nodeList)); + return; + } + + State s = (State) this.stack.next(); + s.state = numstate; + s.nodes = this.nodeList; + } + + private int goTo(int index) + { + int state = state(); + int low = 1; + int high = gotoTable[index].length - 1; + int value = gotoTable[index][0][1]; + + while(low <= high) + { + // int middle = (low + high) / 2; + int middle = (low + high) >>> 1; + + if(state < gotoTable[index][middle][0]) + { + high = middle - 1; + } + else if(state > gotoTable[index][middle][0]) + { + low = middle + 1; + } + else + { + value = gotoTable[index][middle][1]; + break; + } + } + + return value; + } + + private int state() + { + State s = (State) this.stack.previous(); + this.stack.next(); + return s.state; + } + + private ArrayList<Object> pop() + { + return ((State) this.stack.previous()).nodes; + } + + private int index(Switchable token) + { + this.converter.index = -1; + token.apply(this.converter); + return this.converter.index; + } + + @SuppressWarnings("unchecked") + public Start parse() throws ParserException, LexerException, IOException + { + push(0, null, true); + List<Node> ign = null; + while(true) + { + while(index(this.lexer.peek()) == -1) + { + if(ign == null) + { + ign = new LinkedList<Node>(); + } + + ign.add(this.lexer.next()); + } + + if(ign != null) + { + this.ignoredTokens.setIn(this.lexer.peek(), ign); + ign = null; + } + + this.last_pos = this.lexer.peek().getPos(); + this.last_line = this.lexer.peek().getLine(); + this.last_token = this.lexer.peek(); + + int index = index(this.lexer.peek()); + this.action[0] = Parser.actionTable[state()][0][1]; + this.action[1] = Parser.actionTable[state()][0][2]; + + int low = 1; + int high = Parser.actionTable[state()].length - 1; + + while(low <= high) + { + int middle = (low + high) / 2; + + if(index < Parser.actionTable[state()][middle][0]) + { + high = middle - 1; + } + else if(index > Parser.actionTable[state()][middle][0]) + { + low = middle + 1; + } + else + { + this.action[0] = Parser.actionTable[state()][middle][1]; + this.action[1] = Parser.actionTable[state()][middle][2]; + break; + } + } + + switch(this.action[0]) + { + case SHIFT: + { + ArrayList<Object> list = new ArrayList<Object>(); + list.add(this.lexer.next()); + push(this.action[1], list, false); + } + break; + case REDUCE: + { + int reduction = this.action[1]; + if(reduction < 500) reduce_0(reduction); + } + break; + case ACCEPT: + { + EOF node2 = (EOF) this.lexer.next(); + PProgram node1 = (PProgram) pop().get(0); + Start node = new Start(node1, node2); + return node; + } + case ERROR: + throw new ParserException(this.last_token, + "[" + this.last_line + "," + this.last_pos + "] " + + Parser.errorMessages[Parser.errors[this.action[1]]]); + } + } + } + + private void reduce_0(int reduction) throws IOException, LexerException, ParserException + { + switch(reduction) + { + case 0: /* reduce AProgramProgram */ + { + ArrayList<Object> list = new0(); + push(goTo(0), list, false); + } + break; + case 1: /* reduce ALdvoLdvo */ + { + ArrayList<Object> list = new1(); + push(goTo(1), list, false); + } + break; + case 2: /* reduce AEpsilonLdvo */ + { + ArrayList<Object> list = new2(); + push(goTo(1), list, false); + } + break; + case 3: /* reduce ALDvLdv */ + { + ArrayList<Object> list = new3(); + push(goTo(2), list, false); + } + break; + case 4: /* reduce AEpsilonLdv */ + { + ArrayList<Object> list = new4(); + push(goTo(2), list, false); + } + break; + case 5: /* reduce ADecVarDv */ + { + ArrayList<Object> list = new5(); + push(goTo(3), list, false); + } + break; + case 6: /* reduce ADecVar2Dv */ + { + ArrayList<Object> list = new6(); + push(goTo(3), list, false); + } + break; + case 7: /* reduce ALDvbLdvb */ + { + ArrayList<Object> list = new7(); + push(goTo(4), list, false); + } + break; + case 8: /* reduce AEpsilonLdvb */ + { + ArrayList<Object> list = new8(); + push(goTo(4), list, false); + } + break; + case 9: /* reduce ALdfLdf */ + { + ArrayList<Object> list = new9(); + push(goTo(5), list, false); + } + break; + case 10: /* reduce AEpsilonLdf */ + { + ArrayList<Object> list = new10(); + push(goTo(5), list, false); + } + break; + case 11: /* reduce ADfDf */ + { + ArrayList<Object> list = new11(); + push(goTo(6), list, false); + } + break; + case 12: /* reduce AParamsLparam */ + { + ArrayList<Object> list = new12(); + push(goTo(7), list, false); + } + break; + case 13: /* reduce AIblocIb */ + { + ArrayList<Object> list = new13(); + push(goTo(8), list, false); + } + break; + case 14: /* reduce AListeILi */ + { + ArrayList<Object> list = new14(); + push(goTo(9), list, false); + } + break; + case 15: /* reduce AEpsilonLi */ + { + ArrayList<Object> list = new15(); + push(goTo(9), list, false); + } + break; + case 16: /* reduce AIAffI */ + { + ArrayList<Object> list = new16(); + push(goTo(10), list, false); + } + break; + case 17: /* reduce AISiI */ + { + ArrayList<Object> list = new17(); + push(goTo(10), list, false); + } + break; + case 18: /* reduce AITqI */ + { + ArrayList<Object> list = new18(); + push(goTo(10), list, false); + } + break; + case 19: /* reduce AIRetI */ + { + ArrayList<Object> list = new19(); + push(goTo(10), list, false); + } + break; + case 20: /* reduce AIAppI */ + { + ArrayList<Object> list = new20(); + push(goTo(10), list, false); + } + break; + case 21: /* reduce AIEcrI */ + { + ArrayList<Object> list = new21(); + push(goTo(10), list, false); + } + break; + case 22: /* reduce AAffectationIaffectation */ + { + ArrayList<Object> list = new22(); + push(goTo(11), list, false); + } + break; + case 23: /* reduce AIdV */ + { + ArrayList<Object> list = new23(); + push(goTo(12), list, false); + } + break; + case 24: /* reduce AIdtabV */ + { + ArrayList<Object> list = new24(); + push(goTo(12), list, false); + } + break; + case 25: /* reduce AT1Expression */ + { + ArrayList<Object> list = new25(); + push(goTo(13), list, false); + } + break; + case 26: /* reduce AOuExpression */ + { + ArrayList<Object> list = new26(); + push(goTo(13), list, false); + } + break; + case 27: /* reduce AT2T1 */ + { + ArrayList<Object> list = new27(); + push(goTo(14), list, false); + } + break; + case 28: /* reduce AEtT1 */ + { + ArrayList<Object> list = new28(); + push(goTo(14), list, false); + } + break; + case 29: /* reduce AT3T2 */ + { + ArrayList<Object> list = new29(); + push(goTo(15), list, false); + } + break; + case 30: /* reduce AEgalT2 */ + { + ArrayList<Object> list = new30(); + push(goTo(15), list, false); + } + break; + case 31: /* reduce AInferieurT2 */ + { + ArrayList<Object> list = new31(); + push(goTo(15), list, false); + } + break; + case 32: /* reduce AT4T3 */ + { + ArrayList<Object> list = new32(); + push(goTo(16), list, false); + } + break; + case 33: /* reduce APlusT3 */ + { + ArrayList<Object> list = new33(); + push(goTo(16), list, false); + } + break; + case 34: /* reduce AMoinsT3 */ + { + ArrayList<Object> list = new34(); + push(goTo(16), list, false); + } + break; + case 35: /* reduce AT5T4 */ + { + ArrayList<Object> list = new35(); + push(goTo(17), list, false); + } + break; + case 36: /* reduce AMultiplicationT4 */ + { + ArrayList<Object> list = new36(); + push(goTo(17), list, false); + } + break; + case 37: /* reduce ADivisionT4 */ + { + ArrayList<Object> list = new37(); + push(goTo(17), list, false); + } + break; + case 38: /* reduce AT6T5 */ + { + ArrayList<Object> list = new38(); + push(goTo(18), list, false); + } + break; + case 39: /* reduce ANonT5 */ + { + ArrayList<Object> list = new39(); + push(goTo(18), list, false); + } + break; + case 40: /* reduce AExpressionT6 */ + { + ArrayList<Object> list = new40(); + push(goTo(19), list, false); + } + break; + case 41: /* reduce AX1T6 */ + { + ArrayList<Object> list = new41(); + push(goTo(19), list, false); + } + break; + case 42: /* reduce AX2T6 */ + { + ArrayList<Object> list = new42(); + push(goTo(19), list, false); + } + break; + case 43: /* reduce AAppT6 */ + { + ArrayList<Object> list = new43(); + push(goTo(19), list, false); + } + break; + case 44: /* reduce AAppel */ + { + ArrayList<Object> list = new44(); + push(goTo(20), list, false); + } + break; + case 45: /* reduce AListeExpLe */ + { + ArrayList<Object> list = new45(); + push(goTo(21), list, false); + } + break; + case 46: /* reduce AEpsilonLe */ + { + ArrayList<Object> list = new46(); + push(goTo(21), list, false); + } + break; + case 47: /* reduce AListeExpBLeb */ + { + ArrayList<Object> list = new47(); + push(goTo(22), list, false); + } + break; + case 48: /* reduce AEpsilonLeb */ + { + ArrayList<Object> list = new48(); + push(goTo(22), list, false); + } + break; + case 49: /* reduce ASiIsi */ + { + ArrayList<Object> list = new49(); + push(goTo(23), list, false); + } + break; + case 50: /* reduce ASisinonIsi */ + { + ArrayList<Object> list = new50(); + push(goTo(23), list, false); + } + break; + case 51: /* reduce ATantqueItantque */ + { + ArrayList<Object> list = new51(); + push(goTo(24), list, false); + } + break; + case 52: /* reduce ARetournerIret */ + { + ArrayList<Object> list = new52(); + push(goTo(25), list, false); + } + break; + case 53: /* reduce AIappelIappel */ + { + ArrayList<Object> list = new53(); + push(goTo(26), list, false); + } + break; + case 54: /* reduce AIecrireIecrire */ + { + ArrayList<Object> list = new54(); + push(goTo(27), list, false); + } + break; + } + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new0() /* reduce AProgramProgram */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PProgram pprogramNode1; + { + // Block + PLdvo pldvoNode2; + PLdf pldfNode3; + pldvoNode2 = (PLdvo)nodeArrayList1.get(0); + pldfNode3 = (PLdf)nodeArrayList2.get(0); + + pprogramNode1 = new AProgramProgram(pldvoNode2, pldfNode3); + } + nodeList.add(pprogramNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new1() /* reduce ALdvoLdvo */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLdvo pldvoNode1; + { + // Block + PLdv pldvNode2; + TPVirgule tpvirguleNode3; + pldvNode2 = (PLdv)nodeArrayList1.get(0); + tpvirguleNode3 = (TPVirgule)nodeArrayList2.get(0); + + pldvoNode1 = new ALdvoLdvo(pldvNode2, tpvirguleNode3); + } + nodeList.add(pldvoNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new2() /* reduce AEpsilonLdvo */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLdvo pldvoNode1; + { + // Block + + pldvoNode1 = new AEpsilonLdvo(); + } + nodeList.add(pldvoNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new3() /* reduce ALDvLdv */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLdv pldvNode1; + { + // Block + PDv pdvNode2; + PLdvb pldvbNode3; + pdvNode2 = (PDv)nodeArrayList1.get(0); + pldvbNode3 = (PLdvb)nodeArrayList2.get(0); + + pldvNode1 = new ALDvLdv(pdvNode2, pldvbNode3); + } + nodeList.add(pldvNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new4() /* reduce AEpsilonLdv */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLdv pldvNode1; + { + // Block + + pldvNode1 = new AEpsilonLdv(); + } + nodeList.add(pldvNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new5() /* reduce ADecVarDv */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PDv pdvNode1; + { + // Block + TEntier tentierNode2; + TIdentif tidentifNode3; + tentierNode2 = (TEntier)nodeArrayList1.get(0); + tidentifNode3 = (TIdentif)nodeArrayList2.get(0); + + pdvNode1 = new ADecVarDv(tentierNode2, tidentifNode3); + } + nodeList.add(pdvNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new6() /* reduce ADecVar2Dv */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList5 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PDv pdvNode1; + { + // Block + TEntier tentierNode2; + TIdentif tidentifNode3; + TCrochetOuvrant tcrochetouvrantNode4; + TNombre tnombreNode5; + TCrochetFermant tcrochetfermantNode6; + tentierNode2 = (TEntier)nodeArrayList1.get(0); + tidentifNode3 = (TIdentif)nodeArrayList2.get(0); + tcrochetouvrantNode4 = (TCrochetOuvrant)nodeArrayList3.get(0); + tnombreNode5 = (TNombre)nodeArrayList4.get(0); + tcrochetfermantNode6 = (TCrochetFermant)nodeArrayList5.get(0); + + pdvNode1 = new ADecVar2Dv(tentierNode2, tidentifNode3, tcrochetouvrantNode4, tnombreNode5, tcrochetfermantNode6); + } + nodeList.add(pdvNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new7() /* reduce ALDvbLdvb */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLdvb pldvbNode1; + { + // Block + TVirgule tvirguleNode2; + PDv pdvNode3; + PLdvb pldvbNode4; + tvirguleNode2 = (TVirgule)nodeArrayList1.get(0); + pdvNode3 = (PDv)nodeArrayList2.get(0); + pldvbNode4 = (PLdvb)nodeArrayList3.get(0); + + pldvbNode1 = new ALDvbLdvb(tvirguleNode2, pdvNode3, pldvbNode4); + } + nodeList.add(pldvbNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new8() /* reduce AEpsilonLdvb */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLdvb pldvbNode1; + { + // Block + + pldvbNode1 = new AEpsilonLdvb(); + } + nodeList.add(pldvbNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new9() /* reduce ALdfLdf */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLdf pldfNode1; + { + // Block + PDf pdfNode2; + PLdf pldfNode3; + pdfNode2 = (PDf)nodeArrayList1.get(0); + pldfNode3 = (PLdf)nodeArrayList2.get(0); + + pldfNode1 = new ALdfLdf(pdfNode2, pldfNode3); + } + nodeList.add(pldfNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new10() /* reduce AEpsilonLdf */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLdf pldfNode1; + { + // Block + + pldfNode1 = new AEpsilonLdf(); + } + nodeList.add(pldfNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new11() /* reduce ADfDf */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PDf pdfNode1; + { + // Block + TIdentif tidentifNode2; + PLparam plparamNode3; + PLdvo pldvoNode4; + PIb pibNode5; + tidentifNode2 = (TIdentif)nodeArrayList1.get(0); + plparamNode3 = (PLparam)nodeArrayList2.get(0); + pldvoNode4 = (PLdvo)nodeArrayList3.get(0); + pibNode5 = (PIb)nodeArrayList4.get(0); + + pdfNode1 = new ADfDf(tidentifNode2, plparamNode3, pldvoNode4, pibNode5); + } + nodeList.add(pdfNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new12() /* reduce AParamsLparam */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLparam plparamNode1; + { + // Block + TParentheseOuvrante tparentheseouvranteNode2; + PLdv pldvNode3; + TParentheseFermante tparenthesefermanteNode4; + tparentheseouvranteNode2 = (TParentheseOuvrante)nodeArrayList1.get(0); + pldvNode3 = (PLdv)nodeArrayList2.get(0); + tparenthesefermanteNode4 = (TParentheseFermante)nodeArrayList3.get(0); + + plparamNode1 = new AParamsLparam(tparentheseouvranteNode2, pldvNode3, tparenthesefermanteNode4); + } + nodeList.add(plparamNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new13() /* reduce AIblocIb */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIb pibNode1; + { + // Block + TAccoladeOuvrante taccoladeouvranteNode2; + PLi pliNode3; + TAccoladeFermante taccoladefermanteNode4; + taccoladeouvranteNode2 = (TAccoladeOuvrante)nodeArrayList1.get(0); + pliNode3 = (PLi)nodeArrayList2.get(0); + taccoladefermanteNode4 = (TAccoladeFermante)nodeArrayList3.get(0); + + pibNode1 = new AIblocIb(taccoladeouvranteNode2, pliNode3, taccoladefermanteNode4); + } + nodeList.add(pibNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new14() /* reduce AListeILi */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLi pliNode1; + { + // Block + PI piNode2; + PLi pliNode3; + piNode2 = (PI)nodeArrayList1.get(0); + pliNode3 = (PLi)nodeArrayList2.get(0); + + pliNode1 = new AListeILi(piNode2, pliNode3); + } + nodeList.add(pliNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new15() /* reduce AEpsilonLi */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLi pliNode1; + { + // Block + + pliNode1 = new AEpsilonLi(); + } + nodeList.add(pliNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new16() /* reduce AIAffI */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PI piNode1; + { + // Block + PIaffectation piaffectationNode2; + piaffectationNode2 = (PIaffectation)nodeArrayList1.get(0); + + piNode1 = new AIAffI(piaffectationNode2); + } + nodeList.add(piNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new17() /* reduce AISiI */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PI piNode1; + { + // Block + PIsi pisiNode2; + pisiNode2 = (PIsi)nodeArrayList1.get(0); + + piNode1 = new AISiI(pisiNode2); + } + nodeList.add(piNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new18() /* reduce AITqI */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PI piNode1; + { + // Block + PItantque pitantqueNode2; + pitantqueNode2 = (PItantque)nodeArrayList1.get(0); + + piNode1 = new AITqI(pitantqueNode2); + } + nodeList.add(piNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new19() /* reduce AIRetI */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PI piNode1; + { + // Block + PIret piretNode2; + piretNode2 = (PIret)nodeArrayList1.get(0); + + piNode1 = new AIRetI(piretNode2); + } + nodeList.add(piNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new20() /* reduce AIAppI */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PI piNode1; + { + // Block + PIappel piappelNode2; + piappelNode2 = (PIappel)nodeArrayList1.get(0); + + piNode1 = new AIAppI(piappelNode2); + } + nodeList.add(piNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new21() /* reduce AIEcrI */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PI piNode1; + { + // Block + PIecrire piecrireNode2; + piecrireNode2 = (PIecrire)nodeArrayList1.get(0); + + piNode1 = new AIEcrI(piecrireNode2); + } + nodeList.add(piNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new22() /* reduce AAffectationIaffectation */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIaffectation piaffectationNode1; + { + // Block + PV pvNode2; + TEgal tegalNode3; + PExpression pexpressionNode4; + TPVirgule tpvirguleNode5; + pvNode2 = (PV)nodeArrayList1.get(0); + tegalNode3 = (TEgal)nodeArrayList2.get(0); + pexpressionNode4 = (PExpression)nodeArrayList3.get(0); + tpvirguleNode5 = (TPVirgule)nodeArrayList4.get(0); + + piaffectationNode1 = new AAffectationIaffectation(pvNode2, tegalNode3, pexpressionNode4, tpvirguleNode5); + } + nodeList.add(piaffectationNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new23() /* reduce AIdV */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PV pvNode1; + { + // Block + TIdentif tidentifNode2; + tidentifNode2 = (TIdentif)nodeArrayList1.get(0); + + pvNode1 = new AIdV(tidentifNode2); + } + nodeList.add(pvNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new24() /* reduce AIdtabV */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PV pvNode1; + { + // Block + TIdentif tidentifNode2; + TCrochetOuvrant tcrochetouvrantNode3; + PExpression pexpressionNode4; + TCrochetFermant tcrochetfermantNode5; + tidentifNode2 = (TIdentif)nodeArrayList1.get(0); + tcrochetouvrantNode3 = (TCrochetOuvrant)nodeArrayList2.get(0); + pexpressionNode4 = (PExpression)nodeArrayList3.get(0); + tcrochetfermantNode5 = (TCrochetFermant)nodeArrayList4.get(0); + + pvNode1 = new AIdtabV(tidentifNode2, tcrochetouvrantNode3, pexpressionNode4, tcrochetfermantNode5); + } + nodeList.add(pvNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new25() /* reduce AT1Expression */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PExpression pexpressionNode1; + { + // Block + PT1 pt1Node2; + pt1Node2 = (PT1)nodeArrayList1.get(0); + + pexpressionNode1 = new AT1Expression(pt1Node2); + } + nodeList.add(pexpressionNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new26() /* reduce AOuExpression */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PExpression pexpressionNode1; + { + // Block + PExpression pexpressionNode2; + TOu touNode3; + PT1 pt1Node4; + pexpressionNode2 = (PExpression)nodeArrayList1.get(0); + touNode3 = (TOu)nodeArrayList2.get(0); + pt1Node4 = (PT1)nodeArrayList3.get(0); + + pexpressionNode1 = new AOuExpression(pexpressionNode2, touNode3, pt1Node4); + } + nodeList.add(pexpressionNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new27() /* reduce AT2T1 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT1 pt1Node1; + { + // Block + PT2 pt2Node2; + pt2Node2 = (PT2)nodeArrayList1.get(0); + + pt1Node1 = new AT2T1(pt2Node2); + } + nodeList.add(pt1Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new28() /* reduce AEtT1 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT1 pt1Node1; + { + // Block + PT1 pt1Node2; + TEt tetNode3; + PT2 pt2Node4; + pt1Node2 = (PT1)nodeArrayList1.get(0); + tetNode3 = (TEt)nodeArrayList2.get(0); + pt2Node4 = (PT2)nodeArrayList3.get(0); + + pt1Node1 = new AEtT1(pt1Node2, tetNode3, pt2Node4); + } + nodeList.add(pt1Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new29() /* reduce AT3T2 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT2 pt2Node1; + { + // Block + PT3 pt3Node2; + pt3Node2 = (PT3)nodeArrayList1.get(0); + + pt2Node1 = new AT3T2(pt3Node2); + } + nodeList.add(pt2Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new30() /* reduce AEgalT2 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT2 pt2Node1; + { + // Block + PT2 pt2Node2; + TEgal tegalNode3; + PT3 pt3Node4; + pt2Node2 = (PT2)nodeArrayList1.get(0); + tegalNode3 = (TEgal)nodeArrayList2.get(0); + pt3Node4 = (PT3)nodeArrayList3.get(0); + + pt2Node1 = new AEgalT2(pt2Node2, tegalNode3, pt3Node4); + } + nodeList.add(pt2Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new31() /* reduce AInferieurT2 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT2 pt2Node1; + { + // Block + PT2 pt2Node2; + TInferieur tinferieurNode3; + PT3 pt3Node4; + pt2Node2 = (PT2)nodeArrayList1.get(0); + tinferieurNode3 = (TInferieur)nodeArrayList2.get(0); + pt3Node4 = (PT3)nodeArrayList3.get(0); + + pt2Node1 = new AInferieurT2(pt2Node2, tinferieurNode3, pt3Node4); + } + nodeList.add(pt2Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new32() /* reduce AT4T3 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT3 pt3Node1; + { + // Block + PT4 pt4Node2; + pt4Node2 = (PT4)nodeArrayList1.get(0); + + pt3Node1 = new AT4T3(pt4Node2); + } + nodeList.add(pt3Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new33() /* reduce APlusT3 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT3 pt3Node1; + { + // Block + PT3 pt3Node2; + TPlus tplusNode3; + PT4 pt4Node4; + pt3Node2 = (PT3)nodeArrayList1.get(0); + tplusNode3 = (TPlus)nodeArrayList2.get(0); + pt4Node4 = (PT4)nodeArrayList3.get(0); + + pt3Node1 = new APlusT3(pt3Node2, tplusNode3, pt4Node4); + } + nodeList.add(pt3Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new34() /* reduce AMoinsT3 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT3 pt3Node1; + { + // Block + PT3 pt3Node2; + TMoins tmoinsNode3; + PT4 pt4Node4; + pt3Node2 = (PT3)nodeArrayList1.get(0); + tmoinsNode3 = (TMoins)nodeArrayList2.get(0); + pt4Node4 = (PT4)nodeArrayList3.get(0); + + pt3Node1 = new AMoinsT3(pt3Node2, tmoinsNode3, pt4Node4); + } + nodeList.add(pt3Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new35() /* reduce AT5T4 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT4 pt4Node1; + { + // Block + PT5 pt5Node2; + pt5Node2 = (PT5)nodeArrayList1.get(0); + + pt4Node1 = new AT5T4(pt5Node2); + } + nodeList.add(pt4Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new36() /* reduce AMultiplicationT4 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT4 pt4Node1; + { + // Block + PT4 pt4Node2; + TMultiplication tmultiplicationNode3; + PT5 pt5Node4; + pt4Node2 = (PT4)nodeArrayList1.get(0); + tmultiplicationNode3 = (TMultiplication)nodeArrayList2.get(0); + pt5Node4 = (PT5)nodeArrayList3.get(0); + + pt4Node1 = new AMultiplicationT4(pt4Node2, tmultiplicationNode3, pt5Node4); + } + nodeList.add(pt4Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new37() /* reduce ADivisionT4 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT4 pt4Node1; + { + // Block + PT4 pt4Node2; + TDivision tdivisionNode3; + PT5 pt5Node4; + pt4Node2 = (PT4)nodeArrayList1.get(0); + tdivisionNode3 = (TDivision)nodeArrayList2.get(0); + pt5Node4 = (PT5)nodeArrayList3.get(0); + + pt4Node1 = new ADivisionT4(pt4Node2, tdivisionNode3, pt5Node4); + } + nodeList.add(pt4Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new38() /* reduce AT6T5 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT5 pt5Node1; + { + // Block + PT6 pt6Node2; + pt6Node2 = (PT6)nodeArrayList1.get(0); + + pt5Node1 = new AT6T5(pt6Node2); + } + nodeList.add(pt5Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new39() /* reduce ANonT5 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT5 pt5Node1; + { + // Block + TNon tnonNode2; + PT5 pt5Node3; + tnonNode2 = (TNon)nodeArrayList1.get(0); + pt5Node3 = (PT5)nodeArrayList2.get(0); + + pt5Node1 = new ANonT5(tnonNode2, pt5Node3); + } + nodeList.add(pt5Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new40() /* reduce AExpressionT6 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT6 pt6Node1; + { + // Block + TParentheseOuvrante tparentheseouvranteNode2; + PExpression pexpressionNode3; + TParentheseFermante tparenthesefermanteNode4; + tparentheseouvranteNode2 = (TParentheseOuvrante)nodeArrayList1.get(0); + pexpressionNode3 = (PExpression)nodeArrayList2.get(0); + tparenthesefermanteNode4 = (TParentheseFermante)nodeArrayList3.get(0); + + pt6Node1 = new AExpressionT6(tparentheseouvranteNode2, pexpressionNode3, tparenthesefermanteNode4); + } + nodeList.add(pt6Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new41() /* reduce AX1T6 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT6 pt6Node1; + { + // Block + TNombre tnombreNode2; + tnombreNode2 = (TNombre)nodeArrayList1.get(0); + + pt6Node1 = new AX1T6(tnombreNode2); + } + nodeList.add(pt6Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new42() /* reduce AX2T6 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT6 pt6Node1; + { + // Block + PV pvNode2; + pvNode2 = (PV)nodeArrayList1.get(0); + + pt6Node1 = new AX2T6(pvNode2); + } + nodeList.add(pt6Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new43() /* reduce AAppT6 */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PT6 pt6Node1; + { + // Block + PAppel pappelNode2; + pappelNode2 = (PAppel)nodeArrayList1.get(0); + + pt6Node1 = new AAppT6(pappelNode2); + } + nodeList.add(pt6Node1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new44() /* reduce AAppel */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PAppel pappelNode1; + { + // Block + TIdentif tidentifNode2; + TParentheseOuvrante tparentheseouvranteNode3; + PLe pleNode4; + TParentheseFermante tparenthesefermanteNode5; + tidentifNode2 = (TIdentif)nodeArrayList1.get(0); + tparentheseouvranteNode3 = (TParentheseOuvrante)nodeArrayList2.get(0); + pleNode4 = (PLe)nodeArrayList3.get(0); + tparenthesefermanteNode5 = (TParentheseFermante)nodeArrayList4.get(0); + + pappelNode1 = new AAppel(tidentifNode2, tparentheseouvranteNode3, pleNode4, tparenthesefermanteNode5); + } + nodeList.add(pappelNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new45() /* reduce AListeExpLe */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLe pleNode1; + { + // Block + PExpression pexpressionNode2; + PLeb plebNode3; + pexpressionNode2 = (PExpression)nodeArrayList1.get(0); + plebNode3 = (PLeb)nodeArrayList2.get(0); + + pleNode1 = new AListeExpLe(pexpressionNode2, plebNode3); + } + nodeList.add(pleNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new46() /* reduce AEpsilonLe */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLe pleNode1; + { + // Block + + pleNode1 = new AEpsilonLe(); + } + nodeList.add(pleNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new47() /* reduce AListeExpBLeb */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PLeb plebNode1; + { + // Block + TVirgule tvirguleNode2; + PExpression pexpressionNode3; + PLeb plebNode4; + tvirguleNode2 = (TVirgule)nodeArrayList1.get(0); + pexpressionNode3 = (PExpression)nodeArrayList2.get(0); + plebNode4 = (PLeb)nodeArrayList3.get(0); + + plebNode1 = new AListeExpBLeb(tvirguleNode2, pexpressionNode3, plebNode4); + } + nodeList.add(plebNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new48() /* reduce AEpsilonLeb */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + PLeb plebNode1; + { + // Block + + plebNode1 = new AEpsilonLeb(); + } + nodeList.add(plebNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new49() /* reduce ASiIsi */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIsi pisiNode1; + { + // Block + TSi tsiNode2; + PExpression pexpressionNode3; + TAlors talorsNode4; + PIb pibNode5; + tsiNode2 = (TSi)nodeArrayList1.get(0); + pexpressionNode3 = (PExpression)nodeArrayList2.get(0); + talorsNode4 = (TAlors)nodeArrayList3.get(0); + pibNode5 = (PIb)nodeArrayList4.get(0); + + pisiNode1 = new ASiIsi(tsiNode2, pexpressionNode3, talorsNode4, pibNode5); + } + nodeList.add(pisiNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new50() /* reduce ASisinonIsi */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList6 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList5 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIsi pisiNode1; + { + // Block + TSi tsiNode2; + PExpression pexpressionNode3; + TAlors talorsNode4; + PIb pibNode5; + TSinon tsinonNode6; + PIb pibNode7; + tsiNode2 = (TSi)nodeArrayList1.get(0); + pexpressionNode3 = (PExpression)nodeArrayList2.get(0); + talorsNode4 = (TAlors)nodeArrayList3.get(0); + pibNode5 = (PIb)nodeArrayList4.get(0); + tsinonNode6 = (TSinon)nodeArrayList5.get(0); + pibNode7 = (PIb)nodeArrayList6.get(0); + + pisiNode1 = new ASisinonIsi(tsiNode2, pexpressionNode3, talorsNode4, pibNode5, tsinonNode6, pibNode7); + } + nodeList.add(pisiNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new51() /* reduce ATantqueItantque */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PItantque pitantqueNode1; + { + // Block + TTantque ttantqueNode2; + PExpression pexpressionNode3; + TFaire tfaireNode4; + PIb pibNode5; + ttantqueNode2 = (TTantque)nodeArrayList1.get(0); + pexpressionNode3 = (PExpression)nodeArrayList2.get(0); + tfaireNode4 = (TFaire)nodeArrayList3.get(0); + pibNode5 = (PIb)nodeArrayList4.get(0); + + pitantqueNode1 = new ATantqueItantque(ttantqueNode2, pexpressionNode3, tfaireNode4, pibNode5); + } + nodeList.add(pitantqueNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new52() /* reduce ARetournerIret */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIret piretNode1; + { + // Block + TRetour tretourNode2; + PExpression pexpressionNode3; + TPVirgule tpvirguleNode4; + tretourNode2 = (TRetour)nodeArrayList1.get(0); + pexpressionNode3 = (PExpression)nodeArrayList2.get(0); + tpvirguleNode4 = (TPVirgule)nodeArrayList3.get(0); + + piretNode1 = new ARetournerIret(tretourNode2, pexpressionNode3, tpvirguleNode4); + } + nodeList.add(piretNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new53() /* reduce AIappelIappel */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIappel piappelNode1; + { + // Block + PAppel pappelNode2; + TPVirgule tpvirguleNode3; + pappelNode2 = (PAppel)nodeArrayList1.get(0); + tpvirguleNode3 = (TPVirgule)nodeArrayList2.get(0); + + piappelNode1 = new AIappelIappel(pappelNode2, tpvirguleNode3); + } + nodeList.add(piappelNode1); + return nodeList; + } + + + + @SuppressWarnings({ "unchecked", "rawtypes" }) + ArrayList<Object> new54() /* reduce AIecrireIecrire */ + { + @SuppressWarnings("hiding") ArrayList<Object> nodeList = new ArrayList<Object>(); + + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList5 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList4 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList3 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList2 = pop(); + @SuppressWarnings("unused") ArrayList<Object> nodeArrayList1 = pop(); + PIecrire piecrireNode1; + { + // Block + TEcrire tecrireNode2; + TParentheseOuvrante tparentheseouvranteNode3; + PExpression pexpressionNode4; + TParentheseFermante tparenthesefermanteNode5; + TPVirgule tpvirguleNode6; + tecrireNode2 = (TEcrire)nodeArrayList1.get(0); + tparentheseouvranteNode3 = (TParentheseOuvrante)nodeArrayList2.get(0); + pexpressionNode4 = (PExpression)nodeArrayList3.get(0); + tparenthesefermanteNode5 = (TParentheseFermante)nodeArrayList4.get(0); + tpvirguleNode6 = (TPVirgule)nodeArrayList5.get(0); + + piecrireNode1 = new AIecrireIecrire(tecrireNode2, tparentheseouvranteNode3, pexpressionNode4, tparenthesefermanteNode5, tpvirguleNode6); + } + nodeList.add(piecrireNode1); + return nodeList; + } + + + + private static int[][][] actionTable; +/* { + {{-1, REDUCE, 2}, {6, REDUCE, 4}, {8, SHIFT, 1}, }, + {{-1, ERROR, 1}, {28, SHIFT, 6}, }, + {{-1, ERROR, 2}, {29, ACCEPT, -1}, }, + {{-1, REDUCE, 10}, {28, SHIFT, 7}, }, + {{-1, ERROR, 4}, {6, SHIFT, 10}, }, + {{-1, REDUCE, 8}, {5, SHIFT, 11}, }, + {{-1, REDUCE, 5}, {3, SHIFT, 13}, }, + {{-1, ERROR, 7}, {9, SHIFT, 14}, }, + {{-1, REDUCE, 0}, }, + {{-1, REDUCE, 10}, {28, SHIFT, 7}, }, + {{-1, REDUCE, 1}, }, + {{-1, ERROR, 11}, {8, SHIFT, 1}, }, + {{-1, REDUCE, 3}, }, + {{-1, ERROR, 13}, {7, SHIFT, 18}, }, + {{-1, REDUCE, 4}, {8, SHIFT, 1}, }, + {{-1, REDUCE, 2}, {6, REDUCE, 4}, {8, SHIFT, 1}, }, + {{-1, REDUCE, 9}, }, + {{-1, REDUCE, 8}, {5, SHIFT, 11}, }, + {{-1, ERROR, 18}, {4, SHIFT, 22}, }, + {{-1, ERROR, 19}, {0, SHIFT, 23}, }, + {{-1, ERROR, 20}, {1, SHIFT, 24}, }, + {{-1, REDUCE, 7}, }, + {{-1, REDUCE, 6}, }, + {{-1, REDUCE, 12}, }, + {{-1, REDUCE, 15}, {19, SHIFT, 26}, {22, SHIFT, 27}, {24, SHIFT, 28}, {25, SHIFT, 29}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 11}, }, + {{-1, ERROR, 26}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 27}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 28}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 29}, {9, SHIFT, 55}, }, + {{-1, REDUCE, 23}, {3, SHIFT, 56}, {9, SHIFT, 57}, }, + {{-1, ERROR, 31}, {2, SHIFT, 58}, }, + {{-1, REDUCE, 15}, {19, SHIFT, 26}, {22, SHIFT, 27}, {24, SHIFT, 28}, {25, SHIFT, 29}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 16}, }, + {{-1, ERROR, 34}, {16, SHIFT, 60}, }, + {{-1, ERROR, 35}, {6, SHIFT, 61}, }, + {{-1, REDUCE, 17}, }, + {{-1, REDUCE, 18}, }, + {{-1, REDUCE, 19}, }, + {{-1, REDUCE, 20}, }, + {{-1, REDUCE, 21}, }, + {{-1, REDUCE, 41}, }, + {{-1, ERROR, 42}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 43}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 42}, }, + {{-1, ERROR, 45}, {10, SHIFT, 64}, {20, SHIFT, 65}, }, + {{-1, REDUCE, 25}, {11, SHIFT, 66}, }, + {{-1, REDUCE, 27}, {16, SHIFT, 67}, {17, SHIFT, 68}, }, + {{-1, REDUCE, 29}, {12, SHIFT, 69}, {13, SHIFT, 70}, }, + {{-1, REDUCE, 32}, {14, SHIFT, 71}, {15, SHIFT, 72}, }, + {{-1, REDUCE, 35}, }, + {{-1, REDUCE, 38}, }, + {{-1, REDUCE, 43}, }, + {{-1, ERROR, 53}, {10, SHIFT, 64}, {23, SHIFT, 73}, }, + {{-1, ERROR, 54}, {6, SHIFT, 74}, {10, SHIFT, 64}, }, + {{-1, ERROR, 55}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 56}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 46}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 13}, }, + {{-1, REDUCE, 14}, }, + {{-1, ERROR, 60}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 53}, }, + {{-1, ERROR, 62}, {0, SHIFT, 80}, {10, SHIFT, 64}, }, + {{-1, REDUCE, 39}, }, + {{-1, ERROR, 64}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 65}, {1, SHIFT, 24}, }, + {{-1, ERROR, 66}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 67}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 68}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 69}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 70}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 71}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 72}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, ERROR, 73}, {1, SHIFT, 24}, }, + {{-1, REDUCE, 52}, }, + {{-1, ERROR, 75}, {0, SHIFT, 91}, {10, SHIFT, 64}, }, + {{-1, ERROR, 76}, {4, SHIFT, 92}, {10, SHIFT, 64}, }, + {{-1, REDUCE, 48}, {5, SHIFT, 93}, {10, SHIFT, 64}, }, + {{-1, ERROR, 78}, {0, SHIFT, 95}, }, + {{-1, ERROR, 79}, {6, SHIFT, 96}, {10, SHIFT, 64}, }, + {{-1, REDUCE, 40}, }, + {{-1, REDUCE, 26}, {11, SHIFT, 66}, }, + {{-1, REDUCE, 49}, {21, SHIFT, 97}, }, + {{-1, REDUCE, 28}, {16, SHIFT, 67}, {17, SHIFT, 68}, }, + {{-1, REDUCE, 30}, {12, SHIFT, 69}, {13, SHIFT, 70}, }, + {{-1, REDUCE, 31}, {12, SHIFT, 69}, {13, SHIFT, 70}, }, + {{-1, REDUCE, 33}, {14, SHIFT, 71}, {15, SHIFT, 72}, }, + {{-1, REDUCE, 34}, {14, SHIFT, 71}, {15, SHIFT, 72}, }, + {{-1, REDUCE, 37}, }, + {{-1, REDUCE, 36}, }, + {{-1, REDUCE, 51}, }, + {{-1, ERROR, 91}, {6, SHIFT, 98}, }, + {{-1, REDUCE, 24}, }, + {{-1, ERROR, 93}, {7, SHIFT, 41}, {9, SHIFT, 42}, {18, SHIFT, 43}, {28, SHIFT, 30}, }, + {{-1, REDUCE, 45}, }, + {{-1, REDUCE, 44}, }, + {{-1, REDUCE, 22}, }, + {{-1, ERROR, 97}, {1, SHIFT, 24}, }, + {{-1, REDUCE, 54}, }, + {{-1, REDUCE, 48}, {5, SHIFT, 93}, {10, SHIFT, 64}, }, + {{-1, REDUCE, 50}, }, + {{-1, REDUCE, 47}, }, + };*/ + private static int[][][] gotoTable; +/* { + {{-1, 2}, }, + {{-1, 3}, {15, 20}, }, + {{-1, 4}, {14, 19}, }, + {{-1, 5}, {11, 17}, }, + {{-1, 12}, {17, 21}, }, + {{-1, 8}, {9, 16}, }, + {{-1, 9}, }, + {{-1, 15}, }, + {{-1, 25}, {65, 82}, {73, 90}, {97, 100}, }, + {{-1, 31}, {32, 59}, }, + {{-1, 32}, }, + {{-1, 33}, }, + {{-1, 44}, {24, 34}, {32, 34}, }, + {{-1, 45}, {27, 53}, {28, 54}, {42, 62}, {55, 75}, {56, 76}, {57, 77}, {60, 79}, {93, 99}, }, + {{-1, 46}, {64, 81}, }, + {{-1, 47}, {66, 83}, }, + {{-1, 48}, {67, 84}, {68, 85}, }, + {{-1, 49}, {69, 86}, {70, 87}, }, + {{-1, 50}, {43, 63}, {71, 88}, {72, 89}, }, + {{-1, 51}, }, + {{-1, 52}, {24, 35}, {32, 35}, }, + {{-1, 78}, }, + {{-1, 94}, {99, 101}, }, + {{-1, 36}, }, + {{-1, 37}, }, + {{-1, 38}, }, + {{-1, 39}, }, + {{-1, 40}, }, + };*/ + private static String[] errorMessages; +/* { + "expecting: ';', 'entier', identif, EOF", + "expecting: identif", + "expecting: EOF", + "expecting: identif, EOF", + "expecting: ';'", + "expecting: ')', ',', ';'", + "expecting: ')', '[', ',', ';'", + "expecting: '('", + "expecting: '{', identif, EOF", + "expecting: 'entier'", + "expecting: ')', ';'", + "expecting: nombre", + "expecting: ')', 'entier'", + "expecting: '{', ';', 'entier'", + "expecting: ']'", + "expecting: ')'", + "expecting: '{'", + "expecting: '}', 'si', 'tantque', 'retour', 'ecrire', identif", + "expecting: nombre, '(', '!', identif", + "expecting: ')', '[', ']', ',', ';', '(', '|', '&', '+', '-', '/', '*', '=', '<', 'alors', 'faire'", + "expecting: '}'", + "expecting: '='", + "expecting: ')', ']', ',', ';', '|', '&', '+', '-', '/', '*', '=', '<', 'alors', 'faire'", + "expecting: '|', 'alors'", + "expecting: ')', ']', ',', ';', '|', '&', 'alors', 'faire'", + "expecting: ')', ']', ',', ';', '|', '&', '=', '<', 'alors', 'faire'", + "expecting: ')', ']', ',', ';', '|', '&', '+', '-', '=', '<', 'alors', 'faire'", + "expecting: '|', 'faire'", + "expecting: ';', '|'", + "expecting: ')', nombre, '(', '!', identif", + "expecting: '}', 'si', 'sinon', 'tantque', 'retour', 'ecrire', identif, EOF", + "expecting: ')', '|'", + "expecting: ']', '|'", + "expecting: ')', ',', '|'", + "expecting: '}', 'si', 'sinon', 'tantque', 'retour', 'ecrire', identif", + };*/ + private static int[] errors; +/* { + 0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 8, 9, 10, 11, 12, 13, 2, 5, 14, 15, 16, 10, 5, 13, 17, 3, 18, 18, 18, 7, 19, 20, 17, 17, 21, 4, 17, 17, 17, 17, 17, 22, 18, 18, 22, 23, 24, 25, 26, 22, 22, 22, 22, 27, 28, 18, 18, 29, 30, 20, 18, 17, 31, 22, 18, 16, 18, 18, 18, 18, 18, 18, 18, 16, 17, 31, 32, 33, 15, 28, 22, 24, 34, 25, 26, 26, 22, 22, 22, 22, 17, 4, 22, 18, 15, 22, 17, 16, 17, 33, 17, 15, + };*/ + + static + { + try + { + DataInputStream s = new DataInputStream( + new BufferedInputStream( + Parser.class.getResourceAsStream("parser.dat"))); + + // read actionTable + int length = s.readInt(); + Parser.actionTable = new int[length][][]; + for(int i = 0; i < Parser.actionTable.length; i++) + { + length = s.readInt(); + Parser.actionTable[i] = new int[length][3]; + for(int j = 0; j < Parser.actionTable[i].length; j++) + { + for(int k = 0; k < 3; k++) + { + Parser.actionTable[i][j][k] = s.readInt(); + } + } + } + + // read gotoTable + length = s.readInt(); + gotoTable = new int[length][][]; + for(int i = 0; i < gotoTable.length; i++) + { + length = s.readInt(); + gotoTable[i] = new int[length][2]; + for(int j = 0; j < gotoTable[i].length; j++) + { + for(int k = 0; k < 2; k++) + { + gotoTable[i][j][k] = s.readInt(); + } + } + } + + // read errorMessages + length = s.readInt(); + errorMessages = new String[length]; + for(int i = 0; i < errorMessages.length; i++) + { + length = s.readInt(); + StringBuffer buffer = new StringBuffer(); + + for(int j = 0; j < length; j++) + { + buffer.append(s.readChar()); + } + errorMessages[i] = buffer.toString(); + } + + // read errors + length = s.readInt(); + errors = new int[length]; + for(int i = 0; i < errors.length; i++) + { + errors[i] = s.readInt(); + } + + s.close(); + } + catch(Exception e) + { + throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted."); + } + } +} diff --git a/src/sc/parser/ParserException.java b/src/sc/parser/ParserException.java new file mode 100644 index 0000000000000000000000000000000000000000..f3b29bae2d1dd7c38c2b321d8b376410dd56583f --- /dev/null +++ b/src/sc/parser/ParserException.java @@ -0,0 +1,22 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.parser; + +import sc.node.*; + +@SuppressWarnings("serial") +public class ParserException extends Exception +{ + private Token token; + + public ParserException(@SuppressWarnings("hiding") Token token, String message) + { + super(message); + this.token = token; + } + + public Token getToken() + { + return this.token; + } +} diff --git a/src/sc/parser/State.java b/src/sc/parser/State.java new file mode 100644 index 0000000000000000000000000000000000000000..408eae2c5fcafec6514b3bb2a19fa0d2cf23c61f --- /dev/null +++ b/src/sc/parser/State.java @@ -0,0 +1,17 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.parser; + +import java.util.ArrayList; + +final class State +{ + int state; + ArrayList<Object> nodes; + + State(@SuppressWarnings("hiding") int state, @SuppressWarnings("hiding") ArrayList<Object> nodes) + { + this.state = state; + this.nodes = nodes; + } +} diff --git a/src/sc/parser/TokenIndex.java b/src/sc/parser/TokenIndex.java new file mode 100644 index 0000000000000000000000000000000000000000..c1d02be6920aed4753bb47c0f1e092403e7a9a00 --- /dev/null +++ b/src/sc/parser/TokenIndex.java @@ -0,0 +1,191 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package sc.parser; + +import sc.node.*; +import sc.analysis.*; + +class TokenIndex extends AnalysisAdapter +{ + int index; + + @Override + public void caseTParentheseFermante(@SuppressWarnings("unused") TParentheseFermante node) + { + this.index = 0; + } + + @Override + public void caseTAccoladeOuvrante(@SuppressWarnings("unused") TAccoladeOuvrante node) + { + this.index = 1; + } + + @Override + public void caseTAccoladeFermante(@SuppressWarnings("unused") TAccoladeFermante node) + { + this.index = 2; + } + + @Override + public void caseTCrochetOuvrant(@SuppressWarnings("unused") TCrochetOuvrant node) + { + this.index = 3; + } + + @Override + public void caseTCrochetFermant(@SuppressWarnings("unused") TCrochetFermant node) + { + this.index = 4; + } + + @Override + public void caseTVirgule(@SuppressWarnings("unused") TVirgule node) + { + this.index = 5; + } + + @Override + public void caseTPVirgule(@SuppressWarnings("unused") TPVirgule node) + { + this.index = 6; + } + + @Override + public void caseTNombre(@SuppressWarnings("unused") TNombre node) + { + this.index = 7; + } + + @Override + public void caseTEntier(@SuppressWarnings("unused") TEntier node) + { + this.index = 8; + } + + @Override + public void caseTParentheseOuvrante(@SuppressWarnings("unused") TParentheseOuvrante node) + { + this.index = 9; + } + + @Override + public void caseTOu(@SuppressWarnings("unused") TOu node) + { + this.index = 10; + } + + @Override + public void caseTEt(@SuppressWarnings("unused") TEt node) + { + this.index = 11; + } + + @Override + public void caseTPlus(@SuppressWarnings("unused") TPlus node) + { + this.index = 12; + } + + @Override + public void caseTMoins(@SuppressWarnings("unused") TMoins node) + { + this.index = 13; + } + + @Override + public void caseTDivision(@SuppressWarnings("unused") TDivision node) + { + this.index = 14; + } + + @Override + public void caseTMultiplication(@SuppressWarnings("unused") TMultiplication node) + { + this.index = 15; + } + + @Override + public void caseTEgal(@SuppressWarnings("unused") TEgal node) + { + this.index = 16; + } + + @Override + public void caseTInferieur(@SuppressWarnings("unused") TInferieur node) + { + this.index = 17; + } + + @Override + public void caseTNon(@SuppressWarnings("unused") TNon node) + { + this.index = 18; + } + + @Override + public void caseTSi(@SuppressWarnings("unused") TSi node) + { + this.index = 19; + } + + @Override + public void caseTAlors(@SuppressWarnings("unused") TAlors node) + { + this.index = 20; + } + + @Override + public void caseTSinon(@SuppressWarnings("unused") TSinon node) + { + this.index = 21; + } + + @Override + public void caseTTantque(@SuppressWarnings("unused") TTantque node) + { + this.index = 22; + } + + @Override + public void caseTFaire(@SuppressWarnings("unused") TFaire node) + { + this.index = 23; + } + + @Override + public void caseTRetour(@SuppressWarnings("unused") TRetour node) + { + this.index = 24; + } + + @Override + public void caseTEcrire(@SuppressWarnings("unused") TEcrire node) + { + this.index = 25; + } + + @Override + public void caseTLire(@SuppressWarnings("unused") TLire node) + { + this.index = 26; + } + + @Override + public void caseTEpsilon(@SuppressWarnings("unused") TEpsilon node) + { + this.index = 27; + } + + @Override + public void caseTIdentif(@SuppressWarnings("unused") TIdentif node) + { + this.index = 28; + } + + @Override + public void caseEOF(@SuppressWarnings("unused") EOF node) + { + this.index = 29; + } +} diff --git a/src/sc/parser/parser.dat b/src/sc/parser/parser.dat new file mode 100644 index 0000000000000000000000000000000000000000..18852b6b62b6f777f784f58a6cb37b630d39c148 Binary files /dev/null and b/src/sc/parser/parser.dat differ diff --git a/src/test b/src/test new file mode 100644 index 0000000000000000000000000000000000000000..bce80526403b0725c036f067fa1e9b66d46b0f7e --- /dev/null +++ b/src/test @@ -0,0 +1 @@ +( 123 ) \ No newline at end of file diff --git a/src/testGrammaire.sh b/src/testGrammaire.sh new file mode 100644 index 0000000000000000000000000000000000000000..601bc891875966712a48b8b14a05903abfe76c85 --- /dev/null +++ b/src/testGrammaire.sh @@ -0,0 +1,11 @@ +data_input=/home/otofa/IdeaProjects/2022-compilation-otofa-fanomezantsoa/test/input +javac Compiler.java +for fullfile in $data_input/*.l +do + file=$(basename "$fullfile") + filename="${file%.*}" + echo "File: $file" + echo "modified file: $data_input/${filename}.l" + + java Compiler $data_input/${file} -v 2 +done diff --git a/src/ts/Sa2ts.java b/src/ts/Sa2ts.java index 50a80a6c17ef87000261b8a1dbf16dd07675709e..50dce266bd14aa97ee4976647faffe506649dff2 100644 --- a/src/ts/Sa2ts.java +++ b/src/ts/Sa2ts.java @@ -1,36 +1,170 @@ package ts; import sa.*; -import util.Error; public class Sa2ts extends SaDepthFirstVisitor <Void> { + + enum Context { - LOCAL, - GLOBAL, - PARAM + LOCAL, + GLOBAL, + PARAM } - + private Ts tableGlobale; private Ts tableLocaleCourante; private Context context; - - public Ts getTableGlobale(){return this.tableGlobale;} - public Sa2ts() + public Sa2ts(SaNode node) { + tableGlobale = new Ts(); + tableLocaleCourante = null; + context = Context.GLOBAL; + node.accept(this); + } + + // DEC -> var id + public Void visit(SaDecVar node) { + defaultIn(node); + if (context == Context.GLOBAL){ + node.tsItem = tableGlobale.variables.get(node.getNom()); + if (node.tsItem == null) + node.tsItem = tableGlobale.addVar(node.getNom(),4); + else + new Error("la variable n'existe pas"); + } + else if (context == Context.LOCAL){ + node.tsItem = tableLocaleCourante.variables.get( + node.getNom()); + + if (node.tsItem == null){ + node.tsItem = tableLocaleCourante.addVar(node.getNom(), 4); + } + } + else if (context ==Context.PARAM){ + node.tsItem = tableLocaleCourante.variables.get( + node.getNom()); + + if (node.tsItem == null){ + node.tsItem = tableLocaleCourante.addParam(node.getNom()); + } + } + defaultOut(node); + + return null; + } + + // DEC -> var id taille + public Void visit(SaDecTab node){ + defaultIn(node); + node.tsItem = tableGlobale.variables.get(node.getNom()); + if (node.tsItem == null){ + node.tsItem = tableGlobale.addVar(node.getNom(), node.getTaille()*4); + } + defaultOut(node); + return null; + } + + // DEC -> fct id LDEC LDEC LINST + public Void visit(SaDecFonc node) + { + defaultIn(node); + node.tsItem = tableGlobale.fonctions.get(node.getNom()); + if ( node.tsItem == null){ + + int longueur_liste_arg = (node.getParametres() == null)? 0 : node.getParametres().length(); + tableLocaleCourante = new Ts(); + node.tsItem = tableGlobale.addFct(node.getNom(), longueur_liste_arg,tableLocaleCourante,node); + context = Context.PARAM; + if(node.getParametres() != null) node.getParametres().accept(this); + context = Context.LOCAL; + if(node.getVariable() != null) node.getVariable().accept(this); + if(node.getCorps() != null) node.getCorps().accept(this); + context = Context.GLOBAL; + } + + else { + new Error("la variable n'existe pas"); + } + + defaultOut(node); + + return null; + } + + public Void visit(SaVarSimple node) { - tableGlobale = new Ts(); - tableLocaleCourante = null; - context = Context.GLOBAL; + defaultIn(node); + + if(context == Context.GLOBAL){ + node.tsItem = tableGlobale.variables.get(node.getNom()); + if (node.tsItem == null) + new Error("la variable n'existe pas"); + } + if (context == Context.LOCAL || context == Context.PARAM){ + node.tsItem = tableLocaleCourante.variables.get( + node.getNom()); + if (node.tsItem == null) { + node.tsItem = tableGlobale.variables.get(node.getNom()); + if (node.tsItem == null) + new Error("la variable n'existe pas"); + } + } + defaultOut(node); + return null; } - public void defaultIn(SaNode node) + + public Void visit(SaVarIndicee node) { - // System.out.println("<" + node.getClass().getSimpleName() + ">"); + defaultIn(node); + if (node.getIndice()!= null){ + if(context == Context.GLOBAL){ + node.tsItem = tableGlobale.variables.get(node.getNom()); + if (node.tsItem == null) + new Error("la variable n'existe pas"); + } + if (context == Context.LOCAL || context == Context.PARAM){ + node.tsItem = tableLocaleCourante.variables.get(node.getNom()); + if (node.tsItem == null) { + node.tsItem = tableGlobale.variables.get(node.getNom()); + if (node.tsItem == null) + new Error("la variable n'existe pas"); + } + } + node.getIndice().accept(this); + } + else { + new Error("la variable n'existe pas"); + } + defaultOut(node); + return null; } - public void defaultOut(SaNode node) + + + public Void visit(SaAppel node) { - // System.out.println("</" + node.getClass().getSimpleName() + ">"); + defaultIn(node); + int nombreArg = (node.getArguments()==null)? 0: node.getArguments().length(); + node.tsItem = tableGlobale.fonctions.get(node.getNom()); + TsItemFct mainFoncExist = tableGlobale.fonctions.get("main"); + if (node.tsItem == null || mainFoncExist!= null){ + new Error("la variable n'existe pas"); + } + else if (node.tsItem.table.nbArg() != nombreArg) + new Error("la variable n'existe pas"); + if(node.getArguments() != null) node.getArguments().accept(this); + defaultOut(node); + return null; } + public Ts getTableGlobale() { + return tableGlobale; + } + + + + + + } diff --git a/src/ts/Sa2ts.zip b/src/ts/Sa2ts.zip new file mode 100644 index 0000000000000000000000000000000000000000..121246ed57df3024b1f02d9b231d63ce9ad16b50 Binary files /dev/null and b/src/ts/Sa2ts.zip differ diff --git a/src/ts/Ts.java b/src/ts/Ts.java index d95fb75ed1196eb28dbdeee9d450bbbe5f847082..3a43b4d4d3709025412e90cd4c638a3d6d5a41ea 100644 --- a/src/ts/Ts.java +++ b/src/ts/Ts.java @@ -2,60 +2,55 @@ package ts; import java.io.*; import java.util.*; import sa.*; -import util.Type; public class Ts { public Map< String, TsItemFct> fonctions; public Map< String, TsItemVar> variables; private int adrVarCourante; - private int adrArgCourante; + private int adrArgCourant; public int getAdrVarCourante(){return adrVarCourante;} - public int getAdrArgCourante(){return adrArgCourante;} + // les adresses sont en octets, les entiers sont stockés sur 4 octets, d'où cette division par 4 + // ce n'est pas très beau, il faudrait changer ça + public int nbVar(){return adrVarCourante / 4;} + public int nbArg(){return adrArgCourant / 4;} + + public Ts(){ this.fonctions = new HashMap< String, TsItemFct>(); this.variables = new HashMap< String, TsItemVar>(); this.adrVarCourante = 0; - this.adrArgCourante = 0; + this.adrArgCourant = 0; } - public TsItemVar addVar(String identif, Type type) + public TsItemVar addVar(String identif, int taille) { - TsItemVar item = new TsItemVarSimple(identif, type); + TsItemVar item = new TsItemVar(identif, taille); item.portee = this; item.adresse = this.adrVarCourante; - item.isParam = false; - this.adrVarCourante += type.taille(); + this.adrVarCourante += item.getTaille(); this.variables.put(identif, item); return item; } - public TsItemVar addParam(String identif, Type type) + public TsItemVar addParam(String identif) { - TsItemVar item = new TsItemVarSimple(identif, type); + // TsItemVar item = new TsItemVar(identif, 1); + // on compte en octets, un entier est codé sur 4 octets + TsItemVar item = new TsItemVar(identif, 4); item.portee = this; - item.adresse = this.adrArgCourante; + item.adresse = this.adrArgCourant; item.isParam = true; - this.adrArgCourante += type.taille(); - this.variables.put(identif, item); - return item; - } - - public TsItemVar addTab(String identif, Type type, int taille) - { - TsItemVar item = new TsItemVarTab(identif, type, taille); - item.portee = this; - item.adresse = this.adrVarCourante; - this.adrVarCourante += taille * type.taille(); + this.adrArgCourant += item.getTaille(); this.variables.put(identif, item); return item; } - public TsItemFct addFct(String identif, Type typeRetour, int nbArgs, Ts table, SaDecFonc saDecFonc) + public TsItemFct addFct(String identif, int nbArgs, Ts table, SaDecFonc saDecFonc) { - TsItemFct item = new TsItemFct(identif, typeRetour, nbArgs, table, saDecFonc); + TsItemFct item = new TsItemFct(identif, nbArgs, table, saDecFonc); this.fonctions.put(identif, item); return item; } diff --git a/src/ts/TsItemFct.java b/src/ts/TsItemFct.java index 03e87f65dda8622fe8f5de40416054f2ca1d00a8..4acf93d7a39f78a816d267703a9103f9794c59c4 100644 --- a/src/ts/TsItemFct.java +++ b/src/ts/TsItemFct.java @@ -1,6 +1,5 @@ package ts; import sa.*; -import util.Type; public class TsItemFct { @@ -8,22 +7,19 @@ public class TsItemFct { public int nbArgs; public Ts table; public SaDecFonc saDecFonc; - public Type typeRetour; - - public TsItemFct(String identif, Type typeRetour, int nbArgs, Ts table, SaDecFonc saDecFonc){ + + public TsItemFct(String identif, int nbArgs, Ts table, SaDecFonc saDecFonc){ this.identif = identif; this.nbArgs = nbArgs; this.table = table; this.saDecFonc = saDecFonc; - this.typeRetour = typeRetour; } public int getNbArgs(){return this.nbArgs;} public Ts getTable(){return this.table;} - public Type getTypeRetour(){return this.typeRetour;} public String getIdentif(){return this.identif;} public String toString(){ - return this.identif + "\tFCT\t" + typeRetour + "\t" + this.nbArgs; + return this.identif + "\tFCT\t" + this.nbArgs; } } diff --git a/src/ts/TsItemVar.java b/src/ts/TsItemVar.java index 7dae2bb896d63d316875f99ff8a3a45023110c49..b0f2109b9fd36ee5e49649290c8f5bb902e52543 100644 --- a/src/ts/TsItemVar.java +++ b/src/ts/TsItemVar.java @@ -1,20 +1,31 @@ package ts; -import util.Type; -public abstract class TsItemVar { - public Ts portee; - public int adresse; - public String identif; - public int taille; +public class TsItemVar { + public Ts portee; + public int adresse; + public String identif; + public int taille; public boolean isParam; - public Type type; - public int getAdresse(){return this.adresse;} + public TsItemVar(String identif, int taille){ + this.identif = identif; + this.taille = taille; + this.adresse = 0; + this.portee = null; + this.isParam = false; + } + + public int getTaille(){return this.taille;} + public int getAdresse(){return this.adresse;} public String getIdentif(){return this.identif;} - public Ts getPortee() {return this.portee;} - public Type getType() {return this.type;} - public int getTaille(){return this.taille;} + public Ts getPortee(){return this.portee;} + public String toString(){ + if(this.isParam) + return this.identif + "\tPARAM\t" + this.taille + "\t" + this.adresse; + else + return this.identif + "\tVAR \t" + this.taille + "\t" + this.adresse; + } } diff --git a/src/ts/TsItemVarSimple.java b/src/ts/TsItemVarSimple.java deleted file mode 100644 index ae2a555a1149f34755bfb7a4ae4dde02a5345309..0000000000000000000000000000000000000000 --- a/src/ts/TsItemVarSimple.java +++ /dev/null @@ -1,22 +0,0 @@ -package ts; -import util.Type; - -public class TsItemVarSimple extends TsItemVar{ - public TsItemVarSimple(String identif, Type type){ - this.identif = identif; - this.adresse = 0; - this.portee = null; - this.taille = 1; - this.isParam = false; - this.type = type; - } - - public String toString(){ - if(this.isParam) - return this.identif + "\tPARAM\t" + this.type + "\t" + this.adresse; - else - return this.identif + "\tVAR \t" + this.type + "\t" + this.adresse; - } - -} - diff --git a/src/ts/TsItemVarTab.java b/src/ts/TsItemVarTab.java deleted file mode 100644 index 56c0a116605fb11714826d27714c2aa3b046cc5c..0000000000000000000000000000000000000000 --- a/src/ts/TsItemVarTab.java +++ /dev/null @@ -1,19 +0,0 @@ -package ts; -import util.Type; - -public class TsItemVarTab extends TsItemVar{ - public TsItemVarTab(String identif, Type type, int taille){ - this.identif = identif; - this.adresse = 0; - this.portee = null; - this.taille = taille; - this.isParam = false; - this.type = type; - } - - public String toString(){ - return this.identif + "\tTAB \t" + this.type + "\t" + this.adresse + "\t" + this.taille; - } - -} - diff --git a/src/ts/TsParser.java b/src/ts/TsParser.java index 509bff6ee29d53d5f75a8d3928b1c0eb8277ac2a..e858c3d5101be888b8ceaba3d9d31a9bf0236830 100644 --- a/src/ts/TsParser.java +++ b/src/ts/TsParser.java @@ -11,53 +11,59 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import util.Type; public class TsParser { - private Ts tableCourante = null; - private Ts tableGlobale = null; + private enum Scope{LOCAL, GLOBAL} + + private class FuncInfo{ + public String identif = ""; + public int nbArgs = 0; + public Ts ts = new Ts(); + } + + private Ts symbolsTab; + private FuncInfo currentFuncInfo; + private Scope currentScope; public TsParser(){ } - + public Ts parse(String filePath){ + symbolsTab = new Ts(); + currentFuncInfo = null; try { Files.lines(Paths.get(filePath)).forEachOrdered(this::processLine);; } catch(IOException e){ e.printStackTrace(); } - return tableGlobale; + if(currentScope == Scope.LOCAL) + symbolsTab.addFct(currentFuncInfo.identif, currentFuncInfo.nbArgs, currentFuncInfo.ts, null); + return symbolsTab; } private void processLine(String line){ -// System.out.println(line); - var tokens = line.split("([ ]|[\t])+"); - if(tokens[1].equals("GLOBALE")){ - tableGlobale = new Ts(); - tableCourante = tableGlobale; - return; - } - if(tokens[1].equals("LOCALE")){ - tableCourante = tableGlobale.getFct(tokens[3]).getTable(); - return; - } - if(tokens[1].equals("VAR")){ - tableCourante.addVar(tokens[0], Type.fromString(tokens[2])); - return; - } - if(tokens[1].equals("PARAM")){ - tableCourante.addParam(tokens[0], Type.fromString(tokens[2])); - return; - } - if(tokens[1].equals("TAB")){ - tableCourante.addTab(tokens[0], Type.fromString(tokens[2]), Integer.parseInt(tokens[4])); - return; - } - if(tokens[1].equals("FCT")){ - tableGlobale.addFct(tokens[0], Type.fromString(tokens[2]), Integer.parseInt(tokens[3]), new Ts(), null); - return; - } + var lineArgs = line.split("([ ]|[\t])+"); + if(line.contains("LOCAL")) { + if(currentScope != Scope.GLOBAL) + symbolsTab.addFct(currentFuncInfo.identif, currentFuncInfo.nbArgs, currentFuncInfo.ts, null); + currentScope = Scope.LOCAL; + currentFuncInfo = new FuncInfo(); + currentFuncInfo.identif = lineArgs[3]; + + } + else if(line.contains("GLOBALE")) + currentScope = Scope.GLOBAL; + else if(currentScope == Scope.GLOBAL && line.contains("VAR")) + symbolsTab.addVar(lineArgs[0], Integer.parseInt(lineArgs[2].trim())); + else if(currentScope == Scope.LOCAL){ + if(line.contains("PARAM")){ + currentFuncInfo.nbArgs++; + currentFuncInfo.ts.addParam(lineArgs[0]); + } + else if(line.contains("VAR")) + currentFuncInfo.ts.addVar(lineArgs[0], Integer.parseInt(lineArgs[2])); + } } /* public static void main(String args[]){ diff --git a/src/util/Error.java b/src/util/Error.java deleted file mode 100644 index 4a7500040e46a9e9d914f8865cb653da75a2c073..0000000000000000000000000000000000000000 --- a/src/util/Error.java +++ /dev/null @@ -1,21 +0,0 @@ -package util; - -public enum Error{ - NOERROR(0, "sortie normale"), - TYPE(3, "erreur de types"), - TS(4, "table des symboles"), - SYNT(5,"erreur de syntaxe"), - LEX(6, "lexical error"); - - private final String message; - private final int code; - - Error(int code, String message){ - this.code = code; - this.message = message; - } - - public String toString(){return message;} - public String message(){return message;} - public int code(){return code;} -} diff --git a/src/util/Memory.java b/src/util/Memory.java deleted file mode 100644 index 688a9da4134d2c2fcb46c61bedbeda7d4d5ebe70..0000000000000000000000000000000000000000 --- a/src/util/Memory.java +++ /dev/null @@ -1,224 +0,0 @@ -package util; - -/* Big Endian */ - -public class Memory{ - /* stack segment */ - private int ss; - - /* data segment */ - private int ds; - - public int esp; // adresse du sommet de la pile en octets - private int memSize; - private int dataSize; - private int stackSize; - private byte[] mem; - - public Memory(int dataSize, int stackSize){ - this.dataSize = dataSize; - this.stackSize = stackSize; - this.memSize = dataSize + stackSize; - mem = new byte[memSize]; - ss = memSize - 1; - esp = ss; - ds = 0; - } - - public void printStack(){ - for(int adr = ss - 3; adr > esp; adr = adr - 4){ - System.out.print(readInt(adr) + "\t"); - } - System.out.println(); - } - - public int readInt(int address){ - if((address < 0) || (address + 3 > ss)) - throw new RuntimeException("segmentation fault"); - return bytesToInt(mem[address], mem[address + 1], mem[address + 2], mem[address + 3]); - } - - - public boolean readBoolean(int address){ - if((address < 0) || (address > ss)) - throw new RuntimeException("segmentation fault"); - return byteToBoolean(mem[address]); - } - - public byte readByte(int address){ - if((address < 0) || (address > ss)) - throw new RuntimeException("segmentation fault"); - return mem[address]; - } - - public void writeInt(int address, int value){ - if((address < 0) || (address + 3 > ss)) - throw new RuntimeException("segmentation fault"); - - byte[] fourBytes = intToBytes(value); - mem[address] = fourBytes[0]; - mem[address + 1] = fourBytes[1]; - mem[address + 2] = fourBytes[2]; - mem[address + 3] = fourBytes[3]; - } - - public void writeToMemory(int address, int value){ - if((address < 0) || (address + 3 > ss)) - throw new RuntimeException("segmentation fault"); - - byte[] fourBytes = intToBytes(value); - mem[address] = fourBytes[0]; - mem[address + 1] = fourBytes[1]; - mem[address + 2] = fourBytes[2]; - mem[address + 3] = fourBytes[3]; - } - - /* public void writeToMemory(int address, boolean value) - { - if((address < 0) || (address > ss)) - throw new RuntimeException("segmentation fault"); - mem[address] = booleanToByte(value); - }*/ - - - /* revoir c'est quoi cette affaire */ - public int readNBytes(int address, int n){ - // System.out.println("read memory at address " + address); - if((address < 0) || (address + n - 1 > ss)) - throw new RuntimeException("segmentation fault"); - if(n == 1) - return (int)mem[address]; - // if(n == 4) revoir pourquoi c'est commenté !! - return bytesToInt(mem[address], mem[address + 1], mem[address + 2], mem[address + 3]); - - } - - /* public void writeNBytes(int address, int value){ - if((address < 0) || (address + n - 1 > ss)) - throw new RuntimeException("segmentation fault"); - - byte[] fourBytes = intToBytes(value); - mem[address] = fourBytes[0]; - mem[address + 1] = fourBytes[1]; - mem[address + 2] = fourBytes[2]; - mem[address + 3] = fourBytes[3]; - }*/ - - - - public void writeBoolean(int address, boolean value) - { - if((address < 0) || (address > ss)) - throw new RuntimeException("segmentation fault"); - mem[address] = booleanToByte(value); - } - - public void pushInt(int value){ - if(esp - 3 < dataSize) - throw new RuntimeException("stack overflow"); - - byte[] fourBytes = intToBytes(value); - mem[--esp] = fourBytes[3]; - mem[--esp] = fourBytes[2]; - mem[--esp] = fourBytes[1]; - mem[--esp] = fourBytes[0]; - - - } - /* - public void pushBoolean(boolean value){ - if(esp == dataSize) - throw new RuntimeException("stack overflow"); - mem[esp] = booleanToByte(value); - esp--; - - }*/ - - public int getTopInt(){ - // if(esp == ss) - // throw new RuntimeException("empty stack"); - byte byte0 = mem[esp]; - byte byte1 = mem[esp-1]; - byte byte2 = mem[esp-2]; - byte byte3 = mem[esp-3]; - return bytesToInt(byte0, byte1, byte2, byte3); - } - - public int popInt(){ - if(esp + 3 >= ss) - throw new RuntimeException("stack underflow"); - byte byte0 = mem[esp++]; - byte byte1 = mem[esp++]; - byte byte2 = mem[esp++]; - byte byte3 = mem[esp++]; - - return bytesToInt(byte0, byte1, byte2, byte3); - } - - /* public boolean popBoolean() - { - if(esp == ss) - throw new RuntimeException("stack underflow"); - byte byte0 = mem[esp]; - esp++; - return byteToBoolean(byte0); - }*/ - - public int bytesToInt(byte byte0, byte byte1, byte byte2, byte byte3){ - return ((byte0 & 0xFF) << 24) | - ((byte1 & 0xFF) << 16) | - ((byte2 & 0xFF) << 8) | - ((byte3 & 0xFF) << 0); - } - - public byte[] intToBytes2( int data ) { - byte[] result = new byte[4]; - result[0] = (byte) ((data & 0xFF000000) >> 24); - result[1] = (byte) ((data & 0x00FF0000) >> 16); - result[2] = (byte) ((data & 0x0000FF00) >> 8); - result[3] = (byte) ((data & 0x000000FF) >> 0); - return result; -} - public byte[] intToBytes(int i) - { - byte[] result = new byte[4]; - - result[0] = (byte) (i >> 24); - result[1] = (byte) (i >> 16); - result[2] = (byte) (i >> 8); - result[3] = (byte) (i /*>> 0*/); - - return result; - } - - public byte booleanToByte(boolean value) - { - return (value == true)? (byte) 1 : (byte) 0; - } - - public boolean byteToBoolean(byte value) - { - return (value == 1)? true : false; - } - - - /* public static void main(String[] args){ - Memory mem = new Memory(100, 100); - mem.pushInt(3467); - int v = mem.popInt(); - System.out.println("val =" + v); - mem.pushInt(3468); - v = mem.popInt(); - System.out.println("val =" + v); - - mem.writeInt(96, 234); - int val = mem.readInt(96); - System.out.println("val =" + val); - - mem.writeInt(150, 23); - val = mem.readInt(250); - System.out.println("val =" + val); - - }*/ - -} diff --git a/src/util/Type.java b/src/util/Type.java deleted file mode 100644 index 89e5574b53f8b046e757117b7de79748f18dc8fa..0000000000000000000000000000000000000000 --- a/src/util/Type.java +++ /dev/null @@ -1,30 +0,0 @@ -package util; - -public enum Type{ - NUL("nul", 0), - ENTIER("entier", 4), - BOOL("bool", 1); - - private final String nom; - private final int taille; // taille en octets - - Type(String nom, int taille){ - this.nom = nom; - this.taille = taille; - } - - public String toString(){return nom;} - public static Type fromString(String nom){ - if(nom.equals("entier")){return Type.ENTIER;} - if(nom.equals("ENTIER")){return Type.ENTIER;} - if(nom.equals("bool")){return Type.BOOL;} - if(nom.equals("BOOL")){return Type.BOOL;} - if(nom.equals("nul")){return Type.NUL;} - if(nom.equals("NUL")){return Type.NUL;} - return null; - } - - public String nom(){return nom;} - public int taille(){return taille;} - public static boolean checkCompatibility(Type t1, Type t2){return t1 == t2;} -} diff --git a/src/util/graph/ColorGraph.java b/src/util/graph/ColorGraph.java index 55b867e821c8182073a421475d2ab4cb875c7215..b4dca883f1c066c996ad14a9fc8cbb0c9345c011 100644 --- a/src/util/graph/ColorGraph.java +++ b/src/util/graph/ColorGraph.java @@ -34,5 +34,161 @@ public class ColorGraph { } } + /*-------------------------------------------------------------------------------------------------------------*/ + /* associe une couleur à tous les sommets se trouvant dans la pile */ + /*-------------------------------------------------------------------------------------------------------------*/ + + public void select() + { + while (stack.size() != 0){ + int s = stack.pop(); + IntSet couleurVoisins = neighborsColor(s); + int sizeCouleurVoisin = 0; + for (int i = 0;i<couleurVoisins.getSize();i++){ + if (couleurVoisins.isMember(i)){ + sizeCouleurVoisin++;; + } + + } + if (sizeCouleurVoisin != colorNb){ + + IntSet otherColors = new IntSet(colorNb); + for (int i = 0;i<colorNb;i++){ + if (!couleurVoisins.isMember(i)){ + otherColors.add(i); + } + } + color[s] = color[s] == NOCOLOR ? chooseAvailableColor(otherColors): color[s]; + } + + } + } + + /*-------------------------------------------------------------------------------------------------------------*/ + /* récupère les couleurs des voisins de t */ + /*-------------------------------------------------------------------------------------------------------------*/ + + public IntSet neighborsColor(int t) + { + IntSet nColors = new IntSet(colorNb); + for (int i = 0; i<int2Node.length;i++){ + if (int2Node[i].adj(int2Node[t]) && color[i]!= NOCOLOR){ + + nColors.add(color[i]); + } + } + return nColors; + } + + /*-------------------------------------------------------------------------------------------------------------*/ + /* recherche une couleur absente de colorSet */ + /*-------------------------------------------------------------------------------------------------------------*/ + + public int chooseAvailableColor(IntSet colorSet) + { + for (int i = 0;i<colorSet.getSize();i++){ + if (colorSet.isMember(i)){ + colorSet.remove(i); + return i; + + } + } + return NOCOLOR; + } + + /*-------------------------------------------------------------------------------------------------------------*/ + /* calcule le nombre de voisins du sommet t */ + /*-------------------------------------------------------------------------------------------------------------*/ + + public int neighborsNb(int t) + { + int voisins = int2Node[t].degree()/2; + + for (int i = 0; i<removed.getSize(); i++){ + if (removed.isMember(i) && int2Node[t].adj(int2Node[i])){ + voisins -=1; + } + } + + return voisins; + } + + /*-------------------------------------------------------------------------------------------------------------*/ + /* simplifie le graphe d'interférence g */ + /* la simplification consiste à enlever du graphe les temporaires qui ont moins de k voisins */ + /* et à les mettre dans une pile */ + /* à la fin du processus, le graphe peut ne pas être vide, il s'agit des temporaires qui ont au moins k voisin */ + /*-------------------------------------------------------------------------------------------------------------*/ + + public int simplify() + { + int noColoredVertex = vertexNb; + + for (int i = 0;i<vertexNb;i++){ + if (color[i]!=NOCOLOR) + noColoredVertex-=1; + } + + boolean modif = true; + + while (stack.size() != noColoredVertex && modif){ + Node[] nodes = graph.nodeArray(); + + modif = false; + for (Node node : nodes){ + + if (!removed.isMember(node.label())){ + if (neighborsNb(node.label())<colorNb && color[node.label()] == NOCOLOR){ + stack.push(node.label()); + removed.add(node.label()); + modif = true; + + } + } + + } + } + return 0; + } + + /*-------------------------------------------------------------------------------------------------------------*/ + /*-------------------------------------------------------------------------------------------------------------*/ + + public void spill() + { + while (stack.size()!=vertexNb){ + for (int i = 0;i<removed.getSize();i++){ + if (!removed.isMember(i)){ + stack.push(i); + removed.add(i); + spill.add(i); + break; + } + } + simplify(); + } + + } + + + /*-------------------------------------------------------------------------------------------------------------*/ + /*-------------------------------------------------------------------------------------------------------------*/ + + public void color() + { + this.simplify(); + this.spill(); + this.select(); + } + + public void affiche() + { + System.out.println("vertex\tcolor"); + for(int i = 0; i < vertexNb; i++){ + System.out.println(i + "\t" + color[i]); + } + } + + }