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

69
LINES

< > BotCompany Repo | #1003257 // Lesson 1 - The "Super Precise" Engine

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

Libraryless. Click here for Pure Java version (1751L/12K/39K).

1  
!759 // the up-to-date JavaX translator
2  
3  
sclass C { // "sclass" is short for "static class" (JavaX)
4  
  char c;
5  
  bool output;
6  
  
7  
  *() {}
8  
  *(char *c, bool *output) {}
9  
}
10  
11  
sS poemID = "#1003260"; // test dialog
12  
static new L<C> script;
13  
sint i = 0;
14  
sbool fail;
15  
16  
p { // the main program is called "p" in JavaX (for "PROGRAM", or "PUBLIC static void main")
17  
  //addOutput("Hello world!\n"); // simple tester instead of loading poem from website
18  
  
19  
  for (E e : parsePoem(poemID)) {
20  
    if (e.q != null)
21  
      addInput(e.q + "\n");
22  
    else if (e.a != null)
23  
      addOutput(e.a + "\n");
24  
  }
25  
  
26  
  loop();
27  
}
28  
29  
svoid loop() {
30  
  printOut();
31  
  S line;
32  
  while ((line = readLine()) != null) {
33  
    for (char c : chars(line + "\n"))
34  
      onIncomingCharacter(c);
35  
    printOut();
36  
  }
37  
}
38  
39  
svoid addOutput(S text) {
40  
  for (char c : asChars(text))
41  
    script.add(new C(c, true));
42  
}
43  
44  
svoid addInput(S text) {
45  
  for (char c : asChars(text))
46  
    script.add(new C(c, false));
47  
}
48  
49  
svoid onIncomingCharacter(char c) {
50  
  if (fail || get(script, i) == null)
51  
    charPut("?");
52  
  else {
53  
    C x = get(script, i);
54  
    assertFalse(x.output);
55  
    if (c == x.c) {
56  
      ++i;
57  
      printOut();
58  
    } else {
59  
      fail = true;
60  
      charPut("?");
61  
    }
62  
  }
63  
}
64  
65  
svoid printOut() {
66  
  while (!fail && get(script, i) != null && get(script, i).output)
67  
    charPut(get(script, i++).c);
68  
  charPut_flush();
69  
}

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: #1003257
Snippet name: Lesson 1 - The "Super Precise" Engine
Eternal ID of this version: #1003257/1
Text MD5: 2949c3878f6ca90f76b0f035ccbc762f
Transpilation MD5: 8e9ee01729b2d4d842dbe6e69eac5850
Author: stefan
Category: javax / talking robots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-06-12 20:43:37
Source code size: 1430 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 723 / 786
Referenced in: [show references]