The following applet demonstrates a compiler I had to write as part of my Advanced Compilers coursework in November-December 2002. My write-up can be seen here in PDF format (note that I have removed the source code from the write-up).
The compiler compiles the LISP like language TLL (This Little Language) into three-address code (TAC). The TAC is of my own design and in hindsight it could have been designed in a more regular format (see the conclusion of my write-up for further details).
The compiler uses a top-down recursive descent parser written using JavaCC to perform the parsing and to generate an abstract syntax tree (AST). A visitor is then used to walk the AST to generate the TAC.
The second part of the coursework involved generating zero-address code (ZAC) from the TAC for a byte-code interpreter. I have not created an applet for this because unless you know the syntax and semantics of the byte-code interpreter, the generated code would probably not make much sense to you. However, details and testing of my implementation can be see in my write-up above.
The applet below was programmed using SWING. In order to view this applet, you need at least the Java 1.2 plug-in.
Below are some examples you can try for yourself (copy and paste into the applet):
Recursive Factorial: (rec f (n) (if (= n 0) 1 (* n (f (- n 1 )))))
Factorial(10): (let fact (rec f (n) (if (= n 0) 1 (* n (f (- n 1 ))))) (fact 10 ))
Recursive Fibonacci: (rec f (n) (if (= n 0) 1 (if (= n 1) 1 (+ (f (- n 1)) (f (- n 2))))))