简体   繁体   中英

JavaCC: How to print the text of a node?

Imagine I have following code in my jjt file:

void architecture_statement_part() :
{ System.out.println("architecture_statement_part"); }
{
  ( architecture_statement() )*
}

I want print the text, which corresponds to the architecture_statement_part is printed using the println statement.

When something goes wrong with parsing, I will know where exactly to look for the error.

How can I do it?

I tried

void architecture_statement() #void :
{ System.out.println("architecture_statement: " + image.toString()); }

but it led to a compiler error.

void architecture_statement() #void :
{ 
    System.out.println("architecture_statement: " + getToken(1)); 
}

That's what I was looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM