CSC 533: Organization of Programming Languages
Spring 2020
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 -2.5 .67 67.
4E-2 0.99E+12 5.5E5.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).
x # y - 2 + 4 4 + - 1
a > b > c ( a > b ) > c NOT NOT 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:
A AND NOT B OR C
.
- What is the associativity of the operators AND and OR in Modula-2?
Confirm your answer by providing a parse tree for the
expression:
A OR B OR C
. If you claim the rules are ambiguous
with respect to associativity, explain why you reached that conclusion.
- What is the assignment operator in Modula-2 (i.e., the symbol that separates the left and right
sides of an assignment)? In which abstraction rule is this specified?
- How are comments specified in Modula-2? In which abstraction rule is this specified?
- Does the dangling-else problem apply to Modula-2? Justify your
answer.
- Give an example of a for loop (
for_statement
) that is as short as
possible, in terms of number of tokens (where a keyword such as FOR
counts
as only one token).
- Give an example of a while loop (
while_statement
) that is as short as
possible, in terms of number of tokens (where a keyword such as WHILE
counts
as only one token).
- 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.