Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 164: Fall 1999 Midterm Solutions, Exams of Programming Languages

The solutions for the midterm exam of cs 164: introduction to compilers course at university of california, berkeley in fall 1999. It includes solutions for problems related to finite state automata, parse tables, grammars, lr parsing, and transition tables.

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shaila_210h
shaila_210h 🇮🇳

4.3

(36)

184 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 164: Fall 1999
Midterm Solutions
Professor L. Rowe
PROBLEM 1.
Answer the following TRUE/FALSE questions:
All non-deterministic finite state automatons can be converted to a deterministic finite state
automaton: TRUE
An object-oriented program is easier to read and understand than a conventional procedural
program: TRUE
The class of the value assigned to the this variable in a method is the class within which the
method is declared: FALSE
A Java method signature does not include the return type: TRUE
A transient instance variable in Java is not written to persistent storage if the object is output:
TRUE
The class of the Class object is Class: TRUE
A regular expression can specify the set anbn where 0&ltn&lt5, that is {ab, aabb, ...,
aaaabbbb}: TRUE
A shift reduce parser performs reductions in the reverse order specified by a left-most
derivation: FALSE
The string aabb is a sentential form for the grammar S->ab | aSb: TRUE
A JO99 variable has an l-value and r-value: TRUE
An abstract syntax tree is derived from a parse tree by removing extraneous nodes and
restructuring the tree: TRUE
A handle is a simple phrase: TRUE
Some JO99 objects do not have a class: FALSE
The following finite state automation recognizes the laguage specified by the regular
expression a*1a+: FALSE
State Input NextState
0 1 1
0 a 0
1 a 2
2 1 1
2 a 2
Staring state is 0
A context free grammar can be used to recongnize any context sensitive language: FALSE
PROBLEM 2.
Given the parse table and grammar:
_____________________________________
| | b | a | $ || S | A |
|-------------------------------------|
| 0 | s3 | s2 | || 1 | 5 |
| 1 | | |accept|| | |
| 2 | r4 | s2 | r4 || | 4 |
| 3 | | | r1 || | |
| 4 | r3 | | r3 || | |
CS 164, Midterm 1, FALL 1999
CS 164: Fall 1999 Midterm Solutions Professor L. Rowe 1
pf3
pf4

Partial preview of the text

Download CS 164: Fall 1999 Midterm Solutions and more Exams Programming Languages in PDF only on Docsity!

CS 164: Fall 1999

Midterm Solutions

Professor L. Rowe

PROBLEM 1.

Answer the following TRUE/FALSE questions: All non-deterministic finite state automatons can be converted to a deterministic finite state automaton: TRUE An object-oriented program is easier to read and understand than a conventional procedural program: TRUE The class of the value assigned to the this variable in a method is the class within which the method is declared: FALSE A Java method signature does not include the return type: TRUE A transient instance variable in Java is not written to persistent storage if the object is output: TRUE The class of the Class object is Class : TRUE A regular expression can specify the set anbn^ where 0&ltn&lt5, that is {ab, aabb, ..., aaaabbbb}: TRUE A shift reduce parser performs reductions in the reverse order specified by a left-most derivation: FALSE The string aabb is a sentential form for the grammar S->ab | aSb: TRUE A JO99 variable has an l-value and r-value: TRUE An abstract syntax tree is derived from a parse tree by removing extraneous nodes and restructuring the tree: TRUE A handle is a simple phrase: TRUE Some JO99 objects do not have a class: FALSE The following finite state automation recognizes the laguage specified by the regular expression a*1a+: FALSE

State Input NextState 0 1 1 0 a 0 1 a 2 2 1 1 2 a 2 Staring state is 0

A context free grammar can be used to recongnize any context sensitive language: FALSE

PROBLEM 2.

Given the parse table and grammar:

_____________________________________

| | b | a | $ || S | A | |-------------------------------------| | 0 | s3 | s2 | || 1 | 5 | | 1 | | |accept|| | | | 2 | r4 | s2 | r4 || | 4 | | 3 | | | r1 || | | | 4 | r3 | | r3 || | |

| 5 | s6 | | || | | | 6 | | s2 | || | 7 | | 7 | | | r2 || | |


r1: S->b r2: S->AbA r3: A->aA r4: A->a

a) Show a right-most derivation for the input aaba.

S->AbA->Aba->aAba->aaba

b) When parsing the input aaba, how many shifts will be performed?

4

c) Show the parse tree for aaba.

s /|
/ |
A b A /| | / | | a A a | | a

PROBLEM 3.

Given the grammar S->AcD A->ab|aAb D->d|Dd a) What is the language?

anbncdm n, m &gt=

b) Fill-in the following sets: FIRST(s) = {a} FIRST{A} = {a} FIRST{D} = {d} c) Fill-in the following sets: FOLLOW(S) = {$} FOLLOW{A} = {c, b} FOLLOW{D} = {d, $}

error (i.e. blank)

Posted by HKN (Electrical Engineering and Computer Science Honor Society)

University of California at Berkeley

If you have any questions about these online exams

please contactexamfile@hkn.eecs.berkeley.edu.

Posted by HKN (Electrical Engineering and Computer Science Honor Society)University of California at BerkeleyIf yo 4