CS 214: Programming Languages
Spring 2009

Home|Syllabus|Schedule
<<|>>|ANTLR API|ANTLR Testing API|CITkit API

Nested Operations
FrontEnd, Iteration 6

The Old User Story

User Story #2: Arithmetic expressions in Schobbes

Arithmetic expressions (binary arithmetic only) are written prefix with parentheses.

Example: (+ 2 3) and (+ 5 (* 9 18)).

You'll finally get to finish this story. You're mostly there. It's that second example that won't work in your Schobbes interpreter.

Acceptance Tests

Write at least four new CIAT tests with nested operator expressions.

Some cases to care about:

The Lexer

Look at (+ 5 (* 9 18)). Look at your CIAT tests. What's in those programs that your lexer can't handle? Nothing!

The Parser

The CIAT tests should error out at the parser phase. This is because your parser only handles atoms in an operator expression.

Write at least three more assertions for shouldParseOperatorExpressions() with nested operator expressions. Red bar.

Find writing all of these assertions annoying? If you're going to unit test your parser, this is what you have to do. Now if there were a way to use mock objects with a parser, you'd be able to write one test with one assertion (using many mock objects and many expectations).

If you didn't use mock objects to test the interpretation of operator expression, you'd have to test at least as many concrete operator expressions as you are for the parser.

The solution: an operator expression can have expressions as subexpressions, not just atoms.

Fix the expression rule in the parser. Green bars all around!!!!

Um... The TIR Builder?

Why don't you have to do anything with the TIR builder?