Skip to content

MoriSummerz/CompilerConstruction-LanguageO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language O Compiler

A complete compiler for Language O - an object-oriented programming language that compiles to WebAssembly. Features a full compilation pipeline with interactive web playground.

🚀 Quick Start

Interactive Playground (Recommended)

cd LanguageOPlayground
dotnet run
# Open http://localhost:5000/compiler

Command Line

cd LanguageO
dotnet run -- --wasm examples/inheritance_demo.o
wat2wasm examples/inheritance_demo.wat -o examples/inheritance_demo.wasm
node examples/run_oop.js examples/inheritance_demo.wasm

✨ Features

Compiler Stages

  1. Lexical Analysis - Tokenizes source code
  2. Syntax Analysis - Builds Abstract Syntax Tree
  3. Semantic Analysis - Type checking & optimizations
  4. Code Generation - WebAssembly

Language Features

  • OOP: Classes, inheritance, methods, constructors
  • Runtime Execution: Full program execution with Main class entry point
  • Strings: String literals and operations
  • Arrays: Array creation, indexing, length
  • Control Flow: If/else, while loops, return statements
  • Print Operations: toConsole() for output
  • Semantic Checks: 4+ validation checks
  • Optimizations: Constant folding, dead code elimination, unused variable removal

📁 Project Structure

LanguageO/
├── LanguageO.Core/          # Core compiler library
│   ├── Lexer.cs            # Tokenization
│   ├── Parser.cs           # AST construction
│   ├── AST.cs              # Syntax tree nodes
│   ├── SemanticAnalyzer.cs # Checks & optimizations
│   └── WasmCodeGenerator.cs # WASM code generation
├── LanguageO/               # CLI compiler
└── LanguageOPlayground/    # Blazor web app
    └── Pages/Compiler.razor # Interactive playground

🎮 Examples

Inheritance Demo

class Animal is
    var age : Integer(0)
    method getAge : Integer is
        return age
    end
end

class Dog extends Animal is
    method bark is
        var sound : "Woof!"
        sound.toConsole()
    end
end

class Main is
    this() is
        var myDog : Dog()
        myDog.getAge().toConsole()
        myDog.bark()
    end
end

Arrays & Strings

class Main is
    this() is
        var arr : Array[Integer](5)
        arr.set(Integer(0), Integer(10))
        arr.get(Integer(0)).toConsole()
        
        var msg : "Hello, World!"
        msg.toConsole()
    end
end

🎯 Available Examples

The playground includes:

  • Hello World - Basic program
  • Strings Demo - String operations
  • Arrays Demo - Array manipulation
  • OOP Demo - Classes and methods
  • Inheritance Demo - Class hierarchy
  • Math Showcase - Primes, Fibonacci, factorials

🔧 Build & Run

# Build all projects
dotnet build

# Run CLI compiler
cd LanguageO
dotnet run -- --wasm examples/inheritance_demo.o

# Run playground
cd LanguageOPlayground
dotnet run

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published