diff --git a/ArbreAbstrait/Moins.java b/ArbreAbstrait/Moins.java new file mode 100644 index 0000000000000000000000000000000000000000..b3dd32a6f11484fdf946691eca1327111ca12c02 --- /dev/null +++ b/ArbreAbstrait/Moins.java @@ -0,0 +1,19 @@ +public class Moins extends Unaire{ + public Moins(Expression operande, String fl, int line, int col) { + super(operande, 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 f42a339e75a96b7a5cd44f7fc8a37de1c6362fb2..126236c086ba36e63550184a7795a265d56f18c5 100755 --- a/Tests/test_base_with_sementic_issue.input +++ b/Tests/test_base_with_sementic_issue.input @@ -1,8 +1,4 @@ programme Program debutprg - c = c * 2; - b = 3; - d = c <> b; - - lire "oui"; + c = -2; finprg diff --git a/Visitors/ASTVisitor.java b/Visitors/ASTVisitor.java index 1c1af6adace5257e25583fef2fe88fd88cda6c32..1acb5759996eb3528d09903cd6995e3f13dc51a6 100755 --- a/Visitors/ASTVisitor.java +++ b/Visitors/ASTVisitor.java @@ -37,7 +37,7 @@ public interface ASTVisitor { Object visit(InfEgal node); Object visit(Inferieur node); Object visit(Lire node); - // Object visit(Moins node); + Object visit(Moins node); Object visit(Nombre node); Object visit(Non node); diff --git a/Visitors/ByteCodeGenerator.java b/Visitors/ByteCodeGenerator.java index d3dd8152a1d67dbd33c79eae139b198384ee7d06..4f0b76b897704db1c9a5ec4ed21f24bf021d7679 100755 --- a/Visitors/ByteCodeGenerator.java +++ b/Visitors/ByteCodeGenerator.java @@ -62,7 +62,7 @@ public class ByteCodeGenerator implements ASTVisitor { public Object visit(Lire node) { return null; } - // public Object visit(Moins node) { return null; } + public Object visit(Moins node) { return null; } public Object visit(Nombre node) { return null; diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java index fd5a3cf32e86da9a122465a0b85735f68e089a08..e659598a151c6c81f7cc895ce9b18ea7a9be0b0e 100755 --- a/Visitors/SemanticAnalyzer.java +++ b/Visitors/SemanticAnalyzer.java @@ -64,7 +64,7 @@ public class SemanticAnalyzer implements ASTVisitor { public Object visit(Lire node) { return null; } - // public Object visit(Moins node) { return null; } + public Object visit(Moins node) { return null; } public Object visit(Nombre node) { return null; diff --git a/Visitors/SourceCodeGenerator.java b/Visitors/SourceCodeGenerator.java index d825a48b18335d82777618a14d866371f52442a3..52aa723a6660e880e10631497f8010e6b221f536 100755 --- a/Visitors/SourceCodeGenerator.java +++ b/Visitors/SourceCodeGenerator.java @@ -184,11 +184,11 @@ public class SourceCodeGenerator implements ASTVisitor { return null; } - // public Object visit(Moins node){ - // code += "-"; - // node.getOperand().accept(this); - // return null; - // } + public Object visit(Moins node){ + code += node.operateur(); + node.getOperand().accept(this); + return null; + } public Object visit(Nombre node) { code += Integer.toString(node.getValeur()); diff --git a/hepial.cup b/hepial.cup index 079c23077b1dd62d3c4985e046f8e6a9a8079633..596467f396d0536cad5567bceeb3a47f3dfea73b 100755 --- a/hepial.cup +++ b/hepial.cup @@ -90,7 +90,7 @@ relation ::= expr:a EQUALS expr:b {: RESULT = new Egal(a, b, "", aleft | expr:a SUPEQUAL expr:b {: RESULT = new SupEgal(a, b, "", aleft, aright); :}; op_una ::= NOT expr:a {: RESULT = new Non(a, "", aleft, aright); :} - | MINUS expr {: :} + | MINUS expr:a {: RESULT = new Moins(a, "", aleft, aright);:} %prec UMINUS; operand ::= access:access {: RESULT = access; :}