private string CreatePostfixNotation() { char[] operators = new char[] { '|', '+', '-', '*', '/', '(', ')' }; operatorsStack.Push("|"); InfixNotation = InfixNotation.Replace(" ", string.Empty); InfixNotation = InfixNotation + "|"; int position = 0; while (position < InfixNotation.Length) { int length = InfixNotation.IndexOfAny(operators, position) - position; if (length == 0) { length = 1;//in case next block is operator } string block = InfixNotation.Substring(position, length); position += length; AddBlockToStacks(block); } StringBuilder result = new StringBuilder(); Stack <string> tmpStack = new Stack <string>(postfixNotationStack); foreach (var n in tmpStack) { result.Append(n); result.Append(" "); } return(result.ToString()); }
public Signal Function(string symbol, InfixNotation notation, params Signal[] arguments) { if (arguments == null) { throw new ArgumentNullException("arguments"); } return(Function(_library.LookupEntity(symbol, notation, arguments.Length, 1, 0), arguments)); }
public Signal Function(string symbol, InfixNotation notation, IList <Signal> arguments) { if (arguments == null) { throw new ArgumentNullException("arguments"); } return(Function(_library.LookupEntity(symbol, notation, arguments.Count, 1, 0), arguments)); }
public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals, string[] buses) { _id = id; _symbol = symbol; _inputSignalLabels = inputSignals; _outputSignalLabels = outputSignals; _busLabels = buses; _notation = notation; _precedenceGroup = precedence; }
public bool ContainsSymbol(string symbol, InfixNotation notation) { List <IEntity> entities; if (_symbolTable.TryGetValue(symbol, out entities)) { return(entities.Exists(delegate(IEntity e) { return e.Notation == notation; })); } return(false); }
public bool ContainsSymbol(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) { List <IEntity> entities; if (_symbolTable.TryGetValue(symbol, out entities)) { return(entities.Exists(delegate(IEntity e) { return e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses)); })); } return(false); }
public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, bool isGeneric, string[] buses) { _id = id; _symbol = symbol; _inputSignalLabels = new string[0]; _outputSignalLabels = new string[0]; _busLabels = buses; _isGeneric = isGeneric; _notation = notation; _precedenceGroup = precedence; }
public bool TryLookupSymbol(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses, out IEntity entity) { entity = null; List <IEntity> list; if (!_symbolTable.TryGetValue(symbol, out list)) { return(false); } entity = list.Find(delegate(IEntity e) { return(e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses))); }); return(entity != null); }
public Entity LookupEntity(string symbol, InfixNotation notation, int inputSignals) { ReadOnlyCollection <Entity> entry = entityTable.LookupSymbol(symbol, notation); for (int i = 0; i < entry.Count; i++) { Entity entity = entry[i]; if (entity.InputSignals.Length == inputSignals || entity.IsGeneric) { return(entity); } } throw new MathNet.Symbolics.Backend.Exceptions.SymbolNotAvailableException(symbol); }
public bool TryLookupSymbol(string symbol, InfixNotation notation, out ReadOnlyCollection <Entity> entities) { entities = null; List <Entity> list; if (!_symbolTable.TryGetValue(symbol, out list)) { return(false); } list = list.FindAll(delegate(Entity e) { return(e.Notation == notation); }); if (list.Count > 0) { entities = list.AsReadOnly(); return(true); } return(false); }
public bool TryLookupEntity(string symbol, InfixNotation notation, int inputSignals, out Entity entity) { entity = null; ReadOnlyCollection <Entity> entry; if (entityTable.TryLookupSymbol(symbol, notation, out entry)) { for (int i = 0; i < entry.Count; i++) { entity = entry[i]; if (entity.InputSignals.Length == inputSignals || entity.IsGeneric) { return(true); } } } return(false); }
public bool ContainsEntity(string symbol, InfixNotation notation, int inputSignals) { if (!entityTable.ContainsSymbol(symbol)) { return(false); } ReadOnlyCollection <Entity> entry = entityTable.LookupSymbol(symbol, notation); for (int i = 0; i < entry.Count; i++) { Entity entity = entry[i]; if (entity.InputSignals.Length == inputSignals || entity.IsGeneric) { return(true); } } return(false); }
public Entity BuildEntity(MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { string[] inputSignalLabels = new string[_inputs.Count]; for (int i = 0; i < inputSignalLabels.Length; i++) { inputSignalLabels[i] = string.IsNullOrEmpty(_inputs[i].Label) ? "In_" + i.ToString(Context.NumberFormat) : _inputs[i].Label; } string[] outputSignalLabels = new string[_outputs.Count]; for (int i = 0; i < outputSignalLabels.Length; i++) { outputSignalLabels[i] = string.IsNullOrEmpty(_outputs[i].Label) ? "Out_" + i.ToString(Context.NumberFormat) : _outputs[i].Label; } string[] busLabels = new string[_allBuses.Count]; for (int i = 0; i < busLabels.Length; i++) { busLabels[i] = string.IsNullOrEmpty(_allBuses[i].Label) ? "Bus_" + i.ToString(Context.NumberFormat) : _allBuses[i].Label; } return(new Entity(symbol, entityId.Label, entityId.Domain, notation, precedence, inputSignalLabels, outputSignalLabels, busLabels)); }
private Entity ScanEntity(LexerToken token, InfixNotation notation, int inputs) { if (token.IsType(TokenTypes.MathIdentifier)) { return(context.Library.LookupEntity(MathIdentifier.Parse(token.Text))); } else if (token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol { return(context.Library.LookupEntity(token.Text, notation, inputs)); } else //textsymbol or label { Entity entity; if (context.Library.TryLookupEntity(token.Text, notation, inputs, out entity)) { return(entity); } else { string domain = context.Library.Entities.FindDomainOfLabel(token.Text); return(context.Library.LookupEntity(new MathIdentifier(token.Text, domain))); } } }
private IEntity ScanEntity(LexerToken token, InfixNotation notation, int inputs) { if (token.IsType(TokenTypes.MathIdentifier)) { return(library.LookupEntity(MathIdentifier.Parse(token.Text))); } else if (token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol { return(library.LookupEntity(token.Text, notation, inputs)); } else //textsymbol or label { IEntity entity; if (library.TryLookupEntity(token.Text, notation, inputs, out entity)) { return(entity); } else { MathIdentifier id = library.FindEntityByLabel(token.Text); return(library.LookupEntity(id)); } } }
public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, Signal argument) { return Functions(context.Library.LookupEntity(symbol, notation, 1, 1, 0), argument); }
public IEntity LookupSymbol(string symbol, InfixNotation notation, int inputSignals, int outputSignals, int buses) { return(_symbolTable[symbol].Find(delegate(IEntity e) { return e.Notation == notation && ((e.InputSignals.Length == inputSignals && e.OutputSignals.Length == outputSignals && e.Buses.Length == buses) || (e.IsGeneric && e.Buses.Length == buses)); })); }
public IEntity LookupSymbol(string symbol, InfixNotation notation) { return(_symbolTable[symbol].Find(delegate(IEntity e) { return e.Notation == notation; })); }
public static IEntity ReadXmlEntity(FileInfo file, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { if(file == null) throw new ArgumentNullException("file"); XmlReader reader = XmlReader.Create(file.OpenText()); IEntity entity = ReadXmlEntity(reader, entityId, symbol, notation, precedence); reader.Close(); return entity; }
public static Entity ReadXmlEntity(XmlReader reader, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { reader.ReadToFollowing("System", Context.YttriumNamespace); int inputCnt = int.Parse(reader.GetAttribute("inputCount"), Context.NumberFormat); int outputCnt = int.Parse(reader.GetAttribute("outputCount"), Context.NumberFormat); int busCnt = int.Parse(reader.GetAttribute("busCount"), Context.NumberFormat); reader.Close(); string[] inputSignalLabels = new string[inputCnt]; for (int i = 0; i < inputCnt; i++) { inputSignalLabels[i] = "In_" + i.ToString(Context.NumberFormat); } string[] outputSignalLabels = new string[outputCnt]; for (int i = 0; i < outputCnt; i++) { outputSignalLabels[i] = "Out_" + i.ToString(Context.NumberFormat); } string[] busLabels = new string[busCnt]; for (int i = 0; i < busCnt; i++) { busLabels[i] = "Bus_" + i.ToString(Context.NumberFormat); } return(new Entity(symbol, entityId.Label, entityId.Domain, notation, precedence, inputSignalLabels, outputSignalLabels, busLabels)); }
public static Entity ReadXmlEntity(FileInfo file, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { XmlReader reader = XmlReader.Create(file.OpenText()); Entity entity = ReadXmlEntity(reader, entityId, symbol, notation, precedence); reader.Close(); return(entity); }
public NearlySymmetricGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence, int additionalInputs, int additionalOutputs, string[] buses) : base(symbol, label, domain, notation, precedence, true, buses) { this.additionalInputs = additionalInputs; this.additionalOutputs = additionalOutputs; }
public ArbitraryGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence) : base(symbol, label, domain, notation, precedence, true) { }
public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, Signal argument1, Signal argument2) { return Functions(_library.LookupEntity(symbol, notation, 2, 1, 0), argument1, argument2); }
public Signal Function(string symbol, InfixNotation notation, IList<Signal> arguments) { if(arguments == null) throw new ArgumentNullException("arguments"); return Function(_library.LookupEntity(symbol, notation, arguments.Count, 1, 0), arguments); }
public Signal Function(string symbol, InfixNotation notation, params Signal[] arguments) { if(arguments == null) throw new ArgumentNullException("arguments"); return Function(_library.LookupEntity(symbol, notation, arguments.Length, 1, 0), arguments); }
public Signal Function(string symbol, InfixNotation notation, Signal argument1, Signal argument2) { return Function(_library.LookupEntity(symbol, notation, 2, 1, 0), argument1, argument2); }
public Signal Function(string symbol, InfixNotation notation, Signal argument) { return Function(context.Library.LookupEntity(symbol, notation, 1, 1, 0), argument); }
public Signal Function(string symbol, InfixNotation notation, IList<Signal> arguments) { return Function(context.Library.LookupEntity(symbol, notation, arguments.Count, 1, 0), arguments); }
public static IEntity ReadXmlEntity(FileInfo file, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { if (file == null) { throw new ArgumentNullException("file"); } XmlReader reader = XmlReader.Create(file.OpenText()); IEntity entity = ReadXmlEntity(reader, entityId, symbol, notation, precedence); reader.Close(); return(entity); }
/// <returns>precedence group</returns> private int FormatExpression(Signal signal, LinkedList <string> sequence, FormattingOptions options) { if (signal.BehavesAsSourceSignal) { if (signal.Value != null) { IFormattableLeaf leaf = signal.Value as IFormattableLeaf; if (leaf != null) { int prec; sequence.AddLast(leaf.Format(options, out prec)); return(prec); } else { sequence.AddLast(signal.Value.ToString()); return(-1); } } if (!string.IsNullOrEmpty(signal.Label)) { sequence.AddLast(signal.Label); return(-1); } sequence.AddLast("signal"); return(-1); } Port port = signal.DrivenByPort; IEntity entity = port.Entity; int precedence = entity.PrecedenceGroup; InfixNotation notation = entity.Notation; if (notation == InfixNotation.PreOperator) { sequence.AddLast(entity.Symbol); } else if (notation == InfixNotation.None) { sequence.AddLast(entity.Symbol); sequence.AddLast("("); } bool notFirst = false; foreach (Signal s in port.InputSignals) { if (notFirst) { sequence.AddLast(entity.Symbol); } else { notFirst = true; } LinkedListNode <string> before = sequence.Last; int subPrecedence = FormatExpression(s, sequence, options); if (subPrecedence >= precedence && notation != InfixNotation.None) { sequence.AddAfter(before, "("); sequence.AddLast(")"); } } if (notation == InfixNotation.PostOperator) { sequence.AddLast(entity.Symbol); } else if (notation == InfixNotation.None) { sequence.AddLast(")"); } return(precedence); }
public static Entity ReadXmlEntity(string xml, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { StringReader sr = new StringReader(xml); XmlReader reader = XmlReader.Create(sr); return(ReadXmlEntity(reader, entityId, symbol, notation, precedence)); }
public static IEntity ReadXmlEntity(string xml, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { StringReader sr = new StringReader(xml); XmlReader reader = XmlReader.Create(sr); return ReadXmlEntity(reader, entityId, symbol, notation, precedence); }
public Signal Function(string symbol, InfixNotation notation, params Signal[] arguments) { return Function(context.Library.LookupEntity(symbol, notation, arguments.Length, 1, 0), arguments); }
public IEntity BuildEntity(MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { string[] inputSignalLabels = new string[_inputs.Count]; for(int i = 0; i < inputSignalLabels.Length; i++) inputSignalLabels[i] = string.IsNullOrEmpty(_inputs[i].Label) ? "In_" + i.ToString(Config.InternalNumberFormat) : _inputs[i].Label; string[] outputSignalLabels = new string[_outputs.Count]; for(int i = 0; i < outputSignalLabels.Length; i++) outputSignalLabels[i] = string.IsNullOrEmpty(_outputs[i].Label) ? "Out_" + i.ToString(Config.InternalNumberFormat) : _outputs[i].Label; string[] busLabels = new string[_allBuses.Count]; for(int i = 0; i < busLabels.Length; i++) busLabels[i] = string.IsNullOrEmpty(_allBuses[i].Label) ? "Bus_" + i.ToString(Config.InternalNumberFormat) : _allBuses[i].Label; return new Core.Entity(symbol, entityId.Label, entityId.Domain, notation, precedence, inputSignalLabels, outputSignalLabels, busLabels); }
public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals) : this(symbol, label, domain, notation, precedence, inputSignals, outputSignals, new string[0]) { }
public IList <IEntity> LookupSymbols(string symbol, InfixNotation notation) { return(_symbolTable[symbol].FindAll(delegate(IEntity e) { return e.Notation == notation; })); }
public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals) : this(symbol, id, notation, precedence, inputSignals, outputSignals, new string[0]) { }
public IEntity LookupSymbol(string symbol, InfixNotation notation, int inputSignals) { return(_symbolTable[symbol].Find(delegate(IEntity e) { return e.Notation == notation && (e.InputSignals.Length == inputSignals || e.IsGeneric); })); }
public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] inputSignals, string[] outputSignals, string[] buses) : this(symbol, new MathIdentifier(label, domain), notation, precedence, inputSignals, outputSignals, buses) { }
public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, params Signal[] arguments) { return Functions(_library.LookupEntity(symbol, notation, arguments.Length, 1, 0), arguments); }
private IEntity ScanEntity(LexerToken token, InfixNotation notation, int inputs) { if(token.IsType(TokenTypes.MathIdentifier)) return library.LookupEntity(MathIdentifier.Parse(token.Text)); else if(token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol return library.LookupEntity(token.Text, notation, inputs); else //textsymbol or label { IEntity entity; if(library.TryLookupEntity(token.Text, notation, inputs, out entity)) return entity; else { MathIdentifier id = library.FindEntityByLabel(token.Text); return library.LookupEntity(id); } } }
public ReadOnlySignalSet Functions(string symbol, InfixNotation notation, IList<Signal> arguments) { return Functions(_library.LookupEntity(symbol, notation, arguments.Count, 1, 0), arguments); }
public EntityBase(string symbol, MathIdentifier id, InfixNotation notation, int precedence, bool isGeneric) : this(symbol, id, notation, precedence, isGeneric, new string[0]) { }
public SymmetricGenericEntity(string symbol, string label, string domain, InfixNotation notation, int precedence, string[] buses) : base(symbol, label, domain, notation, precedence, true, buses) { }
public EntityBase(string symbol, string label, string domain, InfixNotation notation, int precedence, bool isGeneric, string[] buses) : this(symbol, new MathIdentifier(label, domain), notation, precedence, isGeneric, buses) { }
private Entity ScanEntity(LexerToken token, InfixNotation notation, int inputs) { if(token.IsType(TokenTypes.MathIdentifier)) return context.Library.LookupEntity(MathIdentifier.Parse(token.Text)); else if(token.IsType(TokenTypes.Literal) || token.IsType(TokenTypes.SymbolIdentifier)) //symbol return context.Library.LookupEntity(token.Text, notation, inputs); else //textsymbol or label { Entity entity; if(context.Library.TryLookupEntity(token.Text, notation, inputs, out entity)) return entity; else { string domain = context.Library.Entities.FindDomainOfLabel(token.Text); return context.Library.LookupEntity(new MathIdentifier(token.Text, domain)); } } }
public static IEntity ReadXmlEntity(XmlReader reader, MathIdentifier entityId, string symbol, InfixNotation notation, int precedence) { if(reader == null) throw new ArgumentNullException("reader"); reader.ReadToFollowing("System", Config.YttriumNamespace); int inputCnt = int.Parse(reader.GetAttribute("inputCount"), Config.InternalNumberFormat); int outputCnt = int.Parse(reader.GetAttribute("outputCount"), Config.InternalNumberFormat); int busCnt = int.Parse(reader.GetAttribute("busCount"), Config.InternalNumberFormat); reader.Close(); string[] inputSignalLabels = new string[inputCnt]; for(int i = 0; i < inputCnt; i++) inputSignalLabels[i] = "In_" + i.ToString(Config.InternalNumberFormat); string[] outputSignalLabels = new string[outputCnt]; for(int i = 0; i < outputCnt; i++) outputSignalLabels[i] = "Out_" + i.ToString(Config.InternalNumberFormat); string[] busLabels = new string[busCnt]; for(int i = 0; i < busCnt; i++) busLabels[i] = "Bus_" + i.ToString(Config.InternalNumberFormat); return new Core.Entity(symbol, entityId.Label, entityId.Domain, notation, precedence, inputSignalLabels, outputSignalLabels, busLabels); }