使用 Javacc/push front 流中的一些字符进行预处理?

发布于 2024-08-15 21:38:33 字数 365 浏览 5 评论 0原文

使用javacc我可以在输入流前面推送一些新字符吗?

例如,假设我的解析器解析以下语法:

#define Paragraphs  "Paragraph+"
#define Volume "(Title,(Chapter,${Paragraphs})+)"

Book=${Volume}+;

我如何告诉 javacc 它的扫描器应将 ${Volume} 预处理为 (Title,(Chapter,Paragraph+)+) 在调用解析器之前?

可以使用MORE语句来实现吗?

谢谢

Using javacc can I push some new characters in front of the inputstream ?

for example let's say that my parser parses the following syntax:

#define Paragraphs  "Paragraph+"
#define Volume "(Title,(Chapter,${Paragraphs})+)"

Book=${Volume}+;

How can I tell javacc that its scanner should preprocess ${Volume} to (Title,(Chapter,Paragraph+)+) before invoking the parser ?

Can It be achieved using the MORE statement ?

Thanks

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

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

发布评论

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

评论(2

南街九尾狐 2024-08-22 21:38:33

Token.image 是公共字段,因此您也可以直接设置它。这是我的 JavaCC 书的分词器章节中的一个示例:

TOKEN : {
   {matchedToken.image = image.append("B").toString();}
}

您可以在此处下载本书的所有示例源代码。

Token.image is a public field, so you could also just set it directly. Here's an example in my JavaCC book's tokenizer chapter:

TOKEN : {
   {matchedToken.image = image.append("B").toString();}
}

You can download all the book's example source code here.

淡莣 2024-08-22 21:38:33

好的,我想我已经找到了解决方案:可以在 TOKEN 部分中添加一些 java 语句,并且当前缓冲区在名为“image”的 StringBuilder 中定义:

| <Y:"${"(<NAME)+ "}" >
        {
        String oldValue=image.toString();
        image.setLength(0);
        image.append(my_dict.get(oldValue));
        }

OK, I think I've found the solution: Some java statements can be added in the TOKEN section and the current buffer is defined in a StringBuilder named 'image':

| <Y:"${"(<NAME)+ "}" >
        {
        String oldValue=image.toString();
        image.setLength(0);
        image.append(my_dict.get(oldValue));
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文