Пример #1
0
        private static VhdlFile parse(VhdlParserSettings settings, ICharStream stream, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager)
        {
            vhdlLexer lexer = new vhdlLexer(stream);

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            vhdlParser        parser = new vhdlParser(tokens);

            //--------------------------------------------
            //Optional - add listener
            //vhdlListener listener = new vhdlListener();
            //parser.AddParseListener(listener);
            //--------------------------------------------
            vhdlSemanticErrorListener vhdlSemanticErrorListener = new vhdlSemanticErrorListener(stream.SourceName);

            parser.AddErrorListener(vhdlSemanticErrorListener);

            IParseTree tree = parser.design_file();
            //Console.WriteLine(tree.ToStringTree(parser));
            vhdlVisitor visitor = new vhdlVisitor(settings, rootScope, libraryScope, libraryManager)
            {
                FileName = stream.SourceName
            };
            VhdlFile res = visitor.Visit(tree) as VhdlFile;

            return(res);
        }
Пример #2
0
        /// <summary>
        /// Распарсить входной поток
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="libraryScope"></param>
        /// <param name="tokenStream"></param>
        /// <param name="tree"></param>
        /// <returns></returns>
        private VhdlFile Parse(ICharStream stream, LibraryDeclarativeRegion libraryScope, out CommonTokenStream tokenStream, out IParseTree tree)
        {
            VhdlFile res = null;

            file        = null;
            tree        = null;
            tokenStream = null;
            lock (this)
            {
                try
                {
                    vhdlLexer lexer = new vhdlLexer(stream);

                    tokenStream = new CommonTokenStream(lexer);
                    vhdlParser parser = new vhdlParser(tokenStream);

                    //--------------------------------------------
                    //Optional - add listener
                    //vhdlListener listener = new vhdlListener();
                    //parser.AddParseListener(listener);
                    //--------------------------------------------
                    vhdlSemanticErrorListener vhdlSemanticErrorListener = new vhdlSemanticErrorListener(stream.SourceName);
                    parser.AddErrorListener(vhdlSemanticErrorListener);

                    tree = parser.design_file();
                    //Console.WriteLine(tree.ToStringTree(parser));
                    vhdlVisitor visitor = new vhdlVisitor(settings, rootScope, libraryScope, libraryManager)
                    {
                        FileName = stream.SourceName
                    };
                    res = visitor.Visit(tree) as VhdlFile;
                }
                catch (vhdlSemanticException ex)
                {
                    parseSemanticException = ex;
                }
                catch (vhdlParseException ex)
                {
                    parseSyntaxException = ex;
                }
                catch (Exception ex)
                {
                    parseException = ex;
                }
            }
            ShowErrorMessages();
            return(res);
        }