



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A midterm exam for the computer science 164 course offered by the university of california, berkeley's department of electrical engineering and computer sciences. The exam covers topics such as shift-reduce parsing, nfas, regular expressions, bnf grammars, and recursive descent parsing.
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Department of Electrical Engineering and Computer Sciences Computer Science Division
P. N. Hilfinger CS Fall 1997
CS 164: Midterm
Name: _______________________________________________ Login: _______
all questions in the space provided on the exam paper. Show all work (but be sure to indicate your answers clearly.) The exam is^ You have two hours to complete this test. Please put your login on each sheet, as indicated, in case pages get separated. Answer worth a total of 35+ points (out of the total of 200), distributed as indicated on the individual questions.You may use any notes, books, or computers you please--anything inanimate. We suggest that you read all questions before trying to answer any of them and work first on those about which you feel most confident. You should have 5 problems on 8 pages.
Login:
A shift-reduce parser for this language processes the string
and performs the following actions:
Now for the questions:
a. As far as one can tell from this sample, what is the grammar for the language being parsed?
(Continued on next page)
Login:
b. What is the parse tree for this string?
Login:
the right number gets printed. Be careful: the grammar is not LL(1); you can change it as needed, just so long as you end up recognizing the same language and get the right numbers. Assume that the following functions are available for your use:
Write your program on the next page without using global variables. All assignments should be to local variables only. Do not introduce any new types.
Login:
Here is the parser skeleton. Remember: no global variables; assign only to local variables; do not introduce new types.
void start() { printf ("Maximum operators in any expression = %d\n", _________); } _____ pr
Login:
a. I happened to have an LL(1) parser generator and put the following grammar through it:
The parser generator told me the grammar is not LL(1). Why not?
Login:
Identify the bug in the grammar. Give an example of an input that runs into the error (that is, that requires making a shift/reduce decision for a state and symbol that have a conflict). Propose a simple change to the grammar (and the language it describes) to fix the problem (that is, make an informed guess as to what was really intended).