Libraryless. Click here for Pure Java version (2043L/14K/47K).
1 | !752 |
2 | |
3 | static S inputText = [[ |
4 | a point contains an "x coordinate" |
5 | a point contains an "y coordinate" |
6 | p is a point |
7 | |
8 | A is a B |
9 | a B contains a C |
10 | -> A contains a C |
11 | ]]; |
12 | |
13 | static new L<S> statements; |
14 | static new L<Rule> rules; |
15 | |
16 | p { |
17 | inputText = anToA(inputText); |
18 | L<S> log = toLinesTrim2(inputText); |
19 | L<Int> emptyLines = concatLists(ll(-1), indexesOf(log, ""), ll(l(log))); |
20 | for (int ii = 0; ii+1 < l(emptyLines); ii++) { |
21 | int i = emptyLines.get(ii), j = emptyLines.get(ii+1); |
22 | L<S> l = subList(log, i+1, j); |
23 | continue if empty(l); |
24 | L<Int> arrows = indexesOfLinesStartingWith(l, "->"); |
25 | if (empty(arrows)) |
26 | statements.addAll(l); |
27 | } |
28 | |
29 | rules = parseRules(inputText); |
30 | |
31 | print("Rules:"); |
32 | pslIndent(rules); |
33 | |
34 | print("Statements:"); |
35 | printIndented(nlPrettyPrint(statements)); |
36 | |
37 | L<S> newStatements = inferStuff(); |
38 | print("New statements:"); |
39 | printIndented(nlPrettyPrint(newStatements)); |
40 | } |
41 | |
42 | static L<S> inferStuff() { |
43 | genLog_set(new L(statements)); |
44 | for (Rule rule : rules) { |
45 | L<SS> matches = asList(gSatAnd(rule.in)); |
46 | for (S out : rule.out) |
47 | for (SS match : matches) |
48 | gAdd(replaceVars_autoQuote(out, match)); |
49 | } |
50 | ret new L(subList(gLog(), l(statements))); |
51 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004474 |
Snippet name: | A point contains... |
Eternal ID of this version: | #1004474/1 |
Text MD5: | 9d4c6c68eda47a714afb8d299782a10e |
Transpilation MD5: | ea35cfcbbeeb2ce4d6114014c133014b |
Author: | stefan |
Category: | javax / talking robots |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-18 20:41:59 |
Source code size: | 1268 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 588 / 712 |
Referenced in: | [show references] |