Comp 232

Assignment #4

Due: Monday 10/23/2006

 

Solve the following problems.

 

a)      Given the following grammar and the right sentential form, bBab, draw a parse tree and show the phrases and simple phrases, as well as the handle. 

            S -> aAb | bBA

            A -> ab | aAB

            B -> aB | b

     (See page 203, problem 5b of the text.) 

 

b)      Design a state diagram to recognize one form of the comments of the C-based programming languages, those that begin with /* and end with */.

      (See page 204, programming exercise 1 of the text.)

 

c)      Some programming languages are typeless.  What are the obvious advantages and disadvantages of having no types in a language? 

      (See page 244, problem 2 of the text.)

 

d)      Assume the following Ada program was compiled and executed using static scoping rules.  What value of X is printed in the procedure Sub1?  Under dynamic scoping rules, what value of X is printed in procedure Sub1?

 

procedure Main is

     X : Integer;

     procedure Sub1 is

           begin  - -  of Sub1

           Put(X);

           end;  - -  of Sub1

     procedure Sub2 is

           X : Integer;

           begin  - -  of Sub2

           X := 10;

           Sub1

           end;  - -  of Sub2

     begin  - -  of Main

     X := 5;

     Sub2

            end;  - -  of Main

 

      (See page 245, problem 9 of the text.)