Monday, April 1, 2013

Colon Precedence Correction

The segmentation fault mentioned in the last post that was occurring with some files (like accidentally loaded expected translator test file) was caused by the presence of a colon.  The colon will be a statement separator or will indicate a label at the beginning of a line.  In the translator, the colon is considered an operator.  Eventually there will be a special colon token handler, but this has not yet been implemented.

The problem occurred when the colon operator token was processed as a regular operator.  The precedence of the colon was set to zero, which is also the same as the NULL operator that is put on top of the of hold stack as a blocker to prevent it from being popped (because all operators are suppose to have higher precedences).  However, since the colon also had a zero precedence, the translator popped the NULL operator from the hold stack.  The segmentation fault occurred because the NULL operator had no expression information (a NULL pointer).

To correct this problem, the precedence of the colon operator was changed to a four, which is the same precedence as the End-of-Line operator since a colon is also indicate the end of a statement.

[commit d971d6d436]