3

I'm quite new to the spirit framework, and I'd like to ask you a question concerning my program.

My idea is to implement the C- programming language grammar into spirit (link is here http://marvin.cs.uidaho.edu/Teaching/CS445/c-Grammar.pdf).

I'm creating a tree of nodes containg the whole code (each node will be a subclass of a main CodePart class; such as WhileStatement, IfStatement...).

To each rule, I create a node of the tree using the phoenix::new_ function; for instance:

rule1 = (...)[qi::_val = phoenix::new_<CodePart1>(...)]

My first issue is that a very high number of nodes are created during the parsing; every try of rule creates a new pointer, but none is deleted (I added debug messages in constructors and destructors).

Is the node creation idea a correct one, or am I going the wrong way?

Thanks for your insights.

bob
  • 31
  • 3
  • I think you're going the wrong way. See both http://stackoverflow.com/questions/8259440/boost-spirit-semantic-actions-are-evil and the one I'm marking this as a duplicate of. Finally, here's some hints how to reduce backtracking in general: https://stackoverflow.com/a/23242863/85371 (or some pointers from here: http://stackoverflow.com/questions/41809417/boost-spirit-takes-for-ever-to-parse-expressions/41812443#41812443) – sehe Apr 04 '17 at 21:31
  • I'll look into this, thanks. – bob Apr 07 '17 at 08:08

0 Answers0