Howdy,

I've been using (and loving) Parslet for a few weeks now and have found
myself at a (seemingly common for PEG newcomers) sticking point. I've read

    http://www.dalnefre.com/wp/2011/05/parsing-expression-grammars-part-4/

and have hit a wall trying to work something similar in parslet. Ideally, I
want to parse a subset of the standard C order-of-operations (add, sub,
mult, div, mod, unary ops, pre/post inc, etc). My first attempts looked an
awful lot like

    https://github.com/carlosmn/cparser/blob/master/lib/cparser/parser.rb

and I quickly realized that rules such as

    rule(:multiplicative_expression) do
      (
        unary_expression.as(:left) >>
        multiplicative_operator >>
        multiplicative_expression.as(:right)
      ).as(:multiplicative) | unary_expression
    end

"don't do what you want". A string such as 9 + 3 * 4 / 5 groups the 4 / 5
first, so-on and so-forth. After realizing the error of my ways and
stumbling upon various top-down operator precedence schemes, I'm having a
difficult time shoe-horning the concepts into working parslet rules. I've
even looked an example from PEG.js which purports to do the right thing

    https://github.com/dmajda/pegjs/blob/master/examples/javascript.pegjs

but I still am no closer to understanding the missing pieces.

Any suggestions for doing "suffix iteration" in parslet similar to the way
demonstrated in my first link? Any help would be much appreciated.

Thank you,
 - FJM

Reply via email to