本文整理汇总了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);
//.........这里部分代码省略.........
示例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)
{
//.........这里部分代码省略.........