public static Either <Error, Tuple <string, ExpressionBuilder> > Expr4(string s) { Either <Error, Tuple <string, ExpressionBuilder> > res1 = ExprTerm(s); if (res1.IsLeft) { return(res1.Left); } Tuple <string, ExpressionBuilder> t1 = res1.Right; s = Parser.Space(t1.Item1); ExpressionBuilder e1 = t1.Item2; if (!s.StartsWith(".")) { return(new Tuple <string, ExpressionBuilder>(s, e1)); } s = s.Substring(1); Either <Error, Tuple <string, ExpressionBuilder.Op> > res2 = BinaryOp4(s); if (res2.IsLeft) { return(res2.Left); } Tuple <string, ExpressionBuilder.Op> t2 = res2.Right; s = Parser.Space(t2.Item1); ExpressionBuilder.Op op = t2.Item2; if (!s.StartsWith("(")) { return(new Error(s, "missing (")); } s = Parser.Space(s.Substring(1)); Either <Error, Tuple <string, ExpressionBuilder> > res3 = Expr(s); if (res3.IsLeft) { return(res3.Left); } Tuple <string, ExpressionBuilder> t3 = res3.Right; s = Parser.Space(t3.Item1); if (!s.StartsWith(")")) { return(new Error(s, "missing )")); } s = Parser.Space(s.Substring(1)); ExpressionBuilder e2 = t3.Item2; return(new Tuple <string, ExpressionBuilder>(s, new ExpressionBuilder.Binary(op, e1, e2))); }
public static Either <Error, Tuple <string, ExpressionBuilder> > Expr(string str) { Either <Error, Tuple <string, ExpressionBuilder> > res1 = Expr1(str); if (res1.IsLeft) { return(res1.Left); } var t1 = res1.Right; str = t1.Item1; ExpressionBuilder builder = t1.Item2; bool errorOrEmpty = false; while (!errorOrEmpty) { str = Parser.Space(str); if (!str.IsEmpty()) { Either <Error, Tuple <string, ExpressionBuilder.Op> > res2 = BinaryOp(str); if (!res2.IsLeft) { Tuple <string, ExpressionBuilder.Op> t2 = res2.Right; str = t2.Item1; ExpressionBuilder.Op op = t2.Item2; str = Parser.Space(str); Either <Error, Tuple <string, ExpressionBuilder> > res3 = Expr1(str); if (res3.IsLeft) { return(res3.Left); } Tuple <string, ExpressionBuilder> t3 = res3.Right; str = t3.Item1; ExpressionBuilder e2 = t3.Item2; builder = new ExpressionBuilder.Binary(op, builder, e2); } else { errorOrEmpty = true; } } else { errorOrEmpty = true; } } return(new Tuple <string, ExpressionBuilder>(str, builder)); }
public static Either <Error, Tuple <string, ExpressionBuilder> > Expr1(string s) { Either <Error, Tuple <string, ExpressionBuilder> > res1 = Expr2(s); if (res1.IsLeft) { return(res1.Left); } Tuple <string, ExpressionBuilder> t1 = res1.Right; s = t1.Item1; ExpressionBuilder e = t1.Item2; bool errorOrEmpty = false; while (!errorOrEmpty) { s = Parser.Space(s); if (s.Length != 0) { Either <Error, Tuple <string, ExpressionBuilder.Op> > res2 = BinaryOp1(s); if (res2.IsRight) { Tuple <string, ExpressionBuilder.Op> t2 = res2.Right; s = t2.Item1; ExpressionBuilder.Op op = t2.Item2; s = Parser.Space(s); Either <Error, Tuple <string, ExpressionBuilder> > res3 = Expr2(s); if (res3.IsLeft) { return(res3.Left); } Tuple <string, ExpressionBuilder> t3 = res3.Right; s = t3.Item1; ExpressionBuilder e2 = t3.Item2; e = new ExpressionBuilder.Binary(op, e, e2); } else { errorOrEmpty = true; } } else { errorOrEmpty = true; } } return(new Tuple <string, ExpressionBuilder>(s, e)); }