diff --git a/ArbreAbstrait/Ecrire.java b/ArbreAbstrait/Ecrire.java new file mode 100644 index 0000000000000000000000000000000000000000..213cc4fea8137b3db5a4c09164418733c7f295d9 --- /dev/null +++ b/ArbreAbstrait/Ecrire.java @@ -0,0 +1,33 @@ +/* + * Represent an equal comparaison expression node inside the AST. + */ + + + +public class Ecrire extends Instruction { + private Expression source; + + /** + * Constructor + */ + public Ecrire(Expression source, String fl, int line, int col) { + super(fl, line, col); + this.source = source; + } + + /** + * Get the binary operator + */ + public Expression getSource() { + return this.source; + } + + + + /** + * 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 afe9a63cb7a06e122f57382c6d40ce2cb8edfe20..61236bf0949010374347d4350ea4d0786a1aaf88 100755 --- a/Tests/test_base_with_sementic_issue.input +++ b/Tests/test_base_with_sementic_issue.input @@ -4,4 +4,6 @@ debutprg c = c * 2; b = 3; d = c <> b; + + ecrire "oui"; finprg diff --git a/Visitors/ASTVisitor.java b/Visitors/ASTVisitor.java index 0155cbba387d7e25ef98639ac2daa3014a2debad..370fbd39781fdb0a73f4191271e50142741d77a5 100755 --- a/Visitors/ASTVisitor.java +++ b/Visitors/ASTVisitor.java @@ -26,7 +26,7 @@ public interface ASTVisitor { Object visit(Diff node); Object visit(Division node); - // Object visit(Ecrire node); + Object visit(Ecrire node); Object visit(Egal node); Object visit(Et node); diff --git a/Visitors/ByteCodeGenerator.java b/Visitors/ByteCodeGenerator.java index 6775412657e845bb7f4c81317e587f9edd40bbac..7aab40094544cd7895aea9ce0646a7b235e3e121 100755 --- a/Visitors/ByteCodeGenerator.java +++ b/Visitors/ByteCodeGenerator.java @@ -40,7 +40,7 @@ public class ByteCodeGenerator implements ASTVisitor { return null; } - // public Object visit(Ecrire node) { return null; } + public Object visit(Ecrire node) { return null; } public Object visit(Egal node) { return null; diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java index 72f1e0d16ee828a61161421bd6e6e3c9fd640438..c9e404bdccefc3650c601ad3aa52e36c412bfbe0 100755 --- a/Visitors/SemanticAnalyzer.java +++ b/Visitors/SemanticAnalyzer.java @@ -42,7 +42,7 @@ public class SemanticAnalyzer implements ASTVisitor { return null; } - // public Object visit(Ecrire node) { return null; } + public Object visit(Ecrire node) { return null; } public Object visit(Egal node) { return null; diff --git a/Visitors/SourceCodeGenerator.java b/Visitors/SourceCodeGenerator.java index 66da141e518eae837fcf7106f72976da297073a6..bb123a2c210f7be4fcce21a02df04d8eb4d3465b 100755 --- a/Visitors/SourceCodeGenerator.java +++ b/Visitors/SourceCodeGenerator.java @@ -15,7 +15,7 @@ public class SourceCodeGenerator implements ASTVisitor { /** * Depth level (tabulations) */ - private int level = 0; + private int level = 1; /** * If we are currently declaring function parameters */ @@ -131,13 +131,13 @@ public class SourceCodeGenerator implements ASTVisitor { node.getDroite().accept(this); return null; } - // - // public Object visit(Ecrire node){ - // code += "ecrire "; - // node.getSource().accept(this); - // code += ";"; - // return null; - // } + + public Object visit(Ecrire node){ + code += "ecrire "; + node.getSource().accept(this); + code += ";"; + return null; + } public Object visit(Egal node) { node.getGauche().accept(this); diff --git a/hepial.cup b/hepial.cup index a79d4551c9de79a89435056741d7f9f5c296e6ce..1db2378d8a0b1f7402c2495efe1d2c7ed94d74c0 100755 --- a/hepial.cup +++ b/hepial.cup @@ -24,7 +24,7 @@ non terminal Expression expr, access, operand; non terminal for_instr; non terminal while_instr; non terminal cond_instr; -non terminal write_instr; +non terminal Ecrire write_instr; non terminal read_instr; non terminal Instruction instr; non terminal Affectation assign; @@ -117,7 +117,7 @@ instr_lst ::= {: RESULT = new ArrayList(); :} :}; instr ::= assign:inst {: RESULT = inst; :} - | write_instr {: :} + | write_instr:e {: RESULT = e; :} | read_instr {: :} | cond_instr {: :} | while_instr {: :} @@ -125,8 +125,8 @@ instr ::= assign:inst {: RESULT = inst; :} assign ::= access:dest EQUAL:e expr:src SEMICOLON {: RESULT = new Affectation(dest, src, "", eleft, eright); :}; -write_instr ::= WRITE expr SEMICOLON {: :} - | WRITE STRINGCONST SEMICOLON {: :}; +write_instr ::= WRITE expr:a SEMICOLON {: RESULT = new Ecrire(a, "", aleft, aright); :} + | WRITE STRINGCONST:b SEMICOLON {: RESULT = new Ecrire(new Chaine(b, "",bleft, bright), "", bleft, bright); :}; read_instr ::= READ IDENT SEMICOLON {: :};