JavaCC 中的 NULL 标记

发布于 2024-07-11 02:35:08 字数 412 浏览 5 评论 0原文

我的令牌有奇怪的问题 < NULL:“空”> 在我的 JavaCC 解析器中。 在像解析器这样的表达式中,

String IsNullClause():
{
      String res = "";
}
{
     <IS> {res += " IS ";}
     [<NOT> {res += " NOT ";} ]
     <NULL> {res += " NULL ";}

{
    return res;
}
}

看不到 NULL 标记并抛出“null”预期的异常。 如果我将标记定义更改为 < NULL:“null_val”> 或者其他东西它工作正常。 这是我的错误还是 JavaCC 不接受“null”作为标记值?

I have strange problem with token
< NULL: "null" >
in my JavaCC parser.
In expression like

String IsNullClause():
{
      String res = "";
}
{
     <IS> {res += " IS ";}
     [<NOT> {res += " NOT ";} ]
     <NULL> {res += " NULL ";}

{
    return res;
}
}

parser doesn't see NULL token and throws exception that "null" expected. If I change token definition to < NULL: "null_val" > or something else it works fine.
Is this my mistake or JavaCC doesn't accept 'null' as a token value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森罗 2024-07-18 02:35:08

JavaCC 包中有示例 Java 语言语法,其标记定义如下:

<; NULL: "null" >

所以我很确定 JavaCC 可以处理 null 标记。

您确定 NULL 之前声明的任何标记都不会匹配“null”吗? 令牌按照声明的顺序进行匹配。 您可以尝试在一开始就声明 NULL。

There are sample Java language grammars in JavaCC package, with the following token difinition:

< NULL: "null" >

so I'm pretty sure JavaCC can handle null token.

Are you sure no token declared before NULL matches "null"? Tokens are matched in the order of declaration. You may try to declare NULL at the very beginning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文