I would like to put an optional letter before my variables like 2p where p is an ID and 2 is a NUM. My ID matches only letters, and I would like to keep it that way (i.e. I don’t want to change the regex for ID). I tried something like this, but it didn’t work:
var
: NUM ID
;
This doesn’t work because NUM only matches numbers. I tried changing the regex for NUM to match the empty string ( I think this is how you do it):
num ({digits}{fraction}{exponent}|"")
but id didn’t work. I also tried introducing another rule like this:
var
: number ID;
number:
: NUM
| ''
;
I am guessing there is some symbol in yacc to take care of the empty string that I can put in the grammar, but i am not sure. Any help would be apprecaited.
try this