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).

!759 // the up-to-date JavaX translator

sclass C { // "sclass" is short for "static class" (JavaX)
  char c;
  bool output;
  
  *() {}
  *(char *c, bool *output) {}
}

sS poemID = "#1003260"; // test dialog
static new L<C> script;
sint i = 0;
sbool fail;

p { // the main program is called "p" in JavaX (for "PROGRAM", or "PUBLIC static void main")
  //addOutput("Hello world!\n"); // simple tester instead of loading poem from website
  
  for (E e : parsePoem(poemID)) {
    if (e.q != null)
      addInput(e.q + "\n");
    else if (e.a != null)
      addOutput(e.a + "\n");
  }
  
  loop();
}

svoid loop() {
  printOut();
  S line;
  while ((line = readLine()) != null) {
    for (char c : chars(line + "\n"))
      onIncomingCharacter(c);
    printOut();
  }
}

svoid addOutput(S text) {
  for (char c : asChars(text))
    script.add(new C(c, true));
}

svoid addInput(S text) {
  for (char c : asChars(text))
    script.add(new C(c, false));
}

svoid onIncomingCharacter(char c) {
  if (fail || get(script, i) == null)
    charPut("?");
  else {
    C x = get(script, i);
    assertFalse(x.output);
    if (c == x.c) {
      ++i;
      printOut();
    } else {
      fail = true;
      charPut("?");
    }
  }
}

svoid printOut() {
  while (!fail && get(script, i) != null && get(script, i).output)
    charPut(get(script, i++).c);
  charPut_flush();
}

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: 722 / 784
Referenced in: #1003260 - Script for "Super Precise" Engine (#1003257)
#1003274 - "Super Precise" Engine As Class