Search code examples
c++boost-spiritboost-spirit-qi

boost spirit qi multiple start rules


How can I define a spirit qi grammar which can have more than one starting rule? I am working on an XML grammar and I want to have 4 possible starting rules.

So if I have a grammar called xml_grammar and the base_type is (A, "A"). I also want few other starting rules.


Solution

  • All formal grammars have a single start symbol. If you have multiple start symbols under consideration (say A, B, C and D), you can convert them into a single artificial start symbol S with a rule like:

    S = A | B | C | D