A Visual Basic core compiler implemented in Python.
The current version focuses on a compact and converged subset of VB, with the goal of reliably completing the full pipeline:
.vb source -> tokens -> AST -> semantic -> IR -> Portable C -> executable(optional)
Module ... End ModuleSub ... End SubFunction ... End FunctionDim name As Type = ...Dim name(upperBound) As Type- Types:
Integer,Double,String,Boolean - Expressions:
+ - * / Mod - Comparisons:
= <> < <= > >= - Logic:
And Or Not If ... Then ... ElseIf ... Else ... End IfSelect Case ... Case ... Case Else ... End SelectWhile ... End WhileFor ... To ... [Step ...] ... NextReturn- Function calls
- One-dimensional array reads and writes:
nums(i),nums(i) = value - Built-in
Print(...)
Class,Property,Structure- Multidimensional arrays
- Arrays as function parameters
- Object system
Do ... Loop- Complete standard library and runtime
- Multi-file compilation
This is a VB compiler, but the first-generation backend does not directly generate native macOS executables. Instead, it first emits Portable C and then lets the system clang/cc toolchain compile it.
This is not because macOS cannot run VB. It is because directly emitting native macOS object code would require the project to handle:
arm64or other architecture-specific assembly generation- the
Mach-Oobject format - calling conventions and stack frame details
- platform-specific runtime details
By contrast, the C toolchain on macOS is already mature. The current path is therefore:
VB source -> tokens -> AST -> semantic -> IR -> Portable C -> clang/cc -> executable
This keeps the current implementation focused on:
- VB lexical analysis
- VB parsing
- VB semantic checking
- IR design and lowering
- correctness of the end-to-end compilation pipeline
If the project is extended later, a real native backend can be added while keeping the frontend unchanged.
Inspect tokens:
python -m visual_basic_core_compiler examples/hello.vb --emit-tokensInspect the AST:
python -m visual_basic_core_compiler examples/hello.vb --emit-astInspect IR:
python -m visual_basic_core_compiler examples/hello.vb --emit-irInspect generated C:
python -m visual_basic_core_compiler examples/hello.vb --emit-cGenerate an executable:
python -m visual_basic_core_compiler examples/hello.vb -o build/helloCompile and run directly:
python -m visual_basic_core_compiler examples/hello.vb --runRun all examples in batch and save the results:
sh scripts/run_examples.shsrc/visual_basic_core_compiler/
tests/
examples/
scripts/
build/results_stdout/
build/results_return/
PRD.md
TASKS.md
ARCHITECTURE.md
PYTHONPATH=src python -m unittest discover -s tests -p "test_*.py"The repository also includes archived results for the full example suite:
build/results_stdout/: storesgenerated.c,stdout.txt,stderr.txt, andexit.txtfor each examplebuild/results_return/: stores the same result set for unified comparison and archival
The current examples cover:
- basic arithmetic and function calls
- conditional branches,
ElseIf, andSelect Case While,For, andFor Step- recursion and number-theory programs
- one-dimensional array scanning and array-style exercises
Current test status:
74unittestcases pass- all examples under
examples/have been compiled, run, and archived