public bool Equals(Rank rank) { if (rank == null) { throw new ArgumentNullException(); } if (RankFormat != rank.RankFormat) { return(false); } switch (RankFormat) { case ERankFormat.Full: return(Prefix.Equals(rank.Prefix) && Title.Equals(rank.Title) && Postfix.Equals(rank.Postfix)); case ERankFormat.PrefixAndTitle: return(Prefix.Equals(rank.Prefix) && Title.Equals(rank.Title)); case ERankFormat.TitleAndPostfix: return(Title.Equals(rank.Title) && Postfix.Equals(rank.Postfix)); default: // ERankFormat.TitleOnly return(Title.Equals(rank.Title)); } }
static void Main(string[] args) { TreeNode bin1 = Postfix.InfixToPostfix(Console.ReadLine()); // e.g "5 * 2 + 1" -> "5 2 * 1 +" // Using TreeNode type, not BinOp (Binary Operator) as we cannot guarantee the root node of the abstract syntax tree will be an operator. Console.WriteLine("To postfix:"); foreach (TreeNode node in Traversal.postOrder(bin1)) { Console.Write(node.value + " "); } Console.WriteLine("\nTo infix:"); foreach (TreeNode node in Traversal.inOrder(bin1)) { Console.Write(node.value + " "); } Console.WriteLine("\nTo prefix:"); foreach (TreeNode node in Traversal.preOrder(bin1)) { Console.Write(node.value + " "); } Console.WriteLine(); // Now using reverse polish notation, calculate what the result is. This takes in a postfix-ordered list of TreeNodes. Console.WriteLine("Answer: " + RPN.Evaluate(Traversal.postOrder(bin1))); }
public byte[] GetNew(Encoding New) { List <byte> returned = new List <byte>(); returned.AddRange(Prefix.GetByteArray()); returned.AddRange(NewString.GetTextBaseList(New).GetByteArray().ToArray()); returned.AddRange(Postfix.GetByteArray()); return(returned.ToArray()); }
public byte[] GetOld() { List <byte> returned = new List <byte>(); returned.AddRange(Prefix.GetByteArray()); returned.AddRange(OldString.GetByteArray()); returned.AddRange(Postfix.GetByteArray()); return(returned.ToArray()); }
/// <summary> /// 将infix转换为postfix后进行计算 /// </summary> public static void infixAndPostfixTest() { char[] infixArray = "4+4/2+(4*5-2^(2^2))*1".ToCharArray(); InfixToPostfix infix = new InfixToPostfix(); Postfix postfix = new Postfix(); string[] postfixArray = infix.Translate(infixArray); string result = postfix.GetResult(postfixArray); System.Console.WriteLine(result); }
public bool MovePostfixUp() { if (Postfix.Count == 0) { return(false); } var temp = Postfix[0]; Postfix.RemoveAt(0); OldString.Add(temp); return(true); }
public void MovePostfixUp() { if (Postfix.Count == 0) { return; } var temp = Postfix[0]; Postfix.RemoveAt(0); Notify("Postfix"); OldString.Add(temp); Notify("OldString"); }
public bool MovePostfixDown() { if (OldString.Count == 0) { return(false); } var temp = OldString[OldString.Count - 1]; if (temp.IsText) { return(false); } Postfix.Insert(0, temp); OldString.RemoveAt(OldString.Count - 1); return(true); }
public void MovePostfixDown() { if (OldString.Count == 0) { return; } var temp = OldString[OldString.Count - 1]; if (temp.IsText) { return; } Postfix.Insert(0, temp); Notify("Postfix"); OldString.RemoveAt(OldString.Count - 1); Notify("OldString"); }
public void analisaExpressao(Lexicon lexicon, Semantic semantic) { if (parenthesisCount == 0) { expression.Clear(); } analisaExpressaoSimples(lexicon, semantic); if (!isErrorToken(token) && (token.simbolo == "smaior" || token.simbolo == "smaiorig" || token.simbolo == "sig" || token.simbolo == "smenor" || token.simbolo == "smenorig" || token.simbolo == "sdif")) { expression.Add(token.lexema); updateToken(lexicon); analisaExpressaoSimples(lexicon, semantic); } if (parenthesisCount == 0) { postfix = new Postfix(expression); postfix.convertExpression(); codeGenerator.generateExpression(postfix.convertedExpression, semantic); } }
//E2 -> O1 E1 | e bool E2() { if (now.word == "+" || now.word == "-" || now.word == "*" || now.word == "/") { b = O1(); if (b == false) { return(b); } b = E1(); return(b); } else if (now.word == ";" || now.word == "in") { InfixToPostfix(Infix); Postfix.Add(ee); Postfix.Insert(0, rr); PostfixTo_4_tuple(Postfix); Postfix = new ArrayList(); return(true); } else if (now.word == ">" || now.word == ">=" || now.word == "=") { InfixToPostfix(Infix); Postfix.Add(ee); Postfix.Insert(0, rr); PostfixTo_4_tuple(Postfix); Postfix = new ArrayList(); Infix = new ArrayList(); return(true); } else { return(false); } }
private void buildRegEX() { RegEXPattern = "^"; RegEXPatternWithoutPrefix = "^"; RegEXPatternWithoutSufix = "^"; RegEXPatternWithoutPrefixSufix = "^"; string pref; pref = Prefix.Replace(",", ", *").Replace("[", @"\[").Replace("]", @"\]"); string postf; postf = Postfix.Replace(",", ", *").Replace("[", @"\[").Replace("]", @"\]"); pref = pref.Replace(".", @"\.").Replace("+", @"\+"); postf = postf.Replace(".", @"\.").Replace("+", @"\+"); pref = pref.Replace("(", @"\(").Replace(")", @"\)" + numPostMod); postf = postf.Replace("(", @"\(").Replace(")", @"\)" + numPostMod); RegEXPattern += pref; RegEXPatternWithoutSufix += pref; if (Bytes == 0) { RegEXPattern += postf + "$"; return; } if (Type == "string with spaces") { RegEXPattern += @"[^\" + '"' + "]+" + postf + "$"; RegEXPatternWithoutPrefix += @"[^\" + '"' + "]+" + postf + "$"; RegEXPatternWithoutSufix += @"[^\" + '"' + "]+" + "$"; RegEXPatternWithoutPrefixSufix += @"[^\" + '"' + "]+" + "$"; return; } if (Type == "string") { string adder = ""; if (Prefix.Length > 0) { adder = @"\d"; } RegEXPattern += @"([" + adder + @"a-zA-Z]|_)+(\.*_*[\da-zA-Z]*)*" + numPostMod + postf + "$"; RegEXPatternWithoutPrefix += @"([" + adder + @"a-zA-Z]|_)+(\.*_*[\da-zA-Z]*)*" + numPostMod + postf + "$"; RegEXPatternWithoutSufix += @"([" + adder + @"a-zA-Z]|_)+(\.*_*[\da-zA-Z]*)*" + numPostMod + "$"; RegEXPatternWithoutPrefixSufix += @"([" + adder + @"a-zA-Z]|_)+(\.*_*[\da-zA-Z]*)*" + numPostMod + "$"; return; } if (Type == "fixed" && Bytes < 0) { RegEXPattern += pref + "*" + numPostMod + postf + "$"; RegEXPatternWithoutPrefix += pref + "*" + numPostMod + postf + "$"; RegEXPatternWithoutSufix += pref + "*" + numPostMod + "$"; RegEXPatternWithoutPrefixSufix += pref + "*" + numPostMod + "$"; return; } int bn = Bytes * 8; string bnum = "%[0,1]{1," + bn + "}"; int hn = Bytes * 2; string hnum = @"\$[\dA-Fa-f]{1," + hn + "}"; string dnum = "0*" + dnums[Bytes - 1]; //RegEXPattern += "[" + bnum + "-" + hnum + "-" + dnum + "]" + postf; RegEXPattern += "(" + bnum + "|" + hnum + "|" + dnum + ")" + numPostMod + postf + "$"; RegEXPatternWithoutPrefix += "(" + bnum + "|" + hnum + "|" + dnum + ")" + numPostMod + postf + "$"; RegEXPatternWithoutSufix += "(" + bnum + "|" + hnum + "|" + dnum + ")" + numPostMod + "$"; RegEXPatternWithoutPrefixSufix += "(" + bnum + "|" + hnum + "|" + dnum + ")" + numPostMod + "$"; }
public LovereadSettings(int start, int end, int bookId) { StartPoint = start; EndPoint = end; Postfix = Postfix.Replace("{BookId}", bookId.ToString()); }
/// <summary> /// Converts Infix into postfix notation, sets and returns Postfix. /// If verbosemode set in ctor, prints conversion process /// </summary> /// <returns></returns> public string Convert() { var _stack = VerboseMode ? new StackVerbose <Symbol>(): new Stack_LinkedListBased <Symbol>(); foreach (var s in _symbols) { // if letter or number, push to stack if (!s.IsSymbol) { Postfix += s + " "; } // if opening bracket, push to stack if (s.Data == "(") { _stack.Push(s); } // if closing bracket... else if (s.Data == ")") { while (_stack.Peek().Data != "(") // TODO: surround next with try except block in case _stack.Count == 0 { Postfix += _stack.Pop() + " "; } // append operators to string until "(" _stack.Pop(); // discard "(" } // if "operator"... else if (operators.Contains(s.Data)) { if (_stack.Count == 0) // if stack empty, push to stack { _stack.Push(s); } else { while (_stack.Peek().Data != "(") // traverse stack until "(" ... { if (_stack.Peek() >= s) // if precedence of next item on stack >= this then pop ... { Postfix += _stack.Pop() + " "; } // ... append to Postfix with trailing space else { break; } // ... else if precedence !>= then break if (_stack.Count == 0) // if stack empty then break { break; } } _stack.Push(s); // ... now push new operator to stack } } // else throw exception here ? } for (int i = _stack.Count; i > 0; i--) { Postfix += _stack.Pop() + " "; } Postfix.TrimEnd(); Postfix += "\n"; //_postfix = String.Join(" ", _postfix.ToCharArray()); // to space _postfix TODO: But F***s Up e.g. 100 return(Postfix); }
public static void PostfixTest() { Postfix postfix = new Postfix(); postfix.run(); }
public void Visit(Postfix t, IEnvironment env, object value) { result = new ErrorValue("No Impl Postfix"); return; }
}// end submitButton_Click /// <summary> /// Converts the input string to all lowercase letters and removes all spaces. Then checks if /// the variables being used have values in their textboxes and that they are correct values. /// If not, the user is alerted. The variables in the string are replaced with their values. /// Then, the input string is them converted to postfix format and evaluated. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void submitButton_Click(object sender, EventArgs e) { string infix = evaluationBox.Text; // Get the string from the evaluation textbox System.Diagnostics.Debug.WriteLine(infix); infix = infix.ToLower(); // Converts all upper case characters in the string to lower case infix = infix.Replace(" ", string.Empty); // Remove all spaces from the string System.Diagnostics.Debug.WriteLine(infix); if (variableCheck(ref infix)) { System.Diagnostics.Debug.WriteLine(infix); // Replace all variables with their associated values infix = replaceVariablesWithValues(infix); System.Diagnostics.Debug.WriteLine(infix); //CommandFactory factory = new BasicFactory(); CommandFactory factory = new OptimizedFactory(); // Parse the user's equation from infix into postfix format Parser parser = new Parser(); List<Command> postfix = parser.infixToPostfix(infix, factory); System.Diagnostics.Debug.WriteLine(infix); // Evaluate the postfix format equation Evaluator evaluator = new Postfix(); int result = evaluator.evaluatePostfix(postfix); lblEqual.Visible = true; lblResult.Text = result.ToString(); }// end if }// end submitButton_Click
public bool Open(string path) { try { names.Clear(); msg.Clear(); XDocument xDoc = XDocument.Load(path, LoadOptions.PreserveWhitespace); XElement MSG1Doc = xDoc.Element("MSG1"); foreach (var NAME in MSG1Doc.Element("CharacterNames").Elements()) { int Index = Convert.ToInt32(NAME.Attribute("Index").Value); string OldNameSource = NAME.Element("OldNameSource").Value; string NewName = NAME.Element("NewName").Value; names.Add(new Names(Index, OldNameSource, NewName, NewCharList)); } foreach (var Message in MSG1Doc.Element("MSG").Elements()) { int Index = Convert.ToInt32(Message.Attribute("Index").Value); string Type = Message.Element("Type").Value; string Name = Message.Element("Name").Value; int CharacterNameIndex = Convert.ToInt32(Message.Element("CharacterNameIndex").Value); string SourceBytes_str = Message.Element("SourceBytes").Value; MSG temp = new MSG(Index, Type, Name, CharacterNameIndex, SourceBytes_str); msg.Add(temp); foreach (var Strings in Message.Element("MessageStrings").Elements()) { int StringIndex = Convert.ToInt32(Strings.Attribute("Index").Value); string NewString = Strings.Element("NewString").Value; MSG.MSGstr temp2 = new MSG.MSGstr(StringIndex, NewString, NewCharList) { CharacterIndex = CharacterNameIndex }; temp.Strings.Add(temp2); foreach (var Prefix in Strings.Elements("PrefixBytes")) { int PrefixIndex = Convert.ToInt32(Prefix.Attribute("Index").Value); string PrefixType = Prefix.Attribute("Type").Value; string PrefixBytes = Prefix.Value; temp2.Prefix.Add(new TextBaseElement(PrefixType, Utilities.String.SplitString(PrefixBytes, '-'))); } foreach (var Old in Strings.Elements("OldStringBytes")) { int OldIndex = Convert.ToInt32(Old.Attribute("Index").Value); string OldType = Old.Attribute("Type").Value; string OldBytes = Old.Value; temp2.OldString.Add(new TextBaseElement(OldType, Utilities.String.SplitString(OldBytes, '-'))); } foreach (var Postfix in Strings.Elements("PostfixBytes")) { int PostfixIndex = Convert.ToInt32(Postfix.Attribute("Index").Value); string PostfixType = Postfix.Attribute("Type").Value; string PostfixBytes = Postfix.Value; temp2.Postfix.Add(new TextBaseElement(PostfixType, Utilities.String.SplitString(PostfixBytes, '-'))); } } } OpenFileName = Path.GetFileName(Path.GetFullPath(path)); return(true); } catch (Exception e) { names.Clear(); msg.Clear(); OpenFileName = ""; Logging.Write("PTPfactory", e.ToString()); return(false); } }
public void ConvertsProperly(string input, string result) { Postfix.ToInfix(input).Should().Be(result); }
private void OpenXmlPTP(Stream stream) { XDocument xDoc = XDocument.Load(stream, LoadOptions.PreserveWhitespace); XElement MSG1Doc = xDoc.Element("MSG1"); foreach (var NAME in MSG1Doc.Element("CharacterNames").Elements()) { int Index = Convert.ToInt32(NAME.Attribute("Index").Value); string OldNameSource = NAME.Element("OldNameSource").Value; string NewName = NAME.Element("NewName").Value; Names.Add(new PTPName(Index, OldNameSource, NewName)); } foreach (var Message in MSG1Doc.Element("MSG").Elements()) { int Index = Convert.ToInt32(Message.Attribute("Index").Value); int Type = Message.Element("Type").Value == "MSG" ? 0 : 1; string Name = Message.Element("Name").Value; int CharacterNameIndex = Convert.ToInt32(Message.Element("CharacterNameIndex").Value); PTPMSG temp = new PTPMSG(Index, Type, Name, CharacterNameIndex); Msg.Add(temp); foreach (var Strings in Message.Element("MessageStrings").Elements()) { int StringIndex = Convert.ToInt32(Strings.Attribute("Index").Value); string NewString = Strings.Element("NewString").Value; PTPMSGstr temp2 = new PTPMSGstr(StringIndex, NewString) { CharacterIndex = CharacterNameIndex }; temp.Strings.Add(temp2); foreach (var Prefix in Strings.Elements("PrefixBytes")) { int PrefixIndex = Convert.ToInt32(Prefix.Attribute("Index").Value); string PrefixType = Prefix.Attribute("Type").Value; string PrefixBytes = Prefix.Value; temp2.Prefix.Add(new TextBaseElement(PrefixType == "Text" ? true : false, StringTool.SplitString(PrefixBytes, '-'))); } foreach (var Old in Strings.Elements("OldStringBytes")) { int OldIndex = Convert.ToInt32(Old.Attribute("Index").Value); string OldType = Old.Attribute("Type").Value; string OldBytes = Old.Value; temp2.OldString.Add(new TextBaseElement(OldType == "Text" ? true : false, StringTool.SplitString(OldBytes, '-'))); } foreach (var Postfix in Strings.Elements("PostfixBytes")) { int PostfixIndex = Convert.ToInt32(Postfix.Attribute("Index").Value); string PostfixType = Postfix.Attribute("Type").Value; string PostfixBytes = Postfix.Value; temp2.Postfix.Add(new TextBaseElement(PostfixType == "Text" ? true : false, StringTool.SplitString(PostfixBytes, '-'))); } } } }
private void CalculateButt_Click(object sender, EventArgs e) { try { if (UnionRad.Checked) { if (!InfixBox.Text.Equals("")) { String infix = InfixBox.Text; String posfix = Postfix.ConvertToPostFix(infix); ArraySet res = UnionAndIntersResult(posfix); ResultBox.Text = res.toString(); } } if (PowerSetRad.Checked) { ArraySet res = UnionAndIntersResult(Postfix.ConvertToPostFix(InfixBox.Text)); ResultBox.Text = ArraySet.getPowerSet(res); } if (SubSetRad.Checked) { String expression = InfixBox.Text; String temp = ""; ArraySet temp1 = null; ArraySet temp2; foreach (char i in expression.ToCharArray()) { if (i == 'c') { temp1 = UnionAndIntersResult(Postfix.ConvertToPostFix(temp)); temp = ""; } else { temp += i; } } temp2 = UnionAndIntersResult(Postfix.ConvertToPostFix(temp)); ResultBox.Text = Convert.ToString(ArraySet.isSubsetOf(temp1, temp2)); } if (CartesianRad.Checked) { String expression = InfixBox.Text; expression = expression.Replace('(', ' '); expression = expression.Replace(')', ' '); expression = expression.Replace('x', ' '); int count = 0; foreach (char i in expression.ToArray()) { if (getIndexFromChar(i) != -1) { count++; } } ArraySet[] tempSetList = new ArraySet[count]; count = 0; foreach (char i in expression.ToArray()) { if (getIndexFromChar(i) != -1) { tempSetList[count] = setList[getIndexFromChar(i)]; if (tempSetList[count].size() == 0) { ResultBox.Text = "Error : Cartesian product with an empty set"; return; } count++; } } ResultBox.Text = ArraySet.Cartesian(tempSetList); } }catch (Exception ex) { MessageBox.Show("Error : Incorrect Input" + " : " + ex.Message); } }