Computer Science 164 - Spring 1991 - Yelick - Midterm 1

Computer Science 164 - Spring 1991 - Yelick - Midterm 1 -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Untitled Document UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 1991 K. A. Yelick CS 164: Programming Languages and Compilers Midterm Exam Name: Problem 1 (25 pts total) In Mustang comments are currently specified by a percent sign, %. Some members of the Mustang user community have decided that the comment facility should be replaced to allow for a more general style. A comment now begins with /* and may contain any characters in any order, except that the */ sequence will close them. There is an exception to the closing rule: */ will not close the comment if it is bracketed by a pair of $'s. For example, in the following code the */ in the last line closes the comment. /* The old code is: a := 9; b := a; c := 7; print("About to do the computation"); $ newline; doitnow(a,b) /* Do the program */ $ */ This allows easier commenting-out of code which contains comments. The $ need not be immediately next to the comment, and they are paired like quotes. Part A (5 pts) Write a context-free grammar for comment. You may use the grammar symbol char to represent a single character that is neither $, *, or /. Part B (10 pts) A context free grammar is unnecessarily powerful. Write a regular expression for comments. (You may again use char, but do not make up other symbols.) Part C (10 pts) Using Part B, one could augment the scanner to accept comments, or using Part A one could accepts comments through the parser. Which would you do and why? file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%201991%20-%20Yelick%20-%20Midterm%201.htm (1 of 6)1/27/2007 6:38:04 PM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Untitled Document Problem 2 (30 pts total) Graham R. Hacker (Alyssa's older brother, for those of you who took 60A) spent a few years working for a team of secret code crackers. One of his assignments was to reverse engineer an LALR parser to find an accepting string. He was given the following LALR parsing table, and partially readable list of production rules. Action Goto
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2009 for the course CS 164 taught by Professor Staff during the Spring '08 term at Berkeley.

Page1 / 6

Computer Science 164 - Spring 1991 - Yelick - Midterm 1 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online