A compiler for the MiniSoft language developed with Flex and Bison. This project was created as part of the Compilation course at the University of Science and Technology Houari Boumediene (USTHB).
The MiniSoft compiler implements a complete compilation process for a simple educational programming language. It features:
- Lexical analysis using Flex
- Syntactic analysis using Bison
- Semantic analysis with comprehensive error checking
- Symbol table management
- Detailed error reporting with line and column information
The compiler can detect various errors including:
- Undeclared identifiers
- Duplicate declarations
- Type incompatibilities
- Division by zero (for constant expressions)
- Array index out of bounds
- Attempt to modify constants
- Invalid loop control variables
MiniSoft is a simple programming language with the following features:
- Integer and floating-point data types
- Variable and constant declarations
- Array support
- Arithmetic and logical operations
- Control structures (if-else, while loops, for loops)
- Input/output operations
- Single-line and multi-line comments
MainPrgm L3_software;
Var
<!- Variable declarations ->
let x, y, z: Int;
let a, b: Float;
let arr: [Int; 10];
@define Const PI: Float = 3.14;
@define Const MAX: Int = 100;
BeginPg
{
{-- Main program body --}
x := 10;
y := 20;
z := x + y;
a := 1.5;
b := a * PI;
arr[0] := 5;
if (z > MAX) then {
output("z exceeds maximum");
} else {
output("z is within limits: ", z);
}
for i from 0 to 9 step 1 {
arr[i] := i * 2;
}
do {
x := x - 1;
} while (x > 0);
input(y);
output("You entered: ", y);
}
EndPg;
To build and run the MiniSoft compiler, you need:
- GCC compiler
- Flex lexical analyzer
- Bison parser generator
- Make build system
On Ubuntu/Debian, you can install these with:
sudo apt-get install build-essential flex bison
-
Clone this repository:
git clone https://github.com/your-username/minisoft-compiler.git cd minisoft-compiler
-
Build the compiler:
make
-
Clean build files (optional):
make clean
To compile a MiniSoft program:
./compiler test.txt
This will analyze the input file and report any errors found during the compilation process. If compilation is successful, it will output "Program successfully parsed" and display the symbol table.
lexer.l
: Flex specification for lexical analysisparser.y
: Bison specification for syntactic and semantic analysissymtab.h/c
: Symbol table implementationMakefile
: Build configurationtest.txt
: Example MiniSoft program
The compiler is implemented in three main phases:
- Lexical Analysis: Identifies tokens, validates identifiers and numeric constants
- Syntactic Analysis: Validates program structure and builds an abstract syntax tree
- Semantic Analysis: Performs type checking, validates array accesses, handles constant expressions
Special attention was given to:
- Detecting division by zero in expressions like
a := 1 / (7 - 7)
- Preventing modification of constants
- Validating array indices
- Checking loop control variables
- Hermez Abderrahim
- Belkacemi Abderrahim
This project is licensed under the MIT License - see the LICENSE file for details.