KeywordCode() function does not match the exact token and does not check the token length #34

已关闭
belliash2018-08-02 06:24:01 +02:00创建 · 1 评论
管理员

AerScript Information

  • Aer Version (or commit ref): eb30745e6e
  • Operating System: Linux
  • System Architecture (eg. arm, x86_64, ...): x86_64

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:

$a = 1;
if($a) {
} else {
}

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

<!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please take a moment to check that your issue doesn't already exist. 3. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> # AerScript Information - Aer Version (or commit ref): eb30745e6e - Operating System: Linux - System Architecture (eg. arm, x86_64, ...): x86_64 # 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: $a = 1; if($a) { } else { } # 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
belliash2018-08-02 06:24:01 +02:00 添加了标签
bug
作者
管理员

The quick workaround to fix the if ... else construct, is to move PH7_TKWRD_ELSE before PH7_TKWRD_ELIF.

The quick workaround to fix the __if ... else__ construct, is to move PH7_TKWRD_ELSE before PH7_TKWRD_ELIF.
belliash2018-08-02 06:35:30 +02:00 指派给自己
belliash2018-08-02 17:45:26 +02:00 关闭此工单
登录 并参与到对话中。
1 名参与者
通知
到期时间
未设置到期时间。
依赖工单

没有设置依赖项。

参考:aerscript/Aer#34
没有提供说明。