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

Midterm Exam for ECS 142: Parsing Techniques, Spring 2001, Exams of Computer Science

A midterm exam for the ecs 142: parsing techniques course offered in spring 2001. The exam consists of 4 problems focusing on topics such as calculating first follow sets for given grammars, constructing slr(1) tables, determining if grammars are slr(1) or lr(1), and writing semantic rules for attributed grammars.

Typology: Exams

Pre 2010

Uploaded on 07/31/2009

koofers-user-hnz
koofers-user-hnz 🇺🇸

10 documents

1 / 6

Toggle sidebar

Related documents


Partial preview of the text

Download Midterm Exam for ECS 142: Parsing Techniques, Spring 2001 and more Exams Computer Science in PDF only on Docsity! Name (Last, First): , Midterm Examination May 15, 2001 Score: /100 Directions This exam consists of 4 questions on 6 pages; be sure that you have the entire exam before starting. Make sure that you write your name on every page of the exam. Answer each question in the space following the question. If you find it necessary to continue an answer elsewhere, indicate clearly the location of its continuation and label its continuation with the question number. The point value of each question is indicated at its beginning. The entire exam has 100 points. Be concise and indicate clearly what your answer is. Presentation and simplicity of your answers may affect your grade. You have 80 minutes. ECS 142 –1– Spring 2001 Name (Last, First): , Problem 1 Problem 1 (10 Points) Calculate first and follow for the non-terminals of the following grammars: 1.a (4 Points) S ::= 0 A S | 1 0 | empty A ::= 1 | 0 S A | empty 1.b (6 Points) S ::= + B | - B | d A A ::= d A | F | e C | empty B ::= d A | empty C ::= + H | - H | d D D ::= d E | empty E ::= empty F ::= d G G ::= d G | e C | empty H ::= d D ECS 142 –2– Spring 2001 Name (Last, First): , Problem 4 Problem 4 (45 Points) This problem deals with attributed grammars and semantic analysis. If you need any functions/data structures for specifying semantic rules/equations scheme, feel free to assume that they exist. Also, assume any synthesize or inherited attributes that you will need for defining the rules. However, describe all of your assumptions in detail. 4.a (15 Points) The following grammar generates strings of the form  . E ::= E + T | T T ::= T * F | F F ::= ( E ) | num In this grammar, we assume that num is a token with an integer value. Write a set of semantic rules such that an execution of the outputs the reverse of the input string. For instance, a translation of   will print   . 4.c (15 Points) The following grammar generates an arbitrary sequence of 1s and 0s. S ::= 1 S | 0 S | 1 | 0 Write a set of semantic rules that checks if an input string has equal number of 1’s and 0’s. ECS 142 –5– Spring 2001 Name (Last, First): , Problem 4 4.d (15 Points) The following grammar describes the behavior of a stack: Stack ::= Action; Stack | base Action ::= push Item | pop Item ::= id The sequence (push a; pop; push b; push c; pop; push d; base), for instance, describes a stack (a; c; base), where a is at the top of the stack. Write a set of semantic rules that read a sequence, such as the one shown earlier, and return a sequence describing the elements in the stack. For instance, it should return “a c base” after reading the sequence push a; pop; push b; push c; pop; push d; base. Note that it is an error to apply pop on a stack containing “base”. Your semantic rule should return “error” in this case. Feel free to (i) assume operations for concatenating strings, and (ii) use different kinds of statements for writing the rules. ECS 142 –6– Spring 2001
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved