Beispiel #1
0
        private static void LoadBnfFile(string fileName, Builder mainBuilder)
        {
            Console.WriteLine("Parse BNF file: {0}", fileName);

            var bnf = File.ReadAllText(fileName);

            var metaParser = new MetaParser();
            var meta = metaParser.Parse(bnf);

            var oprimizedBnf = Optimize(bnf);

            var parser = new Parser(new BnfGrammar(meta.Mode));
            var tree = parser.Parse(oprimizedBnf, fileName);
            if (tree.Status == ParseTreeStatus.Error)
            {
                throw new Exception((tree.ParserMessages.Count > 0)
                    ? string.Format("{0}, in {3} file at line {1}, column {2}", tree.ParserMessages[0].Message, tree.ParserMessages[0].Location.Line, tree.ParserMessages[0].Location.Column, fileName)
                    : string.Format(@"Unknow error in BNF file {0}", fileName));
            }

            var builder = new Builder(tree, mainBuilder);
            builder.BuildExpressions();

            foreach (var @using in meta.Usings)
                LoadBnfFile(@using, mainBuilder);
        }
Beispiel #2
0
        private static void LoadBnfFile(string fileName, Builder mainBuilder)
        {
            Console.WriteLine("Parse BNF file: {0}", fileName);


            var bnf = File.ReadAllText(fileName);


            var metaParser = new MetaParser();
            var meta       = metaParser.Parse(bnf);


            var oprimizedBnf = Optimize(bnf);


            var parser = new Parser(new BnfGrammar(meta.Mode));
            var tree   = parser.Parse(oprimizedBnf, fileName);

            if (tree.Status == ParseTreeStatus.Error)
            {
                throw new Exception((tree.ParserMessages.Count > 0)
                                        ? string.Format("{0}, in {3} file at line {1}, column {2}", tree.ParserMessages[0].Message, tree.ParserMessages[0].Location.Line, tree.ParserMessages[0].Location.Column, fileName)
                                        : string.Format(@"Unknow error in BNF file {0}", fileName));
            }


            var builder = new Builder(tree, mainBuilder);

            builder.BuildExpressions();


            foreach (var @using in meta.Usings)
            {
                LoadBnfFile(@using, mainBuilder);
            }
        }