问题
My program that needs to be parsed should be of the form:
program : [declaration]+
;
Which should mean: The program consists of one or more declarations. Declaration on its turn is of course defined in a similar way, and so on...
Currently, I'm getting an error on the + from the Bison parser. How do I define the one or more condition in a correct way with bison?
回答1:
One or more:
declarations
: declaration
| declarations declaration
;
Zero or more:
declarations
: /* empty */
| declarations declaration
;
回答2:
Apparently,
Bison does not support the + or * symbols to denote these things.
How I solved it:
program : declarations
;
declarations : declaration declarations
| declaration
;
来源:https://stackoverflow.com/questions/29235967/bison-one-or-more-occurrences-in-grammar-file