Date: 2026-04-30
Codebase root: /home/wes/gitworkspace/trainingGround/src/main/java/
Report scope: Every file in the PCB language stack, read in full. This is a reference document, not a summary.
src/main/java/
├── Box/
│ ├── Interpreter/
│ │ ├── Interpreter.java 10274 lines (main tree-walk interpreter)
│ │ ├── VecMatHelper.java ~280 lines (vector/matrix math dispatch, added 2026-05-01)
│ │ ├── Environment.java 174 lines (variable scoping)
│ │ ├── BoxFunction.java 125 lines (function runtime object)
│ │ ├── BoxCallable.java ~30 lines (interface)
│ │ ├── BoxClass.java ~40 lines (class stub)
│ │ ├── BoxInstance.java 257 lines (box runtime object)
│ │ ├── CupInstance.java 260 lines (cup runtime object)
│ │ ├── PocketInstance.java 694 lines (pkt runtime object + lifetime)
│ │ ├── TkpInstance.java 670 lines (tkp runtime object + lifetime)
│ │ ├── PucInstance.java 58 lines (puc runtime object; toggles invertedMode)
│ │ ├── XobInstance.java 61 lines (xob runtime object; opaque)
│ │ ├── KnotInstance.java ~100 lines (knot runtime object)
│ │ ├── TonkInstance.java ~100 lines (tonk runtime object)
│ │ ├── KnotRunner.java 316 lines (knot/tonk execution loop)
│ │ ├── KnotAnalyzer.java 485 lines (static control-flow analysis)
│ │ ├── ControlGraph.java ~130 lines (graph data structure)
│ │ ├── ControlNode.java ~40 lines
│ │ ├── ControlRegion.java ~40 lines
│ │ ├── ControlPolarity.java 11 lines (OPEN / CLOSE)
│ │ ├── ControlFamily.java 12 lines (POCKET / CUP)
│ │ ├── TraversalEdge.java ~30 lines
│ │ ├── MatchPair.java ~20 lines
│ │ ├── MatchResult.java ~20 lines
│ │ ├── MatchTable.java ~40 lines
│ │ ├── Crossing.java ~30 lines
│ │ ├── CrossingCluster.java ~30 lines
│ │ ├── CrossingKind.java 16 lines (POCKET_OVER_POCKET, CUP_OVER_CUP, ...)
│ │ ├── EdgeKind.java 12 lines (FORWARD_ADJACENCY, BACKWARD_ADJACENCY, ...)
│ │ ├── RuntimeKind.java 12 lines (KNOT, TONK, POCKET, CUP, ...)
│ │ ├── RegionKind.java 14 lines (SETUP, CONDITION, BODY, ...)
│ │ ├── ReachabilityKind.java 10 lines (DEFAULT_REACHABLE, UNREACHABLE, ...)
│ │ ├── Topology.java 8 lines (ORDINARY / KNOTTED)
│ │ ├── OuterShell.java 9 lines (POCKET_SHAPED / CUP_SHAPED / MIXED)
│ │ ├── Orientation.java 8 lines (FORWARD_BIASED / BACKWARD_BIASED / AMBIGUOUS)
│ │ ├── RuntimeEffect.java 12 lines (FLIP_DIRECTION, BOUNCE, EXIT_STRUCTURE, ...)
│ │ ├── ExecutionPolicy.java 10 lines (DEFAULT, DIRECT_ONLY, DISABLED, ...)
│ │ ├── ContainerPersistence.java 246 lines (load/dump 6 system containers)
│ │ ├── Flow.java 124 lines (FIFO chain + cargo circular buffer)
│ │ ├── Boxer.java 55 lines (box/unbox helpers)
│ │ ├── RunTimeTypes.java 122 lines (32-entry type enum)
│ │ ├── TypesOfObject.java 36 lines (type + token + initializer record)
│ │ ├── SettingToken.java 18 lines (DUMP_PRIORITY / THREAD / DYNAMIC_SAFTY)
│ │ ├── Returns.java 17 lines (forward return exception)
│ │ ├── Snruter.java 14 lines (backward return exception)
│ │ ├── RuntimeError.java ~25 lines
│ │ ├── UnknownVariable.java ~15 lines
│ │ ├── Instance.java ~30 lines
│ │ ├── WesMap.java 118 lines (identity-keyed HashMap for locals)
│ │ ├── Bin.java ~30 lines
│ │ ├── IBox.java / ICup.java / IPkt.java / ITkp.java / IPuc.java / IXob.java / IKnt.java / ITnk.java
│ └── Scanner/
│ └── Scanner.java 901 lines
│ └── Token/
│ ├── TokenType.java 154 lines (main token enum)
│ ├── Token.java ~60 lines
│ ├── TokenTypeEnum.java ~10 lines
│ ├── DynamicEnumTokenType.java ~30 lines
│ └── TTDynamic.java ~20 lines
│ └── Syntax/ (OLD/parallel implementations, not primary)
│ ├── Declaration.java / Expr.java / Stmt.java / Fun.java (alternate AST)
│ └── ArrayTree.java / BaseContain.java / Contain.java / PramMap.java / StackArray.java
├── Parser/
│ ├── Expr.java 3026 lines (primary AST expression hierarchy)
│ ├── Stmt.java 1503 lines (primary AST statement hierarchy)
│ ├── ParserTest.java 5657 lines (the parser itself, named ParserTest)
│ ├── Declaration.java ~40 lines (base class for Stmt and Expr)
│ ├── Fun.java ~30 lines
│ └── TokensToTrack.java ~20 lines
├── resolver/
│ ├── Resolver.java 1192 lines
│ ├── ClassType.java ~10 lines
│ └── FunctionType.java ~10 lines
└── tool/
└── GenerateAST.java 1369 lines (code-generation utility, not runtime)
Total PCB language lines (core stack): approximately 32,000 lines across ~80 files.
All entries are from Box/Token/TokenType.java (~175 lines, updated 2026-05-01).
| Forward Token | Backward Token | Forward keyword | Backward keyword |
|---|---|---|---|
| TRUE | EURT | true | eurt |
| FALSE | ESLAF | false | eslaf |
| TNIRP | tnirp | ||
| RETURN | NRUTER | return | nruter |
| SAVE | EVAS | save | evas |
| READ | DAER | read | daer |
| INTO | OTNI | into | otni |
| RENAME | EMANER | rename | emaner |
| TO | OT | to | ot |
| MOVE | EVOM | move | evom |
| YROOT | TOORY | yroot | toory |
| SIN | NIS | sin | nis |
| COS | SOC | cos | soc |
| TAN | NAT | tan | nat |
| SINH | HNIS | sinh | hnis |
| COSH | HSOC | cosh | hsoc |
| TANH | HNAT | tanh | hnat |
| LOG | GOL | log | gol |
| CONTAINS | SNIATNOC | contains | sniatnoc |
| OPEN | NEPO | open | nepo |
| AND | DNA | and | dna |
| OR | RO | or | ro |
| FUN | NUF | fun | nuf |
| KNOT | TONK | knt | tnk |
| CUP | PUC | cup | puc |
| TEKCOP | pkt | tkp | |
| BOX | XOB | box | xob |
| DERIVE | EVIRED | derive | evired |
| INTEGRATE | ETARGETNI | integrate | etargetni |
| FRESNELS | SLENSREF | fresnels | slensref |
| FRESNELC | CLENSERF | fresnelc | clenserf |
| ASSERT | TRESSA | assert | tressa |
| ABS | SBA | abs | sba |
| SQRT | TRQS | sqrt | trqs |
| FLOOR | ROOLF | floor | roolf |
| CEIL | LIEC | ceil | liec |
| ROUND | DNUOR | round | dnuor |
| SIGN | NGIS | sign | ngis |
| ASIN | NISA | asin | nisa |
| ACOS | SOCA | acos | soca |
| ATAN | NATA | atan | nata |
| ASINH | HNISA | asinh | hnisa |
| ACOSH | HSOCA | acosh | hsoca |
| ATANH | HNATA | atanh | hnata |
| MIN | NIM | min | nim |
| MAX | XAM | max | xam |
| BAND | DNAB | band | dnab |
| BOR | ROB | bor | rob |
| BXOR | ROXB | bxor | roxb |
| BNOT | TONB | bnot | tonb |
| BLEFT | TFELB | bleft | tfelb |
| BRIGHT | THGIRB | bright | thgirb |
| NORM | MRON | norm | mron |
| UNIT | TINU | unit | tinu |
| TRANS | SNART | trans | snart |
| VDET | TEDV | vdet | tedv |
| VINV | VNIV | vinv | vniv |
| TRACE | ECART | trace | ecart |
| VDOT | TODV | vdot | todv |
| CROSS | SSORC | cross | ssorc |
| VADD | DDAV | vadd | ddav |
| VSUB | BUSV | vsub | busv |
| VSCALE | ELACSV | vscale | elacsv |
| BY | YB | by | yb |
| FROM | MORF | from | morf |
| ATKW | TAKW | at | ta |
| CONSTANT | TNATSNOC | constant | tnatsnoc |
| TARGET | TEGRAT | target | tegrat |
| NULL | LLUN | null | llun |
| NILL | LLIN | nill | llin |
| NOT | TON | not | ton |
| RUN | NUR | run | nur |
| ADD | DDA | add | dda |
| REMOVE | EVOMER | remove | evomer |
| CLEAR | RAELC | clear | raelc |
| SIZE | EZIS | size | ezis |
| EMPTY | YTPME | empty | ytpme |
| PUSH | HSUP | push | hsup |
| POP | PXE | pop | pxe |
| SETAT | TATES | setat | tates |
| GETAT | TATEG | getat | tateg |
| SUB | BUS | sub | bus |
| LN | NL | ln | nl |
| EXP | PXE | exp | pxe |
| ALIVE | EVILA | alive | evila |
Note: PXE is shared between the backward-POP keyword pxe and EXP's backward keyword pxe — both map to PXE in the enum. Context disambiguation happens at the parser level.
| Forward | Backward | Purpose |
|---|---|---|
| DOUBLE | (no reverse listed) | double type annotation |
| INT | (no reverse) | int type annotation |
| BIN | (no reverse) | binary type annotation |
| TYPE | EPYT | type query operator |
IDENTIFIER, DOUBLENUM, INTNUM, BINNUM, UNKNOWN, CHAR, STRING
DOT, COMMA, ASIGNMENTEQUALS, SEMICOLON
EQUALSEQUALS, EQUALSNOT, EQUALSPLUS, EQUALSMINUS
NOTEQUALS, PLUSEQUALS, MINUSEQUALS
GREATERTHEN, LESSTHEN, GREATERTHENEQUAL, LESSTHENEQUAL
EQUALGREATERTHEN, EQUALLESSTHEN
PLUS, PLUSPLUS, MINUS, MINUSMINUS
TIMES, POWER, BANG, QMARK
TEMPLID, SINGLEAND, UNDERSCORE
OPENSQUARE, CLOSEDSQUARE, OPENPAREN, CLOSEDPAREN, OPENBRACE, CLOSEDBRACE
FORWARDSLASH, BACKSLASH
EXPELL (>>>), CONSUME (<<<)
SPACE, NEWLINE, TAB, SPACERETURN, BOXXX
LEFTPAREN, RIGHTPAREN, NUMBER, AT, HASH
MOD, MODEQUAL, TIMESEQUAL, EQUALTIMES, EQUALMOD
EQUALDIVIDEFORWARD, EQUALDIVIDEBACKWARD, EQUALPOWER, POWEREQUAL
HATTAG, GATTAH (user-defined type tag declarations)
BOXCONTAINER, CUPCONTAINER, POCKETCONTAINER, KNOTCONTAINER
PUPCONTAINER, COCKETCONTAINER
LUPCONTAINER, LOCKETCONTAINER, LILCONTAINER
PIDCONTAINER, CIDCONTAINER
FLMOVE, FLDESTROY, FLCREATE, FLECREATE, FLEDESTROY, FLSETVALUE
EOF
Total distinct token types: approximately 175 (counting all enum entries on the final line).
From Box/Scanner/Scanner.java (901 lines). The scanner has an internal HashMap<String,TokenType> keywords populated at construction time, plus special-case scanning code for numbers, strings, chars, and operators.
| Keyword string | TokenType |
|---|---|
| true | TRUE |
| eurt | EURT |
| false | FALSE |
| eslaf | ESLAF |
| tnirp | TNIRP |
| return | RETURN |
| nruter | NRUTER |
| save | SAVE |
| evas | EVAS |
| read | READ |
| daer | DAER |
| into | INTO |
| otni | OTNI |
| rename | RENAME |
| emaner | EMANER |
| to | TO |
| ot | OT |
| move | MOVE |
| evom | EVOM |
| yroot | YROOT |
| toory | TOORY |
| sin | SIN |
| nis | NIS |
| cos | COS |
| soc | SOC |
| tan | TAN |
| nat | NAT |
| sinh | SINH |
| hnis | HNIS |
| cosh | COSH |
| hsoc | HSOC |
| tanh | TANH |
| hnat | HNAT |
| log | LOG |
| gol | GOL |
| contains | CONTAINS |
| sniatnoc | SNIATNOC |
| open | OPEN |
| nepo | NEPO |
| and | AND |
| dna | DNA |
| or | OR |
| ro | RO |
| fun | FUN |
| nuf | NUF |
| knt | KNOT |
| tnk | TONK |
| cup | CUP |
| puc | PUC |
| pkt | |
| tkp | TEKCOP |
| box | BOX |
| xob | XOB |
| null | NULL |
| llun | LLUN |
| nill | NILL |
| llin | LLIN |
| not | NOT |
| ton | TON |
| run | RUN |
| nur | NUR |
| add | ADD |
| dda | DDA |
| remove | REMOVE |
| evomer | EVOMER |
| clear | CLEAR |
| raelc | RAELC |
| size | SIZE |
| ezis | EZIS |
| empty | EMPTY |
| ytpme | YTPME |
| push | PUSH |
| hsup | HSUP |
| pop | POP |
| pxe | PXE |
| setat | SETAT |
| tates | TATES |
| getat | GETAT |
| tateg | TATEG |
| sub | SUB |
| bus | BUS |
| ln | LN |
| nl | NL |
| exp | EXP |
| alive | ALIVE |
| evila | EVILA |
| derive | DERIVE |
| evired | EVIRED |
| integrate | INTEGRATE |
| etargetni | ETARGETNI |
| fresnels | FRESNELS |
| slensref | SLENSREF |
| fresnelc | FRESNELC |
| clenserf | CLENSERF |
| assert | ASSERT |
| tressa | TRESSA |
| abs | ABS |
| sba | SBA |
| sqrt | SQRT |
| trqs | TRQS |
| floor | FLOOR |
| roolf | ROOLF |
| ceil | CEIL |
| liec | LIEC |
| round | ROUND |
| dnuor | DNUOR |
| sign | SIGN |
| ngis | NGIS |
| asin | ASIN |
| nisa | NISA |
| acos | ACOS |
| soca | SOCA |
| atan | ATAN |
| nata | NATA |
| asinh | ASINH |
| hnisa | HNISA |
| acosh | ACOSH |
| hsoca | HSOCA |
| atanh | ATANH |
| hnata | HNATA |
| min | MIN |
| nim | NIM |
| max | MAX |
| xam | XAM |
| band | BAND |
| dnab | DNAB |
| bor | BOR |
| rob | ROB |
| bxor | BXOR |
| roxb | ROXB |
| bnot | BNOT |
| tonb | TONB |
| bleft | BLEFT |
| tfelb | TFELB |
| bright | BRIGHT |
| thgirb | THGIRB |
| norm | NORM |
| mron | MRON |
| unit | UNIT |
| tinu | TINU |
| trans | TRANS |
| snart | SNART |
| vdet | VDET |
| tedv | TEDV |
| vinv | VINV |
| vniv | VNIV |
| trace | TRACE |
| ecart | ECART |
| vdot | VDOT |
| todv | TODV |
| cross | CROSS |
| ssorc | SSORC |
| vadd | VADD |
| ddav | DDAV |
| vsub | VSUB |
| busv | BUSV |
| vscale | VSCALE |
| elacsv | ELACSV |
| by | BY |
| yb | YB |
| from | FROM |
| morf | MORF |
| at | ATKW |
| ta | TAKW |
| constant | CONSTANT |
| tnatsnoc | TNATSNOC |
| target | TARGET |
| tegrat | TEGRAT |
0b...b notation; trailing b terminates. Produces BINNUM.. produces DOUBLENUM.. produce INTNUM."..." delimited. Produces STRING.'c' single character. Produces CHAR.// skips to end of line. No tokens produced.\n → NEWLINE, \t → TAB, \r → SPACERETURN. Whitespace is tokenized, not discarded.<<< → CONSUME>>> → EXPELL== EQUALSEQUALS, =! EQUALSNOT, =+ EQUALSPLUS, =- EQUALSMINUS, => EQUALGREATERTHEN, =< EQUALLESSTHEN, =* EQUALTIMES, =% EQUALMOD, =/ EQUALDIVIDEFORWARD, =\ EQUALDIVIDEBACKWARD, =^ EQUALPOWER, != NOTEQUALS, += PLUSEQUALS, -= MINUSEQUALS, *= TIMESEQUAL, ^= POWEREQUAL, <= LESSTHENEQUAL, >= GREATERTHENEQUAL, ++ PLUSPLUS, -- MINUSMINUSAll inner classes of Parser/Expr.java (3026 lines). Every class listed here is a real, loadable AST node. All implement Declaration.Visitor dispatch via an accept() method.
| Class | Constructor fields | Purpose |
|---|---|---|
Assignment |
Token name, Expr value |
Assign a named variable (forward) |
Contains |
Expr container, boolean open, Expr contents |
Test if container holds contents |
Additive |
Expr callee, Token operator, Expr toadd |
add/remove on a container |
ParamContOp |
Expr callee, Token operator, Expr.Literal index |
getat (parameterized container op) |
NonParamContOp |
Expr callee, Token operator |
size/empty/push/pop/clear |
Setat |
Expr callee, Expr.Literal index, Expr toset |
setat on a container |
Sub |
Expr callee, Expr.Literal start, Expr.Literal end |
sub (slice) on a container |
Binary |
Expr left, Token operator, Expr right |
arithmetic/comparison; reverse() swaps AND/OR operands |
Mono |
Expr value, Token operator |
trig/math postfix unary (sin/cos/tan/sinh/cosh/tanh/ln/exp/sqrt) |
Log |
Token operator, Expr valueBase, Expr value |
log base b of x |
Factorial |
Expr value, Token operator |
factorial |
Unary |
Token operator, Expr right |
prefix unary NOT or MINUS |
Call |
Expr callee, Token calleeToken, List<Expr> arguments |
forward function call |
Get |
Expr object, Token name |
property get (dot access) |
Set |
Expr object, Token name, Expr value |
property set |
Type |
Expr target |
type query (forward) — returns RunTimeTypes name |
Template |
Expr container |
template expression (pipe \| operator) |
Link |
Expr container |
link expression |
FlowFwd |
Token bracket |
forward flow open .( |
Derive |
Token operator, Expr expression, Expr byVar, Expr atPoint, Expr constantC |
forward derivative or antiderivative |
Integrate |
Token operator, Expr expression, Expr from, Expr to, Expr byVar, Expr target |
forward definite or inverse integral |
Variable |
Token name |
variable reference lookup |
Literal |
Object value |
numeric, string, or null literal |
LiteralChar |
char value |
char literal |
LiteralBool |
Object value |
boolean literal (true/false) |
| Class | Constructor fields | Purpose |
|---|---|---|
Tnemngissa |
Token name, Expr value |
assign named variable (backward) |
Sniatnoc |
Expr container, boolean open, Expr contents |
contains check (backward) |
Evitidda |
Expr callee, Token operator, Expr toadd |
add/remove on container (backward) |
PoTnocMarap |
Expr callee, Token operator, Expr.Literal index |
getat (backward) |
PoTnocMarapNon |
Expr callee, Token operator |
size/empty/push/pop/clear (backward) |
Tates |
Expr callee, Expr.Literal index, Expr toset |
setat (backward) |
Bus |
Expr callee, Expr.Literal start, Expr.Literal end |
sub/slice (backward) |
Yranib |
Expr left, Token operator, Expr right |
binary arithmetic/comparison (backward) |
Onom |
Expr value, Token operator |
trig/math postfix unary (backward) |
Gol |
Token operator, Expr valueBase, Expr value |
log (backward) |
Lairotcaf |
Expr value, Token operator |
factorial (backward) |
Yranu |
Token operator, Expr right |
prefix unary NOT/MINUS (backward) |
Llac |
Expr callee, Token calleeToken, List<Expr> arguments |
backward function call |
Teg |
Expr object, Token name |
property get (backward) |
Tes |
Expr object, Token name, Expr value |
property set (backward) |
Epyt |
Expr target |
type query (backward) |
FlowBwd |
Token bracket |
backward flow open .) |
Evired |
Token operator, Expr expression, Expr byVar, Expr atPoint, Expr constantC |
backward derivative or antiderivative |
Etargetni |
Token operator, Expr expression, Expr from, Expr to, Expr byVar, Expr target |
backward definite or inverse integral |
| Class | Constructor fields | Purpose |
|---|---|---|
Assignmenttnemgissa |
Token nameForward, Expr value, Token nameBackward |
bidirectional assignment |
Containssniatnoc |
Expr contForward, boolean openForward, Expr contentsShared, Expr contBackward, boolean openBackward |
bidirectional contains |
Addittidda |
Expr calleeForward, Token operatorForward, Expr toadd, Token operatorBackward, Expr calleeBackward |
bidirectional add/remove |
ParCoOppOoCraP |
Expr calleeForward, Token operatorForward, Expr.Literal index, Expr calleeBackward, Token operatorBackward |
bidirectional parameterized container op |
NoPaCoOOoCaPoN |
Expr calleeForward, Token operatorForward, Expr calleeBackward, Token operatorBackward |
bidirectional non-parameterized container op |
Setattates |
Expr calleeForward, Expr.Literal index, Expr toset, Expr calleeBackward |
bidirectional setat |
Subbus |
Expr calleeForward, Expr.Literal start, Expr.Literal end, Expr calleeBackward |
bidirectional sub/slice |
Binaryyranib |
Expr left, Token operatorForward, Token operatorBackward, Expr right |
bidirectional binary arithmetic/comparison |
Loggol |
Token operatorForward, Expr valueBase, Expr value, Token operatorBackward |
bidirectional log |
Callllac |
Expr calleeForward, Token calleeTokenForward, Expr calleeBackward, Token calleeTokenBackward, List<Expr> arguments |
bidirectional function call |
Expressiontmts |
Token expressionToken, Expr expression, Token tnemetatsToken |
bidirectional expression-statement |
Monoonom |
Expr value, Token operatorForward, Token operatorBackward |
bidirectional trig/math unary |
Swap |
Expr swap1, Expr Swap2 |
swap two values (bidirectional) |
| Class | Key fields | Purpose |
|---|---|---|
Box |
Token identifier, List<Expr> expression, String lexeme, Token reifitnedi, boolean isXob |
box/xob declaration |
Cup |
Token identifier, List<Declaration> expression, String lexeme, Token reifitnedi, boolean isPuc |
cup/puc declaration |
Pocket |
Token identifier, List<Stmt> expression, String lexeme, Token reifitnedi, Lifetime lifetime |
pkt/tkp declaration |
Knot |
Token identifier, List<Stmt> expression, String lexeme, Token reifitnedi |
knot declaration |
Tonk |
Token identifier, List<Stmt> expression, String lexeme, Token reifitnedi |
tonk declaration |
PocketOpen(Token ctrl) — .( open bracket
PocketClosed(Token ctrl) — .) close bracket
CupOpen(Token ctrl) — { open bracket
CupClosed(Token ctrl) — } close bracket
BoxOpen(Token ctrl) — [ open bracket
BoxClosed(Token ctrl) — ] close bracket
Kind enum: INDEFINITE, TRAVERSAL, DEPENDENT, CONDITIONAL
Fields on Lifetime: Kind kind, int count, String dependsOn, Expr condition
Static factories:
indefinite() — never expires
traversal(int n) — expires after n traversals
dependent(String name) — expires when named pocket dies
conditional(Expr c) — expires when condition becomes false
LiteralLoob(Object value) — eurt/eslaf (reversed boolean literals)
EOF(Token eof) — end-of-file sentinel
All inner classes of Parser/Stmt.java (1503 lines). All extend Stmt which extends Declaration. All implement reverse().
| Class | Fields | Purpose |
|---|---|---|
Print |
Token keyword, Expr expression |
forward print |
Tnirp |
Token keyword, Expr expression |
backward print |
| Class | Fields | Purpose |
|---|---|---|
Var |
Expr variable, Token name, Token type, int num, Expr initilizer |
forward variable declaration |
Rav |
Token name, Token type, int num, Stmt initilizer |
backward variable declaration |
TemplatVar |
Token name, Token superclass |
template variable (inherits from another container type) |
| Class | Fields | Purpose |
|---|---|---|
Return |
Token keyword, Expr expression |
forward return (throws Returns) |
Nruter |
Token keyword, Expr expression |
backward return (throws Snruter) |
| Class | Fields | Purpose |
|---|---|---|
If |
Expr ifPocket, Expr ifCup, Stmt elseIfStmt, Expr elseCup |
forward if |
Fi |
Expr ifPocket, Expr ifCup, Stmt elseIfStmt, Expr elseCup |
backward if |
Ifi |
Expr ifPocket, Stmt elseIf |
bidirectional if |
| Class | Fields | Purpose |
|---|---|---|
Save |
Token keyword, Expr filePathFileName, Expr objecttosave |
forward save |
Evas |
Token keyword, Expr filePathFileName, Expr objecttosave |
backward save |
Saveevas |
Token keywordForward, Expr filePathFileName, Expr objecttosave, Token keywordBackward |
bidirectional save |
Read |
Token keyword, Expr filePath, Expr objectToReadInto |
forward read |
Daer |
Token keyword, Expr filePath, Expr objectToReadInto |
backward read |
Readdaer |
Token keywordForward, Expr filePath, Expr objectToReadInto, Token keywordBackward |
bidirectional read |
| Class | Fields | Purpose |
|---|---|---|
Rename |
Token keyword, Expr filePathAndName, Expr filenewname |
forward rename file |
Emaner |
Token keyword, Expr filePathAndName, Expr filenewname |
backward rename |
Renameemaner |
Token keywordForward, Expr filePathAndName, Expr filenewname, Token keywordBackward |
bidirectional rename |
Move |
Token keyword, Expr OringialfilePathAndFile, Expr newfilePath |
forward move file |
Evom |
Token keyword, Expr OringialfilePathAndFile, Expr newfilePath |
backward move |
Moveevom |
Token keywordForward, Expr OringialfilePathAndFile, Expr newfilePath, Token keywordBackward |
bidirectional move |
| Class | Fields | Purpose |
|---|---|---|
Run |
Token keyword, Expr filePathToScriptToExecute |
run an external PCB script (forward) |
Nur |
Token keyword, Expr filePathToScriptToExecute |
run an external PCB script (backward) |
| Class | Fields | Purpose |
|---|---|---|
Expel |
Token keyword, Expr toExpell, Expr filePath |
write variable to file, set variable to null (>>>) |
Consume |
Token keyword, Expr boxToFill, Expr filePath |
read file into container (<<<) — STUBBED in interpreter |
| Class | Fields | Purpose |
|---|---|---|
Expression |
Expr expression, Expr noisserpxe |
expression as statement (forward and backward expression) |
StmttmtS |
Token keywordForward, Expr expression, Token keywordBackward |
bidirectional statement wrapping print/return |
Stmtnoisserpxe |
Token statementToken, Expr expression, Token noisserpxeToken |
statement with reversed expression token (backward trig) |
| Class | Fields | Purpose |
|---|---|---|
FLCreate |
Token keyword, int x, int y, int z, String name, boolean collidiable, boolean shouldPhysicsApply, String FlatLanderType, String Color |
create FlatLand entity |
FLMove |
Token keyword, String name, int x, int y, int z |
move FlatLand entity |
FLDestroy |
Token keyword, String name |
destroy FlatLand entity |
FLECreate |
Token keyword, int x, int y, int z, String name, Expr ScriptToExecute |
create FlatLand executable entity |
FLEDestroy |
Token keyword, String name |
destroy FlatLand executable entity |
FLsetValue |
Token keyword, Expr value |
set a FlatLand value |
Parser/ParserTest.java is 5657 lines. It is the live parser; the class name ParserTest is historical. Key structural facts:
Entry point: parse() returns List<Declaration> by calling declaration() in a loop.
Top-level dispatch in declaration():
- If HATTAG → userDefinedType()
- If FUN or NUF → function("function") which parses fun name(params) cup_body or nuf name(params) cup_body
- Otherwise → statement()
statement() dispatch (checked in order):
- PRINT → printStatement()
- TNIRP → tnirpStatement()
- IF → ifStatement()
- FI → fiStatement()
- IFI → ifiStatement()
- RETURN → returnStatement()
- NRUTER → nruterStatement()
- SAVE → saveStatement()
- EVAS → evasStatement()
- READ → readStatement()
- DAER → daerStatement()
- RENAME → renameStatement()
- EMANER → emaenerStatement()
- MOVE → moveStatement()
- EVOM → evomStatement()
- RUN → runStatement()
- NUR → nurStatement()
- EXPELL → expelStatement()
- CONSUME → consumeStatement()
- IDENTIFIER (followed by type token) → varDeclaration() or ravDeclaration()
- Otherwise → expressionStatement()
Expression parsing hierarchy (precedence, lowest to highest):
1. expression() → assignment or bidirectional expression
2. assignment() → Expr.Assignment / Expr.Tnemngissa / Expr.Assignmenttnemgissa
3. or() → AND/DNA/OR/RO binary
4. and() → comparison
5. equality() → EQUALSEQUALS/NOTEQUALS etc.
6. comparison() → GREATERTHEN/LESSTHEN/GREATERTHENEQUAL/LESSTHENEQUAL
7. addition() → PLUS/MINUS binary
8. multiplication() → TIMES/FORWARDSLASH/BACKSLASH/MOD/POWER
9. unary() → NOT/MINUS prefix
10. factorialPostfix() → BANG postfix
11. monoPostfix() → trig/math postfix (sin/cos/tan/sinh/cosh/tanh/ln/exp/yroot/toory)
12. call() → function call callee(args), dot property access
13. primary() → literals, identifiers, containers (box/cup/pkt/knt), calculus operators, parenthesized
Container parsing:
- box() / xob() → [expr, expr, ...] → Expr.Box with isXob=false/true
- cup() / puc() → { stmts } → Expr.Cup with isPuc=false/true
- pocket() / tkp() → ( stmts ) → Expr.Pocket with lifetime parsing
- knot() / tonk() → ( stmts ) → Expr.Knot / Expr.Tonk
Lifetime parsing on pocket:
The parser reads an optional lifetime annotation after the pocket identifier:
- INDEFINITE → Lifetime.indefinite()
- TRAVERSAL n → Lifetime.traversal(n)
- DEPENDENT name → Lifetime.dependent(name)
- CONDITIONAL expr → Lifetime.conditional(expr)
Calculus parsing:
- derive expr by var at point → Expr.Derive / Expr.Evired
- integrate expr from a to b by var → Expr.Integrate / Expr.Etargetni
- fresnels → Mono postfix, body is stub (returns 0/null)
- fresnelc → Mono postfix, Fresnel cosine integral C(x) implemented via power series
- assert → ASSERT → assertStatement() (forward only; tressa no-op in backward)
- Scalar Mono ops (Mono postfix): abs/sba, sqrt/trqs, floor/roolf, ceil/liec, round/dnuor, sign/ngis, asin/nisa, acos/soca, atan/nata, asinh/hnisa, acosh/hsoca, atanh/hnata, bnot/tonb — dispatched via findMono/findOnom in the interpreter
- Scalar Binary ops: min/nim, max/xam, band/dnab, bor/rob, bxor/roxb, bleft/tfelb, bright/thgirb — parsed like two-argument math ops (forward in yroottoory(), backward in same production)
- Vector/Matrix Mono ops: norm/mron, unit/tinu, trans/snart, vdet/tedv, vinv/vniv, trace/ecart — added to forward Mono loop in sinnis() / backward Mono loop in pocket-suffix section
- Vector/Matrix Binary ops: vdot/todv, cross/ssorc, vadd/ddav, vsub/busv, vscale/elacsv — new forward Binary vec loop in sinnis(), backward Binary loop in yroottoory()
Bidirectional forms:
The parser can produce the combined bidirectional nodes (Binaryyranib, Callllac, Addittidda, etc.) when it detects both a forward and backward token in the same grammatical position. The exact merger logic is in the parser but the general pattern is: forward token + shared operand + backward token → produce the *yranib/*llac/etc. combined form.
Box/Interpreter/Interpreter.java is 10274 lines. All 91 visit methods listed below. Status legend: FULL = complete implementation, PARTIAL = implemented but with known gaps, STUB = method exists but body is empty or returns null.
| Visit Method | Status | Notes |
|---|---|---|
visitLiteralExpr |
FULL | returns literal value directly |
visitLiteralBoolExpr |
FULL | handles true/false |
visitLiteralLoobExpr |
FULL | handles eurt/eslaf |
visitLiteralCharExpr |
FULL | returns char |
visitVariableExpr |
FULL | checks locals via WesMap, falls back to globals |
visitAssignmentExpr |
FULL | forward assignment with type enforcement |
visitTnemngissaExpr |
FULL | backward assignment |
visitAssignmenttnemgissaExpr |
FULL | bidirectional assignment |
visitBinaryExpr |
FULL | +, -, *, /, ^, mod, ==, !=, <, >, <=, >=, and, or, min/max, bitwise (band/bor/bxor/bleft/bright), vec/mat ops (vdot/cross/vadd/vsub/vscale); isVecBinaryOp guard bypasses parseBinData for multi-element BoxInstance operands; PUC inversion applies |
visitYranibExpr |
FULL | backward binary; same dispatch including todv/ssorc/ddav/busv/elacsv |
visitBinaryyranibExpr |
FULL | bidirectional binary |
visitUnaryExpr |
FULL | prefix NOT and MINUS (forward) |
visitYranuExpr |
FULL | backward prefix NOT and MINUS |
visitMonoExpr |
FULL | sin/cos/tan/sinh/cosh/tanh/ln/exp/yroot/toory postfix (forward); also abs/sqrt/floor/ceil/round/sign, asin/acos/atan/asinh/acosh/atanh, bnot, fresnelc, norm/unit/trans/vdet/vinv/trace; return type widened to Object to accommodate BoxInstance results (unit, trans, vinv) |
visitOnomExpr |
FULL | backward trig/math/vec postfix; same dispatch via findOnom (Object return type) |
visitMonoonomExpr |
FULL | bidirectional trig postfix |
visitLogExpr |
FULL | forward log base b |
visitGolExpr |
FULL | backward log |
visitLoggolExpr |
FULL | bidirectional log |
visitFactorialExpr |
FULL | forward factorial |
visitLairotcafExpr |
FULL | backward factorial |
visitCallExpr |
FULL | forward function call; checks isForward on BoxFunction |
visitLlacExpr |
FULL | backward function call |
visitCallllacExpr |
FULL | bidirectional function call |
visitGetExpr |
FULL | dot-access property get (forward) |
visitTegExpr |
FULL | dot-access property get (backward) |
visitSetExpr |
FULL | dot-access property set (forward) |
visitTesExpr |
FULL | dot-access property set (backward) |
visitContainsExpr |
FULL | forward contains |
visitSniatnocExpr |
FULL | backward contains |
visitContainssniatnocExpr |
FULL | bidirectional contains |
visitAdditiveExpr |
FULL | forward add/remove on container |
visitEvitiddaExpr |
FULL | backward add/remove |
visitAddittiddaExpr |
FULL | bidirectional add/remove |
visitParamContOpExpr |
FULL | forward getat |
visitPoTnocMarapExpr |
FULL | backward getat |
visitParCoOppOoCraPExpr |
FULL | bidirectional getat |
visitNonParamContOpExpr |
FULL | forward size/empty/push/pop/clear |
visitPoTnocMarapNonExpr |
FULL | backward size/empty/push/pop/clear |
visitNoPaCoOOoCaPoNExpr |
FULL | bidirectional non-parameterized container op |
visitSetatExpr |
FULL | forward setat |
visitTatesExpr |
FULL | backward setat |
visitSetattatesExpr |
FULL | bidirectional setat |
visitSubExpr |
FULL | forward sub/slice |
visitBusExpr |
FULL | backward sub/slice |
visitSubbusExpr |
FULL | bidirectional sub/slice |
visitSwapExpr |
FULL | swap two variable values |
visitTypeExpr |
FULL | forward type query |
visitEpytExpr |
FULL | backward type query |
visitBoxExpr |
FULL | instantiates BoxInstance (or XobInstance if isXob=true) |
visitCupExpr |
FULL | instantiates CupInstance (or PucInstance if isPuc=true) |
visitPocketExpr |
FULL | instantiates PocketInstance with lifetime |
visitKnotExpr |
FULL | instantiates KnotInstance, calls KnotRunner |
visitTonkExpr |
FULL | instantiates TonkInstance, calls KnotRunner backward |
visitTemplateExpr |
PARTIAL | template pipe operator; some cases stubbed |
visitLinkExpr |
PARTIAL | link expression; some cases stubbed |
visitFlowFwdExpr |
FULL | forward flow .( — adds chain to active PocketInstance's Flow |
visitFlowBwdExpr |
FULL | backward flow .) — adds chain to active TkpInstance's Flow |
visitPocketOpenExpr |
STUB | TODO comment in body; returns null |
visitPocketClosedExpr |
STUB | TODO comment in body; returns null |
visitCupOpenExpr |
STUB | TODO comment in body; returns null |
visitCupClosedExpr |
STUB | TODO comment in body; returns null |
visitBoxOpenExpr |
STUB | TODO comment in body; returns null |
visitBoxClosedExpr |
STUB | TODO comment in body; returns null |
visitDeriveExpr |
FULL | central difference (h=1e-8); if isInverted() does antiderivative |
visitEviredExpr |
FULL | backward derivative/antiderivative |
visitIntegrateExpr |
FULL | Simpson's rule (n=1000); if isInverted() does inverse via bisection (200 iter, tol=1e-10) |
visitEtargetniExpr |
FULL | backward definite/inverse integral |
visitEOFExpr |
FULL | no-op; returns null |
visitExpressiontmtsExpr |
FULL | bidirectional expression-statement; routes by forward flag |
| Visit Method | Status | Notes |
|---|---|---|
visitExpressionStmt |
FULL | evaluates expression, discards result |
visitStmttmtSStmt |
FULL | bidirectional print/return statement |
visitStmtnoisserpxeStmt |
FULL | backward trig statement form |
visitPrintStmt |
FULL | forward print to stdout |
visitTnirpStmt |
FULL | backward print to stdout |
visitVarStmt |
FULL | forward variable declaration with optional type |
visitRavStmt |
FULL | backward variable declaration |
visitTemplatVarStmt |
PARTIAL | template variable; inheritance chain partially wired |
visitIfStmt |
FULL | forward if/else with cup body |
visitFiStmt |
FULL | backward if/else |
visitIfiStmt |
FULL | bidirectional if |
visitFunDeclDeclaration |
FULL | function declaration; sets isForward on BoxFunction |
visitStmtDeclDeclaration |
FULL | statement-as-declaration wrapper |
visitFunctionFun |
FULL | function definition (cup body, params list) |
visitFunctionLinkFun |
STUB | link function variant; returns null |
visitSaveStmt |
FULL | write serialized value to file |
visitEvasStmt (inferred) |
FULL | backward save |
visitSaveevasStmt |
FULL | bidirectional save |
visitReadStmt |
FULL | read file into variable |
visitDaerStmt (inferred) |
FULL | backward read |
visitReaddaerStmt |
FULL | bidirectional read |
visitRenameemanerStmt |
FULL | bidirectional rename |
visitMoveevomStmt |
FULL | bidirectional move |
visitExpelStmt |
FULL | >>> writes to file and nulls variable |
visitConsumeStmt |
FULL | <<< reads file line-by-line into container; blank lines skipped; each line parsed as null/bool/double/string via ContainerPersistence.parseValue() |
visitAssertStmt |
FULL | forward only; throws RuntimeError("assertion failed: \<value>") on false/null; truthy non-booleans pass; tressa (backward) is always no-op |
visitRunStmt |
PARTIAL | loads and executes external PCB script file |
visitNurStmt |
PARTIAL | backward run; loads and executes backward |
visitFLCreateStmt |
FULL | creates FlatLand entity |
visitFLMoveStmt |
FULL | moves FlatLand entity |
visitFLDestroyStmt |
FULL | destroys FlatLand entity |
visitFLECreateStmt |
FULL | creates FlatLand executable entity |
visitFLEDestroyStmt |
FULL | destroys FlatLand executable entity |
visitFLsetValueStmt |
FULL | sets a FlatLand value |
interpret(List<Declaration>) — main entry; iterates forward (0→n) or backward (n→0) depending on forward flagexecute(Declaration) — calls accept() on a single nodeevaluate(Expr) — calls accept() on a single expressionresolve(Expr, int) — stores locals distance in WesMaplookUpVariable(Token, Expr) — checks WesMap first, then globalsisInverted() — returns invertedMode ^ !forward for calculus inversion detectionaddToErrorSink(String) — routes unboxable values to NON/LIMBOisTruthy(Object) — null→false, Boolean→value, else→truefindMono(Expr) — return type widened from Double to Object (2026-05-01); dispatches vec/mat mono ops via VecMatHelper.dispatchVecMono before scalar extraction; handles NORM/UNIT/TRANS/VDET/VINV/TRACE returning BoxInstancefindOnom(Expr) — backward equivalent; same Object return wideningisVecBinaryOp(TokenType) — static helper; returns true for VDOT/TODV/CROSS/SSORC/VADD/DDAV/VSUB/BUSV/VSCALE/ELACSV; used as guard before parseBinData in visitBinaryExpr/visitYranibExpr to prevent Boxer.unbox() throwing on multi-element BoxInstance operandsresolver/Resolver.java (1192 lines). The Resolver does a pre-pass over the AST to populate the locals WesMap with variable scope distances. It implements Declaration.Visitor<Void>.
Key fields:
- forward (boolean) — mirrors interpreter direction; controls iteration order
- scopes (Stack
Scope management:
- beginScope() / endScope() — push/pop Maps onto scopes
- declare(Token) — puts name → false in current scope
- define(Token) — puts name → true in current scope
- resolveLocal(Expr, Token) — walks stack from top, records distance in locals
resolve(List<Declaration>) direction control:
if forward: for i=0 to n-1: resolve(stmts[i])
else: for i=n-1 to 0: resolve(stmts[i])
All Resolver visit methods (comprehensive):
- visitBlockStmt — beginScope/resolve stmts/endScope
- visitVarStmt — declare name, resolve initializer, define name
- visitRavStmt — backward var; declare, resolve, define
- visitVariableExpr — check for self-reference in initializer, resolveLocal
- visitAssignmentExpr — resolveLocal for assignment target
- visitTnemngissaExpr — backward assignment resolveLocal
- visitFunctionFun — declare name, beginScope, define params, resolve body, endScope
- visitFunDeclDeclaration — wraps visitFunctionFun
- visitExpressionStmt — resolve expression
- visitIfStmt — resolve condition pocket, resolve cup body, resolve else
- visitFiStmt — backward if
- visitIfiStmt — bidirectional if
- visitPrintStmt — resolve expression
- visitTnirpStmt — resolve expression
- visitReturnStmt — error if not in function; resolve expression
- visitNruterStmt — backward return; error if not in function; resolve expression
- visitCallExpr — resolve callee, resolve arguments
- visitLlacExpr — backward call
- visitCallllacExpr — bidirectional call
- visitGetExpr — resolve object
- visitTegExpr — resolve object (backward)
- visitSetExpr — resolve object, resolve value
- visitTesExpr — resolve object, resolve value (backward)
- visitBoxExpr — beginScope, resolve body items, endScope
- visitCupExpr — beginScope, resolve declarations, endScope
- visitPocketExpr — beginScope, resolve statements, endScope; resolve lifetime condition if CONDITIONAL
- visitKnotExpr — beginScope, resolve statements, endScope
- visitTonkExpr — beginScope, resolve statements, endScope
- visitBinaryExpr — resolve left, resolve right
- visitYranibExpr — backward binary
- visitBinaryyranibExpr — bidirectional binary
- visitUnaryExpr — resolve right
- visitYranuExpr — resolve right
- visitMonoExpr — resolve value
- visitOnomExpr — resolve value
- visitMonoonomExpr — bidirectional mono
- visitLogExpr — resolve base, resolve value
- visitGolExpr — backward log
- visitLoggolExpr — bidirectional log
- visitFactorialExpr — resolve value
- visitLairotcafExpr — backward factorial
- visitContainsExpr — resolve container, resolve contents
- visitSniatnocExpr — backward contains
- visitContainssniatnocExpr — bidirectional contains
- visitAdditiveExpr — resolve callee, resolve toadd
- visitEvitiddaExpr — backward additive
- visitAddittiddaExpr — bidirectional additive
- visitSetatExpr — resolve callee, resolve toset
- visitTatesExpr — resolve callee (backward)
- visitSubExpr — resolve callee
- visitBusExpr — resolve callee (backward)
- visitParamContOpExpr — resolve callee
- visitPoTnocMarapExpr — resolve callee
- visitNonParamContOpExpr — resolve callee
- visitPoTnocMarapNonExpr — resolve callee
- visitSwapExpr — resolve both swap targets
- visitTypeExpr — resolve target
- visitEpytExpr — resolve target
- visitDeriveExpr — resolve expression, byVar, atPoint, constantC
- visitEviredExpr — backward derivative
- visitIntegrateExpr — resolve expression, from, to, byVar, target
- visitEtargetniExpr — backward integrate
- visitFlowFwdExpr — minimal scope check
- visitFlowBwdExpr — minimal scope check
- visitTemplateExpr / visitLinkExpr — resolve container
- visitSaveStmt / visitEvasStmt / visitSaveevasStmt — resolve file path, resolve object
- visitReadStmt / visitDaerStmt / visitReaddaerStmt — resolve file path, resolve target
- visitExpelStmt / visitConsumeStmt — resolve expressions
- visitRunStmt / visitNurStmt — resolve file path
- visitRenameemanerStmt / visitMoveevomStmt — resolve paths
- visitFLCreate/Move/Destroy/ECreate/EDestroy/setValueStmt — minimal or no scope work
- visitLiteralExpr / visitLiteralBoolExpr / visitLiteralLoobExpr / visitLiteralCharExpr — no-ops
- visitEOFExpr — no-op
Primitive scalar types:
Int — Java Integer
Double — Java Double
Bin — binary number
Char — Java char (as Character)
String — Java String
Boolean — Java boolean
Backward-name scalar aliases:
Naeloob — backward Boolean
Gnirts — backward String
Rahc — backward Char
Nib — backward Bin
Elbuod — backward Double
Tni — backward Int
Null sentinels:
NULL — forward null
NILL — forward nill
LLUN — backward null (llun)
LLIN — backward nill (llin)
Container types:
knt — knot
cup — cup
pkt — pocket
box — box
tnk — tonk
tkp — tkp
xob — xob
puc — puc
Control bracket sentinels:
CupOpenRight — { open
CupOpenLeft — } close
PocketOpenRight — ( open
PocketOpenLeft — ) close
BoxOpenRight — [ open
BoxOpenLeft — ] close
Type/function types:
Any — unconstrained
Type — forward type token
Epyt — backward type token
Function — callable
Used by Environment to track declared types. Fields:
- RunTimeTypes runtimeTypeForObject — the enum type
- Token containerType — the declaring token
- Object initilizer — the initial value expression
Environment.assign() checks the stored TypesOfObject.runtimeTypeForObject before allowing assignmentRunTimeTypes.isCompatible() (or equivalent) used to validate assignmentRuntimeErrorObject
└── Instance
├── BoxInstance (implements IBox)
│ ├── XobInstance (extends BoxInstance; overrides all inspection methods to throw)
│ └── CupInstance (extends BoxInstance; implements ICup; bracket-aware body)
│ ├── PucInstance (extends CupInstance; toggles invertedMode on execute())
│ ├── PocketInstance (extends CupInstance; implements IPkt; adds Flow + Lifetime)
│ └── TkpInstance (extends CupInstance; implements ITkp; backward pocket)
├── KnotInstance (implements IKnt; wraps KnotRunner forward)
└── TonkInstance (implements ITnk; wraps KnotRunner backward)
Storage: List<Object> body — ordered list, can contain any PCB value.
Bracket exclusion: control nodes (PocketOpen/Closed, CupOpen/Closed, BoxOpen/Closed wrapped in Stmt.Expression) are excluded from bodySizeExclude(), getat(), remove(), etc. Body indices skip them transparently.
Methods: add(operator, toadd), remove(operator, value), getat(operator, value), size(operator), clear(operator), empty(operator), pop(operator), push(operator, expr), setat(index, toset), sub(start, end), contains(contents).
evaluateBody(): on construction, walks body and calls interpreter.execute() on any Expr nodes; wraps results via Boxer.box().
toString(): [item,item,...]
Extends: BoxInstance.
Opacity rule: getat, setat, sub, contains, remove all override to throw RuntimeError("xob is opaque").
Allowed: add, size, empty, clear, push, pop — structural ops without inspection.
Extends: BoxInstance. Stores originalBody for re-execution.
Bracket-aware indexing: cup has open/close brackets at positions 0 and n-1 of body; all index operations add +1 offset to skip the opening bracket.
execute(): re-evaluates from originalBody; used when a Flow bootstraps the cup inside a pkt/tkp.
clear(): preserves body[0] and body[n-1] (the brackets).
add(): inserts at body.size()-1 (before closing bracket).
Extends: CupInstance.
execute(): wraps super.execute() with interpreter.invertedMode = !interpreter.invertedMode before and after. Double inversion restores normal execution.
Extends: CupInstance. Implements IPkt.
Flow list: List<Flow> flows — each pocket can have multiple Flow objects attached.
Lifetime tracking:
- Lifetime lifetime — the policy (INDEFINITE / TRAVERSAL / DEPENDENT / CONDITIONAL)
- int remainingTraversals — countdown for TRAVERSAL lifetime
- boolean destroyed — Stage 2: body cleared, all flows gone
- boolean stripping — Stage 1: flows cleared, body still readable
- beginDeath() — transitions to stripping
- destroy() — transitions to destroyed; clears body
- probeLifetime() — checks DEPENDENT/CONDITIONAL during execution
- onTraversal() — called before every container operation; enforces TRAVERSAL countdown
- seamCrossAndUpdate() — triggers death sequence
- isAlive() — returns !destroyed && !stripping
- isStripping() — returns stripping && !destroyed
Extends: CupInstance. Implements ITkp. Backward pocket. Structurally identical to PocketInstance but direction is reversed. Same lifetime machinery.
Wrap List<Stmt> body + KnotRunner.
KnotInstance: runner executes forward (knot semantics).
TonkInstance: runner executes backward (tonk semantics).
Forward container ops (visitAdditiveExpr, visitParamContOpExpr, visitNonParamContOpExpr, visitSetatExpr, visitSubExpr, visitContainsExpr) evaluate the callee, then dispatch to the appropriate instance method based on the token type.
Backward ops (visitEvitiddaExpr, etc.) mirror exactly but use the backward-named token.
XobInstance throws RuntimeError for any inspection operation; this is caught by the test suite in XobInstanceTest.
Interpreter.forward (boolean, default = true). When true, interpret() iterates statements 0→n. When false, iterates n→0.
Interpreter.invertedMode (boolean, default = false). Set by PucInstance.execute() before/after super.execute(). This is separate from the direction flag — it controls operator inversion inside a puc block.
| Forward op | Inverted to |
|---|---|
| + | - |
| - | + |
| * | / |
| / | * |
| > | < |
| < | > |
| AND | OR |
| OR | AND |
| push | pop |
| add | remove |
Statement lists: iterated forward or backward based on interpreter.forward.
Knot: always runs its body forward-first; KnotRunner oscillates after boundary.
Tonk: always runs its body backward-first.
Bidirectional AST nodes: the combined nodes (Binaryyranib, Callllac, etc.) contain both a forward and backward variant. At runtime, interpreter.forward selects which branch to execute.
Returns/Snruter: forward return throws Returns(value); backward nruter throws Snruter(value). BoxFunction.call() catches the appropriate exception based on its isForward flag.
BoxFunction.isForward (boolean) — set at function declaration time.
At call() time:
- If isForward and !interpreter.forward → throw RuntimeError("cannot call forward function in backward context")
- If !isForward and interpreter.forward → throw RuntimeError("cannot call backward function in forward context")
When a pkt body contains a function call fn(args), the bootstrap mechanism replaces the fn token itself with the return value. The Flow cargo buffer handles circular replacement. This is the mechanism by which pkt/tkp act as live, self-modifying containers.
isInverted() (calculus mode)return invertedMode ^ !forward
- Forward + not inverted → false → normal derivative/integral
- Backward + not inverted → true → antiderivative/inverse integral
- Forward + inverted (in puc) → true → antiderivative/inverse integral
- Backward + inverted (in puc) → false → normal derivative/integral
All calculus is in the Interpreter's visit methods for Expr.Derive, Expr.Evired, Expr.Integrate, Expr.Etargetni.
visitDeriveExpr)Algorithm: central difference method
h = 1e-8
f(x+h) evaluated by temporarily setting byVar to x+h in environment
f(x-h) evaluated by temporarily setting byVar to x-h
result = (f(x+h) - f(x-h)) / (2*h)
Antiderivative mode (when isInverted() is true): uses trapezoidal/Simpson accumulation from 0 to atPoint.
visitIntegrateExpr)Algorithm: Simpson's rule, n=1000 intervals
h = (to - from) / n
sum = f(from) + f(to)
for i=1 to n-1: sum += (i%2==0 ? 2 : 4) * f(from + i*h)
result = sum * h / 3
Inverse integral mode (when isInverted() is true): bisection search
200 iterations, tolerance = 1e-10
Find t such that integral(from, t) == target
FRESNELS / SLENSREF)Token exists in both the TokenType enum and the keyword map. Parser parses it. Interpreter: STUB. The visitor exists but the body does not compute a Fresnel integral. Returns null or 0.
FRESNELC / CLENSERF)Token added 2026-05-01. Scanner keyword: fresnelc / clenserf. Parser: Mono postfix form (forward and backward). Interpreter: FULL. Computes C(x) = ∫₀ˣ cos(πt²/2) dt via power series. No puc inversion (self-inverse semantics not defined).
Box/Interpreter/ContainerPersistence.java (246 lines).
| Name | File | Open | Close | Token type |
|---|---|---|---|---|
| BIN | bin.box | [ | ] | BOX |
| GAP | gap.xob | [ | ] | XOB |
| NON | non.cup | { | } | CUP |
| LIMBO | limbo.puc | { | } | PUC |
| TRASH | trash.pkt | ( | ) | PKT |
| VOID | void.tkp | ( | ) | TKP |
loadAll()Called from Interpreter constructor. For each container:
1. Reads the file from disk.
2. Validates that the content is wrapped in the expected bracket characters.
3. Parses items: null → null, "true" → Boolean.TRUE, "false" → Boolean.FALSE, numeric string → Double, everything else → String.
4. Calls populateBody() on the live container instance to inject parsed items.
5. For PKT/TKP: injects structural PocketOpen/PocketClosed AST sentinel nodes wrapped in Stmt.Expression at the start and end of the body list.
dumpAll()Installed as a JVM shutdown hook in the Interpreter constructor. For each container: 1. Walks the body list. 2. Serializes: String → quoted string, Double → decimal string, Boolean → "true"/"false", null → "null". 3. Non-serializable objects (boxed instances, functions, etc.) are silently dropped. 4. Writes the bracket-wrapped serialized content to the file.
dumpSnapshot()For cases where trashThreaded or voidThreaded settings are active, a pre-captured snapshot of the body is submitted to a worker thread via dumpSnapshot() rather than inline serialization.
All 11 names are defined in globals at startup:
bin, BIN → the BIN BoxInstance
gap, GAP → the GAP XobInstance
non, NON → the NON CupInstance
limbo, LIMBO → the LIMBO PucInstance
trash, TRASH → the TRASH PocketInstance
void, VOID → the VOID TkpInstance (note: "void" is a valid identifier in PCB)
Three SettingToken objects registered in globals:
- DUMP_PRIORITY — controls which containers are dumped on priority flush
- THREAD — enables threaded dump for trash/void
- DYNAMIC_SAFTY — enables dynamic safety checks (DYNAMICSAFTY feature; wiring partially complete)
Fields:
- Environment closure — captured at definition time
- List<Token> params — parameter name tokens
- String name — function name string
- Expr body — the cup body expression
- Token type — return type annotation token
- List<Token> paramsTypes — parallel list of parameter type annotation tokens
- boolean isLink — true if this is a link function variant
- boolean isForward — true if declared with fun; false if declared with nuf
call(Interpreter interpreter, List<Object> arguments):
1. Direction check: if isForward != interpreter.forward → throw RuntimeError
2. Create new Environment(closure) as execution environment
3. For each param/arg pair: environment.define(params[i].lexeme, arguments[i])
4. Execute the cup body via interpreter.execute(body)
5. Catch Returns (if isForward) or Snruter (if !isForward) → return the value
6. Return null if no explicit return
BoxCallable interface: defines call(Interpreter, List<Object>) and arity().
visitFunDeclDeclaration / visitFunctionFun in Interpreter:
- Parses the fun/nuf keyword to determine isForward
- Creates BoxFunction with captured interpreter.environment as closure
- Defines the function name in the current environment
Defined directly in the Interpreter constructor as lambda-implementing BoxCallable:
- clock — returns System.currentTimeMillis() / 1000.0 as a Double; arity 0
When a pocket body contains a call expression fn(args), the bootstrap mechanism:
1. Detects the fn token as a forward/backward function reference
2. Calls the function
3. Replaces the function-token position in the body with the return value
4. Flow cargo buffer (cargoBuffer) handles the case where multiple replacements happen in sequence; uses circular rotation via cargoIndex
The isForward flag on BoxFunction is checked before argument evaluation. A forward function (fun) called during backward execution (interpreter.forward = false) throws immediately without evaluating arguments. Same for backward function (nuf) called during forward execution.
visitFunctionLinkFun → STUB (returns null). The link function variant exists in the AST (Expr.Link, BoxFunction.isLink) but the runtime path for link function execution is not implemented.
All tests are in src/test/java/Box/Interpreter/. Total: 22 test files, 913 tests, all green as of 2026-05-01.
| File | Lines | Test methods | Coverage focus |
|---|---|---|---|
BoxingTest.java |
604 | 36 | Boxer.box/unbox, type checking, error sink routing to NON/LIMBO |
BoxifyDeboxifyTest.java |
229 | ~30 (static helper pattern) | box/unbox roundtrip on all primitive types |
KnotAnalyzerStressTest.java |
616 | 18 | ControlGraph analysis; all 7 RuntimeKinds, all topology variants |
KnotTonkInstanceTest.java |
381 | 25 | KnotInstance/TonkInstance creation and execution |
PocketInstanceTest.java |
378 | 15 | PocketInstance add/remove/getat/size/clear/empty/push/pop; lifetime |
TkpInstanceTest.java |
372 | 15 | TkpInstance same operations as PocketInstance; backward lifetime |
PucInstanceTest.java |
332 | 14 | PucInstance inversion: operator flipping, double-inversion restore |
KnotRunnerOscillationTest.java |
330 | 14 | Oscillation: forward→backward flip, boundary detection, exit conditions |
FunctionBootstrapTest.java |
303 | 10 | Bootstrap replacement in pkt/tkp bodies; cargo circular buffer |
BoxFunctionArgTest.java |
296 | 12 | Argument passing, type enforcement on params, arity checking |
ActiveIOTest.java |
290 | 14 | dumpPriority, THREAD settings, threaded dump behavior |
InterpreterExpressionTest.java |
278 | 25 | Expression evaluation: arithmetic, trig, comparison, logical |
ContainerPersistenceTest.java |
278 | 11 | loadAll/dumpAll roundtrip; all 6 container formats |
BoxFunctionCallTest.java |
275 | 16 | Direction mismatch errors; forward fn in backward context |
XobInstanceTest.java |
265 | 12 | xob opacity: getat/setat/sub/contains/remove all throw |
SettingsTest.java |
264 | 14 | DYNAMICSAFTY, dumpPriority, THREAD sentinel values |
KnotRunnerRoutingTest.java |
259 | 8 | Control-flow routing through nested brackets |
FlowTest.java |
231 | 14 | Flow.addChain, injectCargoChain, spendToken, cargoBuffer rotation |
EnvironmentTest.java |
214 | 16 | Environment.define/get/assign, type enforcement, scope chaining |
LinkTemplateTest.java |
— | 30 | Link registration, conformance check, contract context stack, C3 rollback |
ContractLayerTest.java |
— | 59 | Seed tagging, lazy Get preservation, contractConfidence, manifest/export generation |
VectorMatrixTest.java |
— | 119 | VecMatHelper unit tests, all vec/mat ops, interpreter Mono/Binary dispatch, puc inversions, error cases |
| Feature | Location | Status |
|---|---|---|
visitConsumeStmt (<<< operator) |
Interpreter.java | COMPLETE as of 2026-05-01 — file read line-by-line into container |
visitPocketOpenExpr |
Interpreter.java | STUB — TODO comment, returns null |
visitPocketClosedExpr |
Interpreter.java | STUB — TODO comment, returns null |
visitCupOpenExpr |
Interpreter.java | STUB — TODO comment, returns null |
visitCupClosedExpr |
Interpreter.java | STUB — TODO comment, returns null |
visitBoxOpenExpr |
Interpreter.java | STUB — TODO comment, returns null |
visitBoxClosedExpr |
Interpreter.java | STUB — TODO comment, returns null |
visitFunctionLinkFun |
Interpreter.java | STUB — returns null |
Fresnel sine integral (fresnels) |
Interpreter.java | STUB — token/parser exist; runtime returns 0/null |
| DYNAMICSAFTY wiring | Interpreter.java / SettingToken.java | PARTIAL — sentinel registered, runtime checks not fully wired |
visitRavStmt |
Interpreter.java | PARTIAL — backward var declaration, some edge cases incomplete |
| Feature | Notes |
|---|---|
visitTemplateExpr |
Template pipe \| operator; some container type combinations not fully handled |
visitLinkExpr |
Link expression partially handled; link functions always return null |
visitRunStmt / visitNurStmt |
External script execution loads and runs but error handling is minimal |
visitTemplatVarStmt |
Template variable inheritance chain partially wired |
| Nested pocket cascading death | COMPLETE as of 2026-05-01 — destroy() now walks body and calls beginDeath() on direct PocketInstance children |
| DYNAMICSAFTY runtime checks | SettingToken.Kind.DYNAMIC_SAFTY registered but the guard logic in container ops is not fully connected |
| Feature | Status |
|---|---|
| REPL / interactive mode | No REPL class found in core stack |
| Error recovery in parser | Parser throws on first error; no synchronization/recovery |
| Stack traces / call stack | RuntimeError carries a Token for position but no call stack |
| Garbage collection / pocket auto-expiry watcher | Lifetime is checked on-access (probeLifetime/onTraversal); no background GC thread |
| Module / import system | No import or module keyword |
| String interpolation | No evidence in scanner or parser |
| Regex | No regex support |
| Networking | No socket or HTTP primitives |
| Type inference | Type annotations are explicit; no inference |
| Feature Category | Feature | Status |
|---|---|---|
| Scanning | All ~100 bidirectional keyword pairs | COMPLETE |
| Scanning | Binary number literals (0b...b) | COMPLETE |
| Scanning | Whitespace tokenization (not discarded) | COMPLETE |
| Scanning | Multi-char compound operators | COMPLETE |
| Parsing | All forward/backward/bidirectional expression forms | COMPLETE |
| Parsing | All container declaration forms (box/xob/cup/puc/pkt/tkp/knt/tnk) | COMPLETE |
| Parsing | Lifetime annotation on pocket/tkp | COMPLETE |
| Parsing | Calculus operators (derive/integrate) | COMPLETE |
| Parsing | Fresnels token | COMPLETE (parsing only; runtime is stub) |
| Parsing | Fresnelc token | COMPLETE |
| Parsing | Assert/tressa | COMPLETE |
| Parsing | Scalar math mono (abs/sqrt/floor/ceil/round/sign/asin/acos/atan/asinh/acosh/atanh/bnot) | COMPLETE |
| Parsing | Scalar binary (min/max/band/bor/bxor/bleft/bright) | COMPLETE |
| Parsing | Vector/matrix mono (norm/unit/trans/vdet/vinv/trace) | COMPLETE |
| Parsing | Vector/matrix binary (vdot/cross/vadd/vsub/vscale) | COMPLETE |
| Parsing | FlatLand command statements | COMPLETE |
| Resolution | Forward/backward scope resolution | COMPLETE |
| Resolution | All container scopes | COMPLETE |
| Interpreter | Arithmetic (all forward and backward) | COMPLETE |
| Interpreter | Comparison operators | COMPLETE |
| Interpreter | Logical operators (and/or/not) | COMPLETE |
| Interpreter | Trig functions (all 6 pairs) | COMPLETE |
| Interpreter | Log/Ln/Exp/Yroot | COMPLETE |
| Interpreter | Factorial | COMPLETE |
| Interpreter | String operations | COMPLETE |
| Interpreter | Variable declaration and assignment | COMPLETE |
| Interpreter | Bidirectional assignment | COMPLETE |
| Interpreter | Forward/backward function call | COMPLETE |
| Interpreter | Function direction enforcement | COMPLETE |
| Interpreter | Forward/backward if-else | COMPLETE |
| Interpreter | Bidirectional if | COMPLETE |
| Interpreter | Forward/backward print | COMPLETE |
| Interpreter | Forward/backward return | COMPLETE |
| Interpreter | Save/read/rename/move (forward/backward/bidirectional) | COMPLETE |
| Interpreter | Expel (>>>) |
COMPLETE |
| Interpreter | box/xob construction | COMPLETE |
| Interpreter | cup/puc construction | COMPLETE |
| Interpreter | pkt/tkp construction with lifetime | COMPLETE |
| Interpreter | knt/tnk construction | COMPLETE |
| Interpreter | All container ops (add/remove/getat/setat/sub/size/empty/clear/push/pop/contains) | COMPLETE |
| Interpreter | xob opacity (all inspection ops throw) | COMPLETE |
| Interpreter | puc inversion (operator flip inside block) | COMPLETE |
| Interpreter | Pocket lifetime (all 4 kinds) | COMPLETE |
| Interpreter | Flow chain + cargo circular buffer | COMPLETE |
| Interpreter | Pocket function bootstrap replacement | COMPLETE |
| Interpreter | Derivative (central difference) | COMPLETE |
| Interpreter | Antiderivative (inverted mode) | COMPLETE |
| Interpreter | Definite integral (Simpson's rule) | COMPLETE |
| Interpreter | Inverse integral (bisection) | COMPLETE |
| Interpreter | Fresnel cosine integral (fresnelc) | COMPLETE |
| Interpreter | Fresnel sine integral (fresnels) | STUB |
| Interpreter | Assert statement | COMPLETE |
| Interpreter | Consume (<<<) |
COMPLETE |
| Interpreter | Scalar math: abs/sqrt/floor/ceil/round/sign | COMPLETE |
| Interpreter | Scalar math: asin/acos/atan/asinh/acosh/atanh | COMPLETE |
| Interpreter | Scalar math: min/max (binary) | COMPLETE |
| Interpreter | Bitwise ops: band/bor/bxor/bnot/bleft/bright | COMPLETE |
| Interpreter | Vector ops: norm/unit/vadd/vsub/vscale/vdot/cross | COMPLETE |
| Interpreter | Matrix ops: trans/vdet/vinv/trace/vdot (2D) | COMPLETE |
| Interpreter | Vec/mat puc inversions | COMPLETE |
| Interpreter | Pocket cascading death | COMPLETE |
| Interpreter | KnotRunner oscillation | COMPLETE |
| Interpreter | KnotAnalyzer control graph | COMPLETE |
| Interpreter | type/epyt query operators | COMPLETE |
| Interpreter | swap expression | COMPLETE |
| Interpreter | Run external script | PARTIAL |
| Interpreter | Link functions | STUB |
| Interpreter | Template expressions | PARTIAL |
| Persistence | All 6 system containers load on startup | COMPLETE |
| Persistence | All 6 system containers dump on shutdown | COMPLETE |
| Persistence | Thread-safe snapshot dump | COMPLETE |
| Persistence | DYNAMICSAFTY wiring | PARTIAL |
| Type system | 32 RunTimeTypes | COMPLETE |
| Type system | Type enforcement on assignment | COMPLETE |
| FlatLand | All FL statement types | COMPLETE |
| Testing | 913 tests, 22 suites, all green (2026-05-01) | COMPLETE |
Both Interpreter and Resolver implement Declaration.Visitor<Object> and Declaration.Visitor<Void> respectively. Every AST node (both Expr and Stmt, both of which extend Declaration) has an accept(Visitor) method. Dispatch is double-dispatch through Java method overloading.
Interpreter is a Thread subclass (noted in MEMORY). This means each interpreter instance can be run in its own OS thread. The bidirectional model runs both strands on shared data: the same globals and environment are used for both directions, and the forward flag is the sole control variable toggling direction.
WesMap<Expr, Integer> is a custom Map implementation that compares keys by lexeme string (for Expr.Variable) or identifier lexeme (for Expr.Knot, Expr.Tonk), not by Java object identity. This allows the resolver and interpreter to use AST node objects as map keys while matching by semantic identity (variable name) rather than object reference.
Environment has an enclosing pointer forming a singly-linked scope chain. getAt(distance, lexeme) walks exactly distance steps up the chain using the distance stored by the Resolver. assign() also walks the chain. This is the standard Lox-derived scope resolution approach.
The KnotAnalyzer builds a ControlGraph composed of:
- ControlNode: each bracket sentinel in the statement list (PocketOpen/Closed/CupOpen/Closed), with index, family (POCKET/CUP), polarity (OPEN/CLOSE)
- ControlRegion: spans between matched bracket pairs, classified by RegionKind (SETUP/CONDITION/BODY/POCKET_ENTRY/CUP_ENTRY/UNWIND/EMPTY/AMBIGUOUS)
- TraversalEdge: directed edges between nodes, typed by EdgeKind (FORWARD_ADJACENCY/BACKWARD_ADJACENCY/CONDITION_TRUE/CONDITION_FALSE/OWNERSHIP_JUMP/UNWIND/ENTRY)
- MatchTable: pairs of matched open/close brackets produced by buildMatchTable()
- CrossingCluster: collection of Crossing objects where bracket pairs interleave, typed by CrossingKind
- Top-level classification: OuterShell (POCKET_SHAPED/CUP_SHAPED/MIXED), Topology (ORDINARY/KNOTTED), Orientation (FORWARD_BIASED/BACKWARD_BIASED/AMBIGUOUS), RuntimeKind (KNOT/TONK/POCKET/CUP/KNOTTED_POCKET/KNOTTED_CUP/AMBIGUOUS)
- Reachability analysis: each node/edge classified by ReachabilityKind (DEFAULT_REACHABLE/REVERSE_REACHABLE/CONDITIONAL_REACHABLE/UNREACHABLE/EXPLICIT_ONLY)
- ExecutionPolicy: each region gets an ExecutionPolicy (DEFAULT/DIRECT_ONLY/UNREACHABLE_CHAIN/DISABLED/DIAGNOSTIC_ONLY) controlling whether KnotRunner executes it
There are two parallel AST families in the codebase:
- Primary (active): Parser/Expr.java (3026 lines), Parser/Stmt.java (1503 lines), Parser/Declaration.java — used by Interpreter and Resolver
- Secondary (legacy/OLD): Box/Syntax/Expr.java (448 lines), Box/Syntax/ExprOLD.java (434 lines), Box/Syntax/Stmt.java (309 lines), Box/Syntax/StmtOLD.java (309 lines) — referenced by TypesOfObject (uses ExprOLD) and some older code paths; not primary
Non-boxable values and runtime errors are routed to NON/LIMBO system containers via interpreter.addToErrorSink(). The BIN container serves as the general discard/sink. The choice of which sink depends on the DYNAMICSAFTY/dumpPriority settings, though that wiring is partially complete.
The PCB language has a first-class bridge to the FlatLand 2D game engine. Statement types (FLCreate, FLMove, FLDestroy, FLECreate, FLEDestroy, FLsetValue) are fully parsed and interpreted. FlatLand entities can be scripted entirely from PCB.
Box/GameSpaceInterpreter/PCBServer.java (362 lines) — an HTTP or socket server wrapper around the Interpreter. Allows PCB scripts to be submitted and executed remotely. Not part of the core language runtime; extends the language to a service-mode deployment.
tool/GenerateAST.java (1369 lines) — a code-generation utility that was used to bootstrap the AST class hierarchy. Not executed at runtime. The generated output was then hand-extended to produce the current Expr.java and Stmt.java.
End of PCB Language Comprehensive Technical State Report. All content derived from direct code inspection of the live codebase as of 2026-04-30.