PMAP System › How PMAP Worksv0.1
The PMAP System

How PMAP Works

The .pmap file is the bridge between any writing style and Pseudo's internal canonical structures.

The .pmap is a data file, not code. It maps text patterns to canonical structure names. The compiler reads it, resolves each line, then processes the canonical AST.

Canonical Internal Structures

These are fixed - they never change. They are the core of Pseudo, built into the compiler:

CanonicalMeaning
FUNC_DEFFunction definition
FOR_LOOPCounted iteration with variable
FOR_EACHElement iteration over collection
WHILE_LOOPCondition-based loop
UNTIL_LOOPInverted while - loop until condition true
IFCondition check
ELSE_IFChained condition
ELSEFallback block
RETURNExit function with value
BREAKExit loop
CONTINUESkip to next iteration
ASSIGNVariable assignment
PRINTOutput to terminal
INPUTGet value from user ($input)
TRY / CATCH / FINALLYError handling blocks
RAISEThrow error
GLOBALDeclare variable as global
SWAPExchange two values

Pattern Matching - No Regex

Pattern matching uses a custom token matcher, not regex. This prevents catastrophic backtracking entirely.

Algorithm

pseudocode
token_match(pattern_tokens, input_tokens):
  while pattern not exhausted and input not exhausted:
    if current pattern token is LITERAL:
      if it matches input token → advance both
      else → NO_MATCH (fail fast)
    if current pattern token is PLACEHOLDER:
      collect tokens until next literal or stop-token
      save to captures

  if all pattern tokens consumed → MATCH(captures)
  else → NO_MATCH

Time: O(tokens in line). No backtracking possible.

Pattern Specificity

More specific patterns (more literal tokens) are tried first automatically:

text
# specificity = 4 (for, from, to, step) - tried first
for {var:name} from {start:expr} to {end:expr} step {step:expr}

# specificity = 3 (for, from, to) - tried second
for {var:name} from {start:expr} to {end:expr}

Resolution Order (per line)

  1. Is it a comment? → COMMENT, done
  2. Is it a function DEF? → check name(args) + indented body below
  3. Is it a function CALL? → check symbol table from pass 1
  4. Is it a builtin call? → check builtin name list
  5. Run .pmap lookup → canonical structure match
  6. Is it an expression? → expression evaluator
  7. Nothing matched → error with suggestions

A .pmap File

example.pmap
@pmap-version 1.0
@pseudo-version >=1.0 <2.0
@language "English"
@author "Sanay"

[FOR_LOOP]
for {var:name} from {start:expr} to {end:expr} step {step:expr}
for {var:name} from {start:expr} to {end:expr}
loop {var:name} from {start:expr} to {end:expr}

[PRINT]
print {value:expr}
show {value:expr}
say {value:expr}

Metadata Headers

HeaderRequiredDescription
@pmap-version 1.0yespmap format version
@pseudo-version >=1.0 <2.0optionalCompatible compiler version range
@language "English"optionalHuman-readable label
@author "name"optionalAttribution
@inherit default.pmapoptionalInherit and extend another pmap
@ignore-defaultoptionalIgnore all default.pmap mappings

Fallback Chain

When no pattern matches, Pseudo falls through:

  1. @inherit chain - custom.pmap → default.pmap → core
  2. Expression fallback - try expression evaluator if operators/calls found
  3. Name resolution - single identifier → look up → auto-print or NameError
  4. Helpful error - suggests matching patterns

Trie + Cache

For performance, Pseudo builds a prefix trie from the first literal token of each pattern. Only patterns starting with the same token as the input line are checked - O(1) trie lookup + O(small subset) pattern check.

The compiled trie is cached as .pmap.cache and invalidated automatically when the .pmap SHA256 hash changes.