CS164 Midterm Examination - Spring 1998, Exams of Programming Languages

A computer science midterm examination for the university of california, berkeley's cs164 course in spring 1998. The examination covers topics such as parsing, pushdown automata, abstract classes, and java programming. Students are required to define terms, answer multiple choice questions, identify sentences recognized by a finite state automaton, construct parse trees, and determine which instance variables can be accessed using given objects.

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shailaja_987c
shailaja_987c 🇮🇳

4.3

(34)

217 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 164 - Spring 98
Midterm Examination
Professor L. Rowe
Problem #1
(30 points) Define the following terms:
parserterminal symbolabstract classmethodabstract syntax treepushdown automatongrammar ruleautomatic parser generator
handleinstancearbitrary rewrite systemsyntax directed translationrvalueleftmost derivationreduce/reduce error
Problem #2
(10 points) Answer the following:
T F A pushdown automaton can recognize a language defined by a regular grammar.
T F A bottom-up parser performs reductions in the same order as a rightmost
derivation.
T F A variable declared in Java to be a type Class can reference the object Object.
T F Class variables cannot be defined in a Java abstract class.
T F A nondeterministic fsa can recognize languages that a deterministic fsa cannot
recognize.
Problem #3
(20 points) Answer the following questions given the fsa:
a) Identify which sentences are recognized by this automaton.
Yes No aab
Yes No bbabca
Yes No bcaabaaabaa
CS164, Midterm, Spring 1998
Computer Science 164 - Spring 98 Midterm Examination Professor L. Rowe 1
pf3
pf4

Partial preview of the text

Download CS164 Midterm Examination - Spring 1998 and more Exams Programming Languages in PDF only on Docsity!

Computer Science 164 - Spring 98

Midterm Examination

Professor L. Rowe

Problem

(30 points) Define the following terms:

  • parser
  • terminal symbol
  • abstract class
  • method
  • abstract syntax tree
  • pushdown automaton
  • grammar rule
  • automatic parser generator
    • handle
    • instance
    • arbitrary rewrite system
    • syntax directed translation
    • rvalue
    • leftmost derivation
    • reduce/reduce error

Problem

(10 points) Answer the following:

T F A pushdown automaton can recognize a language defined by a regular grammar. T F A bottom-up parser performs reductions in the same order as a rightmost derivation. T F A variable declared in Java to be a type Class can reference the object Object. T F Class variables cannot be defined in a Java abstract class. T F A nondeterministic fsa can recognize languages that a deterministic fsa cannot recognize.

Problem

(20 points) Answer the following questions given the fsa:

a) Identify which sentences are recognized by this automaton.

Yes No aab Yes No bbabca Yes No bcaabaaabaa

Computer Science 164 - Spring 98 Midterm Examination Professor L. Rowe 1

Yes No bbcb Yes No abbbbabbabca b) Show a left regular grammar that specifies the language recognized by the fsa. (Hint: write a grammar rule which would produce the fsa using the algorithm given in class.)

c) Describe in English the language recognized by the fsa.

Problem

(20 points) Given the following LR parser tables and grammar rules, answer the following questions.

a ( ) $ S L 0 s2 s3.. 1. 1... acc.. 2 r1 r1 r1 r.. 3 s2 s3.. 5 4 4 s2 s3 s6. 7. 5 r3 r3 r3 r.. 6 r2 r2 r2 r.. 7 r4 r4 r4 r..

The grammar is 1: S -> a 2: S -> '('L')' 3: L -> S 4: L -> LS a) Show the parse tree for the sentence "( ( a ( a ) ) )".

b) Show the parser configurations as it parses that input in the following table. You must use state numbers on the syntax stack. (Hint: 22 configurations are shown in the table -- the parse may take less than, more than, or equal to that number of steps.)

step stack input action 1 0 ( ( a ( a ) ) ) $ shift 3

2 0 3 ( a ( a ) ) ) $ shift 3

3 4

new C(); C ac = new D(); D ad = } }

a) Which instance variables can be accessed using the object ac in the method main?

b) Which instance variables can be accessed using the object ad in the method main?

c) Which instance variables can be accessed in the method called by D.f() in the method main?

Total: 100 points

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 contact [email protected].