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 Examination for ECS 142 - Spring 1997, Exams of Computer Science

A midterm examination for the computer science course ecs 142, offered in spring 1997. The exam consists of three problems dealing with topics such as predictive parsing, ll(1) grammars, lr(1) parsing, and attributed grammars. Students are required to construct parser tables, identify grammar properties, and extend grammar definitions with semantic actions.

Typology: Exams

Pre 2010

Uploaded on 07/31/2009

koofers-user-e7y
koofers-user-e7y 🇺🇸

5

(1)

10 documents

1 / 6

Toggle sidebar

Related documents


Partial preview of the text

Download Midterm Examination for ECS 142 - Spring 1997 and more Exams Computer Science in PDF only on Docsity! Name (Last, First): , Midterm Examination May 8th 1997 Score: /100 Directions This exam consists of 3 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 1997 Name (Last, First): , Problem 1 Problem 1 (35 Points) Problems 1.a and 1.b require you to construct a predictive parser for the following grammer:       ! " # $ % & id " '(" #   )% 1.a) (8 Points) Find * +,.- and * /  /0 sets for the nonterminals of the grammar: First(Expr) = Follow(Expr) = First(Var) = Follow(Var) = First(ExprTail) = Follow(ExprTail) = First(VarTail) = Follow(VarTail) = 1.b (11 Points) Show the predictive parser table for the grammar id   $ Expr ExprTail Var VarTail ECS 142 –2– Spring 1997 Name (Last, First): , Problem 2 2.c (3+7 Points) Is the following grammar an LR(1) grammar? Describe the reasons for your answer. 1.  id    2.   id   3.    4.   id   ECS 142 –5– Spring 1997 Name (Last, First): , Problem 3 Problem 3 (30 Points) This problem deals with attributed grammars and semantic analysis. 3.a (15 Points) Consider the following grammar for specifying binary trees (in linearized form):   num    Extend the above grammar by defining a translation scheme such that a depth-first left-to-right traversal of a parse tree (denoting a binary tree) annotated with semantic actions will entail checking if the binary tree is ordered. A binary tree is ordered if the values of the numbers of the first subtree (      ) are less than the value of the current number and the values of the numbers of the send subtree (       ) are greater than the value of the current number. For instance, (2 (1 nil nil) (3 nil nil)) is ordered but (1 (2 nil nil) (3 nil nil)) is not. Note that you can use any language constructs (such assignments, if-then-else, expressions, boolean expressions etc.) for writing the semantic rules. 3.b (15 Points) The following grammar denotes a language "! $# % &% '#)(*,+.-(0/ +.-1 . 2 342 65  778 9:7<;=  Extend the above grammar by defining a translation scheme such that an execution of the translation scheme will output a string where each occurrence of is replaced by an occurrence of  and each occurrence of  by an occurrence of . For instance, a translation of       will result in        , whereas a translation of        will result in        . Note that if /?>@ , only / A ’s or B s are replaced. Also, note the order of ’s and  ’s replaced. However, if /DCA , all ’s and  ’s are replaced by  ’s and  ’s. ECS 142 –6– Spring 1997
Docsity logo



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