CSC 533: Organization of Programming Languages
Spring 2010

HW1: Syntax and EBNF Grammars


Answer the following questions about the programming langauge Modula-2 by referring to its EBNF at BNF Web Club.

  1. Which of the following are legal numbers in Modula-2? For each legal number, provide a parse tree (with the number abstraction at the root). 00 -3.0 .33 33. 2E-4 0.01E12 5.5E+5.5 0AH
  2. Which of the following are legal expressions in Modula-2? For each legal expression, provide a parse tree (with the expression abstraction at the root). 4 = 4 + 3 + - 3 15 * + 10 3 + 2 * 5 a < b < c 1 + 2 > A & B
  3. What is the order of precedence for the operators AND, OR and NOT in Modula-2? Confirm your answer by providing a parse tree for the expression: NOT A AND B OR C
  4. Describe, in concise English, the format for identifiers (ident) in Modula-2. That is, what characters may be used? What restrictions (if any) are there on order?

  5. What is the assignment operator in Modula-2 (i.e., the symbol that separates the left and right sides of an assignment)?

  6. How are comments specified in Modula-2?

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

  8. Give an example of a definition module (definition_module) that is as short as possible.

  9. Give an example of a program module (program_module) that is as short as possible.

  10. What is the difference between an expression (expression) and a constant expression (const_expression) in Modula-2?