The way PRECC does it (parse a nondeterministic grammar) is to not execute the code associated with the production, but to figure out how the grammar parses first, and then trigger all the code blocks.

It works by sticking the closure in a list, rather than performing it. That can be "undone" during backtracking.

When reading this stuff on the new regex, I was thinking that this would be needed and maybe could be better directly supported in the grammar class...then came to the secion on hypotheticals, and it's not a general solution and has the nits I mentioned earlier.

So to do that ourselves, in the grammer we would code our own speculative execution when needed. If the side-effects are not needed to continue parsing, just push @list, {code} instead of {code}, where @list is a hypothetical variable as described. For things that must actually be done and undone, there is no code block associated with a backtrack through this node, so we have to keep track of where we are with code fragments at the beginning of each branch. Then our program knows when we go down a different branch, and can clean up first.

Be better if there was a backtrack stack we could push code blocks onto.


In reply to Re: Re: Re: Re: hypothetical variables by John M. Dlugosz
in thread hypothetical variables by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.