CuriousX is a modern compiler that translates a C++-like language into WebAssembly. Built for educational purposes, it demonstrates fundamental compiler concepts through a practical implementation.
Try the Online Compiler | Learn More
- Data Types
- Integers and Floating-point numbers
- Strings (basic support)
- Booleans
- Operations
- Arithmetic:
+
,-
,*
,/
- Comparison:
==
,!=
,<=
,>=
,>
,<
- Arithmetic:
- Control Flow
- If-else statements
- Basic blocks
- Functions
- Built-in
print()
function - Variable declarations and assignments
- Built-in
- Lexical Analysis
- Token generation
- Source location tracking
- Comment handling
- Syntax Analysis
- AST generation
- Operator precedence
- Error recovery
- Semantic Analysis
- Type checking
- Scope analysis
- Symbol table management
- Code Generation
- WebAssembly text format output
- Optimization passes
- Runtime support
- C++17 compatible compiler
- CMake 3.25 or higher
- Emscripten (for WebAssembly compilation)
- Git for version control
# Clone the repository
git clone https://github.com/jnyfah/CuriousX.git
cd CuriousX
# Create build directory and build
mkdir build
cmake -B build -S .
cmake --build build
# Configure with Emscripten
emcmake cmake -B build -S .
# Build
cmake --build build
# Start local server
emrun CompilerEditor/index.html
x = 42
y = x + 8
if (y > 0) {
print("Positive")
} else {
print("Non-positive")
}
Newline line:1, col:26 [\n]
VarToken line:2, col:1 [x]
AssignToken line:2, col:3 [=]
IntToken line:2, col:5 [42]
=
/ \
x 42
i32.const 42
local.set 0 ;; x = 42
local.get 0
call $print ;; print(x)
CuriousX/
├── CompilerUtils/ # Utility classes and helpers
├── CuriousX/ # Core compiler implementation
│ ├── Lexer/ # Lexical analysis
│ ├── Parser/ # Syntax analysis
│ ├── Semantic/ # Semantic analysis
│ └── Generation/ # Code generation
├── tests/ # Unit and integration tests
└── CompilerEditor/ # Web interface
The project includes comprehensive tests for each compiler component:
# Build with tests enabled
cmake -B build -DBUILD_TESTS=ON
cmake --build build
# Run tests
cd build && ctest -C Debug -V