Logo University of Washington Department of Computer Science & Engineering
 CSE 401Au '02: Assignment #3, Due in class Monday, 10/28/02
  CSE Home  About Us    Search    Contact Info 

Individual homework

None this week.


As usual, turn in only one solution per group.

1. Researchy topic:

Use a compiler generator to build a handy double precision calculator. The calculator should support recursive expressions, the usual arithmetic operations (exponentiation included), and should support at least four functions (such as sin, cos, tan, atan). You should accept numbers in C-style double format (remember HW1?). In addition, provide a symbol for "the result of the last operation", such as 'x'. For example, here's a possible session with your calculator:

$ calc
> 2.3 + 2.25 * 2
> x - 1

Bonus points: Consider adding the ability to define symbolic "memories" that you can assign to and read.

The nicest part of this homework is that you get to choose what parser generator to use. Here are some suggestions:

  1. The good ol' yacc, which we already have installed. Use the one program that was so good and so early, that it shut down parser generator research for decades. Yacc is described in the book and in the slides. A nice doc can be found here. If you want a smooth sailing, choose this. If you'd like some brownie points, read below (using anything but yacc brings them).
  2. Spirit, a LL(infinite) parser generator that allows generating EBNF grammars directly in C++ source code. Quite ingenious; I recommend at least that you take a look.
  3. ANTLR. A cool parser generator written by Terrence Parr. Generates Java. Definitely worth a look!
  4. Precc - A Prettier Compiler Compiler. Didn't take a close look at it yet, but seems to be good.
  5. JavaCC. Pretty well known, generates Java.
  6. ML-Yacc - much like yacc, generates ML!
  7. Many others - just fire google!

2. Change the lexer to scan the extended token set (also see the project description). Also extend the parser to understand for loops, continue statements, Booleans, and constant expressions as described in the project and in the extended language. It is assumed that you have comments and if-then-else statements in your pocket already.

Your modified parser doesn't need to generate (or evaluate) code, but it should build proper ASTs and print them.

Turn in:

CSE logo Department of Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to cse401-webmaster at cs.washington.edu]