From 58777e499a1b3f41f18bdc4b9ca204a7e908217a Mon Sep 17 00:00:00 2001 From: b21202065 <niels.bauquin@etu.univ-amu.fr> Date: Fri, 2 Feb 2024 17:58:41 +0100 Subject: [PATCH] geg --- src/l.cfg | 45 +++-- src/sa/Sc2sa.java | 423 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 443 insertions(+), 25 deletions(-) diff --git a/src/l.cfg b/src/l.cfg index c562d10..bb53371 100644 --- a/src/l.cfg +++ b/src/l.cfg @@ -41,7 +41,7 @@ lire = 'lire'; int = 'entier'; boolean = 'bool'; nombre = chiffre+; -id = alpha [alpha + chiffre]*; +id = alpha[alpha+chiffre]*; Ignored Tokens @@ -49,44 +49,69 @@ espaces, commentaire; Productions -epsilon = ; +prog = {prog} ldecvar ldecfonc; + exp = {or} exp or exp1 | {exp1} exp1; + exp1 = {and} exp1 and exp2 | {exp2} exp2; + exp2 = {egal} exp2 egal exp3 | {inf} exp2 inf exp3 | {exp3} exp3; + exp3 = {add} exp3 add exp4 | {sub} exp3 sub exp4 | {exp4} exp4; + exp4 = {mult} exp4 mult exp5 | {div} exp4 div exp5 | {exp5} exp5; + exp5 = {not} not exp5 | {exp6} exp6; -exp6 = {parenthesis} gpar exp dpar | {nombre} nombre | {var} var | {vrai} vrai | {faux} faux | {lire} lire gpar dpar; -var = {id} id | {crochets} id gcro exp dcro; +exp6 = {parenthesis} gpar exp dpar | {nombre} nombre | {vrai} vrai | {faux} faux | {af} af | {var} var | {lire} lire gpar dpar; + ins = {affectation} var egal exp pvirg| {fairetantque} tantque exp faire bloc | {fonction} id gpar lexp dpar pvirg| -{sisinon} si exp alors [alors1]: bloc sinon [sinon1]: bloc | {sialors} si exp alors bloc | +{sisinon} si exp alors [alors1]:bloc sinon [sinon1]:bloc | {retour} retour exp pvirg | -{ecrire} ecrire gpar exp dpar pvirg; +{ecrire} ecrire gpar exp dpar pvirg | +{bloc} bloc; + + bloc = {accolades} gacc lins dacc; + lins = {lins} ins lins | {epsilon} epsilon; + lexp = {lexp2} exp lexp2 | {epsilon} epsilon; -lexp2 = {virgule} exp lexp2 | {exp} exp; + +lexp2 = {virgule} virg exp lexp2 | {epsilon} epsilon; + + +af = {af} id gpar lexp dpar; + + +var = {id} id | {crochets} id gcro exp dcro; type = {boolean} boolean | {int} int; + typeopt = {type} type | {epsilon} epsilon; + decvar = {var} type id | {tableau} type id gcro nombre dcro; -decfonc = {fonction} typeopt id gpar [params]: ldecvar dpar [locals]: ldecvar bloc; + +decfonc = {fonction} typeopt id gpar [params]:ldecvar dpar [locals]:ldecvar bloc; + ldecvar = {listedecvar} decvar ldecvar2 | {epsilon} epsilon; -ldecvar2 = {listedecvar2} virg decvar ldecvar2 | {decvar} decvar; + +ldecvar2 = {listedecvar2} virg decvar ldecvar2 | {epsilon} epsilon; + ldecfonc = {listedecfonc} decfonc ldecfonc | {epsilon} epsilon; -prog = {prog} ldecvar ldecfonc; \ No newline at end of file + +epsilon =; diff --git a/src/sa/Sc2sa.java b/src/sa/Sc2sa.java index 0bc4abd..ff001b3 100644 --- a/src/sa/Sc2sa.java +++ b/src/sa/Sc2sa.java @@ -11,12 +11,12 @@ public class Sc2sa extends DepthFirstAdapter public void defaultIn(@SuppressWarnings("unused") Node node) { - //System.out.println("<" + node.getClass().getSimpleName() + ">"); + System.out.println("<" + node.getClass().getSimpleName() + ">"); } public void defaultOut(@SuppressWarnings("unused") Node node) { - //System.out.println("</" + node.getClass().getSimpleName() + ">"); + System.out.println("</" + node.getClass().getSimpleName() + ">"); } public SaProg getRoot() @@ -25,19 +25,412 @@ public class Sc2sa extends DepthFirstAdapter } - // exp3 = {plus} exp3 plus exp4 - /* @Override - public void caseAPlusExp3(APlusExp3 node) + // exp3 = {plus} exp3 plus exp4 + + + + @Override + public void caseStart(Start node) { + super.caseStart(node); + } + + @Override + public void caseAProgProg(AProgProg node) { + SaLDecVar op1 = null; + SaLDecFonc op2 = null; + inAProgProg(node); + node.getLdecvar().apply(this); + op1 = (SaLDecVar) this.returnValue; + node.getLdecfonc().apply(this); + op2 = (SaLDecFonc) this.returnValue; + this.returnValue = new SaProg(op1, op2); + outAProgProg(node); + } + + @Override + public void caseAOrExp(AOrExp node) { + SaExp op1 = null; + SaExp op2 = null; + inAOrExp(node); + node.getExp().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp1().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpOr(op1, op2); + outAOrExp(node); + } + + @Override + public void caseAExp1Exp(AExp1Exp node) { + SaExp op = null; + inAExp1Exp(node); + node.getExp1().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outAExp1Exp(node); + } + + @Override + public void caseAAndExp1(AAndExp1 node) { + SaExp op1 = null; + SaExp op2 = null; + inAAndExp1(node); + node.getExp1().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp2().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpAnd(op1, op2); + outAAndExp1(node); + } + + @Override + public void caseAExp2Exp1(AExp2Exp1 node) { + SaExp op = null; + inAExp2Exp1(node); + node.getExp2().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outAExp2Exp1(node); + } + + @Override + public void caseAEgalExp2(AEgalExp2 node) { + SaExp op1 = null; + SaExp op2 = null; + inAEgalExp2(node); + node.getExp2().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp3().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpEqual(op1, op2); + outAEgalExp2(node); + } + + @Override + public void caseAInfExp2(AInfExp2 node) { + SaExp op1 = null; + SaExp op2 = null; + inAInfExp2(node); + node.getExp2().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp3().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpInf(op1, op2); + outAInfExp2(node); + } + + @Override + public void caseAExp3Exp2(AExp3Exp2 node) { + SaExp op = null; + inAExp3Exp2(node); + node.getExp3().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outAExp3Exp2(node); + } + + @Override + public void caseAAddExp3(AAddExp3 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); - }*/ + SaExp op1 = null; + SaExp op2 = null; + inAAddExp3(node); + node.getExp3().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp4().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpAdd(op1, op2); + outAAddExp3(node); + } + + @Override + public void caseASubExp3(ASubExp3 node) { + SaExp op1 = null; + SaExp op2 = null; + inASubExp3(node); + node.getExp3().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp4().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpAdd(op1, op2); + outASubExp3(node); + } + + @Override + public void caseAExp4Exp3(AExp4Exp3 node) { + SaExp op = null; + inAExp4Exp3(node); + node.getExp4().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outAExp4Exp3(node); + } + + @Override + public void caseAMultExp4(AMultExp4 node) { + SaExp op1 = null; + SaExp op2 = null; + inAMultExp4(node); + node.getExp4().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp5().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpMult(op1, op2); + outAMultExp4(node); + } + + @Override + public void caseADivExp4(ADivExp4 node) { + SaExp op1 = null; + SaExp op2 = null; + inADivExp4(node); + node.getExp4().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp5().apply(this); + op2 = (SaExp) this.returnValue; + this.returnValue = new SaExpDiv(op1, op2); + outADivExp4(node); + } + + @Override + public void caseAExp5Exp4(AExp5Exp4 node) { + SaExp op = null; + inAExp5Exp4(node); + node.getExp5().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outAExp5Exp4(node); + } + + @Override + public void caseANotExp5(ANotExp5 node) { + SaExp op = null; + inANotExp5(node); + node.getExp5().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExpNot(op); + outANotExp5(node); + } + + @Override + public void caseAExp6Exp5(AExp6Exp5 node) { + SaExp op = null; + inAExp6Exp5(node); + node.getExp6().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outAExp6Exp5(node); + } + + @Override + public void caseAParenthesisExp6(AParenthesisExp6 node) { + SaExp op1 = null; + SaExp op2 = null; + SaExp op3 = null; + inAParenthesisExp6(node); + node.getGpar().apply(this); + op1 = (SaExp) this.returnValue; + node.getExp().apply(this); + op2 = (SaExp) this.returnValue; + node.getDpar().apply(this); + op3 = (SaExp) this.returnValue; + this.returnValue = new SaExp(op1,op2,op3); + outAParenthesisExp6(node); + } + + @Override + public void caseANombreExp6(ANombreExp6 node) { + SaExp op = null; + inANombreExp6(node); + node.getNombre().apply(this); + op = (SaExp) this.returnValue; + this.returnValue = new SaExp(op); + outANombreExp6(node); + } + + @Override + public void caseAVraiExp6(AVraiExp6 node) { + super.caseAVraiExp6(node); + } + + @Override + public void caseAFauxExp6(AFauxExp6 node) { + super.caseAFauxExp6(node); + } + + @Override + public void caseAAfExp6(AAfExp6 node) { + super.caseAAfExp6(node); + } + + @Override + public void caseAVarExp6(AVarExp6 node) { + super.caseAVarExp6(node); + } + + @Override + public void caseALireExp6(ALireExp6 node) { + super.caseALireExp6(node); + } + + @Override + public void caseAAffectationIns(AAffectationIns node) { + super.caseAAffectationIns(node); + } + + @Override + public void caseAFairetantqueIns(AFairetantqueIns node) { + super.caseAFairetantqueIns(node); + } + + @Override + public void caseAFonctionIns(AFonctionIns node) { + super.caseAFonctionIns(node); + } + + @Override + public void caseASialorsIns(ASialorsIns node) { + super.caseASialorsIns(node); + } + + @Override + public void caseASisinonIns(ASisinonIns node) { + super.caseASisinonIns(node); + } + + @Override + public void caseARetourIns(ARetourIns node) { + super.caseARetourIns(node); + } + + @Override + public void caseAEcrireIns(AEcrireIns node) { + super.caseAEcrireIns(node); + } + + @Override + public void caseABlocIns(ABlocIns node) { + super.caseABlocIns(node); + } + + @Override + public void caseAAccoladesBloc(AAccoladesBloc node) { + super.caseAAccoladesBloc(node); + } + + @Override + public void caseALinsLins(ALinsLins node) { + super.caseALinsLins(node); + } + + @Override + public void caseAEpsilonLins(AEpsilonLins node) { + super.caseAEpsilonLins(node); + } + + @Override + public void caseALexp2Lexp(ALexp2Lexp node) { + super.caseALexp2Lexp(node); + } + + @Override + public void caseAEpsilonLexp(AEpsilonLexp node) { + super.caseAEpsilonLexp(node); + } + + @Override + public void caseAVirguleLexp2(AVirguleLexp2 node) { + super.caseAVirguleLexp2(node); + } + + @Override + public void caseAEpsilonLexp2(AEpsilonLexp2 node) { + super.caseAEpsilonLexp2(node); + } + + @Override + public void caseAAfAf(AAfAf node) { + super.caseAAfAf(node); + } + + @Override + public void caseAIdVar(AIdVar node) { + super.caseAIdVar(node); + } + + @Override + public void caseACrochetsVar(ACrochetsVar node) { + super.caseACrochetsVar(node); + } + + @Override + public void caseABooleanType(ABooleanType node) { + super.caseABooleanType(node); + } + + @Override + public void caseAIntType(AIntType node) { + super.caseAIntType(node); + } + + @Override + public void caseATypeTypeopt(ATypeTypeopt node) { + super.caseATypeTypeopt(node); + } + + @Override + public void caseAEpsilonTypeopt(AEpsilonTypeopt node) { + super.caseAEpsilonTypeopt(node); + } + + @Override + public void caseAVarDecvar(AVarDecvar node) { + super.caseAVarDecvar(node); + } + + @Override + public void caseATableauDecvar(ATableauDecvar node) { + super.caseATableauDecvar(node); + } + + @Override + public void caseAFonctionDecfonc(AFonctionDecfonc node) { + super.caseAFonctionDecfonc(node); + } + + @Override + public void caseAListedecvarLdecvar(AListedecvarLdecvar node) { + super.caseAListedecvarLdecvar(node); + } + + @Override + public void caseAEpsilonLdecvar(AEpsilonLdecvar node) { + super.caseAEpsilonLdecvar(node); + } + + @Override + public void caseAListedecvar2Ldecvar2(AListedecvar2Ldecvar2 node) { + super.caseAListedecvar2Ldecvar2(node); + } + + @Override + public void caseAEpsilonLdecvar2(AEpsilonLdecvar2 node) { + super.caseAEpsilonLdecvar2(node); + } + + @Override + public void caseAListedecfoncLdecfonc(AListedecfoncLdecfonc node) { + super.caseAListedecfoncLdecfonc(node); + } + + @Override + public void caseAEpsilonLdecfonc(AEpsilonLdecfonc node) { + super.caseAEpsilonLdecfonc(node); + } + + @Override + public void caseAEpsilon(AEpsilon node) { + super.caseAEpsilon(node); + } } -- GitLab