print les strings
This commit is contained in:
@@ -81,11 +81,18 @@ instruction returns [Instruction out]:
|
||||
})*
|
||||
{$out = new DeclarationImp($t.return_type, declare);}
|
||||
| // PRINT
|
||||
PRINT TEXT
|
||||
{
|
||||
String text= $TEXT.getText();
|
||||
$out = new PrintImp(text.substring(1,text.length()-1));
|
||||
}
|
||||
PRINT t1=TEXT
|
||||
{
|
||||
String text= $t1.getText();
|
||||
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 (+-)
|
||||
|
||||
@@ -60,7 +60,11 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -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
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitPrint(this, h);
|
||||
|
||||
@@ -2,5 +2,5 @@ FUNC INT main() {
|
||||
INT a,b,c
|
||||
b:=3
|
||||
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 }
|
||||
Reference in New Issue
Block a user