我最近创建了一个ANTLR3解析器规则
options : foo bar;
Run Code Online (Sandbox Code Playgroud)
它没有编译,我花了一些时间才发现这options是一个保留字(AntlrWorks表示错误,但不是为什么).ANTLR中是否有保留字列表,是否有命名规则的最佳实践(这可能有助于避免这种情况)?
ANTLR v3的保留字是:
Keyword | Description
---------+--------------------------------------------------------
scope | Dynamically-scoped attribute
fragment | lexer rule is a helper rule, not real token for parser
lexer | grammar type
tree | grammar type
parser | grammar type
grammar | grammar header
returns | rule return value(s)
throws | rule throws exception(s)
catch | catch rule exceptions
finally | do this no matter what
options | grammar or rule options
tokens | can add tokens with this; usually imaginary tokens
import | import grammar(s)
请参阅:https://web.archive.org/web/20120314155217/http://www.antlr.org/wiki/display/ANTLR3/ANTLR+Cheat+Sheet(在页面末尾)
不知道解析器规则的"命名约定"(除了它们应该从小写开始,当然不是惯例......).
| 归档时间: |
|
| 查看次数: |
1968 次 |
| 最近记录: |