An interpreter for Classroom Object-Oriented Language (Cool) written in Cool.
This interpreter can be run using the UVA Cool Interpreter. A wrapper script is provided that allows multiple input files to be specified to the Cool Interpreter, and another script is provided to pass all requisite files for the interpreter itself to the Cool Interpreter:
$ export COOL_INTERPRETER=path/to/interpreter/cool
$ bin/cool test/interpret/hello-world.cl
Hello, World!
The interpreter can also run itself:
$ bin/cool --bootstrap test/interpret/hello-world.cl
Hello, World!
The interpreter can also be run using the UVA dialect of Cool:
$ bin/cool test/interpret/compare-bool.cl
ERROR: test/interpret/compare-bool.cl: line 3: left expression type 'Bool' is not type 'Int' for '<' expression
ERROR: test/interpret/compare-bool.cl: line 3: right expression type 'Bool' is not type 'Int' for '<' expression
$ bin/cool --uva test/interpret/compare-bool.cl
true
The UVA dialect has the following differences from the default dialect:
- A
\c
sequence within a string represents a literal backslash followed by the character (Strings), butIO.out_string
interprets the\n
and\t
sequences as a linefeed and tab respectively (IO). - The
<
and<=
comparison operators can be used on operands ofInt
,String
, andBool
(Arithmetic and Comparison Operations, Type Checking Rules, Operational Rules). - A stack overflow runtime error occurs after 1000 outstanding method dispatch
and
new
expressions. (Operational Rules). - Errors are printed without a filename or stack trace.
- Lexical analysis - Nearly complete. The null character cannot be used (the UVA Cool Interpreter does not allow the null character in input strings).
- Parsing - Complete.
- Semantic analysis - Complete.
- Interpreter - Complete.