Compiler for a subset of the C programming language. This compiler generates x86 assembly for a correct source program. It also shows various lexical and syntax errors on erroneous source programs.
This is a compiler for a subset of the C programming language. The syntax of the language is similar to C. Although for the sake of simplicity, the syntax, and features of this language is not as versatile as C. The source program can be written in any file, and passed into the compiler executable as you would do with gcc
.
The compiler generates x86 assembly files as output, as opposed to directly assembling to target machine code. You can use x86 assemblers to generate executables for your machine, or simulate the x86 assembly using any emulator, a popular tool is emu8086.
Will be written soon.
Will be released soon.
The compiler sources are available at inside the src/
directory. You can directly compile them using flex
and bison
.
Run from your terminal:
sudo apt install flex
Run from your terminal:
sudo apt install bison
First give permission to build.sh
:
chmod +x build.sh
Then execute the shell file:
./build.sh
This will generate the compiler executable subcc.o
. You can directly invoke it to your .c
file.
subcc.o mycode.c
The compiler will output two x86 assembly files, code.asm
and optimized_code.asm
. They are identical, but optimized_code.asm
performs some Peephole Optimization on the code of code.asm
.
You can simulate the assembly files using emu8086. This emulator is made for windows. To run it on linux you need to install wine. Which will allow you to run windows applications on linux.
- Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman. 1986. Compilers: principles, techniques, and tools. Addison-Wesley Longman Publishing Co., Inc., USA.
- Linda Torczon and Keith Cooper. 2007. Engineering A Compiler (2nd. ed.). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.
- John Levine and Levine John. 2009. Flex & Bison (1st. ed.). O'Reilly Media, Inc.