Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private: System::Void ButtonCalculate_Click(System::Object^ sender, System::EventArgs^ e) {
- //run the calculation
- {
- Token[] tokens = Tokenize(CalculateExpression);
- }
- //display result
- }
- private: Token Tokenize(String str)
- {
- string[] split = SplitForTokenize(str);
- List<Token> tokens = new List<Token>();
- foreach(string s in split)
- {
- Token t = Token.StringToToken(s);
- if (s == "-")
- {
- if (tokens.Count == 0 || tokens[tokens.Count - 1].GetTokenType == Token.TokenType.Left_Para || tokens[tokens.Count - 1].GetTokenType == Token.TokenType.Operator)
- {
- t.SetValues('_', Token.Associativity.Right, 30, 1);
- }
- }
- tokens.Add(t);
- }
- return tokens.ToArray();
- }
- private: String SplitForTokenize(String str)
- {
- str = str.Replace("*", " * ");
- str = str.Replace("/", " / ");
- str = str.Replace("+", " + ");
- str = str.Replace("-", " - ");
- str = str.Replace("(", " ( ");
- str = str.Replace(")", " ) ");
- str = str.Trim();
- while (str.Contains(" ")
- str = str.Replace(" ", "");
- return str.Split(' ');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement