A space-themed programming language with a custom compiler built using Flex, Bison, and C++. Includes a web-based playground powered by Next.js.
astroscript/
├── backend/
│ └── compiler/
│ ├── lexer/ # Flex lexer definition
│ ├── parser/ # Bison parser grammar
│ ├── semantic/ # Symbol table (semantic analysis)
│ ├── ir/ # Three-address code generator
│ ├── include/ # Shared headers
│ ├── main.cpp # Compiler entry point
│ ├── build/ # Generated files & binary
│ └── Legacy/ # Previous compiler iterations
├── web/ # Next.js website & playground
├── docs/ # Language documentation
├── examples/ # Example AstroScript programs
└── scripts/ # Build & utility scripts
Requires: flex, bison, g++ (with C++17 support)
Structured build with Make (recommended):
make linux
make windows
# or build both
make allmacOS/Linux:
./scripts/build_compiler.shWindows (PowerShell):
.\scripts\build_compiler.ps1Equivalent mapping between script and Make targets:
./scripts/build_compiler.sh↔make linux.\scripts\build_compiler.ps1↔make windows
Build script outputs:
- Windows binary is copied to
web/src/server/compiler/astroscript-windows.exe - Linux binary is copied to
web/src/server/compiler/astroscript-linux
./backend/compiler/build/astroscript examples/comprehensive.asWindows:
.\backend\compiler\build\astroscript.exe .\examples\comprehensive.asRun focused module examples (nested loops, nested conditionals, nested function calls, and more):
./backend/compiler/build/astroscript examples/modules/14-nested-loops-grid.as
./backend/compiler/build/astroscript examples/modules/15-nested-if-else.as
./backend/compiler/build/astroscript examples/modules/16-nested-function-calls.asThe frontend playground example list is generated from examples/modules/index.json and examples/modules/*.as.
Any module example you add there is picked up automatically by npm run dev and npm run build in web/.
Requires: Node.js 20.11+
cd web
npm install
npm run devThe web app now regenerates docs keyword/syntax reference data from compiler sources on dev and build automatically.
Compiler health can be checked via:
GET /api/healthThen open http://localhost:3000 to access the homepage and playground.
Use ASTROSCRIPT_COMPILER_TARGET to switch binaries without code changes.
PowerShell:
$env:ASTROSCRIPT_COMPILER_TARGET = "windows"
# or
$env:ASTROSCRIPT_COMPILER_TARGET = "linux"bash:
export ASTROSCRIPT_COMPILER_TARGET=windows
# or
export ASTROSCRIPT_COMPILER_TARGET=linuxIf unset, the resolver defaults to auto and picks based on OS.
- The web app is deployment-ready with Next.js standalone output and route runtime settings.
- API routes
/api/compileand/api/healthrequire the AstroScript compiler binary to exist at runtime. - Provide
ASTROSCRIPT_COMPILER_PATHif your binary is stored outside the default paths. - If the binary is unavailable in the deployment environment, docs/UI still work and health endpoint reports compiler offline.
mission HelloWorld launch {
transmit "Hello, Universe!".
} success
- Space-themed keywords:
mission,telemetry,transmit,verify,orbit,command - Types:
count(int),real(float),precise(double),flag(bool),symbol(string) - Control flow:
verify/else_verify/otherwise,scenario/trajectory/fallback - Loops:
orbit(while),orbit times(for) - Functions:
commanddefinitions withbackreturns - Compiler phases: Lexing → Parsing → Semantic Analysis → TAC Generation → Optimization → Execution
- Learning bridge: Optimized TAC plus readable C-like translation output for playground comparison
See the docs/ directory or run the website and navigate to /docs.
Rubric tracking is maintained in docs/rubric-compliance.md.
Line-by-line compiler tracing for conditionals, loops, functions, and classes/modules is available in docs/compiler-feature-execution-map.md.
See LICENSE.