develooper Front page | perl.recdescent | Postings from September 2009

Re: Deferred interpretation?

Thread Previous | Thread Next
From:
Damian Conway
Date:
September 8, 2009 06:27
Subject:
Re: Deferred interpretation?
Message ID:
832f158a0909071552k4d054d5es7d9152b9c3c72fec@mail.gmail.com
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.  I don't think that will help me.  If
> 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.  Pass in a boolean areguement to each production, and if that arguement
> is "true" process the action, otherwise, simply return the TEXT of the
> matched expression.
>
> This way, my if statement passes [1] and [0] to the two clauses.  This
> introduces substantial logic into my grammar, though.
>
> 2.  The other way is to build the "parse tree" inside the grammar and
> then "walk" the tree.  This would entail almost completely rewriting my
> grammar actions.  But 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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About