Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose we wish to add a 'select statement to Core as follows: a select statement has the structure select bi -> si 11 b2 ->

image text in transcribed
Suppose we wish to add a 'select statement to Core as follows: a select statement has the structure select bi -> si 11 b2 -> S2 || ... || bn -> Sn end; where bi, ..., bn are boolean expressions (i.e. (cond)'s), and si, ..., Sn are (stmt seqy's; and the number of b's is equal to the number of s's. We execute the select as follows: if bl evaluates to true, execute S1 and you are done; if b1 evaluates to false, and b2 to true, execute S2 and you are done; ...; if bi, ..., b(n-1) evaluate to false and bn to true, execute Sn; if bi, ..., bn all evaluate to false, simply go to the next statement that follows the select (i.e., the select, in this case, is a 'no-op'). Note that the "II" is a new terminal symbol that is used to separate each (cond), stmt seq) pair from the next pair. Now for the problems: 1. (8 points). Add the select statement to Core by modifying the BNF grammar appropriately. (Use "pure BNF", i.e., what we have been using in class. If you were to use "extended BNF, answering the next question will be much harder.) 2. (12 points). Using the notation from the class notes (copies of slides), write down the Execute-select- statement procedure and any other procedures you need to add to Core's interpreter to implement the select statement. Don't worry about the Parse-select-statement procedure. You may assume the array representation of the parse tree when answering this question. You may also assume procedures such as Execute-stm-seq or functions like Eval-Cond etc, already exist. Important Note: The problem is not asking you to show how you can achieve the effect of the select statement by using multiple if statements or anything like that. You are being asked to introduce a new statement into the CORE language so that the CORE programmer can write, as part of his or her CORE program, statements such as: select (x > 0) -> Y = 10; 11 (x > 0) -> X = 10; end; Suppose we wish to add a 'select statement to Core as follows: a select statement has the structure select bi -> si 11 b2 -> S2 || ... || bn -> Sn end; where bi, ..., bn are boolean expressions (i.e. (cond)'s), and si, ..., Sn are (stmt seqy's; and the number of b's is equal to the number of s's. We execute the select as follows: if bl evaluates to true, execute S1 and you are done; if b1 evaluates to false, and b2 to true, execute S2 and you are done; ...; if bi, ..., b(n-1) evaluate to false and bn to true, execute Sn; if bi, ..., bn all evaluate to false, simply go to the next statement that follows the select (i.e., the select, in this case, is a 'no-op'). Note that the "II" is a new terminal symbol that is used to separate each (cond), stmt seq) pair from the next pair. Now for the problems: 1. (8 points). Add the select statement to Core by modifying the BNF grammar appropriately. (Use "pure BNF", i.e., what we have been using in class. If you were to use "extended BNF, answering the next question will be much harder.) 2. (12 points). Using the notation from the class notes (copies of slides), write down the Execute-select- statement procedure and any other procedures you need to add to Core's interpreter to implement the select statement. Don't worry about the Parse-select-statement procedure. You may assume the array representation of the parse tree when answering this question. You may also assume procedures such as Execute-stm-seq or functions like Eval-Cond etc, already exist. Important Note: The problem is not asking you to show how you can achieve the effect of the select statement by using multiple if statements or anything like that. You are being asked to introduce a new statement into the CORE language so that the CORE programmer can write, as part of his or her CORE program, statements such as: select (x > 0) -> Y = 10; 11 (x > 0) -> X = 10; end

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago

Question

1. Identify six different types of history.

Answered: 1 week ago