$25
The goal of our project this semester is to develop a prototype C compiler. This is done by compiling C programs into processors such as x86, MIPS, ARM, or pseudo assemblies. In this class we will use Java assembly code (Jasmin, http://jasmin.sourceforge.net/) as the target codes. The project is divided into several parts including language definition, lexical analyzer, C-grammar, symbol table handlings, parser, and code generation. In the project 2, you will need to decide the set of language features you want to support in your compiler, and write the syntax analyzer.
Instead of generating codes, you will only need to output grammar rules in the code generator part to test whether the grammar is correctly passed. An example code may look like:
program: VOID ID '(' ')' '{' declarations stmts '}'
{ if (TRACEON)
System.out.println("program: VOID ID ( ) { declarations stmts }");}
declarations: type ID ';' declarations
{ if (TRACEON)
System.out.println(“declarations: type ID ; declarations”); } ...
You can find a demo C grammar in this link:
http://www.antlr.org/download/examples-v3.tar.gz.