/// <summary>Generate code to check an and-predicate during or after prediction, /// e.g. &!{foo} becomes !(foo) during prediction and Check(!(foo)); afterward.</summary> /// <param name="andPred">Predicate for which an expression has already been generated</param> /// <param name="code">The expression to be checked</param> /// <param name="li">Current lookahead amount. -1 means "prediction is /// complete, generate a Check() statement".</param> /// <remarks>LLLPG substitutes $LI and $LA before it calls this method.</remarks> public virtual LNode GenerateAndPredCheck(AndPred andPred, LNode code, int li) { if (_currentRule.IsRecognizer && li <= -1) { if (!andPred.Not) { code = F.Call(S.Not, code); } return(F.Call(S.If, code, F.Call(S.Return, F.@false))); } if (andPred.Not) { code = F.Call(S.Not, code); } if (li > -1) { return(code); } else { string asString = (andPred.Pred is LNode ? ((LNode)andPred.Pred).Print(NodeStyle.Expression) : andPred.Pred.ToString()); if (andPred.Not) { asString = "!(" + asString + ")"; } return(ApiCall(_Check, code, F.Literal(asString))); } }
public void VisitChildrenOf(AndPred pred) { if (pred.Pred is Pred) { (pred.Pred as Pred).Call(this); } }
public override void Visit(AndPred andp) { if (!(andp.Prematched ?? false)) { _target.Add(CGH.GenerateAndPredCheck(andp, GetAndPredCode(andp, 0, CGH.LA(0)), -1)); } }
public override void Visit(AndPred pred) { if (pred.PreAction != null && !_codeBeforeAndWarning) { LLPG.Output(Warning, pred, "It's poor style to put a code block {} before an and-predicate &{} because the and-predicate normally runs first."); _codeBeforeAndWarning = true; } VisitChildrenOf(pred); }
public virtual void ReplaceChildrenOf(AndPred pred) { if (pred.Pred is Pred) { var child = (pred.Pred as Pred); if (VisitAndReplace(ref child)) { pred.Pred = child; } } }
/// <summary>Generate code to check an and-predicate during or after prediction, /// e.g. &!{foo} becomes !(foo) during prediction and Check(!(foo)); afterward.</summary> /// <param name="andPred">Predicate for which an expression has already been generated</param> /// <param name="code">The expression to be checked</param> /// <param name="li">Current lookahead amount. -1 means "prediction is /// complete, generate a Check() statement".</param> /// <remarks>LLLPG substitutes $LI and $LA before it calls this method. /// This method can return null to suppress the Check statement.</remarks> public virtual LNode GenerateAndPredCheck(AndPred andPred, LNode code, int li) { if (_currentRule.IsRecognizer && li <= -1) { if (!andPred.Not) { code = F.Call(S.Not, code); } return(F.Call(S.If, code, F.Call(S.Return, F.@false))); } if (andPred.Not) { code = F.Call(S.Not, code); } if (li > -1) { return(code); } else { var errorString = andPred.CheckErrorMessage; if (errorString == "") { return(null); } else if (errorString == null) { if (NoCheckByDefault) { return(null); } errorString = (andPred.Pred is LNode ? ((LNode)andPred.Pred).Print(ParsingMode.Expressions) : andPred.Pred.ToString()); if (andPred.Not) { errorString = "Did not expect " + errorString; } else { errorString = "Expected " + errorString; } } return(ApiCall(_Check, code, F.Literal(errorString))); } }
public override void Visit(AndPred and) { if (_index < _path.Count) { if (and.Prematched != false) { bool pm = _path[_index].AndPreds.Contains(and); if (pm || !_reachedInnerAlts) { and.Prematched = pm; } } } else if (!_reachedInnerAlts) { and.Prematched = false; } }
LNode GetAndPredCode(AndPred pred, int lookaheadAmt, LNode laVar) { if (pred.Pred is LNode) { LNode code = (LNode)pred.Pred; // replace $LI and $LA return(code.ReplaceRecursive(arg => { if (arg.Equals(AndPred.SubstituteLA)) // $LA { return (LNode)laVar; } if (arg.Equals(AndPred.SubstituteLI)) // $LI { return (LNode)F.Literal(lookaheadAmt); } return null; })); } else { Pred synPred = (Pred)pred.Pred; // Buffalo sumBuffalo = (Buffalo)buffalo.Buffalo; Rule recogRule = LLPG.GetRecognizerRule(synPred); recogRule.TryWrapperNeeded(); if (synPred is RuleRef) { return(CGH.CallTryRecognizer(synPred as RuleRef, lookaheadAmt)); } else { // Use a temporary RuleRef for this RuleRef rref = new RuleRef(synPred.Basis, recogRule); return(CGH.CallTryRecognizer(rref, lookaheadAmt)); } } }
public virtual void Visit(AndPred and) { VisitOther(and); }
public override void Visit(AndPred pred) { VisitChildrenOf(pred); }
public override void Visit(AndPred pred) { base.Visit(pred); VisitCode(pred, pred.Pred as LNode); }
private void AutoAddBranchForAndPred(ref InternalList <PredictionBranch> children, AndPred andPred, List <KthSet> alts, Set <AndPred> matched, MSet <AndPred> falsified) { if (!falsified.Contains(andPred)) { var innerMatched = matched.With(andPred); var result = new PredictionBranch(new Set <AndPred>().With(andPred), ComputeAssertionTree2(alts, innerMatched)); falsified.Add(andPred); RemoveFalsifiedCases(alts, falsified); children.Add(result); } }
public override void Visit(AndPred pred) { VisitOther(pred); ReplaceChildrenOf(pred); }