I haven't read everything yet, but I thought I'd post a link to a tutorial of mine before I come back to this. Operator Associativity and Eliminating Left-Recursion in Parse::RecDescent was written for Parse::RecDescent, but the principles apply to other LL parsers too.

Quickly, I think

expr : expr expr binop { [ BINOP => [ $item[3], $item[1], $item[2] ] ] } | term

can be transformed into

expr : term { push($item[1]) } expr_ | term expr_ : expr binop { [ BINOP => [ $item[2], pop(), $item[1] ] ] }

Factoring out common prefixes for speed:

expr : term { push($item[1]) } expr_1 expr_1 : expr_2 | # Automatic match { pop() } expr_2 : expr binop { [ BINOP => [ $item[2], pop(), $item[1] ] ] }

Inlining expr_2 for simplicity:

expr : term { push($item[1]) } expr_ expr_ : expr binop { [ BINOP => [ $item[2], pop(), $item[1] ] ] } | # Automatic match { pop() }

In short, keep looking for terms until you meet something that isn't (an operator), then eat up the last two terms that have been met.

I'll come back later to verify this and put it into 5.10 regex syntax.

Update: Fixed link


In reply to Re: An adventure with 5.10 regular expressions by ikegami
in thread An adventure with 5.10 regular expressions by hipowls

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.