Exemplo n.º 1
0
        public static ParserState Parse(string source, IAbstractSyntaxTreePrinter printer = null, Rule rule = null)
        {
            if (rule == null)
                rule = _grammar.file;

            var state = new ParserState(source);
            try
            {
                if (rule.Match(state))
                {
                    if (state.AtEndOfInput())
                    {
                        if (printer != null)
                            printer.Print(state.GetRoot());

                        return state;
                    }

                    throw new ParsingException(state, rule, message: "Failed to read end of input");
                }

                throw new ParsingException(state, rule, message: "Failed to parse source");
            }
            catch (ParsingException e)
            {
                return state.Exception(e);
            }
        }
Exemplo n.º 2
0
        public static ParserState Parse(string source, IAbstractSyntaxTreePrinter printer = null, Rule rule = null)
        {
            if (rule == null)
            {
                rule = _grammar.file;
            }

            var state = new ParserState(source);

            try
            {
                if (rule.Match(state))
                {
                    if (state.AtEndOfInput())
                    {
                        if (printer != null)
                        {
                            printer.Print(state.GetRoot());
                        }

                        return(state);
                    }

                    throw new ParsingException(state, rule, message: "Failed to read end of input");
                }

                throw new ParsingException(state, rule, message: "Failed to parse source");
            }
            catch (ParsingException e)
            {
                return(state.Exception(e));
            }
        }
Exemplo n.º 3
0
        public static IEnumerable<ParserState> Parse(IAbstractSyntaxTreePrinter printer, string sDir)
        {
            foreach ( var state in Directory.GetFiles("*.c;*.cpp;*.h;*.hpp;").Select(fi => CppFileParser.Parse(fi, printer)) )
            {
                if (state.ParseException != null)
                    throw state.ParseException;

                yield return state;
            }
        }
Exemplo n.º 4
0
        public static IEnumerable <ParserState> Parse(IAbstractSyntaxTreePrinter printer, string sDir)
        {
            foreach (var state in Directory.GetFiles("*.c;*.cpp;*.h;*.hpp;").Select(fi => CppFileParser.Parse(fi, printer)))
            {
                if (state.ParseException != null)
                {
                    throw state.ParseException;
                }

                yield return(state);
            }
        }
Exemplo n.º 5
0
 public static ParserState Parse(string file, IAbstractSyntaxTreePrinter printer = null)
 {
     string text = File.ReadAllText(file);
     return CppSourceParser.Parse(text, printer);
 }
Exemplo n.º 6
0
        public static ParserState Parse(string file, IAbstractSyntaxTreePrinter printer = null)
        {
            string text = File.ReadAllText(file);

            return(CppSourceParser.Parse(text, printer));
        }