Internals › Architecturev0.1 · Reference
Internals

Compiler Architecture

A reference overview of the Pseudo compilation pipeline. Useful for contributors and those building extensions.

This is a reference section. You do not need to understand the internals to use Pseudo.

Pipeline Overview

pipeline
Source (.pseudo)
1. Indentation Parser      → parse_indentation() / build_block_tree()
      │                       Handles tab/space, inline colon blocks
2. Pass 1 - Registration   → run_registration_pass()
      │                       Scans for function/variable definitions
      │                       Builds symbol table before execution
3. PMAP Loader             → PmapLoader.load()
      │                       Parses .pmap, builds prefix trie
      │                       Handles @inherit, @replace, @context
      │                       Cache: SHA256 hash invalidation
4. Pass 2 - Resolver       → MappingResolver.resolve_blocks()
      │                       Matches each line against trie patterns
      │                       Parses expressions via recursive descent
      │                       Builds canonical AST (ProgramNode)
5. Semantic Analyzer       → SemanticAnalyzer.analyze()
      │                       Validates undefined vars/functions
      │                       Checks argument counts
      │                       Generates warnings
6. Interpreter             → Interpreter.run()
      │                       Tree-walking execution
      │                       Scope management (Scope chain)
      │                       Built-in resolution
      │                       Auto-print, step mode, timeout
7. (optional) Complexity   → ComplexityEngine.analyze()
                              Static Big-O analysis
                              Walks AST for loop nesting, recursion

File Map

FilePurpose~Lines
pseudo/__init__.pyPackage entry, version export4
pseudo/parser/tokenizer.pyLexer - character → tokens266
pseudo/parser/normalizer.pyWhitespace normalization56
pseudo/parser/indent_parser.pyIndentation + block tree300
pseudo/parser/ast_nodes.pyAll AST dataclass definitions293
pseudo/parser/expr_parser.pyRecursive descent expression parser577
pseudo/data/default.pmapBundled default English mappings163
pseudo/resolver/pmap_loader.py.pmap parser + prefix trie + cache706
pseudo/resolver/pass1_register.pyFunction/variable registration199
pseudo/resolver/pass2_resolver.pyPattern matching → AST988
pseudo/analyzer/semantic.pyStatic validation + warnings320
pseudo/interpreter/interpreter.pyTree-walking executor1018
pseudo/interpreter/builtins_ds.pyDS classes (Stack, Queue, etc.)421
pseudo/analyzer/complexity.pyBig-O static analysis611
pseudo/compiler.pyPipeline glue + CLI integration256
pseudo/cli.pyargparse CLI entry point293
pseudo/install.py~/.pseudo/ home setup88

Two-Pass Parsing

Pseudo uses two passes to support mutual recursion and forward references:

PassWhat it does
Pass 1 - RegistrationScans the entire file. Registers all function names and global variables into the symbol table. No execution occurs. No .pmap matching occurs.
Pass 2 - ResolverWith the full symbol table available, resolves every line via .pmap pattern matching and builds the canonical AST.

Prefix Trie (Pattern Matching)

All patterns are compiled into a prefix trie keyed by the first literal token. For a line starting with for, only patterns that start with for are tested - O(1) lookup, then O(small subset) pattern check.

Scope Chain

The interpreter maintains a chain of Scope objects:

  • Global scope: top-level variables and functions
  • Local scope: created per function call, parent is always global
  • Reads walk up the chain; writes stay local unless global declared
  • Recursion limit: 1000 call stack depth

Auto-print Signal

Bare expressions and function calls that are not assigned become AutoPrintNode in the AST. The interpreter evaluates them and prints the result if it is non-null (and --no-auto-print is not set).