Generate expression using C ++ boost :: spirit PEG grammar

I am very new to C ++ and boost :: spirit. Trying to learn how to build a simple expression tree with || and && using PEG. I have created many pieces of code from a mini-xml tutorial in documents.

Here is the code , it works for simple strings like "1 || 0", "1 && 0", 1 || 1 & 0 "... but not executed for" (1 || 1). "I don’t quite understand why it is not printing, although it says that the parsing is successful.

Also, please tell me how I can make this code more intuitive and maintainable in the long run.

+3
source share
2 answers

Enabling Spirit debugging support will help:

a) add a definition

#define BOOST_SPIRIT_QI_DEBUG

and b) add inside the constructor of your grammar a

BOOST_SPIRIT_DEBUG_NODE(r);

for all the rules (here r). As a result, the analyzers will print a runtime tree at runtime, showing you which rules are executed with which input and which attribute values ​​have been filled (see here for more details).

As a general note (and this may not apply to you, as you seem to be trying to create an AST), Spirit parsers are completely related. This means that you don’t need semantic actions to handle attributes (see here , here , and here for tips).

+4
source

, Spirit , , " ++" , , :

Boost Spirit. , ANTLR (v2 ++, v3 - , v2) lex yacc .

Boost Spirit - , ++. , - , ++ ( ).

0

All Articles