STREAM Grammar Header Lab

Draft v0.1 packs a log fact into a fixed-width header — 5 characters, or 10 extended. This lab explores the v0.2 question: what if the numbers in the header do their packing work as numbers, read by a small parser — decimal runs, base-36 runs, and factored durations like t1d — so the header becomes a tiny grammar instead of a fixed bitfield, and the time delta has no 4,095 ceiling?

Lab prototype. This page is a working sketch of a proposed grammar form (called G1 here). It is not the Rust kernel and not Loom, and it does not change Draft v0.1 — the adopted 5+5 fixed layout stands exactly as written. Everything runs in your browser; nothing is saved or sent anywhere.

1 · The grammar at a glance

A grammar header starts with # — a character outside the v0.1 alphabet, so a reader can tell grammar form from fixed form at the first character — then three packed characters, then a number run the parser reads by its first character, then an optional extension. A space ends the header and the payload follows.

TokenFormWhat it carries
#1 character, alwaysGrammar marker. Not in the v0.1 alphabet (A–Z a–z 0–9 -_), so the two forms can never be confused.
packed3 base-64 characters, 18 bitsPosition 7 · phase 2 · modality 1 · direction 1 · role presence 4 · estimate 1 · change 1 · extended-follows 1 — the v0.1 short fields except the time delta, which moves out into the run.
delta runVariable lengthTime delta. First character chooses the reading: a digit starts a decimal run (digits until the first non-digit, no ceiling); z starts a base-36 run (0–9 A–Z); t starts a factored run of number+unit pairs (d=86400, h=3600, m=60, s=1). No run at all means delta 0.
+1 character, only if extended-follows = 1Extension marker. Sits where the delta run ended — the parser knows the run is over because a non-digit (or a unit boundary) stopped it.
absence2 base-64 characters, 12 bitsAbsence kind per role, 3 bits each (subject, object, kind, measure): 0 present · 1 not-yet · 2 unknown · 3 withheld · 4 not-applicable · 5 refused · 6 ambiguous · 7 reserved.
check1 base-64 character, 6 bitsXOR-fold of the packed value, absence value, delta and index. It sits at a fixed offset — before the index run — on purpose: the index run is variable-length and must be last so it ends at the space, while the check stays findable without parsing the run first. Short headers carry no check character, exactly as in v0.1.
index runVariable length, lastDictionary index, as a decimal or base-36 run under the same mode rules as the delta — never factored.
(space)1 characterEnds the header. Everything after it is payload.

Parser walkthrough — #Uph5+ACc7

StepTextThe parser reads
1#Grammar marker — this is grammar form, not v0.1 fixed form.
2Uph3 packed characters = 18 bits: position 41, phase 1 (begin), modality 0, direction 0, roles subject+object present, estimate 0, change 0, extended-follows 1.
35First character is a digit, so a decimal run: digits until the first non-digit. The next character is +, so the run ends here — delta = 5.
4+Extension marker — expected, because extended-follows was 1.
5AC2 absence characters = 12 bits: subject present, object present, kind present, measure unknown (2).
6cCheck character at its fixed offset: value 28. The parser later folds the packed, absence, delta and index values and compares.
77Index run: a digit, so decimal — index = 7. It runs to the end of the header.
8(space)Ends the header; the payload follows. Check verifies: stored 28 = computed 28. This is preset B below.

2 · Live encoder

Set the fields; the grammar header, its token breakdown, and the v0.1 fixed-width header for the same fields update live. The encoder's AUTO run mode picks the shorter of decimal vs z+base-36, decimal on ties; factored is a manual choice.

Flags
Roles present
Header form
—

Token breakdown

TokenTextReading
Grammar form (G1)
—
Draft v0.1 fixed form — same fields
—

3 · Decoder

Paste a grammar header (a payload after a space is fine — the header ends at the space). Malformed headers produce a readable error, never a crash. Extended headers have their check character verified.

Token trace

TokenTextReading
Nothing decoded yet.

4 · Presets side by side

The three reference presets, in both forms. Grammar forms here use AUTO run mode unless a form is named.

PresetDraft v0.1Grammar (G1)

The prefix property

The grammar header's first two characters are identical to the v0.1 header's first two — QT…, Up…, I5…. The third character differs only in its lowest bit: v0.1 spends that bit on the top bit of its 12-bit delta, while the grammar spends it on extended-follows (the rest of the delta having moved out into the run). Same head, one bit re-purposed — the two forms are cousins, not strangers.

5 · The trade — what a delta costs

Drag the delta and compare run lengths. Decimal is plain and ceiling-free but spends a whole character on ~3.32 bits; base-36 spends the z on a denser run; factored wins only when the duration is round in days, hours or minutes.

Encoding of the deltaRunCharactersVerdict
Delta 4096 — the overflow caseDecimal run "4096" costs 4 characters and has no ceiling. That one row is the whole argument: 4096 is the first value v0.1's 12-bit delta cannot hold at all, and the grammar holds it for four plain digits.

6 · Overflow worked example — delta 86,400 (24 hours)

Preset A's fields with a delta of 86,400 seconds. v0.1 cannot hold this — its 12-bit delta caps at 4,095 — so in v0.1 this line would need an absolute time in the payload or a new segment. The grammar holds it three ways; each form below is encoded and decoded live, here on the page.

Run modeGrammar headerCharsLive round-trip

Factored wins here — #QTot1d at 7 characters — because 86,400 is exactly one day. That is the factored run's whole niche: round durations compress; arbitrary ones do not.

7 · Self-test

Runs on load and on the button: the three presets in every run mode, a few hundred random round-trips (short and extended, all run modes), single-character corruptions of extended headers, and malformed headers that must be rejected with readable errors. Exact counts are shown — a failure would be shown as a failure.

8 · Honest limits

What the grammar gives up, stated plainly. None of this is hidden in the sections above; it is gathered here so the trade is on one screen.