0
int addr = gen_address();
              $code.addr = addr;
              $code.append(
                  ldc(44),
                  istore(addr),
                  "getstatic java/lang/System/out Ljava/io/PrintStream;",
                iload(addr),
                "invokevirtual java/io/PrintStream/print(I)V");
int addr = gen_address();
              $code.addr = addr;
              $code.append(
                  ldc(22),
                  istore(addr),
                  "getstatic java/lang/System/out Ljava/io/PrintStream;",
                iload(addr),
                "invokevirtual java/io/PrintStream/print(I)V");

This grammar will output a number 44 and 22
But the output will be look like this ( 4422 )

I want to add a space between the numbers so the output would be ( 44 22 )

I think something needs to be changed in the

            "invokevirtual java/io/PrintStream/print(I)V");
Anthon
  • 69,918
  • 32
  • 186
  • 246
boudi
  • 682
  • 1
  • 8
  • 19

1 Answers1

0

Its not easy to understand: Your code seam to be ANTLR action code, right? Your compiler generates a jasmin (java assembler) file, right? And you later execute this file and you expect to see (44 22)?

So if you examine the jasmin code you find that you never printed out a space.

One Option: change invokevirtual java/io/PrintStream/print(I)V to invokevirtual java/io/PrintStream/print(Ljava/lang/String)V; Yet you will have to prepare the arguments for this step, 22 is an integer and you have to convert it to " 22" which is a lot of jasmin code.

A better Option (from my point of view): insert invokevirtual java/io/PrintStream/print(C)V between the two statements. You have to push ' ' (space char) on the stack before you invoke.

CoronA
  • 7,717
  • 2
  • 26
  • 53