public CreateBlock ( ExprOrStmt parent, IList |
||
parent | ExprOrStmt | 親のステートメント |
token | IList |
トークン列 |
start | int | 開始トークン位置 |
end | int | 終了トークンの次の位置 |
delim | char | デリミタ |
return | BlockExpr |
// static KMETHOD ParseStmt_Block(CTX, ksfp_t *sfp _RIX) private static int ParseStmt_Block(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tls, int s, int e) { //Console.WriteLine("ParseStmt_Block name:" + name.Name); Token tk = tls[s]; if(tk.Type == TokenType.CODE) { stmt.map.Add(name, new CodeExpr(tk)); return s + 1; } var parser = new Parser(ctx, stmt.ks); if (tk.Type == TokenType.AST_BRACE) { BlockExpr bk = parser.CreateBlock(stmt, tk.Sub, 0, tk.Sub.Count, ';'); stmt.map.Add(name, bk); return s + 1; } else { BlockExpr bk = parser.CreateBlock(stmt, tls, s, e, ';'); stmt.map.Add(name, bk); return e; } }
// static kstatus_t KonohaSpace_eval(CTX, kKonohaSpace *ks, const char *script, kline_t uline) public dynamic Eval(string script) { var tokens = tokenize(script); var parser = new Parser(ctx, this); var converter = new Converter(ctx, this); var block = parser.CreateBlock(null, tokens, 0, tokens.Count(), ';'); dynamic ast = converter.Convert(block); string dbv = typeof(Expression).InvokeMember("DebugView", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty, null, ast, null); Console.WriteLine("### DLR AST Dump ###"); Console.WriteLine(dbv); var f = ast.Compile(); return f(); }