This project is a custom-built compiler simulation implemented using C# Windows Forms. It parses and evaluates a custom-designed scripting language that supports variables, conditional logic, loops, arrays, and I/O operations.
The compiler scans input code, validates it using Regular Expressions (Regex), and simulates the compilation process with basic syntax analysis, semantic checks, symbol table generation, and intermediate interpretation.
- ๐งพ Lexical Analysis using Regex.
- ๐ Syntax Analysis with grammar-based validation.
- ๐ Symbol Table management with scope support.
- ๐ก Conditional Logic:
is
,elis
,el
constructs (similar to if-else). - ๐ Looping using a
loop(...)
construct. - ๐ฆ Array Declaration with basic initialization.
- ๐จ๏ธ Display Statements (string, variable, expressions).
- โจ๏ธ Input Statements.
- โ Arithmetic Expressions: supports
+
,-
,*
,/
operators. - ๐งฎ Expression Evaluation.
- ๐งช Switch-Case-like structure using
option()
,opt
,def
.
Here are some supported code patterns:
num $a = 10, $y;
display < $a;
{
num $x = 7;
display < $x;
$y = 50;
}
display < $y;
num $a = 2;
num $b = 5;
is($a > $b){
display < 'a is greater';
}
elis($a < $b){
display < 'a is less';
}
el{
display < 'a is equal to b';
}
Component | Technology |
---|---|
Language | C# |
UI Framework | Windows Forms |
Logic Handling | Regex, C# Classes |
IDE | Visual Studio |
num $x;
flo $y;
chr $z;
str $name;
$x = 5;
$name = "John";
num $a = 10;
flo $rate = 3.14;
chr $grade = 'A';
num $x = 5, $y, $z;
flo $a, $b;
$a = 5 + 3;
$x = $y * 2 - 1;
display < 'Hello World';
display < $x;
display < 'Value: ' + $x;
in > $name;
is($x > $y){
...
}
elis($x == $y){
...
}
el{
...
}
loop(num $i = 0; $i < 10; $i + 1){
display < $i;
}
num $arr = new num[1, 2, 3, 4];
option($choice){
opt 1:
display < 'One';
opt 2:
display < 'Two';
def:
display < 'Default';
}
CompilerProject/
โโโ MainForm.cs # Main UI logic with Regex-based parsing
โโโ SymbolTable.cs # Class to store variable name, type, and value
โโโ ScopeSymbolTable.cs# For nested block-level scoping
โโโ Program.cs # App entry point
โโโ CC_project1.sln
โโโ README.md
Name | Type | Value | Scope |
---|---|---|---|
$a | num | 10 | global |
$x | num | 7 | local |
-
Modular Regex Rules:
- Different patterns for declaration, initialization, arithmetic, loops, and conditionals.
-
Queue-based Execution:
- Instructions are parsed and added to a queue for simulation.
-
Block Management:
- Scope-sensitive parsing for nested code blocks.
-
Extensible Design:
- Easily add support for new types and language constructs.
- Clone or download the project.
- Open in Visual Studio.
- Restore NuGet packages if required.
- Press
Start
(F5) to run the Windows Form app. - Paste example code in the
txtInput
textbox. - Press the
Compile
orRun
button (ensure you have that button wired to parsing logic).
- โ Add error highlighting and messages.
- โ GUI improvements with syntax highlighting.
- โณ AST (Abstract Syntax Tree) generation.
- โณ Intermediate Code Generation (ICG).
- โณ Basic optimization strategies.
- โณ Function support and recursion.
- โณ Export symbol table to file.
This project was created as part of a Compiler Construction course to simulate the fundamental concepts of:
- Lexical & Syntactic analysis
- Context-free grammar validation
- Symbol tables and scoping
- Expression evaluation and control flow
This project is for educational and academic use only. All rights reserved ยฉ 2025.
For questions or suggestions, feel free to contact the developer:
Name: Shafia Manzoor LinkedIn: linkedin.com/in/yourprofile