A custom programming language interpreter built in Rust, featuring conditional operators, if-expressions, and a test suite.
Asa is an interpreted programming language that supports:
- Variable declarations and assignments
- Conditional operators for comparisons
- If-else expressions with optional else-if branches
Asa supports six comparison operators:
>- Greater than<- Less than>=- Greater than or equal to<=- Less than or equal to==- Equal to!=- Not equal to
Examples:
let x = 10;
let y = 5;
let result = x > y; // evaluates to true
If-expressions allow conditional execution with full support for else-if chains.
Syntax:
if condition {
// statements
} else if another_condition {
// statements
} else {
// statements
}
Examples:
// Simple if-else
if x > y {
return true;
} else {
return false;
}
// Else-if chain
if x > y {
return 1;
} else if x == y {
return 2;
} else {
return 3;
}
// Assignment from if-expression
let result = if true {
return 10;
} else {
return 20;
};
Asa enforces type consistency:
- Cannot compare numbers with booleans
- Both branches of if-expressions must return compatible types
├── src/
│ ├── lexer.rs # Tokenization of source code
│ ├── parser.rs # Parser combinators and AST generation
│ ├── interpreter.rs # Expression evaluation and execution
│ └── main.rs # CLI and REPL implementation
├── tests/ # Test suite (20+ tests)
└── Cargo.toml # Rust dependencies
- Rust 1.70 or higher
- Cargo
cargo build --releasecargo testThe project includes comprehensive test coverage with:
- 20+ unit tests covering all features
- Conditional operator tests
- If-expression tests
- Type safety validation tests
- CI/CD pipeline that runs tests on push
let x = 10;
let y = 5;
if x > y {
return true;
} else {
return false;
}
let x = 10;
let y = 5;
let result = x > y == true; // (x > y) == true
let score = 85;
let grade = if score >= 90 {
return "A";
} else if score >= 80 {
return "B";
} else if score >= 70 {
return "C";
} else {
return "F";
};
- Conditions are evaluated first
- Only the selected branch is executed (short-circuit evaluation)
- The false branch is never evaluated if the condition is true
- If-expressions must return a value from both branches
- The return value can be assigned to variables
- Both branches must have compatible return types
Asa provides informative error messages for:
- Type mismatches
- Invalid comparisons
- Missing return statements
- Syntax errors
- Runtime errors
-
Full Math Expressions
- Add full PEMDAS support, including exponentiation (^).
- Ensure correct precedence: (), ^, * /, + -, comparisons, logical ops.
- Improve type checking and error messages for invalid mixed expressions.
- Expand grammar slightly to support nested and complex expressions.
-
asac Executable
- Allow running a file:
asac program.asa - Auto-run main() if present; otherwise start a REPL.
- Provide clearer syntax and runtime error messages.
- Package the interpreter as a standalone binary (Cargo release build).
- Allow running a file: