private void _parser_main(YamlFileData file) { Output = new ParserArray(file.LineNumber); Output.Indent = -1; Output.ChildrenIndent = -1; _readNode(file, Output, 0, YamlListType.NotDefined); if (Output.ParserType == ParserTypes.Array) { var parserArray = Output.To <ParserArray>(); // Copy pate handling if (parserArray.Objects.Count > 0 && parserArray.Objects[0].ParserType == ParserTypes.Array) { var tmp_list = new ParserList(0); var tmp_keyValue = new ParserKeyValue("copy_paste", 0); tmp_list.Objects.AddRange(parserArray.Objects); tmp_keyValue.Value = tmp_list; parserArray.Objects.Clear(); parserArray.Objects.Add(tmp_keyValue); } } // Calculate lengths if (Output != null) { _calculateLength(Output); Output.Length = _getLength(Output); } }
private void _calculateLength(ParserObject obj) { switch (obj.ParserType) { case ParserTypes.String: obj.Length = Math.Max(obj.Length, 1); break; case ParserTypes.Aggregate: case ParserTypes.Null: case ParserTypes.Number: obj.Length = 1; break; case ParserTypes.Array: case ParserTypes.List: foreach (var ele in obj) { _calculateLength(ele); } obj.Length = _getLength(obj); break; case ParserTypes.KeyValue: var value = ((ParserKeyValue)obj).Value; _calculateLength(value); obj.Length = _getLength(obj); break; } }
public static List <Object> LoadExpression(string formula) { formula = CommonTool.KillSpace(formula); List <Object> charInput = new List <object>(); ParserObject p = new ParserObject(); Parser(formula, ref p, charInput); return(charInput); }
private static string _loadListToString(ParserObject libList, string id, string value, string def = "") { if (libList == null) { return(def); } string ret = ""; if (libList is ParserString) { ret = libList; } else { Dictionary <int, string> ranges = new Dictionary <int, string>(); try { foreach (var entry in libList) { ranges[Int32.Parse(entry[id])] = entry[value]; } int start = 1; string previous = ""; foreach (var entry in ranges.OrderBy(p => p.Key)) { if (entry.Key == start) { ret += entry.Value + ":"; previous = entry.Value; start = entry.Key + 1; continue; } for (int i = start; i < entry.Key; i++) { ret += previous + ":"; } ret += entry.Value + ":"; previous = entry.Value; start = entry.Key + 1; } } catch (Exception err) { ErrorHandler.HandleException(err); } } return(ret.TrimEnd(':')); }
private static void CreateGridRow(ParserObject obj, DataGridView dataGV, string thisOfDevice, int maxDescLength) { if (obj == null) { return; } List <StateObject> visualStateCollection; if (!string.IsNullOrWhiteSpace(thisOfDevice)) { visualStateCollection = obj.StateCollection.Where(o => o == null || o.Parent.GetParent() == thisOfDevice).ToList(); } else { visualStateCollection = obj.StateCollection; } if (visualStateCollection.Count == 0) { return; } var rowIndex = dataGV.Rows.Add(); var row = dataGV.Rows[rowIndex]; CreateTimeLineGridCell(visualStateCollection, row, 0); for (int i = 1; i < dataGV.ColumnCount; i++) { var j = i - 1; if (j < visualStateCollection.Count) { if (visualStateCollection[j] != null) { if (visualStateCollection[j].State == State.ViewArrow) { if (visualStateCollection[j].ReferenceDirection == RefDirection.Backward) { CreateArrowImageCell(visualStateCollection[j], row, i, null, obj.PrevInterruptedObj); } else if (visualStateCollection[j].ReferenceDirection == RefDirection.Forward) { CreateArrowImageCell(visualStateCollection[j], row, i, obj.NextContinuedObj, null); } } else { CreateGridCell(visualStateCollection[j], row, i, maxDescLength); } } } } }
private void AddColorKeyValue(ParserObject obj, XElement prop, object parsedValue) { XElement colorKeysMember = prop.Element("ColorKeysMember"); if (obj == null || colorKeysMember == null || colorKeysMember.Value == null || !colorKeysMember.Value.ToBoolean()) { return; } if (!obj.ColorKeys.Contains(parsedValue)) { obj.ColorKeys.Add((string)parsedValue); } }
public void SetupParent(ParserObject parent, int indent) { if (parent.Indent == -1) { if (CurrentLineIndent < indent) { throw GetException("Expected list or array declaration."); } parent.Indent = CurrentLineIndent; } if (parent.ChildrenIndent == -1) { parent.ChildrenIndent = CurrentLineIndent; } }
private int _getLength(ParserObject obj) { switch (obj.ParserType) { case ParserTypes.String: return(Math.Max(1, obj.Length)); case ParserTypes.Aggregate: case ParserTypes.Null: case ParserTypes.Number: return(1); case ParserTypes.List: var list = (ParserList)obj; if (list.Objects.Count == 0) { return(0); } return(list.Last().Line - obj.Line + list.Last().Length); case ParserTypes.Array: var array = (ParserArray)obj; if (array.Objects.Count == 0) { return(0); } return(array.Last().Line - obj.Line + array.Last().Length); case ParserTypes.KeyValue: var keyValue = (ParserKeyValue)obj; if (keyValue.Value == null) { return(0); } return(_getLength(keyValue.Value) + keyValue.Line - obj.Line); } return(0); }
public static string LoadFlag(ParserObject entry, Dictionary <string, long> flags, string def = "", bool setZeroToDef = true) { if (entry == null) { return(def); } long flag = 0; if (entry is ParserString) { return(flags[entry.ObjectValue.ToLower()].ToString(CultureInfo.InvariantCulture)); } foreach (var flagEntry in entry.OfType <ParserKeyValue>()) { try { long val = flags[flagEntry.Key.ToLower()]; if (flagEntry.Value == "true") { flag |= val; } else { flag &= ~val; } } catch { throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + flagEntry.Key); } } if (setZeroToDef && flag == 0 && def != "") { return(def); } return(flag.ToString(CultureInfo.InvariantCulture)); }
protected void TryProcessProperties(ParserObject parserObject) { var properties = GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance); foreach (var property in properties) { if (ObjectHasProperty(parserObject, property)) { var parserType = parserObject.HashTable[property.Name]; var propertyType = property.PropertyType; var converter = Converter.GetConverter(propertyType); if (converter == null) { continue; } var value = converter.Convert(parserType); if (converter.IsValueInvalid(value)) { if (PropertyHasDefaultValue(property)) { var potentialDefaultValues = property.GetCustomAttributes(typeof(DefaultValue), false); var defaultValue = potentialDefaultValues[0] as DefaultValue; value = defaultValue.Value; } else { continue; } } property.SetValue(this, value, null); } } }
public void LoadParserObject(string identifier, ParserObject parserObject) { _id = identifier; TryProcessProperties(parserObject); }
private static void CreateArrowImageCell(StateObject stateObj, DataGridViewRow row, int cellIndex, ParserObject nextContinuedObj, ParserObject prevInterruptedObj) { var cell = new DataGridViewImageCell(); if (stateObj == null) { row.Cells[cellIndex] = cell; return; } if (prevInterruptedObj != null) { var tag = new TagArrowInfo { refObj = prevInterruptedObj, stateObj = stateObj }; if (IsArrowClickable(tag)) { cell.Value = ImageExt.ColorReplace(Properties.Resources.forward_arrow, Color.White, ColorTranslator.FromHtml(prevInterruptedObj.BaseColor)); tag.IsClickable = true; tag.ToolTipText = "To PREVIOUS state..."; cell.Tag = tag; } else { cell.Value = Properties.Resources.forward_arrow; tag.IsClickable = false; cell.Tag = new TagArrowInfo { refObj = null, stateObj = stateObj }; } } else if (nextContinuedObj != null) { var tag = new TagArrowInfo { refObj = nextContinuedObj, stateObj = stateObj }; if (IsArrowClickable(tag)) { cell.Value = ImageExt.ColorReplace(Properties.Resources.forward_arrow, Color.White, ColorTranslator.FromHtml(nextContinuedObj.BaseColor)); tag.IsClickable = true; tag.ToolTipText = "To NEXT state..."; cell.Tag = tag; } else { cell.Value = Properties.Resources.forward_arrow; tag.IsClickable = false; cell.Tag = new TagArrowInfo { refObj = null, stateObj = stateObj }; } } else { cell.Value = Properties.Resources.forward_arrow; cell.Tag = new TagArrowInfo { refObj = null, stateObj = stateObj }; } row.Cells[cellIndex] = cell; }
private void _readNode(YamlFileData file, ParserObject parent, int indent, YamlListType listType) { string word_s = null; while (file.CanRead) { char c = file.PeekChar(); switch (c) { case '#': file.SkipLine(); continue; case '\r': // Ignore character file.Position++; continue; case '\n': file.Position++; file.NextLine(); continue; case '-': file.SetupParent(parent, indent); if (listType == YamlListType.NotDefined) { listType = YamlListType.Array; } // Validate parent indent switch (parent.ParserType) { case ParserTypes.List: case ParserTypes.Array: if (file.CurrentLineIndent < parent.ChildrenIndent) { return; } if (file.CurrentLineIndent > parent.ChildrenIndent) { throw file.GetException("Unexpected indent (parent indent: " + parent.Indent + ", parent child indent: " + parent.ChildrenIndent + ", current indent: " + file.CurrentLineIndent + ")."); } break; } if (!(file.Position + 2 < file.Length && file.Data[file.Position + 1] == ' ' && file.IsLetter((char)file.Data[file.Position + 2]))) { throw file.GetException("Expected a space after the hyphen for the list declaration."); } // Array declaration ParserArray array = new ParserArray(file.LineNumber); array.Indent = file.CurrentLineIndent; file.CurrentLineIndent += 2; array.ChildrenIndent = file.CurrentLineIndent; file.Position += 2; _readNode(file, array, file.CurrentLineIndent, YamlListType.NotDefined); switch (parent.ParserType) { case ParserTypes.List: ((ParserList)parent).AddElement(array); break; case ParserTypes.Array: // Used for copy pasting only ((ParserArray)parent).AddElement(array); break; default: throw file.GetException("Unexpected parent node type. It can either be a list or an array, found a '" + parent.ParserType + "'."); } continue; case ' ': file.CurrentLineIndent++; file.Position++; continue; case ':': if (string.IsNullOrEmpty(word_s)) { throw file.GetException("Missing declaration key before ':'."); } file.Position++; file.Trim(); ParserKeyValue keyValue = new ParserKeyValue(word_s, file.LineNumber); keyValue.Indent = parent.Indent; word_s = null; // List declaration if (file.EoL()) { ParserList list = new ParserList(file.LineNumber); list.Indent = -1; list.ChildrenIndent = -1; keyValue.Value = list; _readNode(file, list, file.CurrentLineIndent, YamlListType.NotDefined); } else if (file.Data[file.Position] == '[') // Aggregate parsing, does not support multi-line { file.Position++; ParserAggregate aggregate = new ParserAggregate(file.LineNumber); aggregate.Parent = parent; while (file.CanRead) { c = file.PeekChar(); if (c == '\r' || c == '\n') { throw file.GetException("Unexpected syntax; multi-line aggregate arrays are not supported."); } if (c == ']') { break; } word_s = c == '\"' ? file.ReadValue() : file.ReadWord(); aggregate.AddElement(new ParserString(word_s.Trim(' '), file.LineNumber)); c = file.PeekChar(); while (c != '\n' && (c == ',' || c == ' ' || c == '\r')) { file.Position++; c = file.PeekChar(); } } word_s = null; keyValue.Value = aggregate; } else // KeyValue, get the line number first! { var parserString = new ParserString(null, file.LineNumber); parserString.Value = file.ReadValue(); parserString.Length = file.ValueLength; keyValue.Value = parserString; } switch (parent.ParserType) { case ParserTypes.List: ((ParserList)parent).AddElement(keyValue); break; case ParserTypes.Array: ((ParserArray)parent).AddElement(keyValue); break; } continue; default: file.SetupParent(parent, indent); if (listType == YamlListType.NotDefined) { listType = YamlListType.KeyValue; } // Validate parent indent switch (parent.ParserType) { case ParserTypes.List: if (file.CurrentLineIndent < parent.ChildrenIndent) { return; } if (file.CurrentLineIndent == parent.ChildrenIndent && listType != YamlListType.KeyValue) { return; } if (file.CurrentLineIndent > parent.ChildrenIndent) { throw file.GetException("Unexpected indent while reading key (parent indent: " + parent.Indent + ", parent child indent: " + parent.ChildrenIndent + ", current indent: " + file.CurrentLineIndent + ")."); } break; case ParserTypes.Array: if (file.CurrentLineIndent < parent.ChildrenIndent) { return; } if (file.CurrentLineIndent > parent.ChildrenIndent) { throw file.GetException("Unexpected indent while reading key (parent indent: " + parent.Indent + ", parent child indent: " + parent.ChildrenIndent + ", current indent: " + file.CurrentLineIndent + ")."); } break; } word_s = file.ReadKey(); if (word_s.Length == 0) { throw file.GetException("Null-length word. This is most likely caused by an unexpected character in a string."); } file.Trim(); continue; } } }
private bool FindOrCreateParserObject(int lineNumber, string line, XElement filter, List <object> parsedList, out string objectClass, out string thisValue, out string objectState) { thisValue = null; objectClass = null; objectState = null; var objState = State.Unknown; var objClass = ObjectClass.Unknown; ParserObject obj = null; bool isExistingFound = false; _lastCurrentObject = _currentObj; //_currentObj = null; foreach (var prop in filter.XPathSelectElements("Properties/Property")) { var name = prop.Element("Name"); if (name != null && prop.Element("Name") != null && prop.Element("Name").Value.ToLower() == "this") { if (prop.Element("PatternIndex") == null || prop.Attribute("i") == null) { AppLogger.LogLine(string.Format("Invalid profile definition: missing index {0} of property '{1}'", "'i=' or 'PatternIndex'", "this"), lineNumber); continue; } if (int.TryParse(prop.Element("PatternIndex").Value, out int patternIndex)) { if (patternIndex < _sf.Results.Count) { thisValue = (string)parsedList[patternIndex]; var thisVal = thisValue; objectState = filter.Element("State") != null && !string.IsNullOrWhiteSpace(filter.Element("State").Value) ? filter.Element("State").Value : null; if (!string.IsNullOrWhiteSpace(objectState)) { objState = Enum.IsDefined(typeof(State), objectState) ? objectState.ToEnum <State>() : State.Unknown; } objectClass = filter.Element("ObjectClass") != null && !string.IsNullOrWhiteSpace(filter.Element("ObjectClass").Value) ? filter.Element("ObjectClass").Value : null; if (!string.IsNullOrWhiteSpace(objectClass)) { objClass = Enum.IsDefined(typeof(ObjectClass), objectClass) ? objectClass.ToEnum <ObjectClass>() : ObjectClass.Unknown; } var filterKey = filter.Attribute("key").Value; } } } } if (Enum.IsDefined(typeof(ObjectClass), objClass) && !string.IsNullOrWhiteSpace(thisValue)) { var thisVal = thisValue; var foundInterruptedLastState = State.Unknown; ParserObject foundInterruptedObj = null; var foundExistingObjects = ObjectCollection.Where(x => x.GetThis() == thisVal && x.ObjectClass == objClass && objClass != ObjectClass.Device && //TODO ????????? x.IsFindable == true); isExistingFound = foundExistingObjects != null && foundExistingObjects.Count() > 0; if (isExistingFound) { var isCompletedFound = foundExistingObjects.Any(x => x.StateCollection.Any(y => y.State == State.Completed)); if (isCompletedFound) { //Set isFindable = true foreach (var o in foundExistingObjects) { o.IsFindable = false; } isExistingFound = false; } else { foundInterruptedObj = foundExistingObjects.LastOrDefault(); if (foundInterruptedObj != null) { var foundStateCollection = foundInterruptedObj.StateCollection; if (foundStateCollection != null && foundStateCollection.Count > 0) { //foundInterruptedLastState = foundStateCollection[foundStateCollection.Count - 1].State; var foundStateObj = foundStateCollection.LastOrDefault(x => x.State >= 0); if (foundStateObj != null) { foundInterruptedLastState = foundStateObj.State; if (ObjectCollection[ObjectCollection.Count - 1].GetThis() != thisVal || objState < foundInterruptedLastState) { isExistingFound = false; } } } } } } if (!isExistingFound) { if (foundInterruptedObj != null) { obj = foundInterruptedObj.CreateObjectClone(); obj.BaseColor = foundInterruptedObj.BaseColor; foundInterruptedObj.NextContinuedObj = obj; obj.PrevInterruptedObj = foundInterruptedObj; for (int i = 0; i < foundInterruptedObj.StateCollection.Count; i++) { obj.StateCollection.Add(obj.CreateBlankStateObject()); } } else { var filterKey = filter.Attribute("key").Value; bool isVisible = true; if (filter.Attribute("IsVisible") != null) { isVisible = filter.Attribute("IsVisible").Value.ToBoolean(); } obj = new ParserObject(); obj.ObjectClass = objClass; obj.SetDynProperty("this", thisValue); obj.SetDynProperty("FilterKey", filterKey); obj.SetDynProperty("IsVisible", isVisible); obj.LineNum = lineNumber; obj.LogEntry = line; obj.FilterKey = filterKey; } } else { obj = foundExistingObjects.LastOrDefault(); isExistingFound = true; } _currentObj = obj; if (_currentObj == null) { _currentObj = _lastCurrentObject; isExistingFound = true; } } return(isExistingFound); }
private void _parse(byte[] buffer) { try { _buffer = buffer; _bufferIndex = 0; while (_bufferIndex < buffer.Length) { switch ((char)buffer[_bufferIndex]) { case '/': if (buffer[_bufferIndex + 1] == '/') { _skipLine(); continue; } if (buffer[_bufferIndex + 1] == '*') { _skipCommentBlock(); continue; } break; case ':': ParserKeyValue keyValue = new ParserKeyValue(_word, Line); if (_latest == null && Output != null) { // The file contains multiple arrays ParserArray tempList = new ParserArray(Line); tempList.AddElement(Output); Output.Parent = tempList; Output = tempList; _latest = tempList; } if (_latest == null) { Output = keyValue; _latest = Output; } else { keyValue.Parent = _latest; switch (_latest.ParserType) { case ParserTypes.Array: ((ParserArray)_latest).AddElement(keyValue); _latest = keyValue; break; default: throw new Exception("Expected an Array."); } } break; case '<': _readMultilineQuote(); if (_latest != null) { switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = new ParserString(_word, Line); _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; break; default: throw new Exception("Expected a KeyValue."); } } break; case '(': ParserList list = new ParserList(Line); if (_latest == null) { throw new Exception("Trying to open a List type without a parent."); } switch (_latest.ParserType) { case ParserTypes.List: ((ParserList)_latest).AddElement(list); list.Parent = _latest; _latest = list; break; case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = list; list.Parent = _latest; _latest = list; break; default: throw new Exception("Expected a KeyValue."); } break; case '{': ParserArray array = new ParserArray(Line); if (_latest == null) { // Used for copy pasting inputs, create a temporary list Output = new ParserKeyValue("copy_paste", Line) { Value = new ParserList(Line) }; _latest = Output["copy_paste"]; } switch (_latest.ParserType) { case ParserTypes.List: ((ParserList)_latest).AddElement(array); array.Parent = _latest; _latest = array; break; case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = array; array.Parent = _latest; _latest = array; break; default: throw new Exception("Expected a List."); } break; case '[': ParserAggregate aggregate = new ParserAggregate(Line); if (_latest == null) { throw new Exception("Trying to open an Aggregate type without a parent."); } switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = aggregate; _latest.Length = Line - _latest.Line + 1; aggregate.Parent = _latest; _latest = aggregate; break; default: throw new Exception("Expected a KeyValue."); } break; case ']': case ')': case '}': if (_latest == null) { throw new Exception("Trying to close a statement without knowing its beginning."); } switch (_latest.ParserType) { case ParserTypes.Aggregate: case ParserTypes.Array: case ParserTypes.List: _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; if (_latest is ParserKeyValue) { _latest = _latest.Parent; } break; case ParserTypes.KeyValue: _latest = _latest.Parent; _latest.Length = Line - _latest.Line + 1; break; default: throw new Exception("Expected a KeyValue or an Array."); } break; case '\"': _readQuote(); if (_latest == null) { throw new Exception("Trying to read a quote without a parent."); } switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = new ParserString(_word, Line); _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; break; case ParserTypes.List: ((ParserList)_latest).AddElement(new ParserString(_word, Line)); break; default: throw new Exception("Expected a KeyValue."); } continue; case ',': case '\t': case ' ': case '\r': break; case '\n': Line++; break; default: _readWord(); if (_word == "") { throw new Exception("Null-length word. This is most likely caused by an unexpected character in a string."); } if (_buffer[_bufferIndex] == ':') { continue; } if (_latest != null) { switch (_latest.ParserType) { case ParserTypes.KeyValue: ((ParserKeyValue)_latest).Value = new ParserString(_word, Line); _latest.Length = Line - _latest.Line + 1; _latest = _latest.Parent; break; case ParserTypes.List: case ParserTypes.Aggregate: ((ParserArrayBase)_latest).AddElement(new ParserString(_word, Line)); break; default: // It will be handled by the ':' parsing. break; } } continue; } _bufferIndex++; } } catch (Exception err) { throw new Exception("Failed to parse " + _file + " at line " + Line + ", position " + LinePosition, err); } }
public LogParser(ParserObject target) { this.Target = target; }
public static string LoadFlag <T>(ParserObject entry, string def = "") { if (entry == null) { return(def); } long flag = 0; var flagData = FlagsManager.GetFlag <T>(); if (flagData == null) { throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag provided: " + typeof(T)); } if (entry is ParserString) { long val; if (!flagData.Name2Value.TryGetValue(entry.ObjectValue, out val)) { FlagsManager.AddValue(flagData, entry.ObjectValue); } if (!flagData.Name2Value.TryGetValue(entry.ObjectValue, out val)) { throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + entry.ObjectValue); } return(flagData.Name2Value[entry.ObjectValue].ToString(CultureInfo.InvariantCulture)); } foreach (var flagEntry in entry.OfType <ParserKeyValue>()) { try { long val = 0; if (!flagData.Name2Value.TryGetValue(flagEntry.Key, out val)) { FlagsManager.AddValue(flagData, flagEntry.Key); } if (!flagData.Name2Value.TryGetValue(flagEntry.Key, out val)) { throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + flagEntry.Key); } if (flagEntry.Value == "true") { flag |= val; } else { flag &= ~val; } } catch { throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + flagEntry.Key); } } if (flag == 0 && def != "") { return(def); } return(flag.ToString(CultureInfo.InvariantCulture)); }
protected bool ObjectHasProperty(ParserObject parserObject, PropertyInfo property) { var propertyName = property.Name; return(parserObject.HashTable.ContainsKey(propertyName)); }
static void Parser(string Formula, ref ParserObject p, List <object> charInput) { int begin = 0, end = 0; Formula = Formula.Trim(); if (Formula != null && Formula.Length > 0) { for (int pos = 0; pos < Formula.Length; pos++) { if (p.inSepcialScope || CommonTool.IsFuncPrix(Formula[pos])) { CommonTool.ParenthesesComplete(Formula[pos], ref p.leftCount, ref p.rightCount); CommonTool.FuncConstScopeJudger(Formula[pos], p.leftCount, p.rightCount, ref p.inFuncScope, ref p.inConstScope); if (p.inConstScope) { ParserHelper.ConstsParser(Formula, ref begin, ref end, ref pos, p, charInput); continue; } if (p.inFuncScope) { if (p.leftCount == p.rightCount) { ParserHelper.FuncParser(Formula, ref begin, ref end, ref pos, p, charInput); continue; } } end++; p.inSepcialScope = true; } else if (!CommonTool.IsNumber(Formula[pos])) { if (OperandManager.isOperand(CommonTool.GetSymbol(Formula[pos]))) { OperandManager.ParseOperand(CommonTool.GetSymbol(Formula[pos]), ref Formula, ref pos, ref begin, ref end); } else { if (begin != end) { charInput.Add(CommonTool.StringToFloat(Formula.Substring(begin, end - begin))); } charInput.Add(CommonTool.GetSymbol(Formula[pos])); begin = end = pos + 1; } } else//数字 { end++; } } //after read all the symbols //The last word is numeric the algorithm above is not correct. if (p.inSepcialScope)//const { string constExpression = Formula.Substring(begin, end - begin).ToLower(); if (ConstNumbers.Consts.ContainsKey(constExpression)) { charInput.Add(ConstNumbers.Consts[constExpression]); } } else if (CommonTool.IsNumber(Formula[Formula.Length - 1])) { charInput.Add(CommonTool.StringToFloat(Formula.Substring(begin, end - begin))); } } else { throw new Exception("Formula must contain a word!"); } }