Must be viewed in IE 4.0 or later for greek symbols

Inherited Attributes

P#1: Construct a CFG that allows unsigned integers to be expressed in octal or decimal notation. An octal number is succeeded with an O and a decimal number is succeeded with a D.

Answer:

bnum -> num base
base -> O | D
num -> num dig | dig
dig -> 0 | 1 | 2 | ... | 9
Until now, we have dealt with attribute grammars containing only one attribute. In the above case, we have two different bases and thus we need two attributes. The first attribute is val which we are familiar with. The second needed attribute is type which we will use to help us compute val.

P#2: For each of the following grammar rules, fill in the semantic rule(s) for computing the decimal value of a given string in L(bnum)..

Grammar Rule                  Semantic Rule(s)
------------                  ----------------

bnum -> num base
base -> o
base -> d
num -> num1 dig
num -> dig
dig -> 0
dig -> 1
dig -> 2
dig -> 3
dig -> 4
dig -> 5
dig -> 6
dig -> 7
dig -> 8
dig -> 9
P#3: Show the annotated parse tree for the following number 123o.


Douglas J. Ryan / ryandj@pacificu.edu