In lex/flex, one can match multiple patterns to a token using normal regex rules, but what is the equivalent on the yacc/bison side?
In my code I have two possible grammars for a single task:
IF expression THEN number
IF expression GOTO number
It seemed obvious...
|
IF expression THEN number
|
IF expression GOTO number
{ ... guts of the handler go here... }
But bison complains type clash on default action: <statement> != <>
. Some googling turned up that if you don't have an action for a given entry it assumes the action is { $$ = $1; };
, which is why you get this error. Fair enough.
It would seem this is a common sort of task, so I looked in a half dozen examples of little parsers on github and it seems it is not so common after all.
So what is the correct syntax here?