More grammar issues
Gordon McMillan
gmcm at hypernet.com
Mon Jan 3 08:02:11 EST 2000
Nolan Darilek asks:
> All right. I've begun translating a sizable subset of the
> standard Python grammar into Yacc. I'm building a parse tree with
> the output, but I'm again confused. Most rules have
> clearly-defined outputs. These near the end confuse me, though:
>
> test: and_test ('or' and_test)* | lambdef
> and_test: not_test ('and' not_test)*
> ...
These are written this way so you'll get a chain instead of a
branch. That is, instead of "AND (op1, AND (op2, op3))" you'll
get "AND (op1, op2, op3)". You should also be aware that
"and" and "or" return the value of the last operand evaluated.
- Gordon
More information about the Python-list
mailing list