print les strings

This commit is contained in:
Vu Tuan Minh
2025-04-08 11:38:36 +02:00
parent b4bafcde5d
commit b0aa0d98ff
4 changed files with 19 additions and 8 deletions

View File

@@ -81,11 +81,18 @@ instruction returns [Instruction out]:
})* })*
{$out = new DeclarationImp($t.return_type, declare);} {$out = new DeclarationImp($t.return_type, declare);}
| // PRINT | // PRINT
PRINT TEXT PRINT t1=TEXT
{ {
String text= $TEXT.getText(); String text= $t1.getText();
$out = new PrintImp(text.substring(1,text.length()-1)); ArrayList<String> printer= new ArrayList<String>();
printer.add(text.substring(1,text.length()-1));
}(VIRGULE t2=TEXT
{
String text2= $t2.getText();
printer.add(text2.substring(1,text2.length()-1));
} }
)*
{$out = new PrintImp(printer);}
; ;
//Priorité lit(val, const ou paranthese) -> td_exp (*/%) -> exp (+-) //Priorité lit(val, const ou paranthese) -> td_exp (*/%) -> exp (+-)

View File

@@ -60,7 +60,11 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
@Override @Override
public String visitPrint(PrintImp instr, String indent) { public String visitPrint(PrintImp instr, String indent) {
return indent+ "PRINT \""+instr.t() +"\""; String str = indent + "PRINT ";
for (String elem: instr.t()){
str += "\"" +elem +"\"";
}
return str;
} }
//EXPRESSION //EXPRESSION

View File

@@ -73,7 +73,7 @@ public class Program{
} }
} }
public static record PrintImp(String t) implements Instruction{ public static record PrintImp(ArrayList<String> t) 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.visitPrint(this, h); return v.visitPrint(this, h);

View File

@@ -2,5 +2,5 @@ FUNC INT main() {
INT a,b,c INT a,b,c
b:=3 b:=3
c:=1 c:=1
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp" PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu"
RETURN 4 + 6 * 5 + 2 } RETURN 4 + 6 * 5 + 2 }