a = b = 1 just syntactic sugar?

Greg Ewing (using news.cis.dfn.de) g2h5dqi002 at sneakemail.com
Wed Jun 11 04:33:11 CEST 2003


Martin v. Löwis wrote:
> I think it is as easy as this:
> 
> - Replace a construct FOO* with FOO_seq, and define
> 
>   FOO_seq: /* empty */
>          | FOO FOO_seq
> 
> - Replace a construct [FOO] with FOO_opt, and define
> 
>   FOO_opt: /* empty */
>          | FOO

I don't think it's *quite* that easy, because pgen will
accept something like

    FOO = A B C | A B D

whereas if you naively re-wrote that as

    FOO = X | Y
    X = A B C
    Y = A B D

pgen would complain that the first sets of X and Y
are not disjoint.

So you can't just blindly turn parts of the REs
into non-terminals -- some refactoring may be needed
to get the result to be an LL(1) grammar. A proof
would be required that this refactoring is always
possible.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list