CSC 533: Organization of Programming Languages
Spring 2005

HW2: EBNF Grammar

The following questions all refer to the EBNF of Python. Note that this grammar uses a slight variation on the EBNF syntax described in class: most notably, * denotes zero or more repetitions and + denotes one or more repetitions.

  1. Which of the following are legal literals in Python? For each legal literal, provide a parse tree (with the <literal> abstraction at the root). 00 -2.9 0XA2 092 2E-4 0.01E12 5.5E+5.5 5.
  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. What is the shortest possible function definition (<funcdef>) in Python? Justify your answer.

  4. What is the order of precedence for the operators +, and * in Python? Justify your answer by providing the parse tree for the <expression>:   1+2*3.

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