expression pour printf

This commit is contained in:
Vu Tuan Minh
2025-04-09 12:30:17 +02:00
parent b357a16114
commit 038159108b
3 changed files with 26 additions and 7 deletions

View File

@@ -81,17 +81,28 @@ instruction returns [Instruction out]:
})* })*
{$out = new DeclarationImp($t.return_type, declare);} {$out = new DeclarationImp($t.return_type, declare);}
| // PRINT | // PRINT
PRINT t1=TEXT PRINT
{ {ArrayList<String> printer= new ArrayList<String>();}
String text= $t1.getText(); (t1=TEXT
ArrayList<String> printer= new ArrayList<String>(); {
printer.add(text.substring(1,text.length()-1)); String text= $t1.getText();
}(VIRGULE t2=TEXT printer.add(text.substring(1,text.length()-1));
}
|e1=expression
{ String text_e= $e1.out.toString();
printer.add(text_e);
})
(VIRGULE (t2=TEXT
{ {
String text2= $t2.getText(); String text2= $t2.getText();
printer.add(text2.substring(1,text2.length()-1)); printer.add(text2.substring(1,text2.length()-1));
} }
)* | e2=expression
{
String text_e2= $e2.out.toString();
printer.add(text_e2);
}
))*
{$out = new PrintImp(printer);} {$out = new PrintImp(printer);}
| //READ | //READ
READ i1=ident READ i1=ident

View File

@@ -80,6 +80,13 @@ public class Program{
} }
} }
public static record ReadImp(ArrayList<String> t) implements Instruction{
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitRead(this, h);
}
}
//Type //Type
public static record Type_voidImp() implements Type{ public static record Type_voidImp() implements Type{
@Override @Override

View File

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