Answers to Self-Study Questions

Test Yourself #1

        CFG           Translation rules
        ===           =================
        B -> 0        B.trans = 0
          -> 1        B.trans = 1
          -> B 0      B1.trans = B2.trans * 2
          -> B 1      B1.trans = B2.trans * 2 + 1

        Input
        =====
        1001


        Annotated Parse Tree
        ====================
              (9) B 
                 / \
                /   \
           (4) B     1
              / \
             /   \
        (2) B     0
           / \
          /   \
     (1) B     0
         |
         1

      

Test Yourself #2

image/svg+xml Exp Exp Term Term Factor 2 + 3 * 4 Term Factor Factor IntLitNode 2 IntLitNode 3 IntLitNode 4 TimesNode PlusNode