Parsing BNF Grammar using Boost Spirit with some custom bnf rules

  boost-spirit, boost-spirit-qi, c++

Assuming I have a BNF grammar as shown below. Now a ‘List’ will correspond to all terms before the ‘|’ symbol. However, I want to read the very last number of every ‘List’ as an attribute of the ‘List’.

<code> ::= <code> <line> 12 2 | <line> 24 4 
<line> ::= <ifte> 13 23 | <loop> 24 <<34 | <action> 15 3 
<ifte> ::= if <cond> {<code>} else {<code>} 12

Furthermore, this last number (List attribute) can be optional; I guess to make this easier I might have to maybe use some symbol to enclose the number for easier parsing e.g <<23>>.

The code from here compiles but it doesn’t parse the grammar above.

How can I fix/modify the code link above to suit my needs.

Source: Windows Questions C++

LEAVE A COMMENT