On Fri, May 13, 2011 at 9:48 AM, Dale Schumacher
<dale.schumac...@gmail.com> wrote:
> Parse tree production seems to be the issue at hand here, otherwise
> all of the following are equivalent:
>
> expr = expr op expr | num
> expr = expr op num | num
> expr = num op expr | num
> expr = num (op expr)*

Argh!  Of course the grammar:

expr = num (op expr)*

should actually be:

expr = num (op num)*

We don't want both recursion and iteration at the same time!

> num = [0-9]+:n $<#num, n>
> expr = num:x ( '-' expr:y $<#diff, x, y>:x )* $x

Similarly, this should be:

expr = num:x ( '-' num:y $<#diff, x, y>:x )* $x

to produce these results

> Given "1" produces <#num, 1>
> Given "1-2" produces <#diff, <#num, 1>, <#num, 2>>
> Given "1-2-3" produces <#diff, <#diff, <num, 1>, <#num, 2>>, <#num, 3>>
> which is left-associative.

Hopefully, I haven't made any other silly errors.

_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to