Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

65
LINES

< > BotCompany Repo | #1008783 // "Single Word Parser" Spike 1 [abandoned]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Transpiled version (4162L) is out of date.

1  
!7
2  
3  
sclass Parser {
4  
  new StringTree2 tree;
5  
  
6  
  L<S> tok(S s) { ret javaTok(s); }
7  
  L<S> tokC(S s) { ret javaTokC(s); }
8  
  
9  
  void register(S text, O action) {
10  
    addToStringTree(tree, tokC(text), action);
11  
  }
12  
  
13  
  Parsing parse(S text) {
14  
    ret nu(Parsing,
15  
      parser := this, it := tokC(text).iterator(),
16  
      treesInFlight := ll(new InFlight(tree)));
17  
  }
18  
}
19  
20  
sclass InFlight {
21  
  new L history;
22  
  StringTree2 tree;
23  
  
24  
  *() {}
25  
  *(StringTree2 *tree) {}
26  
  *(L *history, StringTree2 *tree) {}
27  
}
28  
29  
sclass Parsing {
30  
  Parser parser;
31  
  Iterator<S> it;
32  
  new L<InFlight> treesInFlight;
33  
  
34  
  void run {
35  
    while (it.hasNext()) step();
36  
  }
37  
  
38  
  void step {
39  
    S token = it.next();
40  
    for i over treesInFlight: {
41  
      InFlight tree = treesInFlight.get(i);
42  
      StringTree2 tree2 = tree.tree.get(token);
43  
      if (tree2 == null) treesInFlight.remove(i--);
44  
      else treesInFlight.set(i, new InFlight(tree.history, tree2));
45  
    }
46  
    actions();
47  
  }
48  
  
49  
  void actions {
50  
    for (StringTree2 tree : treesInFlight)
51  
      if (tree! != null)
52  
        runAction(tree!);
53  
  }
54  
  
55  
  void runAction(O o) {
56  
    print("Action! " + struct(o));
57  
  }
58  
}
59  
60  
p {
61  
  new Parser p;
62  
  p.register("I am here", "I-am-here");
63  
  Parsing pp = p.parse("yo I am here");
64  
  pp.run();
65  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008783
Snippet name: "Single Word Parser" Spike 1 [abandoned]
Eternal ID of this version: #1008783/7
Text MD5: b2fe80e56b3867c9a33b31421b2365f4
Author: stefan
Category: javax / a.i. parsing
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-02-26 12:22:14
Source code size: 1313 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 466 / 581
Version history: 6 change(s)
Referenced in: [show references]