2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
This quiz has been regraded; your score was affected.
Quiz 4 (Remotely Proctored)
Due Jul 26 at 7pm Points 50 Questions 16
Copyright By PowCoder代写 加微信 powcoder
Available Jul 26 at 7pm – Jul 26 at 8:15pm about 1 hour Time Limit 60 Minutes
Instructions
This is an open-book, open-notes exam. However, you are not allowed to discuss this exam with anyone, including asking for help on the Internet. You are also not allowed to use other devices, nor listen to music, treat this as if you were in a classroom taking an exam. Although in principle you are allowed to use Eclipse and search the Internet while taking the test, you should not need to, and we strongly discourage you from wasting time trying to type code in Eclipse or looking for answers on the Internet. You should be able to answer all the questions on your own. If needed, you may consult the OSU/CSE Javadoc APIs at http://web.cse.ohio- state.edu/software/common/doc/ (http://web.cse.ohio-state.edu/software/common/doc/) .
Do not discuss this exam with anyone in CSE 2231 who has not yet taken the exam. Failure to observe these restrictions will be treated as academic misconduct.
I will be available at my office hour Zoom link: Office Hours (https://osu.zoom.us/j/92361574385? pwd=NGluaC9zRDRIdEUvalVrcG5yb1hvZz09) use this link only if you have questions (it is not a room to wait for something to happen and you will be kicked out if you do not have questions).
https://osu.instructure.com/courses/102483/quizzes/560651 1/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
This quiz was locked Jul 26 at 8:15pm.
Attempt History
Attempt Time Score Regraded
LATEST Attempt 1 60 minutes 26 out of 50 36 out of 50
Correct answers are no longer available. Score for this quiz: 36 out of 50
Submitted Jul 26 at 8:15pm This attempt took 60 minutes.
https://osu.instructure.com/courses/102483/quizzes/560651 2/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Which one of the following describes the correct sequence of steps a compiler runs?
Tokenizing, Parsing, Object Code Generation Object Code Generation, Tokenizing, Parsing Parsing, Tokenizing, Object Code Generation Parsing, Object Code Generation, Tokenizing
In accordance with The Ohio State University Code of Student Conduct, I certify that I have neither received from anyone nor given aid to anyone on this examination, that I shall not discuss the contents of this examination with anyone, and that I have not recorded nor taken any questions or answers from this exam.
By typing your name below, you assert that the statement above is true, and that the answers provided are your own, and that you have read, understood, and agree to abide by the quiz instructions provided above.
Type your full name here:
Choose the correct abstract syntax tree that corresponds to the following BL statement:
https://osu.instructure.com/courses/102483/quizzes/560651 3/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
WHILE true DO
IF next-is-empty THEN
https://osu.instructure.com/courses/102483/quizzes/560651 4/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Consider the following code, and answer questions about the value of p after this code has executed.
https://osu.instructure.com/courses/102483/quizzes/560651 5/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
“Quiz4” impossible to tell “Unnamed”
https://osu.instructure.com/courses/102483/quizzes/560651 6/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
How many user-defined instructions are in the context of p?
impossible to tell 2
What is the correct Abstract Syntax Tree for the body of instruction prowl in p.context?
https://osu.instructure.com/courses/102483/quizzes/560651 7/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
https://osu.instructure.com/courses/102483/quizzes/560651 8/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
What is the correct Abstract Syntax Tree for the body of p?
https://osu.instructure.com/courses/102483/quizzes/560651 9/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
https://osu.instructure.com/courses/102483/quizzes/560651 10/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Suppose a variable p is declared to be of type Program. For each of the following assertions about p decide whether it is true or false (Note: we are not asking about syntax errors in the notation; there should be no syntax errors.)
The value of p.body could be the Statement:
https://osu.instructure.com/courses/102483/quizzes/560651 11/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
compose((BLOCK, ?, ?),
The value of p could be:
(“test”, {}, compose((BLOCK, ?,
(“3test”, {(“2foo”, compose((BLOC
K, ?, ?), <>))}, compose((BLOCK,
?, ?), <>))
The value of p could be:
One of the name-body pairs in p.context could be
(“step”, compose((CALL, ?, “mov
https://osu.instructure.com/courses/102483/quizzes/560651 12/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Consider the following BugsWorld virtual machine program. For each given starting program counter value (pc) and “what the bug sees” (wtbs), determine the next primitive instruction (npi) to be executed.
0 JUMP_IF_NOT_NEXT_IS_NOT_EMPTY 1 21
2 JUMP_IF_NOT_NEXT_IS_NOT_ENEMY 3 17
4 JUMP_IF_NOT_NEXT_IS_WALL
1. pc = 0, wtbs = FRIEND 6 TURNRIGHT npi=
9 JUMP_IF_NOT_NEXT_IS_NOT_FRIEND
14 TURNLEFT
18 MOVE 19 JUMP
2. pc = 2, wtbs = EMPTY npi =
3. pc = 7, wtbs = EMPTY npi =
4. pc = 19, wtbs = WALL npi = TURNRIGHT
https://osu.instructure.com/courses/102483/quizzes/560651 13/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Consider the following context free grammar. boolexpr is the start symbol.
boolexpr → binop boolexpr boolexpr | unop boolexpr | literal binop → AND | OR
unop → NOT
lietral →T|F
Answer 2: TURNRIGHT
Answer 3: INFECT
Answer 4: TURNRIGHT
Which one of the following lists all and only the nonterminal symbols for this grammar? Each selection lists the symbols such that adjacent symbols are separated by “, ” (a comma and a space). None of the selections is claiming that the comma, “,”, is a nonterminal symbol.
boolexpr, binop, unop, lietral
https://osu.instructure.com/courses/102483/quizzes/560651 14/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
→, |, {, }
AND, OR, NOT
boolexpr, binop, unop, lietral, AND, OR, NOT, T, F AND, OR, NOT, T, F
boolexpr, binop, unop, lietral, →, |, {, }
AND, OR, NOT, T, F, →, |, {, }
Which one of the following lists all and only the terminal symbols for this grammar? Each selection lists the symbols such that adjacent symbols are separated by “, ” (a comma and a space). None of the selections is claiming that the comma, “,”, is a terminal symbol.
AND, OR, NOT, T, F
boolexpr, binop, unop, lietral
→, |, {, }
AND, OR, NOT
boolexpr, binop, unop, lietral, →, |, {, }
boolexpr, binop, unop, lietral, AND, OR, NOT, T, F AND, OR, NOT, T, F, →, |, {, }
https://osu.instructure.com/courses/102483/quizzes/560651 15/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Check all the strings below that are valid according to the grammar above. You should ignore the spaces, which are just provided to separate the tokens and would be discarded by a tokenizer. (Note: each correctly checked answer will receive some credit, but each incorrectly checked one will receive a penalty in the same amount. In other words, guessing may cost you.)
Question 12
Original Score: 0 / 1 pts Regraded Score: 1 / 1 pts
This question has been regraded.
AND OR NOT T F T NOT F
Valid Invalid
AND T NOT F
Valid Invalid
https://osu.instructure.com/courses/102483/quizzes/560651 16/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Invalid Valid
Valid Invalid
9 / 12 pts
Consider again the context-free grammar for boolean expressions from above.
The recursive descent parser to parse and evaluate syntactically valid expressions according to this grammar has a single method corresponding to the boolexpr start symbol of this grammar. A tokenizer is used to convert the input into a queue of tokens (Queue
boolexpr → binop boolexpr boolexpr | unop boolexpr | literal binop → AND | OR
unop → NOT
lietral →T|F
https://osu.instructure.com/courses/102483/quizzes/560651 17/20
Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
following tokens: “AND”, “OR”, “NOT”, “T”, and “F”. You may assume that the input is syntactically valid, so that no error checking is necessary.
Write the code of the recursive descent parser in the following method using the grammar above as a guide. For full credit, you must use only one return statement.
The value of an boolexpr string that is just literal is the value of the literal (T is true and F is false). The value of an unop string that is a unop followed by one boolexpr string is the op applied to the value of the following expression. The value of an bionop string that is a binop followed by two boolexpr strings is the op applied to the value of those two expressions, considered as though the operator appeared between the two expressions in the same order, the first expression before the second. For example:
The input string “NOT T”
would result in #tokens = <"NOT", "T", "!"> the returned value would be F
the outgoing value of tokens = <"!">
Given the string “OR T F T”
would result in #tokens = <"OR", "T", "F", "T", "!"> the returned value would be T
the outgoing value of tokens = <"T", "!">
Note: Answers that do not clearly use the grammar above or that evaluate the expressions provided in the slides for “Recursive Descent Parsing” or “Homework 27” will receive no credit.
* Parses an expression and returns its value.
* @updates tokens
* @requires [a boolexpr string is a prefix of tokens]
* @ensures
* valueOfBoolexpr = [value of boolexpr string at start of #tokens] a
* #tokens = [boolexpr string at start of #tokens] * tokens
public static boolean valueOfBoolexpr(Queue
assert tokens != null : “Violation of: tokens is not null”;
* As it is impractical to check the requires clause,
* that is not done here.
// A copy of the grammar for your convenience:
// boolexpr → binop boolexpr boolexpr | unop boolexpr | literal
// binop → AND | OR
// unop → NOT
// lietral → T | F
Your Answer:
boolean result = null;
https://osu.instructure.com/courses/102483/quizzes/560651
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
String first = tokens.dequeue(); if(first.equals(“NOT”)){
boolean temp1 = valueOfBoolexpr(tokens);
result = !temp1; }else{
if(first.equals(“AND”)){
boolean temp1 = valueOfBoolexpr(tokens); boolean temp2 = valueOfBoolexpr(tokens); result = temp1 && temp2;
}else{ if(first.equals(“OR”)){
boolean temp1 = valueOfBoolexpr(tokens); boolean temp2 = valueOfBoolexpr(tokens); result = temp1 ||temp2;
}else{ if(first.equals(“T”){
return result;
result = true; }else{
if(first.equals(“F”){ result= false;
https://osu.instructure.com/courses/102483/quizzes/560651 19/20
2021/9/27 Quiz 4 (Remotely Proctored): SU21 CSE 2231 – SW 2: Dev & Dsgn (4626)
Quiz Score: 36 out of 50
boolean result = false;
String start = tokens.dequeue();
switch (op) {
// We do not need to check for F
case “T”: result = true;
case “NOT”: {result = !valueOfBoolexpr(tokens); break;}
case “AND”: {
//Prevent short-circuit evaluation
boolean first = valueOfBoolexpr(tokens);
boolean second = valueOfBoolexpr(tokens);
result = first && second;
case “OR”: {
//Prevent short-circuit evaluation
boolean first = valueOfBoolexpr(tokens);
boolean second = valueOfBoolexpr(tokens);
result = first && second;
assert false : “Execution should not reach here.”;
return result;
-1 a boolean cannot be null -1 there seems to be a lot of missing }’s -1 The if-else for T-F hurts my feelings
https://osu.instructure.com/courses/102483/quizzes/560651 20/20
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com