Compiler construction: Mini Compiler
- Indentifier Rules
- User defined as in C (Max length 6 character, not case sensitive)
- Data Types:
Data types supported are:
- Integer
- String and
- Character
- Expressions
- Arithmetic operators (+, -, *, /, %)
- Uniray operator
- Paranthesis
- Only Integer supported
- Relational expression to be supported
(>, <, >=, <=, ==, !=)
f. Constants same as in c (character string and integer) constants
e.g. 4int const
‘4’char const
“4”string const
- Statements
- Deleration statement
- …….
- Decleration nd initialization
- Assingment Statement
= …
- Conditional statement (Nesting not allowed)
- Simple if (nesting not allowed)
if then
Endif
- Switch Statement (nesting not allowed)
Switch()
Cases
Value 1:
Break;
.
.
.
Value n:
Endcase
- Repetition Statement (nesting not allowed)
- Repeat
Until ()
- While (relational expression)
Endwhile
- For
= start value, end value, inc/dec
………
Endfor
- I/O Statement
- Input
; - Output
;
- Program Structure
Decleration:
Start
End
- 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:
- Start main.exe file.
- Enter file name that you want to compile i.e(textfile.txt)
- 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.
- 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.
Screen Shoots:
MAIN SCREEN:
INPUT FILE:
TARGET OUTPUT CODE:
No comments:
Post a Comment