Architecture
Documentation for Architecture.
Architecture
Pipeline
source (.ext) β Lexer β tokens β Parser β AST β Compiler β python/bash/binary
β Runtime (exec) / REPL
β .ext module loaderStages
- Lexer (
lexer.py) β tokenization: bracket-aware INDENT/DEDENT (indentation inside()[]{}is ignored, blank lines do not break blocks),0b/0xliterals, strings + f-strings + triple-quoted, the full operator set, inline bash (`...`) and blocks (%% ... %%). - Parser (
parser.py) β recursive descent with operator precedence (matching Python), unary operators, ternary, lambdas, literals (lists/dicts/tuples/sets β including multi-line), indexing and slicing, attribute access, calls with kwargs/*args/**args, comprehensions, tuple unpacking and the full statement grammar: functions, classes with inheritance,if/elif/else,while,for-in,try/except/else/finally,with,import,raise,assert,del,yield,global,nonlocal. - Compiler (
compiler.py) β code generation: topython(withsubprocess.runfor bash),bash(extracted commands) andbinary(bit literals). - Runtime (
runtime/) β in-process execution viaexecof the generated Python; a meta-path finder compiles.extmodules onimport; a REPL with block-completeness detection.
Module system
externum/runtime/__init__.py registers _ExtFinder in sys.meta_path.
import mod finds mod.ext (or pkg.mod.ext) on the search path, compiles
it to Python and loads it as a module β the standard library in lib/ is
written in Externum itself.
Project structure
Externum/
βββ externum/
β βββ lexer.py # Tokenization
β βββ parser.py # Full grammar β AST
β βββ compiler.py # Codegen (python/bash/binary)
β βββ runtime/ # Runtime, .ext import, REPL
β β βββ llm/ # (roadmap)
β β βββ neural/ # (roadmap)
β β βββ distributed/ # (roadmap)
β βββ __main__.py # CLI (run / repl / compile)
βββ lib/ # Standard library (.ext)
β βββ structs.ext # Stack, Queue, Counter
β βββ strings.ext # reverse, slugify, is_palindrome, ...
β βββ mathx.ext # gcd, factorial, fib, ...
β βββ fs.ext # read_file, write_file, ...
βββ examples/ # hello.ext, calc.ext, pokedex.ext
βββ tests/ # 118 unit tests
βββ bin/externum # CLI entry point
βββ setup.py # pip install -e .
βββ WIKI.md # Language specificationAPI contract
externum/__init__.py exposes the core (Lexer, Parser, Compiler,
Runtime) plus reserved future modules: llm (LLMClient,
PromptTemplate, FunctionSchema), neural (Tensor, Module, Linear, Conv2d,
Attention, Autograd), distributed (Actor, Cluster, Stream, Channel),
types (DependentType, RefinementType, EffectType), spec (Spec, Theorem,
Proof, Verify) and debug (TimeTravelDebugger, HotReloader). The imports
are guarded β the package works without these modules.
Roadmap
- Full language: classes, exceptions, modules, lambdas, comprehensions, generators
- REPL, module system, standard library, 118 tests
-
neuralmodule β tensors, autograd, layers (API contract in place) -
llmmodule β model integration (function calling) -
distributedmodule β actors and streams between processes - Full
binarytarget (assembler)