Wright CS 780 - Assignment (3 pages)

Previewing page 1 of 3 page document View the full content.
View Full Document

Assignment



Previewing page 1 of actual document.

View the full content.
View Full Document
View Full Document

Assignment

11 views

Other


Pages:
3
School:
Wright State University
Course:
Cs 780 - Compiler Design and Construction

Unformatted text preview:

Wright State University Department of Computer Science and Engineering CS 780 Fall 2010 Prasad Assignment 1 Due Sept 22 10 pts This assignment asks you to write a short Cool program The purpose is to acquaint you with the Cool language and to give you experience with some of the tools used in the course In this assignment you are to implement a very simple type inference engine for postfix expressions in Cool The input is a sequence of postfix expressions built using integer variables i and j real variables a and b and overloaded binary operators and The output is the sequence of inferred types To accomplish this task you can use a stack as follows A machine with only a single stack for storage is a stack machine Consider the following very primitive language for programming a stack machine and the corresponding action for inferring types Command i j a b q Meaning push int on the stack push int on the stack push real on the stack push real on the stack infer the type of the associated postfix expression using the top two stack entries and pushing the result type back on stack print contents of the stack top quit Here are some additional details The i and j commands simply push the string int on top of the stack The a and b commands simply push the string real on top of the stack The behavior of the resp command is to pop the top two stack entries corresponding to the two sub expresssions and to push the type of the resulting postfix expression on the stack Specifically the type of e1 op e2 is int if both the sub expressions e1 and e2 are of type int otherwise it is real The command prints the contents of the stack top The following examples show the effect of the various commands the input is read from left to right and the top of the stack is on the left that is stack values are the mirror image of the corresponding input expression types input stack j i int a i j int real a b i real i b real int Furthermore the command has the side effect of printing the type of b



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Assignment and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assignment and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?