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

32
LINES

< > BotCompany Repo | #1017737 // Parse Tree Matching Spike [dev.]

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

Download Jar. Libraryless. Click here for Pure Java version (11139L/82K).

1  
!7
2  
3  
p-exp {
4  
  PTElement input = ai_parseToCulledTree("What is {this funny thing}");
5  
  PTElement pat = ai_parseToCulledTree("What is X");
6  
  
7  
  matchTrees(input, pat);
8  
}
9  
10  
svoid matchTrees(PTElement pat, PTElement input) {
11  
  print("Matching: " + pat + " / " + input);
12  
  if (pat == null || input == null) ret;
13  
  if (pat instanceof ChooseCategory && input instanceof ChooseCategory) {
14  
    HaveCategory l = cast first(pat.children);
15  
    HaveCategory r = cast first(input.children);
16  
    if (l != null && r != null && eq(l.category, r.category)) {
17  
      print("Using category: " + l.category);
18  
      matchTrees(l, r);
19  
    }
20  
    ret;
21  
  }
22  
  if (pat instanceof HaveCategory && input instanceof HaveCategory) {
23  
    matchTrees(first(pat.children), first(input.children));
24  
    ret;
25  
  }
26  
  if (pat instanceof ChoosePart && input instanceof ChoosePart) {
27  
    for i to 2:
28  
      matchTrees(pat.children.get(i), input.children.get(i));
29  
    ret;
30  
  }
31  
  print("Non-matching classes: " + className(pat) + " vs " + className(input));
32  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017737
Snippet name: Parse Tree Matching Spike [dev.]
Eternal ID of this version: #1017737/9
Text MD5: 987316029676575b4d84ff5a69c8e0c4
Transpilation MD5: 120ffd9eba6e394a9b00e9661bbc7381
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-05 20:01:58
Source code size: 1041 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 409 / 911
Version history: 8 change(s)
Referenced in: [show references]