示例#1
0
        static int ParseFiles(string grammarFile, string rootParserName, List<string> sourceFiles, string outputFormat)
        {
            if (string.IsNullOrEmpty(grammarFile)) {
                WriteError("Expected a grammar file path");
                return 1;
            }

            Parser parser = new ExtendedBackusNaurFormParser();

            if (!TryParse(parser, grammarFile)) return 1;

            try {
                parser = ParserGenerator.FromEBnf(File.ReadAllText(grammarFile), rootParserName);
            } catch (ParserGenerationException e) {
                foreach (var semanticError in e.Errors) {
                    WriteError("{0}({2},{3}): {1}", grammarFile, semanticError.Message, semanticError.LineNumber, semanticError.ColumnNumber);
                }
            }

            var error = false;

            foreach (var file in sourceFiles) {
                error |= TryParse(parser, file, outputFormat);
            }

            return error ? 1 : 0;
        }
示例#2
0
 public static Parser FromEBnf(string ebnf, string rootParserName = null)
 {
     var parser = new ExtendedBackusNaurFormParser();
     return parser.Parse(ebnf).Generate(rootParserName);
 }
示例#3
0
        public static Parser FromEBnf(string ebnf, string rootParserName = null)
        {
            var parser = new ExtendedBackusNaurFormParser();

            return(parser.Parse(ebnf).Generate(rootParserName));
        }