[Python-Dev] Modifying Grammar/grammar and other foul acts

Guido van Rossum guido at python.org
Sat Mar 6 22:41:01 CET 2010


On Sat, Mar 6, 2010 at 10:26 AM, Gregg Lind <gregg.lind at gmail.com> wrote:
> Sorry, re: question one, forgive the ill-formed question.  I meant more, are
> the parser rules applied "first matching".   Essentially trying to confirm
> that the parser is "top down" or "bottom up" or whether or not it even
> matters.

That's not how it works at all. I can't explain it in a few words --
but any text on LL(1) parsing should clarify this. The parser uses no
backtracking and a 1-token lookahead. The only unusual thing is that
individual rules use a regex-like notation, but that is all converted
to a DFA. If one token is not enough to know which path to take
through the DFA (this may invoke another rule -- but you always know
which one) you're hosed.

I suspect you've introduced ambiguities, though I don't immediately
see where (they could be in the combination of different rules).

Another possibility is that you may be running into problems where the
parser expects a newline at the end of a suite.

(FWIW since you're not proposing a language change, this is
technically off-topic for python-dev. :-)

--Guido

> Thanks for the tip -- it seems to be exactly what I want.  To make it
> explicit, this seems to be fuller (unix) recipe for how to make this style
> of debugging happen.
>
>     $ ./configure --with-pydebug
>     $ make
>     $ set PYTHONDEBUG=1
>     $ ./python -d   # then this shows the parsing info
>
>
> On Sat, Mar 6, 2010 at 10:56 AM, "Martin v. Löwis" <martin at v.loewis.de>
> wrote:
>>
>> > 1.)  I assume the Grammar/grammar is read top to bottom.  Confirm?
>>
>> Confirm - but this is not surprising: *any* source file is typically
>> read from top to bottom. Randoma access reading is typically done for
>> binary files, only.
>>
>> So you must be asking something else, but I can't guess what that might
>> be.
>>
>> > 2.)  More help figuring out how to debug what python *thinks* it's
>> > seeing when it see "def a() {pass}".  It's not getting to the ast
>> > construction stage, as near as I can tell.  What additional breakpoints
>> > can I set to see where it's failing.
>>
>> Enable the D() debugging in parser.c (configure with --with-pydebug,
>> and set PYTHONDEBUG).
>>
>> Regards,
>> Martin
>>
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
>



-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list