Bison one or more entries in the grammar file

My program, which should be analyzed, should look like this:

program   : [declaration]+
          ;

This should mean: a program consists of one or more declarations. The declaration of its rotation, of course, is determined in a similar way, etc ...

I am currently receiving a + error message from the Bison parser. How to determine one or more conditions using a bison?

+4
source share
2 answers

One or more:

declarations
    : declaration
    | declarations declaration
    ;

Zero or more:

declarations
    : /* empty */
    | declarations declaration
    ;
+4
source

Obviously

Bison does not support the + or * characters to denote these things.

How I decided it:

program     : declarations
        ;

declarations    : declaration declarations
        | declaration
        ;
+1
source

All Articles