This commit is contained in:
trochas
2025-04-09 16:12:35 +02:00
3 changed files with 10 additions and 10 deletions

View File

@@ -82,15 +82,15 @@ instruction returns [Instruction out]:
{$out = new DeclarationImp($t.return_type, declare);} {$out = new DeclarationImp($t.return_type, declare);}
| // PRINT | // PRINT
PRINT PRINT
{ArrayList<String> printer= new ArrayList<String>();} {ArrayList<Object> printer= new ArrayList<Object>();}
(t1=TEXT (t1=TEXT
{ {
String text= $t1.getText(); String text= $t1.getText();
printer.add(text.substring(1,text.length()-1)); printer.add(text.substring(1,text.length()-1));
} }
|e1=expression |e1=expression
{ String text_e= $e1.out.toString(); {
printer.add(text_e); printer.add($e1.out);
}) })
(VIRGULE (t2=TEXT (VIRGULE (t2=TEXT
{ {
@@ -99,19 +99,18 @@ instruction returns [Instruction out]:
} }
| e2=expression | e2=expression
{ {
String text_e2= $e2.out.toString(); printer.add($e2.out);
printer.add(text_e2);
} }
))* ))*
{$out = new PrintImp(printer);} {$out = new PrintImp(printer);}
| //READ | //READ
READ i1=ident READ i1=ident
{ {
ArrayList<String> read= new ArrayList<String>(); ArrayList<VarImp> read= new ArrayList<VarImp>();
read.add($i1.out); read.add(new VarImp($i1.out));
}(VIRGULE i2=ident }(VIRGULE i2=ident
{ {
read.add($i2.out); read.add(new VarImp($i1.out));
})* })*
{$out = new ReadImp(read);} {$out = new ReadImp(read);}

View File

@@ -74,14 +74,14 @@ public class Program{
} }
} }
public static record PrintImp(ArrayList t) implements Instruction{ public static record PrintImp(ArrayList<Object> 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);
} }
} }
public static record ReadImp(ArrayList t) implements Instruction{ public static record ReadImp(ArrayList<VarImp> 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.visitRead(this, h); return v.visitRead(this, h);

View File

@@ -62,6 +62,7 @@ public class SymTable {
stackMap.minus(stackMap.indexOf(stackMap.getLast())); stackMap.minus(stackMap.indexOf(stackMap.getLast()));
} }
public PMap<String,ValueTable> peppapeek(){ public PMap<String,ValueTable> peppapeek(){
if(stackMap.isEmpty()){ if(stackMap.isEmpty()){
System.out.println("TEST..............................."); System.out.println("TEST...............................");