COSC3308                                                           TEST-2                                                                  12/1/2004

           

 

                NAME________________________________________________________

                               

                PART-A.               Multiple Choice questions.                                                (60 points)

Answer 15 questions in this PART.

Select the BEST answer by writing down a BIG letter A,B,C,D,E, or F next to each question number

You choose.

 

                First three questions are about the following SNOBOL4 program segment:

 

                                Define(“f1()LOC1”)

                                Define(“f2()LOC2”)

                Main       LOC1 = 1111

                                LOC2 = 2222

                                LOC3 = 3333

                                F2()

                                Output = LOC1  LOC2  LOC3                             :(END)

                F1            LOC1 = 5555

                                Output = LOC1  LOC2  LOC3                             :(Return)

                F2            LOC1 = 4444

                                Output = LOC1  LOC2  LOC3

                                F1()                        

Output = LOC1  LOC2  LOC3                             :(Return)

                END        ;*  End of program Segment

 

                1.             The first output line will contain

a.                    444422223333

b.                   44442222

c.                    44443333                                d.             none above.

2.             The second output line will contain

a.                    555522223333

b.                   555511112222

c.                    55553333                                d.             none above.

3.             The last output line will contain

a.                    111122223333

b.                   555522223333

c.                    444422223333                        d.             none above.

 

                4.             BEAUTY = ‘NICE’  ; NICE  = "GOOD"  ;  Good  = “GOOD”

                OUTPUT  =  $$$$BEAUTY

 

                                Which string will be output?

                                a.             “NotBad”                                              b.             “GOOD”

                                c.             Null String                                             d.             none above.

 

                5.             &fullscan  =  0 ;  &Anchor = 1   ;* We have the default “QuickScan”

Pat  = ‘b’   |  ‘b’  *Pat

                                'bbbb'  Pat  $  Output  Fail

 

                                Which will be included in the  outputs?

                                a.             b                                                              b.             bbbb

                                c.             both.                                                       d.             Neither

 

                6.             &Anchor = 0

                                "A+((C+B))"  Bal  $  Output  Fail

               

                                Which will be included in the outputs?

                                a.             (C+B)                                                      b.             ((C+B))                   c.             A+

                                d.             All above.                                              e.             Two above.                           f.              None

               

                7.             Which can match the null string?

                                a.             POS(2)                                    b.             Break()                   c.             ARB

                                d.             All above.                              e.             Two above.           f.              None above.

               

                8.             Which matches nothing but the null string?

                                a.             Tab(N) and RTab(N)

                                b.             Pos(N) and Rpos(N)

                                c.             @X                                        

d.             All above.                                              e.             Two above.                           f.              None.

 

                9.             differ(X,Y)                                             :S(Good)

                                differ(Y,Z)                                              :S(Good)F(NoGood)

                   

The above two lines are equivalent to:

                                a.                             differ(X,Y)  differ(Y,Z)                         :S(Good)F(NoGood)

                                b.                             Ident(X,Y)    Ident(Y,Z)                       :S(NoGood)F(Good)

                                c.                             Both.                                                      d.             Neither

 

                Next two questions are about the following program segment:

 

                                &Anchor = 0;       &FullScan = 1

                                Define(“P(W,X,Y,Z)”)

                                Pat = Len(1) $  A ARB LEN(1) $  B ARB Len(1) $  C Arb Len(1) $  D  *P(W,X,Y,Z)  Fail

                                “123456”  Pat                                                        :(END)

                P              Output =  W      X  “ “  Y  “ “  Z                     :(Return)

                END        ;*  End of program segment.

                **************************************************

 

                10.           The first two output lines will be

                                a.             1 2 3 4                                     b.             1 2 3 4                                     c.             neither.

                                                1 2 3 5                                                     2 3 4 5

               

11.           Suppose that:       &FullScan = 0

 

                                In this case, the first three output lines would be:

                                a.             1 2 3 4                                     b.             1 2 3 4                                     c.             neither.

                                                1 2 3 5                                                     2 3 4 5

                                                1 2 3 6                                                     2 3 4 6

 

                12.           The Dynamic Scope is more natural when

                                a.             subprograms are not allowed to nest others.

                                b.             local variables need to be visible to subprograms to be subsequently called.

                                c.             Both.                                      d.             Neither.

 

                13.           Which is true of Referencing Environment?

                                a.             Scope rule primarily affects its non-local part.

                                b.             It generally changes each time a subprogram is called or returns.

                                c.             Both.                                      d.             Neither.

 

                14.           An advantage of Pass-by-Reference includes

                                a.             Efficient especially when actual arguments are large arrays.

                                b.             Implementing InOut-Mode semantic.

                                c.             Both.                                      d.             Neither.

 

 

                For next three questions, consider the following program structure:

 

                                main()                                     // main program (function)

                                                int x,y,z;

                                                real a,b,c;

                                                f1()            real x,y;

                                                                                 f11()       // declaration of f11()                          

int y;

                                                                  f11();     // call to f11() by f1()

                                                                ......

                                                f2()            int a,b;

                                                                  f1();       // call to f1() by f2()

                                                                ......

                                                f3()            real z;

                                                                  f2();       // call to f2() by f3()

                                                                ......

                                                f3();                                         // call to f3() by main()

                                                                ......

                               

Note that main() calls f3() which calls f2() which, in turn, calls f1()

                                which calls f11() in that order.

 

                15.           Under the Static Scope rule, the non-local R.E. of f11() includes

                                a.             a(main) and x(f1)

                                b.             b(main) and z(main)

                                c.             both.                                                       d.             neither

 

                16.           Under the Dynamic Scope rule (just hypothetically if not realistically),

                                the non-local R.E. of   f11() includes

                                a.             a(f2) and b(f2)

                                b.             c(main) and z(main)

                                c.             both.                                                       d.             neither.

               

17.           Suppose that f1() just called f11().

                At that point, the Runtime Central Stack would contain an Activation Record of

                a.             main(), f3(), f2(), f1() and f11() in that order.

                b.             main(), f1(), and f11() in that order.

                c.             main(), f3(), f2(), and f1() (without f11()) in that order.

                d.             none above.

 

                PART-B. Other Problems.                                                                                (40 points)

 

                Choose three problems in this PART-B one of which must be Problem-C.

 

A.                  In no more than 8 lines, state differences between the two scope rules in

deciding the R.E.

 

 

                B.           Regarding the last programming assignment (Propositional Logic Checker) based

                                upon the associated example program found on my web page, give statements

needed under each of the following two labels:

                                                ANAND  and

                                                ANOR

 

                               

                C.            Complete the following function definition

                                                define(“Strip(EXP)”)

                                This function will return a string that is obtained from the given expression,

                                EXP, after deleting

                                1. all intermediate blanks and

                                2. all outermost pairs of parentheses of the expression given.

                               

For example,   Strip(      ((A+B * (  C  +  D  * E )  ))  “ )  will become

                                          “A+B*(C+D*E)”

 

 

                D.            In no more than 8 lines, describe ways to improve SNOBOL4.

 

 

E.             In no more than 8 lines, list some subprogram design issues and indicate your

choices/approaches wherever applicable.