Re: Printing PEG structure

Joel de Guzman <[email protected]> Mon, 15 Mar 2010 09:41:50 +0800
Newsgroups gmane.comp.parsers.spirit.devel
Message-ID <[email protected]>
On 3/14/2010 11:39 AM, OvermindDL1 wrote:
> I am curious.  I know that the grammar for Spirit generates a kind of
> bytecode at compile time that the parse functions can go over to do
> the actual parsing (again, optimized at compile time).  I am curious,
> would it be possible to create such a function that goes over that
> bytecode/typetree of Qi/Karma and can print out the PEG string
> representation of what the parsing does?  For terminals it does not
> know about would need to override a function or so that lets it print
> out its representation.
>
> Would be great for debugging though.
>
> rule<...>  r1, r2;
> r1 = int_>>  space>>  double_%',';
> r2 = r1 | (lit('"')>>*~char_('"')>>lit('"'));
> r1.name("r1");
> r2.name("r2");
>
> ostringstream o;
> peg_string(o, r2);
> o.str(); // returns:
>
> r2 = r1 | ('"' (~'"')* '"')
> r1 = int space double (',' double)*
> int = /* however this is defined */
> space = ' '|'\t'|'\r'|'\n'
> double = /* however this is defined */
>
> Or something like that.  Does not need to be pretty, just get the
> point across, would be great to toss into documentation for a created
> parser too.

That's one of the things Hartmut and I want to do with our planned
BoostCon 2010 presentation.

Regards,
-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net
http://www.facebook.com/djowel

Meet me at BoostCon
http://www.boostcon.com/home
http://www.facebook.com/boostcon




------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev