Docsity

Homework VI: Extending Wren Calculator with New Operations, Assignments of Programming Languages

Toggle sidebar
bg1
22C:185 โ€” Fall 2004
Homework VI
1. [15 points]
Using the revised version of the calculator presented on the class Web page, draw the
abstract syntax tree and show how to use the semantic equations to evaluation the key
sequence 10M++6+/-=xMR.
2. [15 points]
This problem refers to the revised version of the calculator presented on the class Web
page. You are to add a clear entry (CE) key to the calculator. The purpose of this key is
to zero the display, but otherwise leave the state of the calculator unchanged. It should
be valid to press this key at any time. Add the BNF to include this new key in the
language, provide appropriate semantic equations, and justify their correctness.
3. [45 points]
Extend the Wren syntax and denotational semantics in our text (Fig. 9.11) to incorporate
three new operations. Add the increment operators of C to Wren. That is, allow (integer)
subexpressions of the forms <variable>++ and ++<variable>. The semantics are to
follow that of C โ€” namely, as an expression, x++ denotes the value of x prior to
increment, while ++x denotes the value of x subsequent to increment; the evaluation of
either subexpression causes the side-effect that x is incremented. Lastly, add the Java
conditional expression -- <boolean expr> ? <integer expr> : <integer expr> -- whose
value is that of the first integer expression when the Boolean is true and the second
when it is false.
Develop the changes for both the syntax and denotational semantics for these added
features. Discuss your choice of the precedence selected for the new operators (e.g.,
what does b ? x : y + z mean), and how your changes to the Wren syntax/semantics
achieve it. Provide the relevant BNF and semantic equations, and include a convincing
argument that your formal definition insures that the informally stated behavior is
obtained.

Partial preview of the text

Download Homework VI: Extending Wren Calculator with New Operations and more Assignments Programming Languages in PDF only on Docsity!

22C:185 โ€” Fall 2004 Homework VI

1. [15 points] Using the revised version of the calculator presented on the class Web page, draw the abstract syntax tree and show how to use the semantic equations to evaluation the key sequence 10 M+ +6 +/- =x MR. 2. [15 points] This problem refers to the revised version of the calculator presented on the class Web page. You are to add a clear entry ( CE ) key to the calculator. The purpose of this key is to zero the display, but otherwise leave the state of the calculator unchanged. It should be valid to press this key at any time. Add the BNF to include this new key in the language, provide appropriate semantic equations, and justify their correctness. 3. [45 points] Extend the Wren syntax and denotational semantics in our text (Fig. 9.11) to incorporate three new operations. Add the increment operators of C to Wren. That is, allow (integer) subexpressions of the forms ++ and ++. The semantics are to follow that of C โ€” namely, as an expression, x++ denotes the value of x prior to increment, while ++x denotes the value of x subsequent to increment; the evaluation of either subexpression causes the side-effect that x is incremented. Lastly, add the Java conditional expression -- ? : -- whose value is that of the first integer expression when the Boolean is true and the second when it is false. Develop the changes for both the syntax and denotational semantics for these added features. Discuss your choice of the precedence selected for the new operators (e.g., what does b? x : y + z mean), and how your changes to the Wren syntax/semantics achieve it. Provide the relevant BNF and semantic equations, and include a convincing argument that your formal definition insures that the informally stated behavior is obtained.