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
Branches
No related tags found
No related merge requests found
public class Et extends Relation{
public class Et extends Binaire{
/**
* Constructor
*/
......@@ -10,7 +10,7 @@ public class Et extends Relation{
* Get the binary operator
*/
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
debutprg
b = 3;
c = c * 2;
b = faux et vrai;
finprg
......@@ -31,7 +31,7 @@ public interface ASTVisitor {
Object visit(Et node);
// Object visit(Faux node);
Object visit(Faux node);
Object visit(Idf node);
// Object visit(InfEgal node);
......@@ -41,7 +41,7 @@ public interface ASTVisitor {
Object visit(Nombre node);
// Object visit(Non node);
// Object visit(Ou node);
Object visit(Ou node);
// Object visit(Parentheses node);
// Object visit(Pour node);
Object visit(Produit node);
......@@ -50,5 +50,5 @@ public interface ASTVisitor {
// Object visit(SupEgal node);
// Object visit(Superieur node);
// Object visit(Tantque node);
// Object visit(Vrai node);
Object visit(Vrai node);
}
......@@ -50,7 +50,7 @@ public class ByteCodeGenerator implements ASTVisitor {
return null;
}
// public Object visit(Faux node) { return null; }
public Object visit(Faux node) { return null; }
public Object visit(Idf node) {
return null;
......@@ -70,7 +70,7 @@ public class ByteCodeGenerator implements ASTVisitor {
// 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; }
......@@ -94,7 +94,7 @@ public class ByteCodeGenerator implements ASTVisitor {
// 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
// erreur de Jasmin quand le bytecode est vide.
......
......@@ -52,7 +52,7 @@ public class SemanticAnalyzer implements ASTVisitor {
return null;
}
// public Object visit(Faux node) { return null; }
public Object visit(Faux node) { return null; }
public Object visit(Idf node) {
return null;
......@@ -72,7 +72,7 @@ public class SemanticAnalyzer implements ASTVisitor {
// 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; }
......@@ -96,5 +96,5 @@ public class SemanticAnalyzer implements ASTVisitor {
// 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 {
public Object visit(Et node) {
node.getGauche().accept(this);
code += " et ";
code += " "+node.operateur()+" ";
node.getDroite().accept(this);
return null;
}
//
// public Object visit(Faux node){
// code += "faux";
// return null;
// }
public Object visit(Faux node){
code += node.valeur();
return null;
}
public Object visit(Idf node) {
code += node.getNom();
......@@ -200,13 +200,13 @@ public class SourceCodeGenerator implements ASTVisitor {
// node.getOperand().accept(this);
// return null;
// }
//
// public Object visit(Ou node){
// node.getGauche().accept(this);
// code += " ou ";
// node.getDroite().accept(this);
// return null;
// }
public Object visit(Ou node){
node.getGauche().accept(this);
code += " "+node.operateur()+" ";
node.getDroite().accept(this);
return null;
}
//
// public Object visit(Parentheses node){
// code += "(";
......@@ -272,11 +272,11 @@ public class SourceCodeGenerator implements ASTVisitor {
// code += "fintantque";
// return null;
// }
//
// public Object visit(Vrai node){
// code += "vrai";
// return null;
// }
public Object visit(Vrai node){
code += node.valeur();
return null;
}
public String getCode() {
return code;
......
......@@ -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 DIVIDE expr:b {: RESULT = new Division(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); :}
| expr DIFF expr {: :}
......@@ -95,8 +95,8 @@ op_una ::= NOT expr {: :}
operand ::= access:access {: RESULT = access; :}
| INTEGERCONST:ib {: RESULT = new Nombre(ib, "", ibleft, ibright); :}
| TRUE {: :}
| FALSE {: :};
| TRUE:o {: RESULT = new Vrai("", oleft, oright);:}
| FALSE:o {: RESULT = new Faux("", oleft, oright);:};
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