Sorry, one more thing. :^)

Angel Faus and I were discussing the best way to handle multiple backtracking thingies in the same regexp without one backtracking thingie trying to use another's index. I suggested pushing a mark (a special value, probably -1) onto the stack; if rePopindex popped a mark, it will have 'failed', and thus it would jump to the address given as its parameter. That would work something like this:

RE: #set up flags and stuff branch $start $advance: rePopindex reAdvance $fail $start: reLiteral "f", $advance rePushindex rePushmark $findo: rePushindex reLiteral "o", $findbar branch $findo $backo: rePopindex $advance $findbar: reLiteral "o", $backo set I0, 1 reFinished $fail: set I0, 0 reFinished
Angel suggested that when we push an address onto the stack, we give it a label as a parameter; if a matching operation fails, it pops an index/label pair off the stack, sets the index and jumps to the label. Something like this:
RE: #set up flags and stuff reOnfail $fail #if there's nothing left on the stack branch $start $advance: reAdvance $start: rePushindex $advance reLiteral "f" $findo: rePushindex $findbar reLiteral "o" branch $findo $findbar: reLiteral "bar" set I0, 1 reFinished $fail: set I0, 0 reFinished
Can you give me any guidance about which will work better in the long run? Angel's idea has ease-of-code-generation and code compactness going for it; mine has explicitness (for debugging) and flexibility. From what I can tell, alternation will be a bitch with either, but mine should be easier; same with optional constructs and lookaheads, from what I can see. (Of course, I could just be blinded because one is my idea and the other is someone else's; that's why I'm asking you.)

Thank you for helping me out with this. Discussing it with an expert has made this a hundred times better than it was.

=cut
--Brent Dax
There is no sig.


In reply to Re: Re: Re: Re: Re: Re: Flattening REs into opcodes for Perl 6 by BrentDax
in thread Flattening REs into opcodes for Perl 6 by BrentDax

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.