Python language spec

Nolan Darilek nolan_d at bigfoot.com
Sun Jan 2 21:15:18 EST 2000


I have a long-standing tradition of taking up personal projects in
which I bite off much more than I can chew. The end result is that
several weeks later I emerge with a bit more knowledge, and either a
semi-working product or much less hair on my head. :) My most recent
attempt is a Python interpreter written to compile a subset of Python
into Muq (http://muq.org/~cynbe/muq/) bytecodes for execution natively
on the server platform.

As I've stated, this project is probably more than I can accomplish,
considering the fact that yesterday I knew nothing about Yacc, and
very little about compiler design. :) I've been cramming for the past
day or so though, and feel that I have made a few strides in
understanding what I'll have to do. Today I've been looking through
the Python language reference, working on rules for expressions.

Here's where my confusion lies. Maybe I'm studying the language
reference and taking it too literally. I'm working slowly through,
section-by-section, writing rules for each construct and testing
them. I'm confused by the expression_list definition, however. It
reads:

expression_list:      expression ("," expression)* [","]

I understand the syntax of the definition, but I don't know what the
syntax for an expression should be. Earlier rules define u_expr,
a_expr, etc. but not a regular expression (I don't mean regexp, just a
no-frills expression :). The only rule which defines 'expression' is:

expression:     or_test | lambda_form

which seems to imply that 'expression' is only a boolean result, which
I'm guessing it isn't. :) After thinking about the problem for a bit
though, I began to wonder if I'm taking rules too literally? For
example, is:

m_expr:         u_expr | m_expr "*" u_expr ...

meant to also describe an expression, but m_expr/u_expr are used
since:

expr:         expr | expr "*" expr ...

may seem less meaningful? This makes sense to me, though I don't
completely understand why:

expr: expr "*" expr { output }
expr: expr "/" expr { output } ...

wouldn't work? In other words, to me the first part of the m_expr rule
(m_expr: m_expr | ...) seems to be redundant. Am I making any sense
here? :) Is the rule in fact defining a standard expression, but
excluding all other operators besides * and /?

If anyone can make sense of my confused ramblings and help me out, I'd
greatly appreciate it. :) I've never done anything of this sort
before, nor have I really delved into studying a language
specification, so this project is a very big learning experience for
me, and hopefully something will actually come of it. :) Thanks.




More information about the Python-list mailing list