示例#1
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);
 }
示例#2
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);
     }
 }
示例#3
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;
 }