ANTLR语法中是否有保留字列表? [英] Is there a list of reserved words in ANTLR grammars?

查看:100
本文介绍了ANTLR语法中是否有保留字列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近创建了ANTLR3解析器规则

I recently created an ANTLR3 parser rule

options : foo bar;

没有编译,花了一些时间才发现options是保留字(AntlrWorks指出了错误,但不是原因). ANTLR中是否有保留字列表,并且在命名规则中有最佳做法(这可能有助于避免这种情况)?

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

推荐答案

ANTLR v3的保留字是:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆