用于解析规则的 C# 产品私有方法的 ANTLR

发布于 2024-12-19 14:15:47 字数 197 浏览 5 评论 0原文

我正在尝试使用 ANTLR 使用 C# 代码生成为简单语言创建解析器。

我已经成功地生产了 MyLangLexer.cs 和 MyLangParser.cs,其中包含非常非常简单的规则,称为“规则”。

问题是生成的方法rule()是私有的。

我想要的只是使用 ANTLR 将字符串解析为 AST。

谢谢你, 我愿意。

I'm trying to use ANTLR to create a parser for simple language using C# code generation.

I have successfully product MyLangLexer.cs and MyLangParser.cs with very very simple rule called 'rule'.

The problem is that the generated method rule() is private.

All I want is to use ANTLR to parse a string into AST.

Thank you,
Ido.

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

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

发布评论

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

评论(1

我还不会笑 2024-12-26 14:15:47

C# v3 目标默认生成私有方法,这与 Java 的目标相反。在您想要公开的规则前面添加关键字 public

grammar MyLang;

...

public rule // rule is now public
  :  other
  ;

other // other is private
  :  ...
  ;

...

The C# v3 target produces private methods by default, in contrary to Java's target. Add the keyword public in front of those rules you want to be public:

grammar MyLang;

...

public rule // rule is now public
  :  other
  ;

other // other is private
  :  ...
  ;

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