Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (10 points) Consider the following grammar of expressions: exp::=idnoexp+expexpexpid::=XYZ no denotes unsigned integers as in the class notes/discussions. Rewrite this grammar such that the

image text in transcribedimage text in transcribedimage text in transcribed

1. (10 points) Consider the following grammar of expressions: exp::=idnoexp+expexpexpid::=XYZ no denotes unsigned integers as in the class notes/discussions. Rewrite this grammar such that the operations will be evaluated strictly left to right; i.e., X+YZ will be evaluated as if it was (X+Y)Z; and XY+Z will be evaluated as if it was (XY)+Z. But do NOT introduce parentheses or other new terminal symbols into the language. (Note: The language APL does something like this.) 2. (10 points) Suppose we wish to add a "> " statement to Core as follows: A statement has the structure: selectb1S1b2S2bnSnend; where b1,, bn are boolean expressions, i.e., > 's; and S1,, Sn are 's; and the number of b's is equal to the number of S 's. The symbol "| " is the same one used in the production but here it is being used to separate each cond , > pair from the next pair. Now for the problem: Add the "select" statement to Core by modifying the BNF grammar appropriately. (Use pure BNF, i.e., what we have been using in class. The book also talks about extended BNF which includes, in addition to what we have used, mechanisms such as repetition ("*'") as in the formalism of regular expressions. We don't use extended BNF because it causes problems when implementing the language.) (In a future homework, we will talk about the semantics of the select statement and see how to implement it. For now, you are only being asked to add it to the BNF grammar of Core.) exp>::=exp+termexptermtermterm!:=idno (2):=s+m+secstintseq:=stmt;{stm0}stmtseti.=assisinifwhileskipserecti::="select"caselist>"endi"aserest:=case{"casecase!!=cond""sim+seq="if"cond>"than"s+m+seg>"erse"s+msef"end"whiles:="while"cond"do"stmetseqt"end"Lass:sns:::Lvar="exp1SKip:i="skip"cond::=comp""::=expcompopexpcondcondexpr::=termexpr"+tfermexprterm:=faetor>11term""faetorfactor:=var::=select-stmt::="select"cond"""samt-sea"11"..."ll"cond""stmtses"end;" 1. (20 points) In the last homework, you were asked to define the BNF grammar, i.e., the productions, corresponding to the "" statement. In this homework, you have to write the (pseudo-)code corresponding the printSelect () and execSelect () procedures, in the style that we used in class. You do not have to implement the parseselect () procedure (unless you want to do it for fun!) You may use either the approach in which the array PT representing the abstract parse-tree was directly accessible to the print () and exec () procedures or the one in which we introduced a Parsetree class that provided appropriate methods to the client code to work with the abstract parse tree. You may want to use the following BNF productions for the : select >::= select end; ::= > > || You may assume that procedures such as execStmtSeq(), printstmtSeq(), and functions such as evalCond () etc. already exist

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

To find integral of sin(logx) .

Answered: 1 week ago

Question

What is Centrifugation?

Answered: 1 week ago