Boost logo

Boost Users :

Subject: Re: [Boost-users] boost.spirit.qi : how to disable semantic actions
From: Nat Goodspeed (nat_at_[hidden])
Date: 2010-06-17 07:54:11


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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net