

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
Main points of this exam paper are: Semantic Actions, Abstract Syntax, Tree Data, Data Type, Synthesized, Error Recovery, Follow Sets, Miscellaneous Parsing, Unambiguous Grammar, Discard Actions
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Consider the design of a small language using only the letters "z", "o", and the slash character "/". A comment in this language starts with "/o" and ends after the very next "o/". Comments do not nest.
Give a single regular expression that matches exactly one complete comment and nothing else. For full credit, use only the core regular expression notations A+B, AB, A*, A+, ∈ (epsilon), and "abc".
Consider the following grammars and associated semantic actions. In the actions, the operations And, Or, and Not are constructors for an abstract syntax tree data type. For each grammar, answer three things.
(a)
(b) Remember: Say whether each attribute of a non-terminal is inherited or synthesized and why. Show the value of the attributes of G after parsing ¬(A^(A=>B)).
CS 164, Fall/2000 Midterm #1 Professor Aiken 1
Give a grammar with the following First and Follow sets. Your grammar should have exactly two productions per non-terminal and no epsilon productions. The non-terminals are X, Y, Z and the terminals are a, b, c, d, e, f.
Consider the following grammar.
S -> S a | b | error a
(a) Show the DFA for recognizing viable prefixes of this grammar. Use LR(0) items, and treat error as a terminal. (b) Tools such as bison use error productions in the following way. When a parsing error is encountered (i.e., the machine cannot shift, reduce, or accept):
Show the sequence of stack configurations of an SLR(1) parser for the grammar above on the following input. Be sure to show all shift, reduce, and discard actions (for both stack and input).
bacadfa
(a) Give an unambiguous grammar that is not LR(1).
(b) How many strings are in the language of the grammar S -> aS?
(c) Which of LL(1), SLR(1), and LR(1) can parse strings in the following grammar, and why?
A -> a|c B -> b|c
Problem #3 - First and Follow Sets (20 points) 2