异常中的 JavaCC 行号

发布于 2025-01-12 22:38:35 字数 454 浏览 3 评论 0原文

我使用 JavaCC 来解析我的脚本... 我在 types.get 的 *.jj 中有这样的东西,

private Type parseType() throws MyScriptException:
{
    Token token;
}
{   (   token = <INT>
    |   token = <FLOAT>
    |   token = <BOOL>
    |   token = <STRING>
   )
    { return types.get(token.image); }
}

当出现任何问题时,我会从 MyScriptException 类型抛出异常。 但我需要在输出中导致错误的行。 我可以将错误代码行集成到 MyScriptException 中吗?

i use JavaCC for parsing my script...
I have something like this in my *.jj

private Type parseType() throws MyScriptException:
{
    Token token;
}
{   (   token = <INT>
    |   token = <FLOAT>
    |   token = <BOOL>
    |   token = <STRING>
   )
    { return types.get(token.image); }
}

in types.get I throw an exception from type MyScriptException when anything goes wrong.
But I need in the output from which line the error was caused.
Can I integrate the line from error in MyScriptException?

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

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

发布评论

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

评论(1

青春如此纠结 2025-01-19 22:38:35

Token 类具有给出令牌位置的属性:

  /** The line number of the first character of this Token. */
  public int beginLine;
  /** The column number of the first character of this Token. */
  public int beginColumn;
  /** The line number of the last character of this Token. */
  public int endLine;
  /** The column number of the last character of this Token. */
  public int endColumn;

The Token class has attributes that give the location of the token:

  /** The line number of the first character of this Token. */
  public int beginLine;
  /** The column number of the first character of this Token. */
  public int beginColumn;
  /** The line number of the last character of this Token. */
  public int endLine;
  /** The column number of the last character of this Token. */
  public int endColumn;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文