Homework VII

(60 points)

 

 

A Prolog version of the scan/parse/interpret process for the Pelican language is provided in the file 'pelican_ds' in our class directory. A very similar scan process was considered in an earlier homework, and the parser is based on a DCG grammar similar to those used previously. The interpreter closely follows the denotational semantics we have discussed. Our class directory also contains several example Pelican programs. Note that the 'pelican_ds' program does not work properly under SWI-Prolog so it will be necessary to use SICStus.

 

This homework is a follow-on to problem 3 in Homework VI. Extend the Pelican syntax and denotational semantics to incorporate three new operations. Add the increment operators of C to Pelican. 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 the scanner, parser and interpreter 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 Pelican system achieve it.

 

Your submission for this problem should consist of a printout that contains a listing of your code, plus thorough testing of all parts of the code that you have changed or added. You should clearly indicate those places where the code is new, and inclusion of thorough testing of each change/addition is considered an integral part of completing this assignment. In addition, you should submit your code file (only) electronically to the directory Hwk7 for class c185.