// Generation of Model and Parser private int Generate() { if (this.input == null) { return(1); } // EBNF-like file -> AST/Grammar Model Grammar grammar = null; Parser parser = new Parser(); try { grammar = parser.Parse(this.input).AST; } catch (ParseException) { Console.Error.WriteLine("Parsing failed, best effort parser error:"); Console.Error.WriteLine(parser.BestErrorToString()); return(1); } if (this.output == Output.AST) { return(this.Export(grammar.ToString())); } if (this.output == Output.Grammar) { return(this.Export( new Emitter.BNF() { EmitInfo = this.emitInfo, Sources = this.sources } .Generate(grammar) .ToString())); } // Grammar Model -> Generator/Parser Model Model model = new Factory().Import(grammar).Model; if (this.output == Output.Model) { if (this.format == Format.Dot) { return(this.Export(this.Dotify(model))); } return(this.Export(model.ToString())); } // Generator/Parser Model -> CSharp code Emitter.CSharp code = new Emitter.CSharp() { EmitInfo = this.emitInfo, EmitRule = this.emitRule, Namespace = this.emitNamespace, Sources = this.sources } .Generate(model); return(this.Export(code.ToString())); }
private void Generate(string file) { Grammar grammar = AsModel.BNF; Generator.Model model = new Generator.Factory().Import(grammar).Model; this.Log(model.ToString()); Emitter.CSharp code = new Emitter.CSharp().Generate(model); Console.WriteLine(code.ToString()); }