This is a compiler implementation that includes lexical, syntactic,semantic analysis, and machine code for a custom programming language named MinING. The compiler is written in Rust and uses LOGOS as a lexer generator and LALRPOP for parsing.
- Lexical analysis with token identification
- Syntax parsing
- Semantic analysis
- Symbol table generation
- Support for various data types:
- INTEGER
- FLOAT
- CHAR
- Arrays of these types
- Program structure with global variables, declarations, and instructions
- Control structures (IF-ELSE, FOR loops)
- Input/Output operations (READ, WRITE)
- Make sure you have Rust installed on your system. If not, install it from rustup.rs
- Clone this repository:
git clone https://github.com/Abdou-bnm/MinIng/ cd MinIng - Build the project:
cargo build
The compiler can be run in two modes:
To compile a program from a file:
cargo run path/to/your/program.txtTo run the built-in example program:
cargo runPrograms should follow this basic structure:
VAR_GLOBAL {
// Global variable declarations
}
DECLARATION {
// Constant declarations
}
INSTRUCTION {
// Program instructions
}
Here's a simple example program:
VAR_GLOBAL {
INTEGER X = 1;
FLOAT Y = 2.0;
CHAR Z[5] = "Hello";
}
DECLARATION {
CONST INTEGER MAX = 100;
}
INSTRUCTION {
READ(X);
IF(X > 0) {
Y = Y + X;
} ELSE {
Y = 0;
}
WRITE("Result: ", Y);
}
- Global variables: Declared in VAR_GLOBAL section
- Constants: Declared in DECLARATION section with CONST keyword
- Supported types: INTEGER, FLOAT, CHAR
- Array declarations supported with size in brackets
- Arithmetic: +, -, *, /
- Comparison: >, <, >=, <=, ==
- Assignment: =, +=
- IF-ELSE statements
- FOR loops with format: FOR(var = start : step : end)
- READ(variable): Read input into a variable
- WRITE(expression): Output an expression
- Support for string literals in WRITE statements
Use %% for single-line comments:
%% This is a comment
The compiler provides detailed feedback at each stage:
-
Lexical Analysis
- Shows all tokens found
- Reports any lexical errors
-
Syntactic Analysis
- Confirms successful parsing
- Reports syntax errors
-
Semantic Analysis
- Displays the Abstract Syntax Tree (AST)
- Shows program structure
- Reports semantic errors
-
Symbol Table
- Displays all symbols and their properties
The compiler provides clear error messages for:
- File reading errors
- Lexical errors (invalid tokens)
- Syntax errors (invalid program structure)
- Semantic errors (type mismatches, undefined variables, etc.)
This compiler is built using several Rust crates:
- LALRPOP for parser generation
- Logos for lexical analysis
- Colored for terminal output formatting
- KARA Nabil
- MEDJBER Abderrahim
- BENAMIROUCHE Abderaouf
- HIRECHE Hichem
- CHABATI Rayan
- NAILI Walid
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License - see the LICENSE file for details