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.

  1. 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
  2. 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?

  3. How are identifiers (identifier) and names (name) different in Python? If possible give an example for each of the following criteria:
  4. What is the shortest possible function definition (funcdef) in Python? Justify your answer.

  5. What is the order of precedence for the operators +, * and ** in Python? Justify your answer.

  6. 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.

  7. Does the dangling-else problem apply to Python? Justify your answer.