Exercises for Week 10

Exercises for Week 10#

This week’s TA exercise is getting to know two items.

  1. Creating dummy parsers for testing the implementation of lexers.

  2. End-to-end testing of compilers (time permitting).

Dummy Parsers#

A dummy parser is a parser that, rather than building an AST from the lexed tokens, simply emits each token as it is read from the input. This is especially useful for verifying that your lexer works as expected.

Your first task is to write a parser that does this.

End-to-end testing#

Unlike other domains, compiler testing generally does not involve unit testing. Instead, most positive tests are end-to-end, while negative tests are end-to-wherever-the-error-occurs. This makes the test suite more robust to modifications of the AST and the addition of features.

Your second task is to develop an end-to-end testing framework for your compiler. You may choose to use a unit testing framework to write your end-to-end tests, such as OUnit or Alcotest, or you may choose to hand-write your test execution.

In any case, for each test, your framework should:

  • read Dolphin source code

  • try to compile the source code to a binary

    • if compilation fails, compare the failure to an expected error

    • if compilation succeeds, execute the compiled code and compare the output to an expected output

Ideally, the entire suite should be runnable without any human interaction, and make it easy to identify which tests failed.