CSC 533: Organization of Programming Languages
Spring 2012
HW2: Syntax and EBNF Grammars
Answer the following questions about the programming langauge Modula-2 by referring to
its EBNF at
BNF Web Club.
- 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).
000 -4 .67 67.
2E-4 0.01E6 1.2E+1.2 BAH
- 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).
9 = 9 + 2 + - 2 15 * - 10
3 * 2 - 5 a > b > c 3 - 1 < A & B
- 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
- 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?
- What is the assignment operator in Modula-2 (i.e., the symbol that separates the left and right
sides of an assignment)?
- How are comments specified in Modula-2?
- Are semicolons statement terminators or statement separators in Modula-2? That is, does every statement in a block end with a semicolon (including the last one), or are there just semicolons between statements (but not after the last one)? Justify your answer.
- Does the dangling-else problem apply to Modula-2? Justify your
answer.
- Give an example of a definition module (
definition_module
) that is as short as
possible.
- Give an example of a program module (
program_module
) that is as short as
possible.