ANTLR 语法中是否有保留字列表? [英] Is there a list of reserved words in ANTLR grammars?
问题描述
我最近创建了一个ANTLR3解析器规则
options : foo bar;
没有编译,我花了一些时间才发现 options
是一个保留字(AntlrWorks 指出了错误,但没有指出原因).ANTLR 中是否有保留字列表,并且在命名规则方面是否有最佳实践(这可能有助于避免这种情况)?
ANTLR v3的保留字是:
<前>关键字 |描述---------+--------------------------------------------------------范围|动态范围的属性片段|词法分析器规则是一个辅助规则,不是解析器的真正标记词法分析器 |语法类型树 |语法类型解析器|语法类型语法 |语法头返回 |规则返回值抛出|规则抛出异常赶上|捕获规则异常终于|无论如何都要这样做选项|语法或规则选项代币 |可以用这个添加令牌;通常是虚构的记号进口|导入语法不知道命名约定"w.r.t.解析器规则(除了它们应该以小写开头,这当然不是惯例......).
I recently created an ANTLR3 parser rule
options : foo bar;
which didn't compile and it took me some time to discover that options
was a reserved word (AntlrWorks indicated an error but not why). Is there a list of reserved words in ANTLR and are there best practices in naming rules (which might help avoid this)?
The reserved words of ANTLR v3 are:
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)
See: https://web.archive.org/web/20120314155217/http://www.antlr.org/wiki/display/ANTLR3/ANTLR+Cheat+Sheet (at the end of the page)
Don't know of a "naming convention" w.r.t. parser rules (other than they should start with a lower case, which is not convention, of course...).
这篇关于ANTLR 语法中是否有保留字列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!