Skip to content

dnovick-byte/ASA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asa Programming Language

A custom programming language interpreter built in Rust, featuring conditional operators, if-expressions, and a test suite.

Overview

Asa is an interpreted programming language that supports:

  • Variable declarations and assignments
  • Conditional operators for comparisons
  • If-else expressions with optional else-if branches

Features

Conditional Operators

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

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;
};

Type Safety

Asa enforces type consistency:

  • Cannot compare numbers with booleans
  • Both branches of if-expressions must return compatible types

Project Structure

├── 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

Building from Source

Prerequisites

  • Rust 1.70 or higher
  • Cargo

Build

cargo build --release

Run Tests

cargo test

Testing

The 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

Examples

Basic Program

let x = 10;
let y = 5;

if x > y {
    return true;
} else {
    return false;
}

Operator Precedence

let x = 10;
let y = 5;
let result = x > y == true;  // (x > y) == true

Nested Conditions

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";
};

Language Semantics

Evaluation Order

  1. Conditions are evaluated first
  2. Only the selected branch is executed (short-circuit evaluation)
  3. The false branch is never evaluated if the condition is true

Return Values

  • If-expressions must return a value from both branches
  • The return value can be assigned to variables
  • Both branches must have compatible return types

Error Handling

Asa provides informative error messages for:

  • Type mismatches
  • Invalid comparisons
  • Missing return statements
  • Syntax errors
  • Runtime errors

Future Work

  1. 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.
  2. 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).

About

ASA is a custom programming language built in Rust. It lexes, parses, and interprets ASA source files, falling back to a REPL if no main() exists. This project adds a new language feature by updating the grammar, lexer, parser, interpreter, and tests, with CI for automated checks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages