CSC 533: Organization of Programming Languages
Spring 2008
HW2: Syntax and EBNF Grammars
Answer the following questions about the scripting language Python by referring to
its EBNF at
www.python.org/doc/current/ref/grammar.txt.
- Which of the following are legal floating-point numbers (
floatnumber
) in Python?
For each legal floating-point number, provide a parse tree (with the
floatnumber
abstraction at the root).
00 -2.9 .5 5.
2E-4 0.01E12 5.5E+5.5 3.0X
- Describe, in concise English, the format for identifiers (
identifier
)
in Python. That is, what
characters may be used? What restrictions (if any) are there on order?
- How are identifiers (
identifier
) and names (name
)
different in Python? If possible give an example for each of the following criteria:
- an identifier that is not also a name
- a name that is not also an identifier
- both an identifier and a name
- What is the shortest possible function definition (
funcdef
) in
Python? Justify your answer.
- What is the order of precedence for the operators +, * and
** in Python? Justify your answer.
- In C++ and Java, an assignment returns a value, allowing the programmer to
chain assignments together, e.g., x = y = 0;. Can assignments similary
be chained in Python?
Justify your answer.
- Does the dangling-else problem apply to Python? Justify your
answer.