A complete compiler for Language O - an object-oriented programming language that compiles to WebAssembly. Features a full compilation pipeline with interactive web playground.
cd LanguageOPlayground
dotnet run
# Open http://localhost:5000/compilercd 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- Lexical Analysis - Tokenizes source code
- Syntax Analysis - Builds Abstract Syntax Tree
- Semantic Analysis - Type checking & optimizations
- Code Generation - WebAssembly
- ✅ OOP: Classes, inheritance, methods, constructors
- ✅ Runtime Execution: Full program execution with
Mainclass 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
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
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
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
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 all projects
dotnet build
# Run CLI compiler
cd LanguageO
dotnet run -- --wasm examples/inheritance_demo.o
# Run playground
cd LanguageOPlayground
dotnet run