Esempio n. 1
0
 public void StaticError(String input)
 {
     try {
         ICharStream  stream = CharStreams.fromstring(input);
         ITokenSource lexer  = new ExceptionLexer(stream, outputStream, error);
         ITokenStream tokens = new CommonTokenStream(lexer);
         CMMParser    parser = new CMMParser(tokens);
         parser.BuildParseTree = true;
         parser.RemoveErrorListeners();
         CMMErrorListener errorListener = new CMMErrorListener();
         errorListener.outputStream = outputStream;
         errorListener.errorShow    = error;
         parser.AddErrorListener(errorListener);
         CMMErrorStrategy errorStrategy = new CMMErrorStrategy();
         parser.ErrorHandler = errorStrategy;
         parser.statements();
     }
     catch (Exception e1) {
         outputStream?.Print(e1.Message);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 准备生成代码
        /// </summary>
        private IParseTree prepareForCodeGen()
        {
            errorPanel.Errors = null;
            textEditor.Errors = null;

            String input = textEditor.Text;

            if (String.IsNullOrEmpty(input))
            {
                return(null);
            }

            var listener = new CMMErrorListener();

            ICharStream  stream = CharStreams.fromstring(input);
            ITokenSource lexer  = new ExceptionLexer(stream, listener);
            ITokenStream tokens = new CommonTokenStream(lexer);
            CMMParser    parser = new CMMParser(tokens);

            parser.RemoveErrorListeners();

            parser.AddErrorListener(listener);
            parser.ErrorHandler = new CMMErrorStrategy();

            parser.BuildParseTree = true;
            IParseTree tree = parser.statements();

            //如果出错,转到错误面板并返回null
            if (listener.errors.Count != 0)
            {
                handleCompileTimeError(listener.errors);
                return(null);
            }
            var graph = new ParseTreeGrapher().CreateGraph(tree, CMMParser.ruleNames);

            drawTreePanel.Graph = graph;

            return(tree);
        }
Esempio n. 3
0
        private void performCheck()
        {
            Debug.WriteLine("perform check");

            Dispatcher.Invoke(() => {
                string input = textEditor.Text;
                if (string.IsNullOrEmpty(input))
                {
                    return;
                }
                errorPanel.Errors = null;
                textEditor.Errors = null;
                Task.Run(() => {
                    var listener = new CMMErrorListener();

                    ICharStream stream  = CharStreams.fromstring(input);
                    ITokenSource lexer  = new ExceptionLexer(stream, listener);
                    ITokenStream tokens = new CommonTokenStream(lexer);
                    CMMParser parser    = new CMMParser(tokens);
                    parser.RemoveErrorListeners();


                    parser.AddErrorListener(listener);
                    parser.ErrorHandler = new CMMErrorStrategy();

                    parser.BuildParseTree = true;
                    IParseTree tree       = parser.statements();

                    if (listener.errors.Count != 0)
                    {
                        Dispatcher.Invoke(() => {
                            errorPanel.Errors = listener.errors;
                            textEditor.Errors = listener.errors;
                        });
                    }
                });
            });
        }