nand2tetris / web-ide

A web-based IDE for https://nand2tetris.org
https://nand2tetris.github.io/web-ide
Other
38 stars 11 forks source link

[bug]: expected end of input #313

Closed isaaclyman closed 1 month ago

isaaclyman commented 1 month ago

Program

Assembler

Interface

Website (https://nand2tetris.github.io/web-ide)

Contact Details

mail@isaaclyman.com

What happened?

In order to solve the "Mult" project in chapter 4, I opened projects/04/Mult/Mult.asm in the Assembler and pasted in the following code:

@R2
M=0

(LOOP)
  @R1
  D=M
  @END
  D;JEQ

  @R0
  D=M
  @R2
  M=M+D
  @R1
  M=M-1
  @LOOP
  0;JMP
(END)
  @END
  0;JMP

Below the editor window, I immediately get the message:

Line 22: expected end of input

I also see a red underline on the line that says @R0 after the blank line in the middle of the loop. The online Assembler will not translate this code. However, the legacy Assembler translates it with no issues at all.

Additional Comments

No response

Do you want to try to fix this bug?

Code of Conduct

DavidSouther commented 1 month ago

@isaaclyman thank you for raising the issue!

@netalondon can you take a look and see why we can't handle multiple empty lines in the assembler?

isaaclyman commented 1 month ago

I've tried a couple of things, by the way:

DavidSouther commented 1 month ago

The error I see is actually on line 13:

image

Which can be "fixed" by changing that to M=D+M or M=D+A

image

So we need to update the parser to include all the permutations in https://github.com/nand2tetris/web-ide/blob/main/simulator/src/languages/grammars/asm.ohm#L24-L35 and also that error message was very poor.

netalondon commented 1 month ago

@DavidSouther I think it's intentional that we allow only D+M as specified in the book.

I'll get working on having a more user-friendly error message for this.

isaaclyman commented 1 month ago

I would say the error message itself isn't the only problem. Observe how the red underline is on the wrong line below:

image

If you actually count out the lines (which has to be done manually, since line numbers aren't shown), line 21 is where the problem is. But the red underline appears at the end of line 18, which confuses the situation further.

DavidSouther commented 1 month ago

This is the new error message:

image

This is a correct change from the Java IDE, which did allow both. This aligns the assembler with figure 4.5 in the 2nd edition of the book. As for why, from Shimon:

I think that for the sake of "better education" is better to adhere to the book/course specs to the letter. Also, allowing commutativity hints that D+M is an expression, where in fact it is simply a mnemonic.