CSCI 410 Mid-Term Exam [Solutions]

 

Fall 2004 [Somo]

October 25, 2004

 

Problem 1

 

{wcwR | w in (0|1)*}

or

Palindromes

(Many other answers possible).

 

Problem 2

 

S ŕ A c A

A ŕ O A

        | e

O ŕ a | b

 

Problem 3

 

 

Problem 4

 

Class Main {

            public static void main(String [] args)

{

 

            Foo x;                          Soln: S; Type Foo undefined

           

 

            int y;

            int z;

            y = 0;

            z = 0;

 

 

if (y = = = 3) y = 10;    Soln: P; Two operators together (= =, =)

                                        or Invalid right operand

 

 

 

            y = z.foo ();                  Soln: S; Method call on non-reference type

 

 

 

            y = 345xyz;                  Soln: P; Invalid expression (2 operands

 together)

 

 

 

                        y = xyz345;                  Soln: S; Undefined variable ‘xyz345’

 

 

 

                        y = y @ z;                    Soln: L; Invalid lexeme “@”

 

            }

 

}

 


Problem 5

 

 



Problem 6

 


N ŕ N1 D                   {N.value = N1.value * 10 + D.value;}

 

        | D                        {N.value = D.value;}

 

 

D ŕ ‘0’                       {D.value = 0;}

 

        | ‘1’                      {D.value = 1;}

 

         .

 

         .

         

         .

 

       | ‘9’                       {D.value = 9;}

 

 

 

The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees