Uses 911K of libraries. Compilation Failed (4496L/23K).
!7 cprint { class State extends ProbabilisticMachine2.State { ImmutableListWalker<S> inputWalker; Chain stack; public State makeDescendant() { State s = prepareDescendant(new State); s.inputWalker = inputWalker; s.stack = stack; ret s; } void doneWithSubroutine { if (stack == null) ret; State s = makeDescendant(); s.stack = dropFirst(s.stack); process(s, first(stack)); } void step { doneWithSubroutine(); } } record SequenceCons(a, b) > State { void step { State s = makeDescendant(); s.stack = chainPlus(s.stack, b); process(s, a); } } record grab(S what) > Executable { void step(State state) { if (state.inputWalker.atEnd()) ret; S token = state.inputWalker!; if (eq(token, what)) { State s = state.makeDescendant(); s.inputWalker = s.inputWalker.next(); } } } class EndOfInput > Executable { void step(State state) { print("end of input reached"); super.step(); } } // what: string or a GrammarClass Executable sequence(O... steps) { if (empty(steps)) ret new Executable; ret foldl_noSeed((a, b) -> new SequenceCons(a, b), steps); } start-thread { Sequence main = sequence( new grab("Hello"), new grab("world"), new EndOfInput); printIndentedStruct(main); S input = "Hello world"; new ProbabilisticMachine2 pm; pm.withState(new State { { inputWalker = new ImmutableListWalker(javaTokC(input)); } }, r { main.step(pm.currentState!); }); stepAllWithStats(pm); } }
Began life as a copy of #1030667
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030671 |
Snippet name: | Superpositional Parsing Spike, simpler version [dev.] |
Eternal ID of this version: | #1030671/2 |
Text MD5: | b8283c014609ff5e42bd6fc5fa981964 |
Transpilation MD5: | e2429af447048028edff3a2fcc9a9d22 |
Author: | stefan |
Category: | javax / gazelle |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-02-25 22:23:44 |
Source code size: | 1771 bytes / 78 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 201 / 256 |
Version history: | 1 change(s) |
Referenced in: | #1030672 - ProbabilisticMachine2 with continuations Spike [dev.] |