0

I want to parse for instance:

const unsigned int varname;

where the number of qualifiers is unknown and the list of qualifier keywords is also unknown (since new ones can be introduced using using).

But using the PEG grammar

declaration <- qualifier* varname ';'
qualifier <- identifier
varname <- identifier

does not work because qualifier* consumes the variable name since it matches. Is there a way to do this or do I have to extract the last identifier manually in the reduction rule?

Mircode
  • 432
  • 5
  • 12

1 Answers1

0

Ok I got it.

declaration <- qualifier* varname ';'
qualifier <- !varname identifier
varname <- identifier &';'
identifier <- [a-zA-Z_] [a-zA-Z_0-9]* ws
ws <- ' '*
Mircode
  • 432
  • 5
  • 12