Is there a list of reserved words in ANTLR grammars?

自闭症网瘾萝莉.ら 提交于 2019-11-30 21:57:01
Bart Kiers

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...).

Using the reserved words of your target language can also cause problems.

I spent a day trying to figure out why my grammar wouldn't work only to realize it was getting messed up by the "enum" rule in my grammar I had named "enum".

This may or may not be an issue depending on what the target language is. I was using the default Java target, and it certainly was, so if that's the case you should check the list of reserved keywords for your target language as well.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!