Exemple #1
0
        public void CompileAndRun()
        {
            DisplayResults item = _singleton.Results[_singleton.Results.Count - 1];

            _singleton._page_calc.DoScroll(item);

            string plain_ole_command = _calculation_buffer[_calculation_buffer.Count - 1];

            calculatorParser parser = Parser(plain_ole_command);
            IParseTree       tree   = parser.expressionResult();

            IParseTree[] all_nodes = DFSVisitor.DFS(tree as ParserRuleContext).ToArray();

            if (CheckForExceptions(plain_ole_command, parser, tree, all_nodes))
            {
                return;
            }
            if (CheckForErrorToken(plain_ole_command, parser, tree, all_nodes))
            {
                return;
            }
            if (CheckForResult(plain_ole_command, parser, tree, all_nodes))
            {
                return;
            }

            string result = "Unknown.";

            Results[Results.Count - 1].result.Text = BuildFormattedCommandAndResult(plain_ole_command, 0, result);
            NotifyPropertyChanged("Results");
        }
Exemple #2
0
        private void InDigit(string digit)
        {
            DisplayResults item = _singleton.Results[_singleton.Results.Count - 1];

            _singleton._page_calc.DoScroll(item);

            string plain_ole_command = _calculation_buffer[_calculation_buffer.Count - 1] + digit;

            _calculation_buffer[_calculation_buffer.Count - 1] = plain_ole_command;
            int ErrorPos = plain_ole_command.Length;

            byte[]           byteArray = Encoding.UTF8.GetBytes(plain_ole_command);
            calculatorParser pp        = new calculatorParser(
                new CommonTokenStream(
                    new calculatorLexer(
                        new AntlrInputStream(
                            new StreamReader(
                                new MemoryStream(byteArray)).ReadToEnd()))));
            IParseTree   tree   = pp.expressionResult();
            ITokenStream ts     = pp.TokenStream;
            string       result = AllTokens(ts).Reverse().Skip(1).First().Text;

            Results[Results.Count - 1].result.Text = BuildFormattedCommandAndResult(plain_ole_command, ErrorPos, result);
            NotifyPropertyChanged("Results");
        }