public new static TWhile Claim(StringClaimer claimer) { Claim failpoint = claimer.FailPoint(); Claim c = claimer.Claim(While); if (!c.Success) { failpoint.Fail(); return(null); } TExpression condition = TExpression.Claim(claimer); if (condition == null) { failpoint.Fail(); return(null); } TExpression action = TExpression.Claim(claimer); TWhile whileBlock = new TWhile { _condition = condition, _action = action }; return(whileBlock); }
public new static TProgram Claim(StringClaimer claimer) { TProgram prog = new TProgram(); TExpression e; while ((e = TExpression.Claim(claimer)) != null) { claimer.Claim(SemiColon); prog._expressions.Add(e); } return(prog); }
public new static TIf Claim(StringClaimer claimer) { Claim failpoint = claimer.FailPoint(); Claim c = claimer.Claim(If); if (!c.Success) { failpoint.Fail(); return(null); } TExpression condition = TExpression.Claim(claimer); if (condition == null) { failpoint.Fail(); return(null); } TExpression action = TExpression.Claim(claimer); TIf ifblock = new TIf { _condition = condition, _action = action }; c = claimer.Claim(Else); if (!c.Success) { return(ifblock); } TExpression otherwise = TExpression.Claim(claimer); if (otherwise == null) { c.Fail(); } else { ifblock._otherwise = otherwise; c.Pass(); } return(ifblock); }
public new static TLeftExpression Claim(StringClaimer claimer) { Claim failTo = claimer.FailPoint(); TExpression newLeft = TExpression.Claim(claimer); if (newLeft == null) { failTo.Fail(); return(null); } newLeft = LeftClaim(claimer, newLeft); if (newLeft != null) { return((TLeftExpression)newLeft); } failTo.Fail(); return(null); }
public new static TLeftExpression LeftClaim(StringClaimer claimer, TExpression left) { Claim failTo = claimer.FailPoint(); TOperator operand = TOperator.Claim(claimer); if (operand == null) { failTo.Fail(); return(null); } TExpression right = TExpression.Claim(claimer); if (right == null) { failTo.Fail(); return(null); } TArithmetic newArith = new TArithmetic { _leftArg = left, _rightArg = right, _op = operand }; if (!(right is TLeftExpression t) || t.GetAssociativity() == Associativity.Na) { return(newArith); } int prec = operand.GetPrecedence(); int rPrec = t.GetPrecedence(); if (prec >= rPrec && (prec != rPrec || operand.GetAssociativity() != Associativity.LeftToRight)) { return(newArith); } newArith._rightArg = t.GetLeft(); t.SetLeft(newArith); return(t); }
new public static TFor Claim(StringClaimer claimer) { Claim c = claimer.Claim(FOR); if (!c.Success) { return(null); } TExpression[] exprs = new TExpression[4]; claimer.Claim(LEFT_BRACKET); int claimed = 0; for (; claimed < 3; claimed++) { if ((exprs[claimed] = TExpression.Claim(claimer)) == null) // Out of Expressions. :( { break; } } claimed--; c = claimer.Claim(RIGHT_BRACKET); if ((exprs[3] = TExpression.Claim(claimer)) == null && !c.Success) { if (claimed >= 0 && exprs[claimed] != null) { exprs[3] = exprs[claimed]; exprs[claimed] = null; } } TFor newFor = new TFor(); newFor.initial = exprs[0]; newFor.condition = exprs[1]; newFor.after = exprs[2]; newFor.body = exprs[3]; return(newFor); }