Skip to content
Snippets Groups Projects
Commit 21a1c816 authored by lucien.noel's avatar lucien.noel
Browse files

et, ou, vrai, faux créés

parent 244f8886
No related branches found
No related tags found
No related merge requests found
public class Et extends Relation{ public class Et extends Binaire{
/** /**
* Constructor * Constructor
*/ */
...@@ -10,7 +10,7 @@ public class Et extends Relation{ ...@@ -10,7 +10,7 @@ public class Et extends Relation{
* Get the binary operator * Get the binary operator
*/ */
public String operateur() { public String operateur() {
return "-"; return "et";
} }
/** /**
......
public class Faux extends Operande {
public Faux(String fl, int line, int col) {
super(fl, line, col);
}
public String valeur() {
return "faux";
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor) {
return visitor.visit(this);
}
}
/*
* Base class that represent an expression node inside the AST.
*/
public abstract class Operande extends Expression {
/**
* Constructor
*/
public Operande(String fl, int line, int col) {
super(fl, line, col);
}
}
public class Ou extends Binaire{
/**
* Constructor
*/
public Ou(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
super(operandeGauche, operandeDroite, fl, line, col);
}
/**
* Get the binary operator
*/
public String operateur() {
return "ou";
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor){
return visitor.visit(this);
}
}
public class Vrai extends Operande {
public Vrai(String fl, int line, int col) {
super(fl, line, col);
}
public String valeur() {
return "vrai";
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor) {
return visitor.visit(this);
}
}
This diff is collapsed.
programme Program programme Program
debutprg debutprg
b = 3;
c = c * 2; c = c * 2;
b = faux et vrai;
finprg finprg
...@@ -31,7 +31,7 @@ public interface ASTVisitor { ...@@ -31,7 +31,7 @@ public interface ASTVisitor {
Object visit(Et node); Object visit(Et node);
// Object visit(Faux node); Object visit(Faux node);
Object visit(Idf node); Object visit(Idf node);
// Object visit(InfEgal node); // Object visit(InfEgal node);
...@@ -41,7 +41,7 @@ public interface ASTVisitor { ...@@ -41,7 +41,7 @@ public interface ASTVisitor {
Object visit(Nombre node); Object visit(Nombre node);
// Object visit(Non node); // Object visit(Non node);
// Object visit(Ou node); Object visit(Ou node);
// Object visit(Parentheses node); // Object visit(Parentheses node);
// Object visit(Pour node); // Object visit(Pour node);
Object visit(Produit node); Object visit(Produit node);
...@@ -50,5 +50,5 @@ public interface ASTVisitor { ...@@ -50,5 +50,5 @@ public interface ASTVisitor {
// Object visit(SupEgal node); // Object visit(SupEgal node);
// Object visit(Superieur node); // Object visit(Superieur node);
// Object visit(Tantque node); // Object visit(Tantque node);
// Object visit(Vrai node); Object visit(Vrai node);
} }
...@@ -50,7 +50,7 @@ public class ByteCodeGenerator implements ASTVisitor { ...@@ -50,7 +50,7 @@ public class ByteCodeGenerator implements ASTVisitor {
return null; return null;
} }
// public Object visit(Faux node) { return null; } public Object visit(Faux node) { return null; }
public Object visit(Idf node) { public Object visit(Idf node) {
return null; return null;
...@@ -70,7 +70,7 @@ public class ByteCodeGenerator implements ASTVisitor { ...@@ -70,7 +70,7 @@ public class ByteCodeGenerator implements ASTVisitor {
// public Object visit(Non node) { return null; } // public Object visit(Non node) { return null; }
// public Object visit(Ou node) { return null; } public Object visit(Ou node) { return null; }
// public Object visit(Parentheses node) { return null; } // public Object visit(Parentheses node) { return null; }
...@@ -94,7 +94,7 @@ public class ByteCodeGenerator implements ASTVisitor { ...@@ -94,7 +94,7 @@ public class ByteCodeGenerator implements ASTVisitor {
// public Object visit(Unaire node) { return null; } // public Object visit(Unaire node) { return null; }
// public Object visit(Vrai node) { return null; } public Object visit(Vrai node) { return null; }
// TODO: Remplacez le return, celui-ci n'est là que pour ne pas provoquer une // TODO: Remplacez le return, celui-ci n'est là que pour ne pas provoquer une
// erreur de Jasmin quand le bytecode est vide. // erreur de Jasmin quand le bytecode est vide.
......
...@@ -52,7 +52,7 @@ public class SemanticAnalyzer implements ASTVisitor { ...@@ -52,7 +52,7 @@ public class SemanticAnalyzer implements ASTVisitor {
return null; return null;
} }
// public Object visit(Faux node) { return null; } public Object visit(Faux node) { return null; }
public Object visit(Idf node) { public Object visit(Idf node) {
return null; return null;
...@@ -72,7 +72,7 @@ public class SemanticAnalyzer implements ASTVisitor { ...@@ -72,7 +72,7 @@ public class SemanticAnalyzer implements ASTVisitor {
// public Object visit(Non node) { return null; } // public Object visit(Non node) { return null; }
// public Object visit(Ou node) { return null; } public Object visit(Ou node) { return null; }
// public Object visit(Parentheses node) { return null; } // public Object visit(Parentheses node) { return null; }
...@@ -96,5 +96,5 @@ public class SemanticAnalyzer implements ASTVisitor { ...@@ -96,5 +96,5 @@ public class SemanticAnalyzer implements ASTVisitor {
// public Object visit(Unaire node) { return null; } // public Object visit(Unaire node) { return null; }
// public Object visit(Vrai node) { return null; } public Object visit(Vrai node) { return null; }
} }
...@@ -148,15 +148,15 @@ public class SourceCodeGenerator implements ASTVisitor { ...@@ -148,15 +148,15 @@ public class SourceCodeGenerator implements ASTVisitor {
public Object visit(Et node) { public Object visit(Et node) {
node.getGauche().accept(this); node.getGauche().accept(this);
code += " et "; code += " "+node.operateur()+" ";
node.getDroite().accept(this); node.getDroite().accept(this);
return null; return null;
} }
//
// public Object visit(Faux node){ public Object visit(Faux node){
// code += "faux"; code += node.valeur();
// return null; return null;
// } }
public Object visit(Idf node) { public Object visit(Idf node) {
code += node.getNom(); code += node.getNom();
...@@ -200,13 +200,13 @@ public class SourceCodeGenerator implements ASTVisitor { ...@@ -200,13 +200,13 @@ public class SourceCodeGenerator implements ASTVisitor {
// node.getOperand().accept(this); // node.getOperand().accept(this);
// return null; // return null;
// } // }
//
// public Object visit(Ou node){ public Object visit(Ou node){
// node.getGauche().accept(this); node.getGauche().accept(this);
// code += " ou "; code += " "+node.operateur()+" ";
// node.getDroite().accept(this); node.getDroite().accept(this);
// return null; return null;
// } }
// //
// public Object visit(Parentheses node){ // public Object visit(Parentheses node){
// code += "("; // code += "(";
...@@ -272,11 +272,11 @@ public class SourceCodeGenerator implements ASTVisitor { ...@@ -272,11 +272,11 @@ public class SourceCodeGenerator implements ASTVisitor {
// code += "fintantque"; // code += "fintantque";
// return null; // return null;
// } // }
//
// public Object visit(Vrai node){ public Object visit(Vrai node){
// code += "vrai"; code += node.valeur();
// return null; return null;
// } }
public String getCode() { public String getCode() {
return code; return code;
......
...@@ -80,7 +80,7 @@ op_bin ::= expr:a PLUS expr:b {: RESULT = new Addition(a, b, "", a ...@@ -80,7 +80,7 @@ op_bin ::= expr:a PLUS expr:b {: RESULT = new Addition(a, b, "", a
| expr:a TIMES expr:b {: RESULT = new Produit(a, b, "", aleft, aright); :} | expr:a TIMES expr:b {: RESULT = new Produit(a, b, "", aleft, aright); :}
| expr:a DIVIDE expr:b {: RESULT = new Division(a, b, "", aleft, aright);:} | expr:a DIVIDE expr:b {: RESULT = new Division(a, b, "", aleft, aright);:}
| expr:a AND expr:b {: RESULT = new Et(a, b, "", aleft, aright);:} | expr:a AND expr:b {: RESULT = new Et(a, b, "", aleft, aright);:}
| expr OR expr {: :}; | expr:a OR expr:b {: RESULT = new Ou(a, b, "", aleft, aright);:};
relation ::= expr:a EQUALS expr:b {: RESULT = new Egal(a, b, "", aleft, aright); :} relation ::= expr:a EQUALS expr:b {: RESULT = new Egal(a, b, "", aleft, aright); :}
| expr DIFF expr {: :} | expr DIFF expr {: :}
...@@ -95,8 +95,8 @@ op_una ::= NOT expr {: :} ...@@ -95,8 +95,8 @@ op_una ::= NOT expr {: :}
operand ::= access:access {: RESULT = access; :} operand ::= access:access {: RESULT = access; :}
| INTEGERCONST:ib {: RESULT = new Nombre(ib, "", ibleft, ibright); :} | INTEGERCONST:ib {: RESULT = new Nombre(ib, "", ibleft, ibright); :}
| TRUE {: :} | TRUE:o {: RESULT = new Vrai("", oleft, oright);:}
| FALSE {: :}; | FALSE:o {: RESULT = new Faux("", oleft, oright);:};
access ::= IDENT:id {: RESULT = new Idf(id, "", idleft, idright); :}; access ::= IDENT:id {: RESULT = new Idf(id, "", idleft, idright); :};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment