CS 31600 - Programming Languages Project

This project is due Friday, May 11.

The main idea of this project is for you to pick a programming language from a list given below and use that language to write a program that parses strings in the language of prefix arithmetic expressions and outputs the expressions in (parenthesised) infix notation along with the expression's value. (In other words, you are going to redo part of Assignment 2, but in a new language. This project is also equivalent to the example language Expr0 from Assignment 3.)

Here are some details. You can work on this project in pairs. Choose a partner (if you wish) and then choose one of the languages from the following list. Each language can be used by just one team, so when you pick a language, you need to send me an email telling me who your partner is and what language you have chosen. The languages will be handed out in a first come, first served manner. (If your chosen language is already assigned to someone, I'll write back to you and let you know. I'll try to keep this page updated with who has chosen which language). If you are already familiar with one of these languages, then pick a different one.

After you have chosen a language, get it installed on your computer. (Most of these languages have fairly simple, ML like, installers that give you a REPL. Some of the "installers" are no more complicated than unzipping a file.) Work your way through a simple tutorial about the language.

Write a program (or a function, or a collection of functions) that reads a string that is written in the following language of prefix arithmetic expressions and parses the string to a (binary) expression tree. Then your program (or functions) should walk the expression tree and produce an infix output string and a numeric value.

      Prefix -> BinOp Prefix Prefix
              | UnOp Prefix
              | Number

       BinOp -> '+' | '-' | '*' | '/' | '^'

       UnOp  -> '~' | 'S'     /* '~' is negation, 'S' is square root */

      Number -> any valid double (or real) number
The nicest kind of solution would be a program that reads from standard input and writes to standard output. That is, a program that would read one prefix expression from each line of standard input, and then write, to standard output, one line for each expression with the expression's infix notation and the expression's value. But doing that much I/O might be tricky in some of these languages. So you could also approach this in an ML kind of way, where you write your code in one file, "read" that file into the interpreter, then "read" into the interpreter a second file of tests that run your code on a bunch of input strings, writing the output into the display of the REPL. However you handle the input and output, your final solution should contain a reasonable collections of test expressions and a README.txt file that explains how your tests should be run and what their results should look like.

Here is a minimal collection of prefix expressions (taken from Assignment 3). You can assume, as in these examples, that every token is surrounded by whitespace, so that converting a string into a list (or array) of tokens is fairly straight forward. (If you can find a tokenizer in the stadard library of your chosen language, go ahead and use it.)

   "+ 2 * 3 4"
   "* + 2 3 4"
   "+ - 2 3 4"
   "- 2 + 3 4"
   "~ ^ 2 3"
   "^ ~ 2 3"
   "/ + ~ -1 S - ^ -1 2 * * 4 1 -1 * 2 1"
Your output infix expressions should have the exact same format as described in the file InfixPrinter.java from Assignment 2.

Turn in a zip file called CS316ProjectSurname.zip (where Surname is the last name of either team member) containing the appropriate source files that solve this problem, your tests, and a brief explanation of how you expect your tests to be run and what their results should look like.

When the projects are turned in, I will make them available from this page, so that you can see how this problem gets solved in a variety of programming languages.

This project is due Friday, May 11 (the last day of final exam week).


Return to the main homework page.
Return to the CS 31600 home page.


compliments and criticisms