public static SyntaxTree CreateFromSteam(Stream stream)
        {
            ErrorHandler handler = new ErrorHandler();
            // parse input args, and open input file
            ASTScanner scanner = new ASTScanner(stream);

            scanner.SetHandler(handler);

            Parser parser = new Parser(scanner, handler);

            parser.Parse();

            RootNode root = parser.GetASTRoot();

            if (root != null)
            {
                lastValidRoot = root;
            }
            return(new SyntaxTree(lastValidRoot, scanner.GetTokens(), handler.SortedErrorList().ToImmutableList()));
        }
Example #2
0
        private static void TestParser(string path)
        {
            using (Stream file = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                ErrorHandler handler = new ErrorHandler();
                // parse input args, and open input file
                Scanner scanner = new ASTScanner(file);
                scanner.SetHandler(handler);

                Parser parser = new Parser(scanner, handler);
                if (!parser.Parse())
                {
                    handler.SortedErrorList().ToList().ForEach(e =>
                    {
                        Console.WriteLine(e.Message);
                    });
                }
                else
                {
                    var ast = parser.GetASTRoot();
                }
            }
        }