public bool HasValidArg(OperatorDescr that, out string msg) { msg = null; if (that == null) { return(true); } switch (assoc) { case AssocType.fx: case AssocType.xf: if (this.prec <= that.prec) { msg = GT_error(this, that); } return(msg == null); case AssocType.fy: case AssocType.yf: if (this.prec < that.prec) { msg = GE_error(this, that); } return(msg == null); } throw new ApplicationException( string.Format("HasValidArg (...) not legal for operator {0}", this)); }
public OperatorToken(OpDescrTriplet triplet, OperatorDescr prevOd) { this.triplet = triplet; this.prevOd = prevOd; if (triplet.HasInfixDef) { if (triplet.HasPrefixDef) { type = TT.InPre; } else if (triplet.HasPostfixDef) { type = TT.InPost; } else { type = TT.In; } } else if (triplet.HasPrefixDef) { type = TT.Pre; } else if (triplet.HasPostfixDef) { type = TT.Post; } role = type; }
public void Assign(string name, int prec, AssocType assoc, bool user) { AssocGroup fixType = GetFixType(assoc); od = triplet[(int)fixType]; od.Name = (name == "','") ? "," : name; od.Prec = prec; od.Assoc = assoc; od.User = user; od.IsInfix = (fixType == AssocGroup.Infix); od.IsPrefix = (fixType == AssocGroup.Prefix); od.IsPostfix = (fixType == AssocGroup.Postfix); od.LeftRelOp = (assoc == AssocType.yfx || assoc == AssocType.fy || assoc == AssocType.yf) ? RelOp.LE : RelOp.LT; od.RightRelOp = (assoc == AssocType.xfy || assoc == AssocType.fy || assoc == AssocType.yf) ? RelOp.LE : RelOp.LT; // An operator can be either prefix or postfix, but not both. In addition, it can be infix. if (fixType == AssocGroup.Prefix) { triplet[(int)AssocGroup.Postfix].Undefine(); } else if (fixType == AssocGroup.Postfix) { triplet[(int)AssocGroup.Prefix].Undefine(); } }
public OpDescrTriplet(string name, int prec, AssocType assoc, bool user) { this.name = name; triplet = new OperatorDescr[3]; for (int i = 0; i < 3; i++) { triplet[i] = new OperatorDescr(); } Assign(name, prec, assoc, user); }
public bool IsBinaryOperator(string name, out OperatorDescr od) { OpDescrTriplet triplet; if (TryGetValue(name, out triplet)) { return(triplet.HasBinOpDef(out od)); } od = null; return(false); }
public void Unassign(string name, AssocType assoc) { AssocGroup fixType = GetFixType(assoc); od = triplet[(int)fixType]; if (od == null || od.Assoc == AssocType.None) { IO.Error("Operator '{0}' does not have an association type '{1}'", name, assoc); } triplet[(int)fixType].Undefine(); }
string GE_error(OperatorDescr od0, OperatorDescr od1) { if (od0 == od1) { return(string.Format( "Parentheses required for this combination of {0}-operators '{1}'.", od0.Assoc, od0.Name)); } else { return(string.Format( "Precedence of {0} must be greater than or equal to the precedence of {1}", od0, od1)); } }
public bool HasUnOpDef(out OperatorDescr od) { return((od = triplet[1]).IsDefined || (od = triplet[2]).IsDefined); }
public bool HasBinOpDef(out OperatorDescr od) { return((od = triplet[0]).IsDefined); }
string GE_error(OperatorDescr od0, OperatorDescr od1) { return(string.Format( "Precedence of {0} must be greater than or equal to the precedence of {1}", od0, od1)); }