Inheritance: ExprOrStmt
Exemplo n.º 1
0
 private static void TopStmtTyCheck_ParamsDecl(KStatement stmt, Syntax syn, KGamma gma)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 2
0
 public static void ExprTyCheck_Expr(KStatement stmt, Syntax syn, KGamma gma)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 // static KMETHOD ParseExpr_Parenthesis(CTX, ksfp_t *sfp _RIX)
 private static KonohaExpr ParseExpr_Parenthesis(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int s, int c, int e)
 {
     Token tk = tls[c];
     if(s == c) {
         KonohaExpr expr = stmt.newExpr2(ctx, tk.Sub, 0, tk.Sub.Count);
         return KModSugar.Expr_rightJoin(ctx, expr, stmt, tls, s + 1, c + 1, e);
     }
     else {
         KonohaExpr lexpr = stmt.newExpr2(ctx, tls, s, c);
         if(lexpr == null) {
             return null;
         }
         if (lexpr.syn == null)
         {
             lexpr.syn = stmt.ks.GetSyntax(lexpr.tk.Keyword);
         }
         if(lexpr.syn.KeyWord == KeywordType.DOT) {
             lexpr.syn = stmt.ks.GetSyntax(KeywordType.ExprMethodCall); // CALL
         }
         else if(lexpr.syn.KeyWord != KeywordType.ExprMethodCall) {
             Console.WriteLine("function calls  .. ");
             syn = stmt.ks.GetSyntax(KeywordType.Parenthesis);    // (f null ())
             lexpr  = new ConsExpr(ctx, syn, lexpr, null);
         }
         stmt.addExprParams(ctx, lexpr, tk.Sub, 0, tk.Sub.Count, true/*allowEmpty*/);
         return KModSugar.Expr_rightJoin(ctx, lexpr, stmt, tls, s + 1, c + 1, e);
     }
 }
Exemplo n.º 6
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;
     }
 }
Exemplo n.º 7
0
 private static void ExprTyCheck_MethodCall(KStatement stmt, Syntax syn, KGamma gma)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 private static KonohaExpr ParseExpr_Dot(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int s, int c, int e)
 {
     Console.WriteLine("s={0}, c={1}", s, c);
     Debug.Assert(s < c);
     if (isFieldName(tls, c, e))
     {
         KonohaExpr expr = stmt.newExpr2(ctx, tls, s, c);
         expr = new ConsExpr(ctx, syn, tls[c + 1], expr);
         return KModSugar.Expr_rightJoin(ctx, expr, stmt, tls, c + 2, c + 2, e);
     }
     if (c + 1 < e) c++;
     return new ConsExpr(ctx, syn, tls[c], ReportLevel.ERR, "expected field name: not " + tls[c].Text);
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
0
 // ast.h
 // static KMETHOD UndefinedParseExpr(CTX, ksfp_t *sfp _RIX)
 public static KonohaExpr UndefinedParseExpr(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int start, int c, int end)
 {
     Token tk = tls[c];
     ctx.SUGAR_P(ReportLevel.ERR, tk.ULine, 0, "undefined expression parser for '{0}'", tk.Text);
     return null;
 }
Exemplo n.º 13
0
 // static KMETHOD ParseExpr_Term(CTX, ksfp_t *sfp _RIX)
 public static KonohaExpr ParseExpr_Term(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int s, int c, int e)
 {
     Debug.Assert(s == c);
     Token tk = tls[c];
     KonohaExpr expr = new TermExpr();
         //new_W(Expr, SYN_(kStmt_ks(stmt), tk->kw));
     //Expr_setTerm(expr, 1);
     expr.tk = tk;
     return Expr_rightJoin(ctx, expr, stmt, tls, s + 1, c + 1, e);
 }
Exemplo n.º 14
0
 // static KMETHOD ParseExpr_Op(CTX, ksfp_t *sfp _RIX)
 public static KonohaExpr ParseExpr_Op(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int s, int c, int e)
 {
     Token tk = tls[c];
     KonohaExpr expr = null;
     KonohaExpr rexpr = stmt.newExpr2(ctx, tls, c + 1, e);
     KMethod mn = (s == c) ? syn.Op1 : syn.Op2;
     if (mn != null && syn.ExprTyCheck == ctx.kmodsugar.UndefinedExprTyCheck)
     {
         //kToken_setmn(tk, mn, (s == c) ? MNTYPE_unary: MNTYPE_binary);
         syn = stmt.ks.GetSyntax(KeywordType.ExprMethodCall);  // switch type checker
     }
     if (s == c)
     { // unary operator
         expr = new ConsExpr(ctx, syn, tk, rexpr);
     }
     else
     {   // binary operator
         KonohaExpr lexpr = stmt.newExpr2(ctx, tls, s, c);
         expr = new ConsExpr(ctx, syn, tk, lexpr, rexpr);
     }
     return expr;
 }
Exemplo n.º 15
0
 // static kExpr *Expr_rightJoin(CTX, kExpr *expr, kStmt *stmt, kArray *tls, int s, int c, int e)
 public static KonohaExpr Expr_rightJoin(Context ctx, KonohaExpr expr, KStatement stmt, IList<Token> tls, int s, int c, int e)
 {
     if(c < e && expr != null) {
         //WARN_Ignored(_ctx, tls, c, e);
     }
     return expr;
 }