Problem Statement:
Sometime when we have this non-terminal:
P() :{}
{
A() <B> C()
}
The generated P() node will have 2 children, i.e, A() and C(); and they can be access using P.jjtGetChild(0) and P.jjtGetChild(1); but we cannot access token <B> conveniently, except using A.jjtGetLastToken().next.
There are 2 options to fix this issue.
Option 1:
Add a wrapper with <B>, for example:
P() :{}
{
A() B() C()
}
B() :{}
{
<B>
}
So in the definition of P(), token <B> is replaced with a non-terminal B().
Option 2: Using JJTree decoration
P() :{}
{
A() <B> #B C()
}
So a node B() will be generated by JJTree and added into P(); in this case P() will have 3 children, A(), B(), and C().
JJTree decoration only affect the expansion immediately left of it.
So
P() :{}
{
A() <AB> <B> #B C()
}
Node B() will contain only a token <B>;
and
P() :{}
{
A() ( <AB> <B> ) #B C()
}
Node B() will contain both <AB> and <B>;