retest non block with if then else
This commit is contained in:
@@ -81,9 +81,9 @@ instruction returns [Instruction out]:
|
|||||||
$out =new Return_instrImp($e.out);}
|
$out =new Return_instrImp($e.out);}
|
||||||
| //BLOC
|
| //BLOC
|
||||||
BacO
|
BacO
|
||||||
(dec=list_decls ins2=list_instr
|
(dec=list_decls instr2=list_instr
|
||||||
{
|
{
|
||||||
$out=new BlocDecImp($dec.out,$ins2.out);
|
$out=new BlocDecImp($dec.out,$instr2.out);
|
||||||
}
|
}
|
||||||
| instr3=list_instr
|
| instr3=list_instr
|
||||||
{ $out= new BlocImp($instr3.out);
|
{ $out= new BlocImp($instr3.out);
|
||||||
@@ -128,13 +128,13 @@ instruction returns [Instruction out]:
|
|||||||
})*
|
})*
|
||||||
{$out = new ReadImp(read);}
|
{$out = new ReadImp(read);}
|
||||||
| //IF THEN ELSE FIN
|
| //IF THEN ELSE FIN
|
||||||
IF ex1=expression THEN ins1=list_instr
|
IF ex1=expression THEN ins1=instruction
|
||||||
(FIN
|
(FIN
|
||||||
{$out= new IfThenImp($ex1.out, $ins1.out);}
|
{$out= new IfThenImp($ex1.out, $ins1.out);}
|
||||||
| ELSE ins2=list_instr FIN
|
| ELSE ins2=instruction FIN
|
||||||
{$out= new IfThenElseImp($ex1.out, $ins1.out,$ins2.out); }
|
{$out= new IfThenElseImp($ex1.out, $ins1.out,$ins2.out); }
|
||||||
)
|
)
|
||||||
| WHILE exp1=expression DO ins3=list_instr DONE
|
| WHILE exp1=expression DO ins3=instruction DONE
|
||||||
{$out = new WhileImp($exp1.out,$ins3.out);}
|
{$out = new WhileImp($exp1.out,$ins3.out);}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -103,9 +103,7 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
String str = indent + "IF ";
|
String str = indent + "IF ";
|
||||||
str +=(instr.e().accept(this, ""));
|
str +=(instr.e().accept(this, ""));
|
||||||
str +=" THEN ";
|
str +=" THEN ";
|
||||||
for(int i=0; i<instr.i1().size();i++){
|
str+= instr.i1().accept(this, "");
|
||||||
str+= instr.i1().get(i).accept(this, "");
|
|
||||||
}
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,13 +112,9 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
String str = indent + "IF ";
|
String str = indent + "IF ";
|
||||||
str +=(instr.e().accept(this, ""));
|
str +=(instr.e().accept(this, ""));
|
||||||
str +=" THEN ";
|
str +=" THEN ";
|
||||||
for(int i=0; i<instr.i1().size();i++){
|
str+= instr.i1().accept(this, "");
|
||||||
str+= instr.i1().get(i).accept(this, "");
|
|
||||||
}
|
|
||||||
str +=" ELSE ";
|
str +=" ELSE ";
|
||||||
for(int i=0; i<instr.i2().size();i++){
|
str+= instr.i2().accept(this, "");
|
||||||
str+= instr.i2().get(i).accept(this, "");
|
|
||||||
}
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,9 +133,7 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
String str = indent+"WHILE ";
|
String str = indent+"WHILE ";
|
||||||
str += (instr.e().accept(this, ""));
|
str += (instr.e().accept(this, ""));
|
||||||
str+= " DO ";
|
str+= " DO ";
|
||||||
for(int i=0; i<instr.i1().size();i++){
|
str+= instr.i1().accept(this, "");
|
||||||
str+= instr.i1().get(i).accept(this, "");
|
|
||||||
}
|
|
||||||
str+= " DONE";
|
str+= " DONE";
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,21 +102,21 @@ public class Program{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record IfThenImp(Expression e, ArrayList<Instruction> i1) implements Instruction {
|
public static record IfThenImp(Expression e, Instruction i1) implements Instruction {
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||||
return v.visitIfThen(this, h);
|
return v.visitIfThen(this, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record IfThenElseImp(Expression e, ArrayList<Instruction> i1, ArrayList<Instruction> i2) implements Instruction {
|
public static record IfThenElseImp(Expression e, Instruction i1, Instruction i2) implements Instruction {
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||||
return v.visitIfThenElse(this, h);
|
return v.visitIfThenElse(this, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record WhileImp(Expression e, ArrayList<Instruction> i1) implements Instruction {
|
public static record WhileImp(Expression e, Instruction i1) implements Instruction {
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||||
return v.visitWhile(this, h);
|
return v.visitWhile(this, h);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ FUNC INT main() {
|
|||||||
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu", c*5+b
|
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu", c*5+b
|
||||||
IF 1 THEN a:=a+1 FI
|
IF 1 THEN a:=a+1 FI
|
||||||
IF 2 THEN b:=c+1 ELSE
|
IF 2 THEN b:=c+1 ELSE
|
||||||
b:=c+1
|
b:=c+1
|
||||||
READ a, b, c, d
|
|
||||||
FI
|
FI
|
||||||
RETURN 4 + 6 * 5 + 2 }
|
RETURN 4 + 6 * 5 + 2 }
|
||||||
Reference in New Issue
Block a user