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

merge

parents 8079ffa0 1e76d082
No related branches found
No related tags found
No related merge requests found
/*
* 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);
}
}
/*
* Represent an equal comparaison expression node inside the AST.
*/
public class Lire extends Instruction {
private Expression dest;
/**
* Constructor
*/
public Lire(Expression dest, String fl, int line, int col) {
super(fl, line, col);
this.dest = dest;
}
/**
* Get the binary operator
*/
public Expression getDestination() {
return this.dest;
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor){
return visitor.visit(this);
}
}
programme Program
debutprg
c = 1 + 2;
c = non vrai;
c = c * 2;
b = 3;
d = c <> b;
lire "oui";
finprg
......@@ -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);
......@@ -36,7 +36,7 @@ public interface ASTVisitor {
Object visit(InfEgal node);
Object visit(Inferieur node);
// Object visit(Lire node);
Object visit(Lire node);
// Object visit(Moins node);
Object visit(Nombre node);
......
......@@ -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;
......@@ -60,7 +60,7 @@ public class ByteCodeGenerator implements ASTVisitor {
public Object visit(Inferieur node) { return null; }
// public Object visit(Lire node) { return null; }
public Object visit(Lire node) { return null; }
// public Object visit(Moins node) { return null; }
......
......@@ -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;
......@@ -62,7 +62,7 @@ public class SemanticAnalyzer implements ASTVisitor {
public Object visit(Inferieur node) { return null; }
// public Object visit(Lire node) { return null; }
public Object visit(Lire node) { return null; }
// public Object visit(Moins node) { return null; }
......
......@@ -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);
......@@ -177,13 +177,13 @@ public class SourceCodeGenerator implements ASTVisitor {
return null;
}
// public Object visit(Lire node){
// code += "lire ";
// node.getDestination().accept(this);
// code += ";";
// return null;
// }
//
public Object visit(Lire node){
code += "lire ";
node.getDestination().accept(this);
code += ";";
return null;
}
// public Object visit(Moins node){
// code += "-";
// node.getOperand().accept(this);
......
......@@ -24,8 +24,8 @@ non terminal Expression expr, access, operand;
non terminal for_instr;
non terminal while_instr;
non terminal cond_instr;
non terminal write_instr;
non terminal read_instr;
non terminal Ecrire write_instr;
non terminal Lire read_instr;
non terminal Instruction instr;
non terminal Affectation assign;
non terminal Unaire op_una;
......@@ -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,10 +125,10 @@ 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 {: :};
read_instr ::= READ IDENT:a SEMICOLON {: RESULT = new Lire(new Idf(a, "", aleft, aright), "", aleft, aright); :};
cond_instr ::= IF expr THEN body ELSE body ENDIF {: :}
| IF expr THEN body ENDIF {: :};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment