/cminus-compiler

This was a project for my Compiler Construction class at Villanova.

Primary LanguageC

==================== Cminus Compiler By Christine Fossaceca

Makefile File for compiling/building program using make utility.

README.txt This file.

symtab.c The file holding all of the functions to generate and query the symbol table.

symtab.h Header file for symtab.c

symtab.o Class output file created by gcc compiler for symtab.c

parseMain.c Template C file containing the main routine for testing the parser.

cminus.l Template Flex input file for generating scanner

cminus.y Template Bison file to generate the header file for token values.

cminus.tab.c Autogenerated file for header file with token values

cminus.tab.h Autogenerated header file with token values

lex.yy.c Lexical analyzer autogenerated file called by main

lex.yy.o Class output file created by gcc compiler for lex.yy.c

parseMain.o Class output file created by gcc compiler for parseMain.c

parse actual parserinvoked by ./scan

gencode code generator invoked by ./gencode

gencode.c The file holding all of the code generation functions

gencodeMain.c Parse file

gencodeMain.o Class output file created by gcc compiler for gencodeMain.c

gencode.o Class output file created by gcc compiler for gencode.c

genLabel.c Given file to create labels

addtest.c C file testing add functionality

addtest.j Jasmin byte code file for addtest.c

arraytest2.c Global vs local arraytest file test 2

arraytest2.j Jasmin byte code file for arraytest2.c

arraytest.c Global vs local arraytest file

arraytest.j Jasmin bytecode

concat.c Given file to concatenate strings

D-Java.exe Java disassmbler

Functions.c File to test function declarations and calls

Functions.j Jasmin Bytecode of Functions.c

functiontest.c File to test function declarations and calls

functiontest.j Jasmin Bytecode of functiontest.j

globvartest.c Testing global variables

globvartest.j Jasmin bytecode for globvartest.j

HelloWorld.c File to test the function of the print command

HelloWorld.j Jasmin bytecode of print command

iftest.c Testing of if statements

iftest.j Jasmin bytecode of if statements

jasmin.jar Jasmin jar file

Main.class Main class file to be run in java

manyvariables.c a test of many variables and arrays in c

manyvariables.j Jasmin bytecode testing arrays and variables

relops1.c a test of the relative operators

relops1.j Jasmin bytecode for the first relops.c file

relops2.c A second relative operators test

relops2.j Jasmin bytecode for relops2.c

scan.c Test of scanf functionality

scan.j Jasmin bytecode for scanf

simptest2.c simple program test file

simptest2.j simple program output

simptest3.c simple program test file

simptest3.j simple program output

simptest.c simple program test file

simptest.j simple program output

SomeClass.c example program from slides

SomeClass.j example program output

subtest.c testing subtraction and division

subtest.j output of subtraction and division

whiletest.c testing a while loop

whiletest.j output in bytecode of a while loop

arith.c file testing arithmatic operations and identifiers

arith.j output of arith.c bytecode

bsort.c bubble sort program

bsort.j output of bsort.c bytecode

bsorti.c bubble sort program with scanning

bsorti.j output of bsort.c bytecode

arr1 - arr3.c examples of global and local arrays

arr1 - arr3.j examples of global and local array in bytecode

fact.c simple printf file

fact.j output of fact.c bytecode

func1 - func5.c examples of different simple functions

func1 - func5.j function examples in bytecode

gcd.c greatest common denominator program

gcd.j output of gcd.c bytecode

gcdi.c Finding greatest common denominator with Euclid's method

gcdi.j output of gcdi.c bytecode

if1.c example of an if statement

if1.j bytecode of an if statement

if2.c example of an if statement

if1.j bytecode of an if statement

loop.c example of a while loop

loop.j bytecode of a while loop

sq.c a function to square a variable

sq.j bytecode to square a variable

ssort.c simple sorting program

ssort.j output of ssort.c bytecode

ssorti.c simple sorting program with scanning

ssorti.j output of ssorti.c bytecode

sum.c more math operation testing

sum.j output of sum.c bytecode

============== How to compile

Do

make gencode

**When you do 'make gencode', you will get a lot of warnings, however, none of these warnings prevent compilation, and should just be ignored.

========== How to run

By default, the generated parse(parse or parse.exe) reads from stdin and writes to stdout. You can redirect these to read from or write out to a file. E.g,

./gencode <test1.c >test1.j

java -jar jasmin.jar test1.j

java Main

===================== Known limitation/bugs

When you do make gencode, you will get a lot of warnings, however, none of these warnings prevent compilation, and should just be ignored.

None. Works on all files, and fulfills all of the requirements. All of the files listed here can be compiled. In addition, scanf works as well.

Printing only works with variables and arrays (not strings) as that is not supported in C-Minus

The extra credit scan function also works