boost.spirit.qi : how to disable semantic actions

Hi All, I'am using spirit::qi for developping a parser. Thanks boost for this great job. My issue is that I would like to test the syntax of my grammar before performing semantic actions. Is these any way to do that, I mean parse a string without performing the defined semantic actions ? Thanks in advance for any help Oli

I'am using spirit::qi for developping a parser. Thanks boost for this great job. My issue is that I would like to test the syntax of my grammar before performing semantic actions. Is these any way to do that, I mean parse a string without performing the defined semantic actions ? Thanks in advance for any help
There isn't such a thing in Spirit. But you're the second one to ask so I assume it has some value to implement something allowing to achieve this behavior (a directive? i.e. noactions[...] would inhibit the execution of all semantic actions for the embedded parser). I believe this is possible without too much effort. I'll see what I can do. Regards Hartmut --------------- Meet me at BoostCon www.boostcon.com

Hi Hartmut, First of all, many thanks for your answer. I'm really new to spirit so I have no idea how to do that myself except managing a flag to have a different behavior in implemented semantic actions and this will be hard to manage for operators. Perhaps there is another solution to my purpose : I have implemented a simple interpretor for a domain specific langage (like basic) based on semantic actions. What I would like is to check the syntax so without performing any action and I found it stupid to dublicate the grammar without the actions. I would also like to disable actions for loop implementation in my simple langage. In fact I use the raw directive to get the string associated to the block inside the loop and parse this block (it containes semantic actions) as many times as the loop size. The issue is that the semantic actions associated to the block sub rules are called even if the loop size is 0 and I have to manage this case in my langage. On that point, perhaps i'am also not using spirit in the right way. If you have any advices, they are welcome. Regards Oli
I'am using spirit::qi for developping a parser. Thanks boost for this great job. My issue is that I would like to test the syntax of my grammar before performing semantic actions. Is these any way to do that, I mean parse a string without performing the defined semantic actions ? Thanks in advance for any help
There isn't such a thing in Spirit. But you're the second one to ask so I assume it has some value to implement something allowing to achieve this behavior (a directive? i.e. noactions[...] would inhibit the execution of all semantic actions for the embedded parser). I believe this is possible without too much effort. I'll see what I can do.
Regards Hartmut
--------------- Meet me at BoostCon www.boostcon.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

olivier musse wrote:
Perhaps there is another solution to my purpose : I have implemented a simple interpretor for a domain specific langage (like basic) based on semantic actions. What I would like is to check the syntax so without performing any action and I found it stupid to dublicate the grammar without the actions.
I would also like to disable actions for loop implementation in my simple langage. In fact I use the raw directive to get the string associated to the block inside the loop and parse this block (it containes semantic actions) as many times as the loop size. The issue is that the semantic actions associated to the block sub rules are called even if the loop size is 0 and I have to manage this case in my langage. On that point, perhaps i'am also not using spirit in the right way. If you have any advices, they are welcome.
Relatively few current interpreters directly rescan the source characters during execution. Perhaps a different approach would address both your issues. It's more typical for a language parser's semantic actions to construct an Abstract Syntax Tree, an internal linked structure (using class objects of your own) that represents the program specified by the source code. If you run the parser to construct the AST and then stop, it's a syntax check without execution: simply discard the AST. Even if you choose to execute, you can discard the original source code at that point because you've already captured its essentials in your AST. You walk the AST for execution. The node representing an 'if' or loop construct captures the relevant conditional expression; evaluating that expression allows you to decide whether, or how many times, to evaluate the dependent statements. I hope this terse sketch is clear enough.
participants (3)
-
Hartmut Kaiser
-
Nat Goodspeed
-
olivier musse