开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜