Uses 911K of libraries. Compilation Failed (4496L/23K).
1 | !7 |
2 | |
3 | cprint {
|
4 | class State extends ProbabilisticMachine2.State {
|
5 | ImmutableListWalker<S> inputWalker; |
6 | Chain stack; |
7 | |
8 | public State makeDescendant() {
|
9 | State s = prepareDescendant(new State); |
10 | s.inputWalker = inputWalker; |
11 | s.stack = stack; |
12 | ret s; |
13 | } |
14 | |
15 | void doneWithSubroutine {
|
16 | if (stack == null) ret; |
17 | State s = makeDescendant(); |
18 | s.stack = dropFirst(s.stack); |
19 | process(s, first(stack)); |
20 | } |
21 | |
22 | void step {
|
23 | doneWithSubroutine(); |
24 | } |
25 | } |
26 | |
27 | record SequenceCons(a, b) > State {
|
28 | void step {
|
29 | State s = makeDescendant(); |
30 | s.stack = chainPlus(s.stack, b); |
31 | process(s, a); |
32 | } |
33 | } |
34 | |
35 | record grab(S what) > Executable {
|
36 | void step(State state) {
|
37 | if (state.inputWalker.atEnd()) ret; |
38 | S token = state.inputWalker!; |
39 | if (eq(token, what)) {
|
40 | State s = state.makeDescendant(); |
41 | s.inputWalker = s.inputWalker.next(); |
42 | } |
43 | } |
44 | } |
45 | |
46 | class EndOfInput > Executable {
|
47 | void step(State state) {
|
48 | print("end of input reached");
|
49 | super.step(); |
50 | } |
51 | } // what: string or a GrammarClass |
52 | |
53 | Executable sequence(O... steps) {
|
54 | if (empty(steps)) ret new Executable; |
55 | ret foldl_noSeed((a, b) -> new SequenceCons(a, b), steps); |
56 | } |
57 | |
58 | start-thread {
|
59 | Sequence main = sequence( |
60 | new grab("Hello"),
|
61 | new grab("world"),
|
62 | new EndOfInput); |
63 | |
64 | printIndentedStruct(main); |
65 | |
66 | S input = "Hello world"; |
67 | new ProbabilisticMachine2 pm; |
68 | pm.withState(new State {
|
69 | {
|
70 | inputWalker = new ImmutableListWalker(javaTokC(input)); |
71 | } |
72 | }, r {
|
73 | main.step(pm.currentState!); |
74 | }); |
75 | |
76 | stepAllWithStats(pm); |
77 | } |
78 | } |
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: | 474 / 581 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |