A strong-typed, low-level programming language with light syntax designed for performance and expressiveness. Features enhanced ternary operators, symbol-based loops, and a robust semantic type checker for compile-time safety.
- π― Strong Type System: Compile-time type checking for
int,float,string,bool - π₯ Light Syntax: Minimal keywords, enhanced ternary replaces if/else
- π Symbol-Based Loops:
@ x > 0 { x--; }replaceswhile - β‘ Low-Level Control: Direct data manipulation without abstraction overhead
- ποΈ Enhanced Ternary:
condition ? actionandcondition ? action : else - π§ Full Expressions: Arithmetic, logical, comparison with proper precedence
- π¦ Block Statements: Lightweight scoped code blocks
- π§ͺ Professional Testing: 47+ Unity tests with full CI/CD integration
- π Semantic Analysis: Symbol table & type checker ensure correctness and prevent runtime surprises
After parsing, the compiler performs semantic validation through a type checker (src/semantic/typeChecker.c + src/semantic/symbolTable.c).
-
Symbol Table Management: Tracks variable declarations, types, scope depth, and initialization status.
-
Scope Handling: Global scope plus nested block scopes with shadowing support.
-
Declaration Validation: Prevents redeclaration in the same scope, enforces correct initializer types.
-
Assignment Validation: Ensures left-hand side is a variable, type-compatible, and initialized.
-
Expression Validation:
- Numeric-only arithmetic operators.
- Boolean-only logical operators.
- Type promotion (
int β float).
-
Error Handling: Detailed error codes for type mismatches, uninitialized variables, and invalid expressions.
int x; // Declared but not initialized
x = 5; // β
valid
float y = x; // β
int β float allowed
bool b = x; // β type error: cannot assign int to bool// Traditional if/else: // Enhanced ternary:
if (condition) { condition ? {
action1(); action1();
action2(); action2();
} };
if (x > 0) { x > 0 ? {
result = x; result = x;
} else { } : {
result = 0; result = 0;
} };// Traditional while: // Enhanced while:
while (condition) { @ condition {
statements; statements;
} }
// Traditional for: // Enhanced for pattern:
for (int i = 0; i < 10; i++) { int i = 0; @ i < 10; {
process(i); process(i);
} i++;
}
// Inline example:
@ x > 0 { x--; print(x); } // While x > 0, decrement and printint count = 42; // Strong typing required
float rate = 3.14159; // Precise numeric types
string name = "Compiler"; // String literals
bool active = true; // Boolean values// Arithmetic with precedence
int result = 2 + 3 * 4; // Result: 14 (multiply first)
float calc = value / 2.0; // Type-aware operations
// Increment/Decrement
int pre = ++counter; // Pre-increment
int post = value--; // Post-decrement
// Compound assignments
total += x * 2; // Equivalent to: total = total + (x * 2)
balance *= 1.05; // Compound operations
// Logical and comparison
bool valid = x > 0 && y <= 100; // Logical operators
bool equal = a == b; // Comparison operators
bool check = !condition; // Logical NOT// If-only statements
authenticated ? access_granted();
valid_input ? process_data();
// Ternary assignment
int max = a > b ? a : b;
string status = online ? "Connected" : "Offline";
// Block conditionals
score >= 90 ? {
grade = "A";
bonus_points += 10;
} : {
grade = "B";
bonus_points += 5;
};
// Compound operations in conditionals
balance > 0 ? account += interest : account -= fee;// Basic while loops
@ x > 0 {
x--;
process(x);
}
@ !empty(queue) {
item = dequeue();
handle(item);
}
// For-like patterns (declaration + while)
int i = 0; @ i < 10; {
print(i);
i++;
}
float x = 1.0; @ x < 100.0; {
result += x;
x *= 2; // Geometric progression
}
// Complex conditions
@ balance > 0 && attempts < 5; {
transaction = process_payment();
balance -= transaction.amount;
attempts++;
}
// Nested loops
int row = 0; @ row < height; {
int col = 0; @ col < width; {
matrix[row][col] = calculate(row, col);
col++;
}
row++;
}{
int local_var = 10; // Block-scoped variables
float temp = local_var * 2.5;
result = temp;
}
// local_var and temp out of scope here// Combining loops and conditionals
int count = 0; @ count < 1000; {
count % 100 == 0 ? {
print("Milestone: " + count);
count > 500 ? break; // Future: break statement
};
count++;
}
// Loop with conditional processing
bool found = false;
int i = 0; @ i < array_size && !found; {
array[i] == target ? {
found = true;
index = i;
};
i++;
}- GCC or Clang compiler
- CMake (3.10+)
- Git
# Clone and setup
git clone https://github.com/Blopaa/Compiler.git
cd Compiler
git checkout dev
# Add Unity testing framework
git submodule add https://github.com/ThrowTheSwitch/Unity.git test/unity
git submodule update --init --recursive
# Build
mkdir build && cd build
cmake ..
make
# Run compiler demo
./compiler
# Run test suite
./test_runnerβββββββββββββββ ββββββββββββββββ βββββββββββββββ βββββββββββββββββββββ
β Source βββββΆβ Lexer βββββΆβ Parser βββββΆβ Semantic Analyzer β
β"@ x>0{x--;}"β β (Tokenizer) β β (AST Gen) β β (Type Checker) β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ βββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββ βββββββββββββββ ββββββββββββββββ
β Tokens β β AST Tree β β Checked AST β
β [@,x,>,0,{, β βββββββββββββββ ββββββββββββββββ
β x,--,;,}] β
ββββββββββββββββ
Compiler/
βββ src/
β βββ main.c # Entry point and demo
β βββ lexer/ # Tokenization
β βββ parser/ # AST generation
β βββ semantic/ # Symbol table + type checker
β βββ errorHandling/ # Error reporting
βββ test/ # Unity tests
βββ build/ # Build directory
βββ CMakeLists.txt # Build configuration
βββ README.md
Professional Unity testing framework with comprehensive coverage:
# Run all tests
./test_runner
# Expected output: XX Tests 0 Failures 0 Ignored - OK
# Memory leak detection (Linux/macOS)
valgrind --leak-check=full ./test_runnerTest Categories:
- β Type declarations and assignments
- β Arithmetic operations with precedence
- β Enhanced ternary conditionals
- β Block statements and scoping
- β Symbol-based while loops
- β Logical and comparison operators
- β Increment/decrement operations
- β Compound assignments
- β Error handling and edge cases
- β Complex mixed expressions
Program β Statement*
Statement β VarDecl | Block | WhileLoop | ExprStatement
VarDecl β Type IDENTIFIER ('=' Expression)? ';'
Block β '{' Statement* '}'
WhileLoop β '@' Expression Block
Expression β EnhancedTernary
EnhancedTernary β LogicalOr ('?' (Expression | Block) (':' (Expression | Block))?)?
LogicalOr β LogicalAnd ('||' LogicalAnd)*
LogicalAnd β Equality ('&&' Equality)*
Equality β Comparison (('=='|'!=') Comparison)*
Comparison β Term (('<'|'>'|'<='|'>=') Term)*
Term β Factor (('+'|'-') Factor)*
Factor β Unary (('*'|'/'|'%') Unary)*
Unary β ('!'|'++'|'--'|'-') Unary | Primary ('++'|'--')?
Primary β NUMBER | STRING | BOOLEAN | IDENTIFIER | '(' Expression ')'
| Pattern | Traditional | Enhanced | Example |
|---|---|---|---|
| If-only | if (cond) stmt |
cond ? stmt |
valid ? process(); |
| If-else | if (cond) s1 else s2 |
cond ? s1 : s2 |
x > 0 ? pos() : neg(); |
| While | while (cond) body |
@ cond body |
@ i < 10 { print(i); } |
| For-like | for(init;cond;inc) body |
init; @ cond; body |
int i=0; @ i<10; {code; i++;} |
- Postfix/Prefix:
++,--,!, unary- - Multiplicative:
*,/,% - Additive:
+,- - Comparison:
<,>,<=,>= - Equality:
==,!= - Logical AND:
&& - Logical OR:
|| - Enhanced Ternary:
?: - Assignment:
=,+=,-=,*=,/=
We welcome contributions! To get started:
- Fork the repository and clone with
--recursive - Create a feature branch (
git checkout -b feature/new-feature) - Add Unity tests for your changes in
test/test_main.c - Ensure all tests pass (
./test_runner) - Follow existing code style and documentation standards
- Submit a Pull Request
void test_your_feature(void) {
Input res = splitter("your test code;");
Token tokens = tokenization(res);
ASTNode ast = ASTGenerator(tokens);
TEST_ASSERT_NOT_NULL(ast);
TEST_ASSERT_FALSE(hasErrors());
freeTokenList(tokens);
freeAST(ast);
}
// Add to main(): RUN_TEST(test_your_feature);See CONTRIBUTING.md for detailed guidelines.
This project is licensed under the MIT License - see the LICENSE.md file for details.
β If you find this project interesting, please give it a star! β
Report Bug β’ Request Feature β’ Documentation
Strong-typed, low-level programming language with light syntax