Re: Deferred interpretation?
[email protected] (Mike Diehl) Wed, 9 Sep 2009 08:54:17 -0600
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
On Monday 07 September 2009 16:52:31 Damian Conway wrote: > Mike Diehl pondered: > > Well, I've continued to think about this and I've got some more > > questions. > > > > I did read up on the <defer: directive. =A0I don't think that will help= me. > > =A0If I'm missing something, please let me know. > > No, it won't help. The problem is that you want to *parse* every command, > but not *execute* every command (only the ones in the correct branches of > the if). > > > So, I've come up with two different ways to handle this situation: > > > > 1. =A0Pass in a boolean areguement to each production, and if that > > arguement is "true" process the action, otherwise, simply return the TE= XT > > of the matched expression. > > > > This way, my if statement passes [1] and [0] to the two clauses. =A0This > > introduces substantial logic into my grammar, though. > > > > 2. =A0The other way is to build the "parse tree" inside the grammar and > > then "walk" the tree. =A0This would entail almost completely rewriting = my > > grammar actions. =A0But this way would also, potentially?, allow me to > > compile my language and forgo the parser step alltogether. > > > > Which method would you recommend? > > Definitely, the second approach. There's a good reason that people > usually separate compilation and execution: namely that mixing them is > both vastly more complex and considerably more error-prone. > > Damian I did finally, rewrite the whole thing using the second approach. This was= =20 CONSIDERABLY more complex, as I had to navigate a fairly complex parse tree= =2E =20 I think I've done something wrong, as I'm still finding bugs... I'll do so= me=20 more reading, though. Anyway, this is a nice final design, though. Because I now have a parse tr= ee,=20 I have the potential of serializing that data structure to an external file= =20 and saving the expense of launching the parser each time my program runs. = =20 This amounts to creating a JIT compiler! Should be MUCH more efficient,=20 right? Any recommendations between the various modules for this purpose? =20 Data::Dumper, Storable, Serialize? BTW Damian, RD is a nice piece of work. It's almost FUN to use. =2D-=20 Take care and have fun, Mike Diehl.