示例#1
0
 public static Symbol Get(Context ctx, string name, Symbol def, SymPol pol)
 {
     /*if (pol == SYMPOL_RAW)
     {
         return ctx.share.SymbolMap[name];
     }
     else
     {
         ksymbol_t sym, mask = 0;
         name = ksymbol_norm(buf, name, &len, &hcode, &mask, pol);
         sym = Kmap_getcode(_ctx, _ctx->share->symbolMapNN, _ctx->share->symbolList, name, len, hcode, SPOL_ASCII, def);
         if(def == sym) return def;
         return sym | mask;
     }*/
     if (!ctx.share.SymbolMap.ContainsKey(name))
     {
         ctx.share.SymbolMap.Add(name, new Symbol() { Name = name });
     }
     return ctx.share.SymbolMap[name];
 }
示例#2
0
 // static KMETHOD ParseStmt_Toks(CTX, ksfp_t *sfp _RIX)
 private static int ParseStmt_Toks(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tls, int s, int e)
 {
     if (s < e)
     {
         var a = new List<Token>();
         while (s < e)
         {
             a.Add(tls[s]);
             s++;
         }
         //kObject_setObject(stmt, name, a);
         //stmt.map.Add(name, a);
         throw new NotImplementedException();
         return e;
     }
     return -1;
 }
示例#3
0
 // static int ParseStmt(CTX, ksyntax_t *syn, kStmt *stmt, ksymbol_t name, kArray *tls, int s, int e)
 public int ParseStmt(Context ctx, Syntax syn, Symbol name, IList<Token> tls, int s, int e)
 {
     //Console.WriteLine("ParseStmt {0}, {0}", name.Name, tls[s].Text);
     return syn.ParseStmt(ctx, this, syn, name, tls, s, e);
 }
示例#4
0
 // 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;
     }
 }
示例#5
0
 // static KMETHOD ParseStmt_Params(CTX, ksfp_t *sfp _RIX)
 private static int ParseStmt_Params(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tokens, int s, int e)
 {
     int r = -1;
     Token tk = tokens[s];
     if (tk.Type == TokenType.AST_PARENTHESIS)
     {
         var tls = tk.Sub;
         int ss = 0;
         int ee = tls.Count;
         if (0 < ee && tls[0].Keyword == KeywordType.Void) ss = 1;  //  f(void) = > f()
         BlockExpr bk = new Parser(ctx, stmt.ks).CreateBlock(stmt, tls, ss, ee, ',');
         stmt.map.Add(name, bk);
         r = s + 1;
     }
     return r;
 }
示例#6
0
 public static int ParseStmt_Usymbol(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tls, int s, int e)
 {
     int r = -1;
     Token tk = tls[s];
     if (tk.Type == TokenType.USYMBOL)
     {
         stmt.map.Add(name, new SingleTokenExpr(tk));
         r = s + 1;
     }
     return r;
 }
示例#7
0
 public static int ParseStmt_Type(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tls, int s, int e)
 {
     int r = -1;
     Token tk = tls[s];
     if (tk.IsType)
     {
         //kObject_setObject(stmt, name, tk);
         stmt.map.Add(name, new SingleTokenExpr(tk));
         r = s + 1;
     }
     return r;
 }
示例#8
0
 public static int ParseStmt_Expr(Context ctx, KStatement stmt, Syntax syn, Symbol name, IList<Token> tls, int s, int e)
 {
     int r = -1;
     var expr = stmt.newExpr2(ctx, tls, s, e);
     if (expr != null)
     {
         //dumpExpr(_ctx, 0, 0, expr);
         //kObject_setObject(stmt, name, expr);
         stmt.map.Add(name, expr);
         r = e;
     }
     return r;
 }
示例#9
0
 public KKeyWord kmap_getcode(string name, SPOL spol, Symbol def)
 {
     if (keywordMap.ContainsKey(name))
     {
         return keywordMap[name];
     }
     if (def == Symbol.NewID)
     {
         //keywordList.Add(name);
         //keywordMap.Add(name, null);
     }
     return null;
 }
示例#10
0
 public KKeyWord keyword_(string name, Symbol def)
 {
     return kmap_getcode(name, SPOL.ASCII | SPOL.POOL, def);
 }