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

65
LINES

< > BotCompany Repo | #1002015 // Java Interpreter (hotwirable)

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

Libraryless. Click here for Pure Java version (628L/5K/15K).

1  
!752
2  
3  
static O interpret(S java) {
4  
  ret new JavaInterpreter().interpret(java);
5  
}
6  
7  
// to trigger function inclusion
8  
9  
static void dummy() {
10  
  eq(null, null);
11  
  collapseWord(null);
12  
}
13  
14  
static class JavaInterpreter {
15  
  int i;
16  
  L<S> tok;
17  
  L<S> allowedFunctions = litlist("eq", "collapseWord");
18  
  
19  
  O interpret(S java) {
20  
    i = 1;
21  
    tok = javaTok(java);
22  
    if (litlist("ret", "returns").contains(get(tok, i))) {
23  
      i += 2;
24  
      O result = expression();
25  
      consume(";");
26  
      ret result;
27  
    }
28  
    
29  
    throw fail("huh? " + i + " " + get(tok, i));
30  
  }
31  
  
32  
  void consume(S x) {
33  
    assertEquals(get(tok, i), x);
34  
    i += 2;
35  
  }
36  
  
37  
  S consume() {
38  
    S t = t();
39  
    assertNotNull(t);
40  
    i += 2;
41  
    ret t;
42  
  }
43  
  
44  
  S t() {
45  
    ret get(tok, i);
46  
  }
47  
  
48  
  O expression() {
49  
    if (isQuoted(t()))
50  
      ret unquote(consume());
51  
    if (isIdentifier(t())) {
52  
      S fname = consume();
53  
      consume("(");
54  
      new L args;
55  
      while (neq(t(), ")")) {
56  
        args.add(expression());
57  
        if (eq(t(), ","))
58  
          consume();
59  
      }
60  
      consume(")");
61  
      ret call(mainClass(), fname, toObjectArray(args));
62  
    }
63  
    throw fail(t());
64  
  }
65  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002015
Snippet name: Java Interpreter (hotwirable)
Eternal ID of this version: #1002015/1
Text MD5: 0af211027b0c00b87d68af2a84a605e9
Transpilation MD5: e9d7b9c8518ab6fe24c691dd73b1aa74
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-13 19:12:44
Source code size: 1215 bytes / 65 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 643 / 957
Referenced in: [show references]