diff --git a/ArbreAbstrait/Division.java b/ArbreAbstrait/Division.java new file mode 100755 index 0000000000000000000000000000000000000000..cee264cc8096a2e0e0566808c780087fc66a22c5 --- /dev/null +++ b/ArbreAbstrait/Division.java @@ -0,0 +1,26 @@ +/* + * Represent an addition expression node inside the AST. + */ + +public class Division extends Arithmetique { + /** + * Constructor + */ + public Division(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) { + super(operandeGauche, operandeDroite, fl, line, col); + } + + /** + * Get the binary operator + */ + public String operateur() { + return "/"; + } + + /** + * Accepts a AST visitor + */ + Object accept(ASTVisitor visitor){ + return visitor.visit(this); + } +} diff --git a/Tests/test_base_with_sementic_issue.input b/Tests/test_base_with_sementic_issue.input index 675861eeb2c2108e9efe7715e5457c7c09686a2d..93e1ccf5ca7341f4b62d4c65ad9e0d0f5c68187a 100755 --- a/Tests/test_base_with_sementic_issue.input +++ b/Tests/test_base_with_sementic_issue.input @@ -2,5 +2,5 @@ programme Program debutprg b = 3; - c = c - 2; + c = c / 2; finprg diff --git a/Visitors/ASTVisitor.java b/Visitors/ASTVisitor.java index d9fae68287e56c6741d339c68b01bf456e69cafb..5f0e0666d07bac4fbee34ba1359d3d993f1cf148 100755 --- a/Visitors/ASTVisitor.java +++ b/Visitors/ASTVisitor.java @@ -19,7 +19,7 @@ public interface ASTVisitor { Object visit(DeclarationProgramme node); // Object visit(DeclarationVariable node); // Object visit(Diff node); -// Object visit(Division node); + Object visit(Division node); // Object visit(Ecrire node); Object visit(Egal node); // Object visit(Et node); diff --git a/Visitors/ByteCodeGenerator.java b/Visitors/ByteCodeGenerator.java index 37c1db83adbb5476d3b678d99d903872515dc975..d4fe13f82aa35d91a83948eb8cd19b826a45a60d 100755 --- a/Visitors/ByteCodeGenerator.java +++ b/Visitors/ByteCodeGenerator.java @@ -26,7 +26,7 @@ public class ByteCodeGenerator implements ASTVisitor{ // public Object visit(Diff node) { return null; } -// public Object visit(Division node) { return null; } + public Object visit(Division node) { return null; } // public Object visit(Ecrire node) { return null; } diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java index 579a7e0818b97ec64912220e4939ec4759c02d86..12e32f8e5749b04312461fb90c03cc3ce55df895 100755 --- a/Visitors/SemanticAnalyzer.java +++ b/Visitors/SemanticAnalyzer.java @@ -28,7 +28,7 @@ public class SemanticAnalyzer implements ASTVisitor { // public Object visit(Diff node) { return null; } -// public Object visit(Division node) { return null; } + public Object visit(Division node) { return null; } // public Object visit(Ecrire node) { return null; } diff --git a/Visitors/SourceCodeGenerator.java b/Visitors/SourceCodeGenerator.java index 96fb77687d89aab77c1b415f87b4134c975565e9..572222ecad40537609bbc079cb28aab3ff7f2092 100755 --- a/Visitors/SourceCodeGenerator.java +++ b/Visitors/SourceCodeGenerator.java @@ -123,12 +123,12 @@ public class SourceCodeGenerator implements ASTVisitor{ // return null; // } // -// public Object visit(Division node){ -// node.getGauche().accept(this); -// code += " / "; -// node.getDroite().accept(this); -// return null; -// } + public Object visit(Division node){ + node.getGauche().accept(this); + code += " / "; + node.getDroite().accept(this); + return null; + } // // public Object visit(Ecrire node){ // code += "ecrire "; diff --git a/hepial.cup b/hepial.cup index bb16b12927ef8cc6972e3db16a89882f85d22462..74de5d3238a915a9674f6268231f7c44bfe518b4 100755 --- a/hepial.cup +++ b/hepial.cup @@ -78,7 +78,7 @@ declar_const ::= CONSTANT type IDENT EQUAL expr SEMICOLON {: :}; op_bin ::= expr:a PLUS expr:b {: RESULT = new Addition(a, b, "", aleft, aright); :} | expr:a MINUS expr:b {: RESULT = new Soustraction(a, b, "", aleft, aright); :} | expr TIMES expr {: :} - | expr DIVIDE expr {: :} + | expr:a DIVIDE expr:b {: RESULT = new Division(a, b, "", aleft, aright);:} | expr AND expr {: :} | expr OR expr {: :}; diff --git a/parser.java b/parser.java index cd55c68f35a9e45e397983541a432b2f6433a308..62206d13a8639df71c96790b70b42b3506b17b58 100644 --- a/parser.java +++ b/parser.java @@ -1,7 +1,7 @@ //---------------------------------------------------- // The following code was generated by CUP v0.11a beta 20060608 -// Wed Nov 23 18:32:15 CET 2022 +// Wed Nov 23 18:56:00 CET 2022 //---------------------------------------------------- import java_cup.runtime.*; @@ -10,7 +10,7 @@ import java.io.*; import java.util.*; /** CUP v0.11a beta 20060608 generated parser. - * @version Wed Nov 23 18:32:15 CET 2022 + * @version Wed Nov 23 18:56:00 CET 2022 */ public class parser extends java_cup.runtime.lr_parser { @@ -747,7 +747,13 @@ class CUP$parser$actions { case 17: // op_bin ::= expr DIVIDE expr { Binaire RESULT =null; - + int aleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int aright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Expression a = (Expression)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int bleft = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left; + int bright = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right; + Expression b = (Expression)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value; + RESULT = new Division(a, b, "", aleft, aright); CUP$parser$result = parser.getSymbolFactory().newSymbol("op_bin",20, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT); } return CUP$parser$result; diff --git a/sym.java b/sym.java index 94a5a6eb0deff3f1f887c04bed0894d72c8477dd..9e2f5eb614d62b6dd6f3d48cc62cdcda8061a7cc 100644 --- a/sym.java +++ b/sym.java @@ -1,7 +1,7 @@ //---------------------------------------------------- // The following code was generated by CUP v0.11a beta 20060608 -// Wed Nov 23 18:32:15 CET 2022 +// Wed Nov 23 18:56:00 CET 2022 //---------------------------------------------------- /** CUP generated class containing symbol constants. */