// 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); } }
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; }
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); }
// 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; }