[Community Puzzle] Simple Pascal (PL/0) Compiler - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @JDOnline,validated by @Eulero314,@JeZzElLutin and @TAFITA_Julis.
If you have any issues, feel free to ping them.

Thanks for this great, great puzzle!

My solution fails the remote test 4 “Unknown var”. Is this test similar to the corresponding local test? I cannot think of edge cases, except if a procedure has the same name, but that case is not specified in the puzzle instructions. Or a name that is a keyword or not an identifier.

The output could have included line numbers (and variable/procedure names?) to make the result easier to debug and to read.

The puzzle states: “All math and comparison operations work from left to right (e.g. there won’t be cases like 2 + 7 * 9).”. I find this strange, because the “2+7*9” expression is correctly processed by the grammar, and I would expect a hard puzzle with mathematical expressions and parentheses to require operator priority.

var i;

jmp 0, 1
int 0, 4
lit 0, 2
lit 0, 7
lit 0, 9
opr 0, 4 <-- *
opr 0, 2 <-- +
sto 0, 3
opr 0, 0

Validator 4 still features one unknown variable (not procedure), but there’s one known variable at the same time. Hope this will help you find out what the issue of your code may be.

For operator priority, I’ll let the author answer your question. What I do know is that the statement has almost reached the upper limit of 5000 characters, and it’s difficult to squeeze in more characters to state the operator precedence applicable to PL/0 (as all operators need to be mentioned, not just + - * /), if harder cases have to be included.

Thanks! I sometime raised “Invalid expr” instead of “Unknown var” and did not write the right line number.

1 Like