Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] languages/Pynie

5 views
Skip to first unread message

Klaas-Jan Stol

unread,
Feb 26, 2007, 9:20:59 AM2/26/07
to Perl 6 Internals
hi,

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).

This grammar is ALMOST done, but now I'm kinda stuck, because there is
some infinite recursion :-(
It would also need some cleanup, and of course testing. It looks like we
need to rewrite some rules.

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.
However, this would also allow for:

x = a not b

and

x = in c

Which is of course wrong. Maybe we need an extra operator type? (not
infix, not prefix, but "multiop" or whatever, to allow for multi-token
operators).

regards,
kjs

PynieMoreGrammarUpdates.patch

Patrick R. Michaud

unread,
Feb 26, 2007, 10:48:43 AM2/26/07
to Klaas-Jan Stol, Perl 6 Internals
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

0 new messages