开发者

Preprocessing with Javacc/ push front some chars in the stream?

开发者 https://www.devze.com 2022-12-14 20:01 出处:网络
Using javacc can I push some new chara开发者_如何学编程cters in front of the inputstream ? for example let\'s say that my parser parses the following syntax:

Using javacc can I push some new chara开发者_如何学编程cters 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


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.


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));
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号