|
The syntax for term is
term : integerConstant
| stringConstant
| keywordConstant
| varName
| varName '[* expression ']'
| subroutineCall
| '(' expression ')'
| unaryOp term
My concern is with the last line, doesn't this allow y + ~---~-~-~-~--~x and so on ad infinitum?
Is this intended? Usually you would require parenthesis around each unary operator, so shouldn't the syntax be
term unaryOp?
( integerConstant
| stringConstant
| keywordConstant
| varName
| varName '[* expression ']'
| subroutineCall
| '(' expression ')'
)
or even better
term ( unaryOp? integerConstant
| '~'? stringConstant
| '~'? keywordConstant
| unaryOp? varName
| unaryOp? varName '[* expression ']'
| unaryOp? subroutineCall
| unaryOp? '(' expression ')'
)
if we want to stop taking negative strings and booleans at syntax check.
Did you correct this implicitly in your code or are we just lucky that the provided Jack code is not malformed?
New user here, thanks for any answers
|