Saturday, January 22, 2011

Translator – First/Last Operand – Unary Operators

Expression type errors involving unary operators were not pointing to the correct tokens.  This was caused because no operands were being attached to unary operators pushed to the done stack. Consider this statement:
Z$ = A$ + -B
The -B tokens should be reported as an “expecting string expression” error. However, only the B token was being reported because the first and last operand of the negate operator was being set to the first and last operand of its operand from the done stack, which was the B token.

The solution was to only attach the last operand from the operand popped from the done stack and leaving the first operand set to nothing of the unary operator token, which will cause the code to use the negate token itself as the first operand.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)