CSC 533: Organization of Programming Languages
HW2: Syntax and EBNF Grammars
Answer the following questions about the scripting language Python by referring to
its EBNF at
- 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 (
in Python. That is, what
characters may be used? What restrictions (if any) are there on order?
- How are identifiers (
identifier) and names (
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 (
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