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

71
LINES

< > BotCompany Repo | #1002683 // Parsing Simplified NL (dev.)

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

Libraryless. Click here for Pure Java version (3196L/21K/69K).

1  
!759
2  
3  
static boolean printNulls = true, full = true;
4  
5  
static L<S> inputs = toLinesFullTrim([[
6  
  hello
7  
  "hello!"
8  
  hello you
9  
  hello < you
10  
  [hello]
11  
  [hello] [you]
12  
  [hello < you]
13  
  
14  
  [ ? < Is < it < safe < to < allow [PowerTOP] to [make < all < the < changes < located on < the < Tunables < tab] ]
15  
  [ I < was < going to < create < a < startup script < for < it ]
16  
]]);
17  
18  
static S snlRules = [[
19  
  // highest (strongest binding) level 
20  
  <identifier> = idword
21  
  <quoted> = subword
22  
  ? = idword
23  
  ! = idword
24  
  
25  
  <subword> = word
26  
  <idword> = word
27  
  
28  
  // juxtaposition on highest level
29  
  <word> <word> = word
30  
  
31  
  // bracketing takes us to highest level
32  
  [ <lowest> ] = subword
33  
  ( <lowest> ) = subword
34  
  
35  
  // < is intermediate
36  
  <word> = arrows
37  
  <word> < <arrows> = arrows
38  
  
39  
  = lowest // allow empty here
40  
  <arrows> = lowest
41  
]];
42  
43  
p {
44  
  for (S input : inputs) {
45  
    Explain exp = full
46  
      ? explainFull(input, snlRules, "lowest")
47  
      : explain(input, snlRules, "lowest");
48  
    print();
49  
    print("PARSING: " + input);
50  
    print();
51  
    if (exp == null)
52  
      print("No parse");
53  
    else {
54  
      //printStructure(exp.e);
55  
      printTree(0, exp);
56  
    }
57  
    print();
58  
  }
59  
}
60  
61  
static void printTree(int indent, Explain e) {
62  
  if (e == null) {
63  
    // this would print "null" for every <identifier> etc
64  
    if (printNulls)
65  
      print(indent(indent) + "null");
66  
  } else {
67  
    print(indent(indent) + e.className() + " | " + e.string());
68  
    for (Explain sub : e.subs)
69  
      printTree(indent+2, sub);
70  
  }
71  
}

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: #1002683
Snippet name: Parsing Simplified NL (dev.)
Eternal ID of this version: #1002683/1
Text MD5: fce1f37cafbc47462d56645f858ed8aa
Transpilation MD5: b1c76008175b872c594dd4809c4a70f6
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-13 20:12:08
Source code size: 1573 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 744 / 783
Referenced in: [show references]