A computable, self-delimiting parser for E #
This is the parser for AdditiveComplexity.E, the prefix (Polish-form) AST
serialization of CodeLayer/AdditiveComplexity.lean. E is a prefix code by construction
(E_append_inj); this module exhibits the computable decoder that recovers a serialized
program and its trailing bits from any description, discharging EParserSpec.
What this establishes #
parseE,primrec_parseE: a total,PrimrecparserList Bool → Option (Code × List Bool).parseE_E_append:parseErecovers exactly(e, r)from anyE e ++ r.parseE_eq_some: the domain characterization — a successful parse consumed exactly a serialization,parseE w = some (e, r) → w = E e ++ r.EParserSpec,eParserSpec: the parser specification and its packaged witness.
What this does NOT establish (flagged) #
- Nothing beyond the parser, its specification and the witness.
The parser specification. A computable parser recovering a serialized machine e and its
trailing argument r from any description E e ++ r — and ONLY from a description of that
shape.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The parser: a nested fold over an explicit stack of open frames #
The 3-bit opcode of an E-node, in the same order E itself matches on.
Instances For
An open frame on the parse stack: a node's opcode together with the children parsed for it so far, in the order they were parsed.
Instances For
The number of children a tag's node takes: 0 for the four leaves, 2 for pair/comp/
prec, 1 for rfind' — read off E's own case split.
Equations
- AdditiveComplexity.opArity t = bif t.1 then bif t.2.1 && t.2.2 then 1 else 2 else 0
Instances For
Builds the Code a completed tag denotes from its (already-parsed) children, taken in the
order collected. Only ever applied where cs.length = opArity t (opArity_buildOp_eq_E
records what this produces there); off that domain cs.headI/cs.tail.headI pad with a junk
default and the result carries no meaning.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One step of absorbing a newly-completed child c into the innermost open frame: if it
completes that frame, the built code becomes the next child to absorb into the frame below
(cascading); otherwise absorption stops there, and every frame from that point on (the state's
first component turns false) passes through unchanged.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Absorbs a newly-completed code c0 into a parse stack, cascading as far as it goes: true
with the completed top-level code if the whole stack collapses, false with the resulting
(shorter or equal-length) stack otherwise.
Equations
- AdditiveComplexity.absorbFold stack c0 = List.foldl AdditiveComplexity.absorbStep (true, c0, []) stack
Instances For
The parser's running state: the partial (0/1/2-bit) tag being read, the stack of open frames (innermost first), and, once a top-level code has been read off, its slot together with every bit seen since.
Equations
Instances For
One bit's transition: if the slot is already filled, the bit is just appended to the trailing remainder; otherwise it extends the partial tag, and a completed 3-bit tag either opens a new frame (arity > 0) or is immediately absorbed (arity 0, a leaf).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Folds bitStep over a bit-list from the fresh state.
Instances For
The parser. Total; primrec_parseE below is its computability, parseE_E_append and
parseE_eq_some its correctness.
Equations
Instances For
Bit-level identities #
absorbFold: reconstruction #
The main forward invariant, and parseE_eq_some #
parseE recovers a serialization: parseE_E_append #
parseE recovers exactly what E serialized, together with any trailing bits. The
second clause of EParserSpec.
parseE is Primrec. The first clause of EParserSpec.