// creates specific operation like index, initlist, objectconst ets. public AleOperation(string name, AleOperationType type) { string s = name.Trim(); int n = s.Length; for (int i = 0; i < n; i++) { if (Char.IsWhiteSpace(s, i)) { throw new System.ArgumentException("Invalid operation name"); } } AleOperationType[] validTypes = { AleOperationType.Index, AleOperationType.InitList, AleOperationType.ObjectConst, AleOperationType.KeyValue, AleOperationType.PropertyValue }; if (Array.IndexOf(validTypes, type) < 0) { throw new System.ArgumentException("Invalid operation type"); } _Name = s; _Hash = _Name.GetHashCode(); _Associativity = 0; _Precedence = 0; _InstanceTypeCode = TypeCode.Empty; _OperationType = type; _Flags = AleString.HasAlphaNumChar(name); Parameters = null; Evaluator = null; }
// creates operator public AleOperation(string name, int precedence, uint associativity, AleOperationType type = AleOperationType.Evaluation) { string s = name.Trim(); if (!CheckOperatorName(s)) { throw new System.ArgumentException("Invalid operator name"); } if ((associativity == 0) || ((associativity & OPERATOR_PREFIX) == OPERATOR_PREFIX) || ((associativity & OPERATOR_POSTFIX) == OPERATOR_POSTFIX) || ((associativity & OPERATOR_INFIX) == OPERATOR_INFIX)) { throw new System.ArgumentException("Invalid operator associativity"); } AleOperationType[] validTypes = { AleOperationType.Evaluation, AleOperationType.Assignment, AleOperationType.CompoundAssignment, AleOperationType.Increment, AleOperationType.MemberAccess, AleOperationType.ElementAccess }; if (Array.IndexOf(validTypes, type) < 0) { throw new System.ArgumentException("Invalid operation type"); } _Name = s; _Hash = _Name.GetHashCode(); _Associativity = associativity; _Precedence = precedence; _InstanceTypeCode = TypeCode.Empty; _OperationType = type; _Flags = AleString.HasAlphaNumChar(name) | (name.IndexOf(' ') >= 0 ? OPERATOR_OPTION_HASWHITESPACE : 0); Parameters = null; Evaluator = null; }
// creates function or method public AleOperation(string name) { string s = name.Trim(); if (!CheckFunctionName(s)) { throw new System.ArgumentException("Invalid function name"); } _Name = s; _Hash = _Name.GetHashCode(); _Associativity = 0; _Precedence = 0; _InstanceTypeCode = TypeCode.Empty; _OperationType = AleOperationType.Evaluation; _Flags = AleString.HasAlphaNumChar(name); Parameters = null; Evaluator = null; }
private bool CheckFunctionName(string name) { if (String.IsNullOrEmpty(name) || !AleString.IsCharAlpha(name, 0)) { return(false); } int[] textUnits = StringInfo.ParseCombiningCharacters(name); int n = textUnits.Length; for (int i = 1; i < n; i++) { if (!AleString.IsCharAlphaNum(name, textUnits[i])) { return(false); } } return(true); }