Saturday, November 16, 2013

Recreator – Unary Operator Problems

Many of the other translator tests were being recreated correctly including tests #7 (errors), #8 (more errors), #9 (semicolon errors), #10 (expression errors), #11 (temporary errors), and #14 (parser errors) once the expected results were updated as these did not have the not yet implemented INPUT and REM statements or colons.  However, tests #13 (negative constants) and #17 (constants) were not recreated correctly due to problems involving unary operators.

A problem occurred when a negate unary operator preceded a numeric constant.  When created, there was no space between the negate operator and the number.  If this statement is translated again, the negate operator and the number become a negative constant, which is not the same, through technically equivalent.  This will cause the line change detection in the program model to incorrectly detect a change.  The unary operator recreate function was modified to also add a space after the unary operator if the operand begins with a digit or decimal point.

A problem occurred with the negate integer operator.  The precedence of the negate integer was incorrectly set to 40 causing parentheses to be added incorrectly during recreation.  The precedence should have been 48, the same as the negate double operator, so the table entry for was corrected.

A problem occurred when a unary operator followed a power (exponential) operator, a higher precedence operator.  The operand was incorrectly surrounded with parentheses.  This binary operator recreate function was modified to also check if the second operand is a unary operator then the operand is not surrounded by parentheses.

These corrections allowed tests #13 and #17 to be recreated correctly.  The regression test script was also modified to not ignore white space when comparing to the expected results.  Without this change, the first problem above was not detected.  The memory test was already not ignoring white space.  I'm not sure what the reason was for making the regression test ignore white space.

[commit cf67d09f36]

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.)