CS 412/413
Introduction to Compilers and Translators
Spring 2000
Cornell University

Homework 2: Syntactic Analysis

due: Friday, February 11, in class

  1. Consider the following grammar:

    S ® S + S | S * S | S ^ S | ( S ) | num

    This grammar is ambiguous; we would like the grammar to have parse trees in which exponentiation (^) has higher precedence than multiplication (*), and both have higher precedence than addition (+).

    1. Write an LL(1) grammar that accepts the same language as this grammar and respects the desired operator precedence. (You need not ensure that the operators are left-associative, however.)
    2. Write an LR(1) grammar that accepts the same language, but enforces both the correct precedence and left-associativity of the operators.
  2. Appel 3.3(a,f,g)
  3. Appel 3.6
  4. Appel 3.10
  5. Appel 3.12