Reputation: 443
I have my lexical scanner implemented in Ragel, and I need a token to use when I recognize white-space of various sorts. But other than separating other tokens, I don't care about the white-space. If I pass it in to my Lemon parser, I'll have to insert many extra rules to get rid of it, which will make my grammar ugly and slow down parsing. But the only way I've found to get Lemon to generate a token for white-space is to put in a reduce rule that I never intend to use.
Currently, I have a rule list0 ::= .
to allow for an empty list, so I added a list0 ::= SP.
. Is there no cleaner way to just declare a token, without using it in a reduce rule?
Upvotes: 1
Views: 208
Reputation: 853
You can use %nonassoc
, %right
, or %left
to reserve a terminal token.
%nonassoc SECRET_TOKEN .
program ::= .
will generate:
#define SECRET_TOKEN 1
Upvotes: 1