Reputation: 111
I'm trying to optimize my javacc parser and I have a question about defining tokens in the grammar definition.
Is it good or bad practice? Does it affect much the performance of the parser.
example:
void name() :
{
Token name;
}
{
name = < NAME : ( < LETTER > | < DIGIT > ){2, 7}>
{
System.out.println(name.image);
}
}
Upvotes: 1
Views: 75
Reputation: 16221
It won't affect performance, but it will affect readability and maintainability. Keep in mind that the order of token definitions can make a difference to the meaning. I suggest putting all token definitions up front.
Upvotes: 2