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


C# Grammar.ReportConflicts方法代码示例

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


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

示例1: Generate

        internal void Generate(List<AutomatonState> states, Grammar grammar)
        {
            StreamWriter tWrtr = null;
            StreamWriter sWrtr = null;
            StreamWriter cWrtr = null;
            TextWriter   save = Console.Out;

			this.grammar = grammar;

            // did we specify out filename in command line or the file? (command line takes precedence)
            string outFile = GPCG.OutFileName;
            if (outFile == null)
              outFile = grammar.OutFileName;

            if (outFile != null)
            {
                try
                {
                    FileStream fStrm = new FileStream(outFile, FileMode.Create);
                    sWrtr = new StreamWriter(fStrm);
                    Console.WriteLine("GPPG: sending output to {0}", outFile);
                    Console.SetOut(sWrtr);
                }
                catch (IOException x)
                {
                    Console.Error.WriteLine("GPPG: Error. File redirect failed");
                    Console.Error.WriteLine(x.Message);
                    Console.Error.WriteLine("GPPG: Terminating ...");
                    Environment.Exit(1);
                }
            }

            if (grammar.TokFileName != null) // generate token list file
            {
                try {
                    FileStream fStrm = new FileStream( grammar.TokFileName, FileMode.Create );
                    tWrtr = new StreamWriter( fStrm );
                    tWrtr.WriteLine( "// Symbolic tokens for parser for grammar file \"{0}\"", grammar.InputFileIdent );
                }
                catch (IOException x) {
                    Console.Error.WriteLine( "GPPG: Error. Failed to create token namelist file" );
                    Console.Error.WriteLine( x.Message );
                    tWrtr = null;
                }
            }

            if (GPCG.ShareTokens && grammar.DatFileName != null) // serialize Terminals dictionary.
            {
                FileStream fStrm = null;
                try {
                    // Insert marker to carry Terminal.max into the serialized structure.
                    Terminal.InsertMaxDummyTerminalInDictionary( grammar.terminals );
                   
                    fStrm = new FileStream( grammar.DatFileName, FileMode.Create );
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize( fStrm, grammar.terminals );
                }
                catch (IOException x) {
                    Console.Error.WriteLine( "GPPG: Error. Failed to create token serialization file" );
                    Console.Error.WriteLine( x.Message );
                }
                finally {
                    if (fStrm != null)
                        fStrm.Close();
                    Terminal.RemoveMaxDummyTerminalFromDictionary( grammar.terminals );
                }
            }

            if (grammar.DiagFileName != null) // generate conflict list file
            {
                try
                {
                    FileStream cStrm = new FileStream(grammar.DiagFileName, FileMode.Create);
                    cWrtr = new StreamWriter(cStrm);
                    cWrtr.WriteLine("// Parser Conflict Information for grammar file \"{0}\"", grammar.InputFileIdent);
                    cWrtr.WriteLine();
                }
                catch (IOException x)
                {
                    Console.Error.WriteLine("GPPG: Error. Failed to create conflict information file");
                    Console.Error.WriteLine(x.Message);
                    cWrtr = null;
                }
            }

            GenerateCopyright();

            GenerateUsingHeader();

            if (grammar.Namespace != null)
            {
                Console.WriteLine("namespace {0}", grammar.Namespace);
                Console.WriteLine('{');
            }

            if (!GPCG.ImportedTokens)
			    GenerateTokens(grammar.terminals, tWrtr);
            grammar.ReportConflicts(cWrtr);

            GenerateClassHeader(grammar.ParserName);
//.........这里部分代码省略.........
开发者ID:pomma89,项目名称:GardenPoints.T4,代码行数:101,代码来源:CodeGenerator.cs

示例2: Generate

        internal void Generate(List<AutomatonState> states, Grammar grammar)
        {
            StreamWriter tWrtr = null;
            StreamWriter sWrtr = null;
            StreamWriter cWrtr = null;
            TextWriter   save = Console.Out;

            this.grammar = grammar;
            if (grammar.OutFileName != null)
            {
                try
                {
                    FileStream fStrm = new FileStream(grammar.OutFileName, FileMode.Create);
                    sWrtr = new StreamWriter(fStrm);
                    Console.WriteLine("GPPG: sending output to {0}", grammar.OutFileName);
                    Console.SetOut(sWrtr);
                }
                catch (IOException x)
                {
                    Console.Error.WriteLine("GPPG: Error. File redirect failed");
                    Console.Error.WriteLine(x.Message);
                    Console.Error.WriteLine("GPPG: Terminating ...");
                    Environment.Exit(1);
                }
            }

            if (grammar.TokFileName != null) // generate token list file
            {
                try
                {
                    FileStream fStrm = new FileStream(grammar.TokFileName, FileMode.Create);
                    tWrtr = new StreamWriter(fStrm);
                    tWrtr.WriteLine("// Symbolic tokens for parser for grammar file \"{0}\"", grammar.InputFileName);
                }
                catch (IOException x)
                {
                    Console.Error.WriteLine("GPPG: Error. Failed to create token namelist file");
                    Console.Error.WriteLine(x.Message);
                    tWrtr = null;
                }
            }

            if (grammar.DiagFileName != null) // generate conflict list file
            {
                try
                {
                    FileStream cStrm = new FileStream(grammar.DiagFileName, FileMode.Create);
                    cWrtr = new StreamWriter(cStrm);
                    cWrtr.WriteLine("// Parser Conflict Information for grammar file \"{0}\"", grammar.InputFileName);
                    cWrtr.WriteLine();
                }
                catch (IOException x)
                {
                    Console.Error.WriteLine("GPPG: Error. Failed to create conflict information file");
                    Console.Error.WriteLine(x.Message);
                    cWrtr = null;
                }
            }

            GenerateCopyright();

            GenerateUsingHeader();

            if (grammar.Namespace != null)
            {
                Console.WriteLine("namespace {0}", grammar.Namespace);
                Console.WriteLine('{');
            }

            GenerateTokens(grammar.terminals, tWrtr);
            grammar.ReportConflicts(cWrtr);

            GenerateClassHeader(grammar.ParserName);
            foreach (LexSpan span in grammar.prologCode)
            {
                InsertCodeSpan(span);
            }
            GenerateInitializeMethod(states, grammar.productions, grammar.nonTerminals);
            GenerateActionMethod(grammar.productions);
            GenerateToStringMethod();
            InsertCodeSpan(grammar.epilogCode);
            GenerateClassFooter();

            if (grammar.Namespace != null)
                Console.WriteLine('}');

            if (tWrtr != null)
            {
                tWrtr.WriteLine("// End symbolic tokens for parser");
                tWrtr.Close(); // Close the optional token name stream
            }

            if (cWrtr != null)
            {
                cWrtr.WriteLine("// End conflict information for parser");
                cWrtr.Close(); // Close the optional token name stream
            }

            if (sWrtr != null)
            {
//.........这里部分代码省略.........
开发者ID:spark-shading-language,项目名称:spark,代码行数:101,代码来源:CodeGenerator.cs


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