argamanza / CSimple-Compiler

A Simple Compiler for a Simple Programming Language :wink:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C-Simple Compiler

By Tzahi Argaman

Created as a project for "Introduction to Compilation" course.

The compiler with all its parts was planned and built to be used with CSimple Programming Language - The language which the compiler was made for, as introduced here by Prof. Christopher Kruegel.

Please read the CSimple Manual before using the compiler to understand its structure and requirements.

Compiler Checklist

  • Scanner (Lexer)
  • Parser
  • Semantics
  • Finished Compiler

Getting Started

Fork or download the content of the repository to your computer. The compiler source code can be found inside the src folder.

Prerequisites

To compile the compiler (:confused:) you will need the following tools:

  • flex 2.5.35
  • bison (GNU Bison) 3.0.2
  • cc 4.8.4

Installing

Open the folder which contains the scanner.l and parser.y and run the following commands by order inside your terminal:

lex scanner.l // creates 'lex.yy.c'
yacc parser.y -d // creates 'y.tab.c' & 'y.tab.h'
cc lex.yy.c y.tab.c -o compiler -ll // compiles the scanner and parser into `compiler`

Now you have your own CSimple Compiler!

Running the Tests:

There are two ways to test the compiler;

  1. Write C-Simple code input inside your terminal:
./compiler // execute the compiler runnable file, it now waits for input
  1. Test the compiler using a test file with C-Simple code:
./compiler < test_file.c // run the compiler with the 'test_file.c' content

The input (whether it’s raw input or a test file) must be at least one procedure, which contains the rest of the code, for more info see this part of the CSimple Manual which explains the structure of the CSimple Language.

For this reason, (code must contain at least one procedure and the last statement in the procedure must be a return statement) the minimum structure of an input code, even if the test subject does not concern procedures, will be as follows:

procedure foo() return integer
{
  * Input code *

  return 0;
}

Built With

Contributing

Work in progress...

Versioning

Work in progress...

Authors

License

Work in progress...

Acknowledgments

About

A Simple Compiler for a Simple Programming Language :wink:


Languages

Language:Yacc 77.1%Language:Lex 22.9%