Skip to content

mdc1205/bccl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BCC - Basic C-like Compiler

A simple tree-walk interpreter written in Rust for a Python-like language. This interpreter demonstrates the fundamental concepts of language implementation including lexical analysis, parsing, and evaluation.

Features

  • Lexical Analysis: Tokenizes source code into meaningful symbols
  • Recursive Descent Parser: Parses tokens into an Abstract Syntax Tree (AST)
  • Tree-Walk Evaluator: Executes the AST by traversing it
  • Error Handling: Comprehensive error reporting with source location information using Ariadne
  • REPL Mode: Interactive Read-Eval-Print Loop for experimentation
  • File Execution: Run programs from source files

Supported Language Features

Data Types

  • Integers: 42, -10
  • Floating Point: 3.14, -2.5
  • Strings: "hello world"
  • Booleans: true, false

Operations

  • Arithmetic: +, -, *, /
  • Assignment: x = 5
  • Parentheses: (2 + 3) * 4

Examples

# Basic arithmetic
5 + 3 * 2

# Variable assignment
x = 10
y = 5
result = x + y

# Mixed type operations
pi = 3.14
radius = 5
area = pi * radius * radius

# String operations
greeting = "Hello"
name = "World"
message = greeting + " " + name

Usage

REPL Mode

cargo run

File Execution

cargo run example.bcc

Architecture

The interpreter follows a traditional three-stage design:

  1. Lexer (src/lexer.rs): Converts source code into tokens
  2. Parser (src/parser.rs): Builds an AST from tokens
  3. Evaluator (src/evaluator.rs): Executes the AST

See the individual documentation files in /docs for detailed explanations of each component.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages