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.
- 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
- 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
- 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?
- 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.
- What is the difference between an expression (
expression
) and a constant expression
(const_expression
) in
Modula-2?
- Give one example of an expression that is also a constant expression.
- Give one example of an expression that is not a constant expression.