On Mon, Feb 26, 2007 at 03:20:59PM +0100, Klaas-Jan Stol wrote:
> I've done some more work on the grammar of Pynie.
> 
> This patch also includes the other patch I sent yesterday (so that one 
> can be skipped).

Applied, thanks.  I'll be making some cleanups momentarily.

> This grammar is ALMOST done, but now I'm kinda stuck, because there is 
> some infinite recursion :-(

Yes, the Python reference grammar has a number of left-recursive 
rules, which PGE doesn't handle.  We'll want to refactor those rules
to avoid the left recursion.

For example, Python has things like

    primary ::= atom | attributeref | subscription | slicing | call

    attributeref ::= primary "." identifier

    subscription ::= primary "[" expression_list "]"

which ends up being left-recursive.  I'm thinking we should
refactor this to be more like the perl6 grammar, so that we end
up with

    token primary { <atom> <postop>* }

    token postop { 
        | <attributeref> 
        | <subscription>
        | <simple_slicing>
        | <extended_slicing>
    }

    rule attributeref { <'.'> <identifier> }

    rule subscription { <'['> <expression_list> <']'> }

> Another thing: Python allows for:
>     x = a not in b
> and
>     x = a is not c
> 
> I fixed this with adding a "prefix:in" rule and a "infix:not" rule. 
> ...

The Python reference grammar appears to use top-down parsing for
all of its operators.  In pynie I started out by using a bottom-up
parser for operators (because it was simpler to implement)... but
perhaps we should stick to top-down for the entire grammar, at
least to begin with.  There are other places where Python appears
to call into the middle of the expression stack, as in the
"test" rule:

    test ::=  or_test | lambda_form

Thanks again!

Pm

Reply via email to