Compiler / Interpreter
Introduction
A compiler is a program that can read a program in one language - the source language - and translate it into an equivalent program in another language - the target language;
An interpreter is another common kind of language processor. Instead of producing a target program as a translation, an interpreter appears to directly execute the operations specified in the source program on inputs supplied by the user
There is two parts during the compilation: analysis and synthesis:
- The analysis part reads the stream of characters making up the source program and groups the characters into meaningful sequences (Lexical Analysis), then it imposes a grammatical structure on them (Semantic Analysis). It then uses this structure to create an intermediate representation of the source program. After syntax and semantic analysis of the source program, many compilers generate an explicit low-level or machine-like intermediate representation, which we can think of as a program for an abstract machine.
- The synthesis part constructs the desired target program from the intermediate representation.
Implemented Features
In this project, we've implemented the first part of the compilation, which is the Analysis phase until an intermediate representation of the source program is generated. The intermediate code is generated in the C language and maps the structure of an assembly source code (usage of registers and conditional or non conditional jumps, non-use of conditional structure (if else) or loop (for, while) ).
The program can also be used as an interpreter. It executes the commands giver by the user without producing an intermediate code.
Languages used
- C
- Lex
- YACC