KeywordCode() function does not match the exact token and does not check the token length #34
Closed
opened 4 years ago by belliash
·
1 comments
Loading…
Reference in new issue
There is no content yet.
Delete Branch '%!s(MISSING)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
AerScript Information
eb30745e6e
Your problem description
Two weeks ago, with
dff0a5c968
commit, I have reimplemented the KeywordCode() function. Originally it contained some generated code that was hard to work with. The new version is much easier, but introduces one serious bug, that currently breaks the if() { } else {} expression. At least I don't know about any other issues yet.The root cause here, is that pTokenLookup structure implements the list of keywords and KeywordCode() tries to match the extracted text from source file to the keyword. However if there are several keywords containing similar name (eg. else and elseif) then the first one is matched. This function does not match the exact token and do not check the length.
Because elseif is listed before else, the construction is not working. Interpreter matches else keyword to the PH7_TKWRD_ELIF instead of PH7_TKWRD_ELSE.
Simple test:
Expected results
if($a) {} else {} should work, but actually it is generating syntax error about missing opening bracket after else keyword.
Current results
Error: if/else/elseif: Missing '(' in test.aer:3
Compile error
The quick workaround to fix the if ... else construct, is to move PH7_TKWRD_ELSE before PH7_TKWRD_ELIF.