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.

  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           -2.5           .67            67.
        4E-2         0.99E+12       5.5E5.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).
        x # y           - 2 + 4           4 + - 1		
        a > b > c       ( a > b ) > c     NOT NOT 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: A AND NOT B OR C.

  4. 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.

  5. 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?

  6. How are comments specified in Modula-2? In which abstraction rule is this specified?

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

  8. 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).

  9. 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).

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