当前位置: 首页>>代码示例>>C#>>正文


C# Grammar.AddRulesForSyntacticPredicates方法代码示例

本文整理汇总了C#中Antlr3.Tool.Grammar.AddRulesForSyntacticPredicates方法的典型用法代码示例。如果您正苦于以下问题:C# Grammar.AddRulesForSyntacticPredicates方法的具体用法?C# Grammar.AddRulesForSyntacticPredicates怎么用?C# Grammar.AddRulesForSyntacticPredicates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Antlr3.Tool.Grammar的用法示例。


在下文中一共展示了Grammar.AddRulesForSyntacticPredicates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public virtual void Process()
        {
            bool exceptionWhenWritingLexerFile = false;
            string lexerGrammarFileName = null;		// necessary at this scope to have access in the catch below

            Stopwatch timer = Stopwatch.StartNew();

            // Have to be tricky here when Maven or build tools call in and must new Tool()
            // before setting options. The banner won't display that way!
            if ( Verbose && showBanner )
            {
                ErrorManager.Info( "ANTLR Parser Generator  Version " + AssemblyInformationalVersion );
                showBanner = false;
            }

            try
            {
                SortGrammarFiles(); // update grammarFileNames
            }
            catch ( Exception e )
            {
                ErrorManager.Error( ErrorManager.MSG_INTERNAL_ERROR, e );
            }

            foreach ( string grammarFileName in GrammarFileNames )
            {
                // If we are in make mode (to support build tools like Maven) and the
                // file is already up to date, then we do not build it (and in verbose mode
                // we will say so).
                if ( Make )
                {
                    try
                    {
                        if ( !BuildRequired( grammarFileName ) )
                            continue;
                    }
                    catch ( Exception e )
                    {
                        ErrorManager.Error( ErrorManager.MSG_INTERNAL_ERROR, e );
                    }
                }

                if ( Verbose && !Depend )
                {
                    Console.Out.WriteLine( grammarFileName );
                }
                try
                {
                    if ( Depend )
                    {
                        BuildDependencyGenerator dep = new BuildDependencyGenerator( this, grammarFileName );
            #if false
                        IList<string> outputFiles = dep.getGeneratedFileList();
                        IList<string> dependents = dep.getDependenciesFileList();
                        Console.Out.WriteLine( "output: " + outputFiles );
                        Console.Out.WriteLine( "dependents: " + dependents );
            #endif
                        Console.Out.WriteLine( dep.GetDependencies().Render() );
                        continue;
                    }

                    Grammar rootGrammar = GetRootGrammar( grammarFileName );
                    // we now have all grammars read in as ASTs
                    // (i.e., root and all delegates)
                    rootGrammar.composite.AssignTokenTypes();
                    //rootGrammar.composite.TranslateLeftRecursiveRules();
                    rootGrammar.AddRulesForSyntacticPredicates();
                    rootGrammar.composite.DefineGrammarSymbols();
                    rootGrammar.composite.CreateNFAs();

                    GenerateRecognizer( rootGrammar );

                    if ( PrintGrammar )
                    {
                        rootGrammar.PrintGrammar( Console.Out );
                    }

                    if (Report)
                    {
                        GrammarReport2 greport = new GrammarReport2(rootGrammar);
                        Console.WriteLine(greport.ToString());
                    }

                    if ( Profile )
                    {
                        GrammarReport report = new GrammarReport(rootGrammar);
                        Stats.WriteReport( GrammarReport.GRAMMAR_STATS_FILENAME,
                                          report.ToNotifyString() );
                    }

                    // now handle the lexer if one was created for a merged spec
                    string lexerGrammarStr = rootGrammar.GetLexerGrammar();
                    //[email protected]("lexer grammar:\n"+lexerGrammarStr);
                    if ( rootGrammar.type == GrammarType.Combined && lexerGrammarStr != null )
                    {
                        lexerGrammarFileName = rootGrammar.ImplicitlyGeneratedLexerFileName;
                        try
                        {
                            TextWriter w = GetOutputFile( rootGrammar, lexerGrammarFileName );
                            w.Write( lexerGrammarStr );
//.........这里部分代码省略.........
开发者ID:antlr,项目名称:antlrcs,代码行数:101,代码来源:AntlrTool.cs

示例2: ImportGrammar

        /** Import the rules/tokens of a delegate grammar. All delegate grammars are
         *  read during the ctor of first Grammar created.
         *
         *  Do not create NFA here because NFA construction needs to hook up with
         *  overridden rules in delegation root grammar.
         */
        public virtual void ImportGrammar( IToken grammarNameToken, string label )
        {
            string grammarName = grammarNameToken.Text;
            //[email protected]("import "+gfile.getName());
            string gname = grammarName + GrammarFileExtension;
            TextReader br = null;
            try
            {
                string fullName = Tool.GetLibraryFile( gname );
                if (!File.Exists(fullName))
                {
                    gname = grammarName + AltGrammarFileExtension;
                    fullName = Tool.GetLibraryFile(gname);
                }

                //FileReader fr = new FileReader( fullName );
                //br = new BufferedReader( fr );
                br = new StringReader( System.IO.File.ReadAllText( fullName ) );
                Grammar delegateGrammar = null;
                delegateGrammar = new Grammar( Tool, gname, composite );
                delegateGrammar.label = label;

                AddDelegateGrammar( delegateGrammar );

                delegateGrammar.ParseAndBuildAST( br );
                delegateGrammar.AddRulesForSyntacticPredicates();
                if ( !ValidImport( delegateGrammar ) )
                {
                    ErrorManager.GrammarError( ErrorManager.MSG_INVALID_IMPORT,
                                              this,
                                              grammarNameToken,
                                              this,
                                              delegateGrammar );
                    return;
                }
                if ( this.type == GrammarType.Combined &&
                     ( delegateGrammar.name.Equals( this.name + grammarTypeToFileNameSuffix[(int)GrammarType.Lexer] ) ||
                      delegateGrammar.name.Equals( this.name + grammarTypeToFileNameSuffix[(int)GrammarType.Parser] ) ) )
                {
                    ErrorManager.GrammarError( ErrorManager.MSG_IMPORT_NAME_CLASH,
                                              this,
                                              grammarNameToken,
                                              this,
                                              delegateGrammar );
                    return;
                }
                if ( delegateGrammar.grammarTree != null )
                {
                    // we have a valid grammar
                    // deal with combined grammars
                    if ( delegateGrammar.type == GrammarType.Lexer && this.type == GrammarType.Combined )
                    {
                        // ooops, we wasted some effort; tell lexer to read it in
                        // later
                        LexerGrammarTemplate.SetAttribute( "imports", grammarName );
                        // but, this parser grammar will need the vocab
                        // so add to composite anyway so we suck in the tokens later
                    }
                }
                //[email protected]("Got grammar:\n"+delegateGrammar);
            }
            catch ( IOException ioe )
            {
                ErrorManager.Error( ErrorManager.MSG_CANNOT_OPEN_FILE,
                                   gname,
                                   ioe );
            }
            finally
            {
                if ( br != null )
                {
                    try
                    {
                        br.Close();
                    }
                    catch ( IOException ioe )
                    {
                        ErrorManager.Error( ErrorManager.MSG_CANNOT_CLOSE_FILE,
                                           gname,
                                           ioe );
                    }
                }
            }
        }
开发者ID:jamilgeor,项目名称:antlrcs,代码行数:90,代码来源:Grammar.cs


注:本文中的Antlr3.Tool.Grammar.AddRulesForSyntacticPredicates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。