Wednesday, October 9, 2013

Mini Compiler for C language [Compiler Construction Project]

Compiler construction: Mini Compiler
Design and implement a compiler for the programming language having the following specifications:
  1. Indentifier Rules
  1. User defined as in C (Max length 6 character, not case sensitive)


  1. Data Types:
Data types supported are:
  1. Integer
  2. String and
  3. Character


  1. Expressions
  1. Arithmetic operators (+, -, *, /, %)
  2. Uniray operator
  3. Paranthesis
  4. Only Integer supported
  5. Relational expression to be supported
(>, <, >=, <=, ==, !=)
   f.    Constants same as in c (character string and integer) constants
e.g.    4int const
‘4’char const
“4”string const
  1. Statements
  1. Deleration statement


…….


  1. Decleration nd initialization


=, ……


  1. Assingment Statement


=


  1. Conditional statement (Nesting not allowed)


  1. Simple if (nesting not allowed)


if then




       Endif


  1. Switch Statement (nesting not allowed)


Switch()
Cases
        Value 1:
Break;
.
.
.
         Value n:
break;
Endcase


  1. Repetition Statement (nesting not allowed)
  1. Repeat




Until ()


  1. While (relational expression)




Endwhile


  1. For = start value, end value, inc/dec
………
Endfor
  1. I/O Statement
  1. Input ;
  2. Output ;




  1. Program Structure


Decleration:




Start




End


  1. Requirements

  • Write RE + CFG for the language
  • Write Lexical Analysizer and RDP for the language
  • Merge the semantic Analyser and the parser
Assembly code generation intel X86 based
__________________________________________________________________

MAIN PROJECT

This project will assemble the c code into assembly. The assembly routines that I have write and attached at the end can be used with MASAM to generate machine code (exe file).

Click Here to fork project on github.
Descriptino project Files: 
 1. ERRORS.h     // Error handling Library
 2. main.cpp        // Main Compiler Code
 3. main.exe        // Executable file of Main Compiler
 4. program.txt     //Sample Code in c that is to be compiled
 5. resource.h      // resources library
 6. textfile.txt         // Sample Code in c that is to be compiled

How to use mini Compiler:
  1.  Start main.exe file.
  2. Enter file name that you want to compile i.e(textfile.txt)
  3. If there are no  errors in your program it will generate target code file i.e (target_textfile.asm) in the same  directory where mini compiler  is copied.
  4. Assemble the code with any assembler to  generate machine code. Note: for input output statement I have  write assembly  routines  for decimal, hexadecimal, octal, binary.
MASAM assembly routines are included in the download package.

Screen Shoots:
MAIN SCREEN:

INPUT FILE:

TARGET OUTPUT CODE:

                  

No comments:

Post a Comment