Uses 911K of libraries. Compilation Failed (4422L/23K).
!7 cprint { srecord Superposition(Cl options) { *(O... options) { this.options = asList(options); } } 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); } } asclass GrammarClass {} sclass Statement > GrammarClass {} abstract class Executable { abstract void step(State state) {} } record grab(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(); } } } // what: string or a GrammarClass 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 { Superposition main = sequence( new Superposition( sequence( new grab("I"), new grab("think"), new Superposition( sequence( new grab("that"), new grab(Statement) ), new grab(Statement) ) ), sequence( new grab("Do"), new grab("you"), new grab("think"), new grab("that"), new grab(Statement), new grab("?") ), new grab(Statement) ), new EndOfInput); printIndentedStruct(main); S input = "I think that you're right"; new ProbabilisticMachine2 pm; State state = pm.addState(new State); state.inputWalker = new ImmutableListWalker(javaTokC(input)); process(state, main); } void process(State state, O code) { if (code cast Superposition) { fOr (O option : code.options) pm.addState(state.prepareDescendant(new State { void step { process(state, option); } })); } else if (code cast Executable) { pm.addState(new State { void step { code.step(state, code); } }); } else fail("Unknown code type: " + code); } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030667 |
Snippet name: | Superpositional Parsing Spike [dev.] |
Eternal ID of this version: | #1030667/11 |
Text MD5: | ab7a2476cb382aaddd4111602b68ae54 |
Transpilation MD5: | 704e84cc76d42c8b914e331298078fca |
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:24:53 |
Source code size: | 2984 bytes / 123 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 218 / 424 |
Version history: | 10 change(s) |
Referenced in: | #1030671 - Superpositional Parsing Spike, simpler version [dev.] |