From 959ed44c32fabf26ce861dda439af2ae2b630610 Mon Sep 17 00:00:00 2001 From: b21223327 <zakaria.bazizi@etu.univ-amu.fr> Date: Wed, 21 Feb 2024 14:28:21 +0100 Subject: [PATCH] fixing things here check point --- src/add1.l | 4 + src/add1.sa | 1 + src/add1.sc | 60 ++++++++++++ src/lParser/node/ABoolType.java | 95 +++++++++++++++++++ src/lParser/node/AEntierType.java | 95 +++++++++++++++++++ ...ppelfncAppelfnc.java => AFonctionIns.java} | 10 +- src/sa/Sc2sa.java | 18 ++-- src/ts/Sa2ts.java | 3 +- test/result.txt | 20 +--- 9 files changed, 271 insertions(+), 35 deletions(-) create mode 100644 src/add1.l create mode 100644 src/add1.sa create mode 100644 src/add1.sc create mode 100644 src/lParser/node/ABoolType.java create mode 100644 src/lParser/node/AEntierType.java rename src/lParser/node/{AAppelfncAppelfnc.java => AFonctionIns.java} (96%) diff --git a/src/add1.l b/src/add1.l new file mode 100644 index 0000000..7d1a3bb --- /dev/null +++ b/src/add1.l @@ -0,0 +1,4 @@ +main() +ecrire(3 + 10); +{ +} diff --git a/src/add1.sa b/src/add1.sa new file mode 100644 index 0000000..58404a6 --- /dev/null +++ b/src/add1.sa @@ -0,0 +1 @@ +(SaProg null (SaLDecFonc (SaDecFonc main null null null (SaInstBloc (SaLInst (SaInstEcriture (SaExpAdd 3 10)) null))) null)) diff --git a/src/add1.sc b/src/add1.sc new file mode 100644 index 0000000..741d658 --- /dev/null +++ b/src/add1.sc @@ -0,0 +1,60 @@ +<Start> + <AProg> + <ALdec> + <AEpsilon> + </AEpsilon> + </ALdec> + <ALstdecfncLdf> + <ADeclafoncDecfonc> + <ATypeopt> + <AEpsilon> + </AEpsilon> + </ATypeopt> + <ALdec> + <AEpsilon> + </AEpsilon> + </ALdec> + <ALdec> + <AEpsilon> + </AEpsilon> + </ALdec> + <AInstrBloc> + <AListeinstrLi> + <AWriteIns> + <AAndExp> + <AEqualsAnd> + <AAddEquals> + <APlusAdd> + <AMultAdd> + <ANegMult> + <AE6Neg> + <ANombreE6> + </ANombreE6> + </AE6Neg> + </ANegMult> + </AMultAdd> + <ANegMult> + <AE6Neg> + <ANombreE6> + </ANombreE6> + </AE6Neg> + </ANegMult> + </APlusAdd> + </AAddEquals> + </AEqualsAnd> + </AAndExp> + </AWriteIns> + <AEpsilonLi> + <AEpsilon> + </AEpsilon> + </AEpsilonLi> + </AListeinstrLi> + </AInstrBloc> + </ADeclafoncDecfonc> + <ALdf> + <AEpsilon> + </AEpsilon> + </ALdf> + </ALstdecfncLdf> + </AProg> +</Start> diff --git a/src/lParser/node/ABoolType.java b/src/lParser/node/ABoolType.java new file mode 100644 index 0000000..fee3076 --- /dev/null +++ b/src/lParser/node/ABoolType.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package lParser.node; + +import lParser.analysis.*; + +@SuppressWarnings("nls") +public final class ABoolType extends PType +{ + private TBool _bool_; + + public ABoolType() + { + // Constructor + } + + public ABoolType( + @SuppressWarnings("hiding") TBool _bool_) + { + // Constructor + setBool(_bool_); + + } + + @Override + public Object clone() + { + return new ABoolType( + cloneNode(this._bool_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseABoolType(this); + } + + public TBool getBool() + { + return this._bool_; + } + + public void setBool(TBool node) + { + if(this._bool_ != null) + { + this._bool_.parent(null); + } + + if(node != null) + { + if(node.parent() != null) + { + node.parent().removeChild(node); + } + + node.parent(this); + } + + this._bool_ = node; + } + + @Override + public String toString() + { + return "" + + toString(this._bool_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._bool_ == child) + { + this._bool_ = null; + return; + } + + throw new RuntimeException("Not a child."); + } + + @Override + void replaceChild(@SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) + { + // Replace child + if(this._bool_ == oldChild) + { + setBool((TBool) newChild); + return; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/lParser/node/AEntierType.java b/src/lParser/node/AEntierType.java new file mode 100644 index 0000000..62ef59d --- /dev/null +++ b/src/lParser/node/AEntierType.java @@ -0,0 +1,95 @@ +/* This file was generated by SableCC (http://www.sablecc.org/). */ + +package lParser.node; + +import lParser.analysis.*; + +@SuppressWarnings("nls") +public final class AEntierType extends PType +{ + private TEntier _entier_; + + public AEntierType() + { + // Constructor + } + + public AEntierType( + @SuppressWarnings("hiding") TEntier _entier_) + { + // Constructor + setEntier(_entier_); + + } + + @Override + public Object clone() + { + return new AEntierType( + cloneNode(this._entier_)); + } + + @Override + public void apply(Switch sw) + { + ((Analysis) sw).caseAEntierType(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; + } + + @Override + public String toString() + { + return "" + + toString(this._entier_); + } + + @Override + void removeChild(@SuppressWarnings("unused") Node child) + { + // Remove child + if(this._entier_ == child) + { + this._entier_ = 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; + } + + throw new RuntimeException("Not a child."); + } +} diff --git a/src/lParser/node/AAppelfncAppelfnc.java b/src/lParser/node/AFonctionIns.java similarity index 96% rename from src/lParser/node/AAppelfncAppelfnc.java rename to src/lParser/node/AFonctionIns.java index cc91e8f..a9928f9 100644 --- a/src/lParser/node/AAppelfncAppelfnc.java +++ b/src/lParser/node/AFonctionIns.java @@ -5,7 +5,7 @@ package lParser.node; import lParser.analysis.*; @SuppressWarnings("nls") -public final class AAppelfncAppelfnc extends PAppelfnc +public final class AFonctionIns extends PIns { private TId _id_; private TGparenthese _gparenthese_; @@ -13,12 +13,12 @@ public final class AAppelfncAppelfnc extends PAppelfnc private TDparenthese _dparenthese_; private TPointvirgule _pointvirgule_; - public AAppelfncAppelfnc() + public AFonctionIns() { // Constructor } - public AAppelfncAppelfnc( + public AFonctionIns( @SuppressWarnings("hiding") TId _id_, @SuppressWarnings("hiding") TGparenthese _gparenthese_, @SuppressWarnings("hiding") PLe _le_, @@ -41,7 +41,7 @@ public final class AAppelfncAppelfnc extends PAppelfnc @Override public Object clone() { - return new AAppelfncAppelfnc( + return new AFonctionIns( cloneNode(this._id_), cloneNode(this._gparenthese_), cloneNode(this._le_), @@ -52,7 +52,7 @@ public final class AAppelfncAppelfnc extends PAppelfnc @Override public void apply(Switch sw) { - ((Analysis) sw).caseAAppelfncAppelfnc(this); + ((Analysis) sw).caseAFonctionIns(this); } public TId getId() diff --git a/src/sa/Sc2sa.java b/src/sa/Sc2sa.java index 9bce3d5..5562015 100644 --- a/src/sa/Sc2sa.java +++ b/src/sa/Sc2sa.java @@ -623,7 +623,7 @@ public class Sc2sa extends DepthFirstAdapter { inAReturnIns(node); SaExp op1 = null ; - node.getRetourner().apply(this); + node.getExp().apply(this); op1 = (SaExp) this.returnValue ; returnValue = new SaInstRetour(op1); outAReturnIns(node); @@ -754,8 +754,7 @@ public class Sc2sa extends DepthFirstAdapter @Override public void caseAEpsilon(AEpsilon node) { - inAEpsilon(node); - outAEpsilon(node); + this.returnValue = null; } public void inAExprLe(AExprLe node) @@ -792,10 +791,8 @@ public class Sc2sa extends DepthFirstAdapter public void caseAEpsilonLe(AEpsilonLe node) { inAEpsilonLe(node); - if(node.getEpsilon() != null) - { - node.getEpsilon().apply(this); - } + node.getEpsilon().apply(this); + this.returnValue = null ; outAEpsilonLe(node); } @@ -840,6 +837,7 @@ public class Sc2sa extends DepthFirstAdapter { inAEpsilonLse(node); node.getEpsilon().apply(this); + this.returnValue = null ; outAEpsilonLse(node); } @@ -1023,10 +1021,8 @@ public class Sc2sa extends DepthFirstAdapter public void caseATypeopt(ATypeopt node) { inATypeopt(node); - if(node.getEpsilon() != null) - { - node.getEpsilon().apply(this); - } + node.getEpsilon().apply(this); + this.returnValue = null ; outATypeopt(node); } diff --git a/src/ts/Sa2ts.java b/src/ts/Sa2ts.java index 50a80a6..0c9f4a6 100644 --- a/src/ts/Sa2ts.java +++ b/src/ts/Sa2ts.java @@ -15,8 +15,7 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { public Ts getTableGlobale(){return this.tableGlobale;} - public Sa2ts() - { + public Sa2ts() { tableGlobale = new Ts(); tableLocaleCourante = null; context = Context.GLOBAL; diff --git a/test/result.txt b/test/result.txt index f75fcdf..fb3272b 100644 --- a/test/result.txt +++ b/test/result.txt @@ -416,21 +416,21 @@ saParser.parser.ParserException: [1,1] expecting: '(' ' ERROR evaluateSa for input appel1.l : 'syntax error -saParser.parser.ParserException: [1,1] expecting: '(' +saParser.parser.ParserException: [1,39] expecting: 'entier', 'bool', 'nul' at saParser.parser.Parser.parse(Parser.java:190) at sa.LoadSa.<init>(LoadSa.java:32) at SaVM.main(SaVM.java:27) ' ERROR evaluateSa for input appel2.l : 'syntax error -saParser.parser.ParserException: [1,1] expecting: '(' +saParser.parser.ParserException: [1,39] expecting: 'entier', 'bool', 'nul' at saParser.parser.Parser.parse(Parser.java:190) at sa.LoadSa.<init>(LoadSa.java:32) at SaVM.main(SaVM.java:27) ' ERROR evaluateSa for input appel3.l : 'syntax error -saParser.parser.ParserException: [1,1] expecting: '(' +saParser.parser.ParserException: [1,39] expecting: 'entier', 'bool', 'nul' at saParser.parser.Parser.parse(Parser.java:190) at sa.LoadSa.<init>(LoadSa.java:32) at SaVM.main(SaVM.java:27) @@ -765,13 +765,6 @@ saParser.parser.ParserException: [1,42] expecting: 'entier', 'bool', 'nul' at SaVM.main(SaVM.java:27) ' -ERROR evaluateSa for input tab1.l : 'syntax error -saParser.parser.ParserException: [1,1] expecting: '(' - at saParser.parser.Parser.parse(Parser.java:190) - at sa.LoadSa.<init>(LoadSa.java:32) - at SaVM.main(SaVM.java:27) -' - ERROR evaluateSa for input tab2.l : 'syntax error saParser.parser.ParserException: [1,1] expecting: '(' at saParser.parser.Parser.parse(Parser.java:190) @@ -786,13 +779,6 @@ saParser.parser.ParserException: [1,1] expecting: '(' at SaVM.main(SaVM.java:27) ' -ERROR evaluateSa for input tab4.l : 'syntax error -saParser.parser.ParserException: [1,1] expecting: '(' - at saParser.parser.Parser.parse(Parser.java:190) - at sa.LoadSa.<init>(LoadSa.java:32) - at SaVM.main(SaVM.java:27) -' - ERROR evaluateSa for input tantque1.l : 'syntax error saParser.parser.ParserException: [1,1] expecting: '(' at saParser.parser.Parser.parse(Parser.java:190) -- GitLab