예제 #1
0
        private void EqualsButtonClick(object sender, RoutedEventArgs e)
        {
            // TODO(patrik): Do the calculation here
            string labelStr = resultLabel.Text;

            Console.WriteLine("DEBUG: Calculation String - '{0}'", labelStr);

            lexer.Reset(labelStr);
            try
            {
                // NOTE(patrik): Try to do the calculations
                Node   node   = parser.Parse();
                double result = node.GenerateNumber();

                // NOTE(patrik): Check if theres an error in generating the number
                if (double.IsPositiveInfinity(result) || double.IsNegativeInfinity(result))
                {
                    error = true;
                    return;
                }

                Console.WriteLine("DEBUG: Calculation Result - '{0}'", result);

                resultLabel.Text = result.ToString(CultureInfo.InvariantCulture);
            }
            catch (SyntaxErrorException)
            {
                // NOTE(patrik): Generate an error to the user
                error            = true;
                resultLabel.Text = "SYNTAX ERROR";
                Console.WriteLine("DEBUG: Calculation Error");
            }
        }