CSCI 410 Mid-Term Exam [Solutions]
Fall 2004 [Somo]
October 25, 2004
{wcwR | w in (0|1)*}
or
Palindromes
(Many other answers possible).
S ŕ A c A
A ŕ O A
| e
O ŕ a | b


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;}