Exemple #1
0
        static void Main(string[] args)
        {
            // standard ANTLR code
            // we get the input
            ICharStream chars = CharStreams.fromPath(args[0]);
            // we set up the lexer
            SQLLexer lexer = new SQLLexer(chars);
            // we use the lexer
            CommonTokenStream stream = new CommonTokenStream(lexer);
            // we set up the parser
            SQLParser parser = new SQLParser(stream);

            // we find the root node of our parse tree
            var tree = parser.statements();

            // we create our visitor
            CreateVisitor          createVisitor = new CreateVisitor();
            List <ClassDescriptor> classes       = createVisitor.VisitStatements(tree);

            // we choose our code generator...
            ICodeGenerator generator;

            // ...depending on the command line argument
            if (args.Count() > 1 && args[1] == "kotlin")
            {
                generator = new KotlinCodeGenerator();
            }
            else
            {
                generator = new CSharpCodeGenerator();
            }

            Console.WriteLine(generator.ToSourceCode("SQLDataTypes", classes));
        }
Exemple #2
0
        public void ParseSpecFile(string specification_file_name)
        {
            var listener = new ErrorListener <IToken>();
            // Try current location, or template directory.
            var location = specification_file_name;

            if (!File.Exists(location))
            {
                location = Piggy._template_directory + "\\" +
                           specification_file_name;
                if (!File.Exists(location))
                {
                    Console.WriteLine("File " + specification_file_name + " does not exist.");
                    throw new Exception();
                }
            }

            var          stream = CharStreams.fromPath(location);
            ITokenSource lexer  = new SpecLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            var          parser = new SpecParserParser(tokens);

            parser.BuildParseTree = true;
            parser.AddErrorListener(listener);
            var spec_ast = parser.spec();

            if (listener.had_error)
            {
                Console.WriteLine(spec_ast.GetText());
                throw new Exception();
            }

            ParseTreeWalker.Default.Walk(this, spec_ast);
        }
Exemple #3
0
    public void Load()
    {
        lineMaterial = new Material(Shader.Find("Sprites/Default"));

        var stream = CharStreams.fromPath(filePath);
        var lexer  = new GravisLexer(stream);
        var tokens = new CommonTokenStream(lexer);
        var parser = new GravisParser(tokens)
        {
            BuildParseTree = true
        };
        var loader = new LoadListener();
        var tree   = parser.file_input();

        ParseTreeWalker.Default.Walk(loader, tree);

        RelinkSubspaces(loader.subspaces, loader.nodes);

        var volume = new Volume();
        var parts  = Node.FindIsolatedGraphs(loader.nodes);

        for (var i = 0; i < parts.Count; i++)
        {
            var nodes = parts[i];
            Node.AlignNodesByForceDirected(nodes);
            DrawNodes(nodes, i, volume);
        }

        var orbit = Camera.main.GetComponent <DragMouseOrbit>();

        orbit.target   = volume.GetCenter();
        orbit.distance = volume.GetRadius() * 2;
    }
        private void CompilePrepare()
        {
            if (File.Exists(mainIniFile))
            {
                SinumerikLexer  definitionLexer  = new SinumerikLexer(CharStreams.fromPath(mainIniFile), null, _errorTextWriter);
                SinumerikParser definitionParser = new SinumerikParser(new CommonTokenStream(definitionLexer), null, _errorTextWriter);
                definitionParser.BuildParseTree = true;
                IParseTree definitionTree = definitionParser.parse();

                GlobalVarsVisitor globalVars = new GlobalVarsVisitor(mainScope);
                globalVars.Visit(definitionTree);
            }

            foreach (var fileName in Directory.EnumerateFiles(subDir))
            {
                SinumerikLexer  subLexer  = new SinumerikLexer(CharStreams.fromPath(fileName), null, _errorTextWriter);
                SinumerikParser subParser = new SinumerikParser(new CommonTokenStream(subLexer), null, _errorTextWriter);

                subParser.BuildParseTree = true;
                IParseTree subTree = subParser.parse();

                SymbolVisitor subSymbolVisitor = new SymbolVisitor(functions);
                subSymbolVisitor.Visit(subTree);
            }

            mainLexer = new SinumerikLexer(CharStreams.fromstring(_text.Text), null, _errorTextWriter);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            {                                                                                            //InputStreamの作り方サンプル
                CharStreams.fromstring("🍴 = 🍐 + \"😎\";(((x * π))) * µ + ∰; a + (x * (y ? 0 : 1) + z);"); //stringから

                using (var fs = File.OpenRead(args[0]))
                    CharStreams.fromStream(fs, Encoding.UTF8); //Streamから(ファイルストリームでもメモリストリームでも)
            }

            var inputStream = CharStreams.fromPath(args[0], Encoding.UTF8);    //ファイルパスから
            var lexer       = new ExpressionLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new ExpressionParser(tokenStream);

            var inputTree = parser.input();

            var(isSuccess, value) = new Visitor().Visit(inputTree);
            if (isSuccess)
            {
                Console.WriteLine($"success. {value}");
            }
            else
            {
                Console.WriteLine("error.");
            }
        }
        public CSharpParserWrapper(string filepath)
        {
            var charStream = CharStreams.fromPath(filepath);
            var lexer      = new CSharpLexer(charStream);

            Tokens = new CommonTokenStream(lexer);
            Parser = new CSharpParser(Tokens);
            Parser.BuildParseTree = true;
        }
 public static bool TryParseFile <T>(string fileName, out T ast, out List <FifthCompilationError> errors)
     where T : IAstNode
 {
     TypeRegistry.DefaultRegistry.LoadPrimitiveTypes();
     InbuiltOperatorRegistry.DefaultRegistry.LoadBuiltinOperators();
     ast    = (T)ParseAndAnnotate <T>(CharStreams.fromPath(fileName));
     errors = new List <FifthCompilationError>();
     return(true);
 }
Exemple #8
0
        public static IEnumerable <Tuple <string, Diagram> > ParseFile(string path)
        {
            ANTLRv4Lexer      lexer  = new ANTLRv4Lexer(CharStreams.fromPath(path));
            CommonTokenStream stream = new CommonTokenStream(lexer);
            ANTLRv4Parser     parser = new ANTLRv4Parser(stream);
            var tree    = parser.grammarSpec();
            var visitor = new ListDiagramVisitor();

            return(visitor.VisitGrammarSpec(tree));
        }
Exemple #9
0
        static void Main(string[] args)
        {
            ICharStream  stream = CharStreams.fromPath(args[0]);
            ITokenSource lexer  = new YARSpgLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            YARSpgParser parser = new YARSpgParser(tokens);

            parser.BuildParseTree = true;
            IParseTree tree = parser.yarspg();
        }
Exemple #10
0
        static void Main(string[] args)
        {
            //Adding translating tools for bools
            var charStream = CharStreams.fromPath("firstProgram.txt");

            var lexer = new GrammarLexer(charStream);

            var tokenStream = new CommonTokenStream(lexer);

            var parser = new GrammarParser(tokenStream)
            {
                BuildParseTree = true
            };

            var tree = parser.program();


            var listener = new ScopeListener();

            var ParseTreeWalker = new ParseTreeWalker();

            ParseTreeWalker.Walk(listener, tree);

            MainScopeClass.Scopes = listener.Scopes;



            var visitor = new PrintVisitor();



            visitor.VisitProgram(tree);
            Console.WriteLine("Basic visitor done!");

            var typeVisitor = new TypeCheckerVisitor();

            typeVisitor.VisitProgram(tree);
            Console.WriteLine("Typechecker visitor done!");


            Console.WriteLine("Checking scopes:");

            foreach (var Scope in listener.Scopes)
            {
                Console.WriteLine("Scope start:");
                foreach (var element in Scope.SymbolTable)
                {
                    Console.WriteLine(element);
                }
            }



            Console.ReadLine();
        }
Exemple #11
0
    static void Main(string[] args)
    {
        var options = lfmt.FormatOptions.Parse(args);

        if (options == null)
        {
            return;
        }

        ICharStream charStream = null;

        switch (options.inputMode)
        {
        case "text":
            charStream = CharStreams.fromstring(options.input);
            break;

        case "file":
            charStream = CharStreams.fromPath(options.input);
            break;

        case "stdin":
            charStream = CharStreams.fromTextReader(Console.In);
            break;

        default:
            // show error messages
            return;
        }

        IFormatWriter writer = null;

        switch (options.outputMode)
        {
        case "stdout":
            writer = new StdoutWriter();
            break;

        case "file":
            writer = new FileWriter(options.output);
            break;

        default:
            // show error messages
            return;
        }

        lfmt.Formatter.Format(charStream, writer, options);

        charStream.Release(0);
        writer.Close();
    }
        private void MyParseMethod(string path)
        {
            var          stream = CharStreams.fromPath(path);
            ITokenSource lexer  = new DOTLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            var          parser = new DOTParser(tokens)
            {
                BuildParseTree = true
            };
            IParseTree tree    = parser.graph();
            var        printer = new KeyPrinter();

            printer.RuleMoved += CheckState;
            printer.Terminal  += TerminalHandler;
            ParseTreeWalker.Default.Walk(printer, tree);
        }
        public override void Parse(FileInfo file)
        {
            Lexer lexer = new CSharpLexer(CharStreams.fromPath(file.FullName));

            CommonTokenStream tokens = new CommonTokenStream(lexer);

            CSharpParser parser = new CSharpParser(tokens);

            ParserRuleContext context = parser.compilation_unit();

            var children = context.children;

            foreach (IParseTree child in children)
            {
                this.ParseNode(child);
            }
        }
        public override void Parse(FileInfo file)
        {
            Lexer lexer = new JavaScriptLexer(CharStreams.fromPath(file.FullName));

            CommonTokenStream tokens = new CommonTokenStream(lexer);

            JavaScriptParser parser = new JavaScriptParser(tokens);

            ParserRuleContext context = parser.program();

            var children = context.children;

            foreach (IParseTree child in children)
            {
                this.ParseNode(child);
            }
        }
    static void Main(string[] args)
    {
        bool   show_tree   = false;
        bool   show_tokens = false;
        string file_name   = null;
        string input       = null;

        for (int i = 0; i \ < args.Length; ++i)
        {
            if (args[i].Equals("-tokens"))
            {
                show_tokens = true;
                continue;
            }
            else if (args[i].Equals("-tree"))
            {
                show_tree = true;
                continue;
            }
            else if (args[i].Equals("-input"))
            {
                input = args[++i];
            }
            else if (args[i].Equals("-file"))
            {
                file_name = args[++i];
            }
        }
        ICharStream str = null;

        if (input == null && file_name == null)
        {
            str = CharStreams.fromStream(System.Console.OpenStandardInput());
        }
        else if (input != null)
        {
            str = CharStreams.fromString(input);
        }
        else if (file_name != null)
        {
            str = CharStreams.fromPath(file_name);
        }
Exemple #16
0
        private IEnumerable <IParseTree> BuildParseTrees()
        {
            List <IParseTree> parseTrees = new List <IParseTree>();

            foreach (string file in files)
            {
                ICharStream  stream = fromFile ? CharStreams.fromPath(file) : CharStreams.fromString(file);
                ITokenSource lexer  = new DazelLexer(stream);
                ITokenStream tokens = new CommonTokenStream(lexer);
                DazelParser  parser = new DazelParser(tokens)
                {
                    BuildParseTree = true
                };
                parser.AddErrorListener(new DazelErrorListener());

                parseTrees.Add(parser.start());
            }

            return(parseTrees);
        }
        static void Main(string[] args)
        {
            Test();
            if (args.Length == 0)
            {
                Console.WriteLine("");
                Console.WriteLine("Usage: ControlScriptLanguage.exe inputfile");
                Console.WriteLine("");
                return;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            string filename = args[0];

            //From ANTLR4 Doc (antlr.org).
            ICharStream  streamInput           = CharStreams.fromPath(filename);
            ITokenSource lexer                 = new ControlScriptLanguageLexer(streamInput);
            ITokenStream flowTokens            = new CommonTokenStream(lexer);
            ControlScriptLanguageParser parser = new ControlScriptLanguageParser(flowTokens);

            Console.WriteLine(codePrefix);
            parser.script();
            Console.WriteLine(codeSuffix);
        }
Exemple #18
0
    static Antlr4.Runtime.Tree.IParseTree DoParse(string input)
    {
        bool   show_tree   = false;
        bool   show_tokens = false;
        bool   old         = false;
        bool   two_byte    = false;
        string file_name   = null;

        System.Text.Encoding encoding = null;
        ICharStream          str      = null;

        if (input == null && file_name == null)
        {
            str = CharStreams.fromStream(System.Console.OpenStandardInput());
        }
        else if (input != null)
        {
            str = CharStreams.fromString(input);
        }
        else if (file_name != null)
        {
            if (two_byte)
            {
                str = new TwoByteCharStream(file_name);
            }
            else if (old)
            {
                FileStream fs = new FileStream(file_name, FileMode.Open);
                str = new Antlr4.Runtime.AntlrInputStream(fs);
            }
            else if (encoding == null)
            {
                str = CharStreams.fromPath(file_name);
            }
            else
            {
                str = CharStreams.fromPath(file_name, encoding);
            }
        }
        var lexer = new ArithmeticLexer(str);

        if (show_tokens)
        {
            StringBuilder new_s = new StringBuilder();
            for (int i = 0; ; ++i)
            {
                var ro_token = lexer.NextToken();
                var token    = (CommonToken)ro_token;
                token.TokenIndex = i;
                new_s.AppendLine(token.ToString());
                if (token.Type == Antlr4.Runtime.TokenConstants.EOF)
                {
                    break;
                }
            }
            System.Console.Error.WriteLine(new_s.ToString());
            lexer.Reset();
        }
        var tokens          = new CommonTokenStream(lexer);
        var parser          = new ArithmeticParser(tokens);
        var listener_lexer  = new ErrorListener <int>();
        var listener_parser = new ErrorListener <IToken>();

        lexer.AddErrorListener(listener_lexer);
        parser.AddErrorListener(listener_parser);
        DateTime before = DateTime.Now;

        ArithmeticParser.File_Context tree = parser.file_();
        DateTime after = DateTime.Now;

        System.Console.Error.WriteLine("Time: " + (after - before));
        if (listener_lexer.had_error || listener_parser.had_error)
        {
            System.Console.Error.WriteLine("Parse failed.");
        }
        else
        {
            System.Console.Error.WriteLine("Parse succeeded.");
        }
        if (show_tree)
        {
            System.Console.Error.WriteLine(tree.ToStringTree(parser));
        }
        System.Environment.Exit(listener_lexer.had_error || listener_parser.had_error ? 1 : 0);
        return(tree);
    }
Exemple #19
0
    static void Main(string[] args)
    {
        bool   show_tree   = false;
        bool   show_tokens = false;
        string file_name   = null;
        string input       = null;

        for (int i = 0; i < args.Length; ++i)
        {
            if (args[i].Equals("-tokens"))
            {
                show_tokens = true;
                continue;
            }
            else if (args[i].Equals("-tree"))
            {
                show_tree = true;
                continue;
            }
            else if (args[i].Equals("-input"))
            {
                input = args[++i];
            }
            else if (args[i].Equals("-file"))
            {
                file_name = args[++i];
            }
        }
        ICharStream str = null;

        if (input == null && file_name == null)
        {
            StringBuilder sb = new StringBuilder();
            int           ch;
            while ((ch = System.Console.Read()) != -1)
            {
                sb.Append((char)ch);
            }
            input = sb.ToString();

            str = CharStreams.fromString(input);
        }
        else if (input != null)
        {
            str = CharStreams.fromString(input);
        }
        else if (file_name != null)
        {
            str = CharStreams.fromPath(file_name);
        }
        var lexer = new ArithmeticLexer(str);

        if (show_tokens)
        {
            StringBuilder new_s = new StringBuilder();
            for (int i = 0; ; ++i)
            {
                var ro_token = lexer.NextToken();
                var token    = (CommonToken)ro_token;
                token.TokenIndex = i;
                new_s.AppendLine(token.ToString());
                if (token.Type == Antlr4.Runtime.TokenConstants.EOF)
                {
                    break;
                }
            }
            System.Console.Error.WriteLine(new_s.ToString());
            lexer.Reset();
        }
        var tokens          = new CommonTokenStream(lexer);
        var parser          = new ArithmeticParser(tokens);
        var listener_lexer  = new ErrorListener <int>();
        var listener_parser = new ErrorListener <IToken>();

        lexer.AddErrorListener(listener_lexer);
        parser.AddErrorListener(listener_parser);
        var tree = parser.file();

        if (listener_lexer.had_error || listener_parser.had_error)
        {
            System.Console.Error.WriteLine("parse failed.");
        }
        else
        {
            System.Console.Error.WriteLine("parse succeeded.");
        }
        if (show_tree)
        {
            System.Console.Error.WriteLine(tree.ToStringTree(parser));
        }
        System.Environment.Exit(listener_lexer.had_error || listener_parser.had_error ? 1 : 0);
    }
Exemple #20
0
    static void Main(string[] args)
    {
        bool   show_tree   = false;
        bool   show_tokens = false;
        string file_name   = null;
        string input       = null;

        for (int i = 0; i \ < args.Length; ++i)
        {
            if (args[i].Equals("-tokens"))
            {
                show_tokens = true;
                continue;
            }
            else if (args[i].Equals("-tree"))
            {
                show_tree = true;
                continue;
            }
            else if (args[i].Equals("-input"))
            {
                input = args[++i];
            }
            else if (args[i].Equals("-file"))
            {
                file_name = args[++i];
            }
        }
        ICharStream str = null;

        if (input == null && file_name == null)
        {
            str = CharStreams.fromStream(System.Console.OpenStandardInput());
        }
        else if (input != null)
        {
            str = CharStreams.fromString(input);
        }
        else if (file_name != null)
        {
            str = CharStreams.fromPath(file_name);
        }
        var lexer = new < lexer_name > (str);

        if (show_tokens)
        {
            StringBuilder new_s = new StringBuilder();
            for (int i = 0; ; ++i)
            {
                var ro_token = lexer.NextToken();
                var token    = (CommonToken)ro_token;
                token.TokenIndex = i;
                new_s.AppendLine(token.ToString());
                if (token.Type == Antlr4.Runtime.TokenConstants.EOF)
                {
                    break;
                }
            }
            System.Console.Error.WriteLine(new_s.ToString());
            lexer.Reset();
        }
        var tokens          = new CommonTokenStream(lexer);
        var parser          = new < parser_name > (tokens);
        var listener_lexer  = new ErrorListener \ < int > ();
        var listener_parser = new ErrorListener \ < IToken > ();

        lexer.AddErrorListener(listener_lexer);
        parser.AddErrorListener(listener_parser);
        DateTime before = DateTime.Now;
        var      tree   = parser.< start_symbol > ();
        DateTime after  = DateTime.Now;

        System.Console.Error.WriteLine("Time: " + (after - before));
        if (listener_lexer.had_error || listener_parser.had_error)
        {
            System.Console.Error.WriteLine("Parse failed.");
        }
        else
        {
            System.Console.Error.WriteLine("Parse succeeded.");
        }
        if (show_tree)
        {
            System.Console.Error.WriteLine(tree.ToStringTree(parser));
        }
        System.Environment.Exit(listener_lexer.had_error || listener_parser.had_error ? 1 : 0);
    }
Exemple #21
0
    static void Main(string[] args)
    {
        bool   show_tree   = false;
        bool   show_tokens = false;
        bool   old         = false;
        bool   two_byte    = false;
        string file_name   = null;
        string input       = null;

        System.Text.Encoding encoding = null;
        for (int i = 0; i \ < args.Length; ++i)
        {
            if (args[i].Equals("-tokens"))
            {
                show_tokens = true;
                continue;
            }
            else if (args[i].Equals("-two-byte"))
            {
                two_byte = true;
                continue;
            }
            else if (args[i].Equals("-old"))
            {
                old = true;
                continue;
            }
            else if (args[i].Equals("-tree"))
            {
                show_tree = true;
                continue;
            }
            else if (args[i].Equals("-input"))
            {
                input = args[++i];
            }
            else if (args[i].Equals("-file"))
            {
                file_name = args[++i];
            }
            else if (args[i].Equals("-encoding"))
            {
                ++i;
                encoding = Encoding.GetEncoding(
                    args[i],
                    new EncoderReplacementFallback("(unknown)"),
                    new DecoderReplacementFallback("(error)"));
                if (encoding == null)
                {
                    throw new Exception(@"Unknown encoding. Must be an Internet Assigned Numbers Authority (IANA) code page name. https://www.iana.org/assignments/character-sets/character-sets.xhtml");
                }
            }
        }
        ICharStream str = null;

        if (input == null && file_name == null)
        {
            str = CharStreams.fromStream(System.Console.OpenStandardInput());
        }
        else if (input != null)
        {
            str = CharStreams.fromString(input);
        }
        else if (file_name != null)
        {
            if (two_byte)
            {
                str = new TwoByteCharStream(file_name);
            }
            else if (old)
            {
                FileStream fs = new FileStream(file_name, FileMode.Open);
                str = new Antlr4.Runtime.AntlrInputStream(fs);
            }
            else if (encoding == null)
            {
                str = CharStreams.fromPath(file_name);
            }
            else
            {
                str = CharStreams.fromPath(file_name, encoding);
            }
        }
Exemple #22
0
    static void Main(string[] args)
    {
        bool   show_tree   = false;
        bool   show_tokens = false;
        bool   old         = false;
        bool   two_byte    = false;
        string file_name   = null;
        string input       = null;

        System.Text.Encoding encoding = null;
        for (int i = 0; i < args.Length; ++i)
        {
            if (args[i].Equals("-tokens"))
            {
                show_tokens = true;
                continue;
            }
            else if (args[i].Equals("-two-byte"))
            {
                two_byte = true;
                continue;
            }
            else if (args[i].Equals("-old"))
            {
                old = true;
                continue;
            }
            else if (args[i].Equals("-tree"))
            {
                show_tree = true;
                continue;
            }
            else if (args[i].Equals("-input"))
            {
                input = args[++i];
            }
            else if (args[i].Equals("-file"))
            {
                file_name = args[++i];
            }
            else if (args[i].Equals("-encoding"))
            {
                ++i;
                encoding = Encoding.GetEncoding(
                    args[i],
                    new EncoderReplacementFallback("(unknown)"),
                    new DecoderReplacementFallback("(error)"));
                if (encoding == null)
                {
                    throw new Exception(@"Unknown encoding. Must be an Internet Assigned Numbers Authority (IANA) code page name. https://www.iana.org/assignments/character-sets/character-sets.xhtml");
                }
            }
        }
        ICharStream str = null;

        if (input == null && file_name == null)
        {
            str = CharStreams.fromStream(System.Console.OpenStandardInput());
        }
        else if (input != null)
        {
            str = CharStreams.fromString(input);
        }
        else if (file_name != null)
        {
            if (two_byte)
            {
                str = new TwoByteCharStream(file_name);
            }
            else if (old)
            {
                FileStream fs = new FileStream(file_name, FileMode.Open);
                str = new Antlr4.Runtime.AntlrInputStream(fs);
            }
            else if (encoding == null)
            {
                str = CharStreams.fromPath(file_name);
            }
            else
            {
                str = CharStreams.fromPath(file_name, encoding);
            }
        }
        var lexer = new JavaScriptLexer(str);

        if (show_tokens)
        {
            StringBuilder new_s = new StringBuilder();
            for (int i = 0; ; ++i)
            {
                var ro_token = lexer.NextToken();
                var token    = (CommonToken)ro_token;
                token.TokenIndex = i;
                new_s.AppendLine(token.ToString());
                if (token.Type == Antlr4.Runtime.TokenConstants.EOF)
                {
                    break;
                }
            }
            System.Console.Error.WriteLine(new_s.ToString());
            lexer.Reset();
        }
        var tokens          = new CommonTokenStream(lexer);
        var parser          = new JavaScriptParser(tokens);
        var listener_lexer  = new ErrorListener <int>();
        var listener_parser = new ErrorListener <IToken>();

        lexer.AddErrorListener(listener_lexer);
        parser.AddErrorListener(listener_parser);
        DateTime before = DateTime.Now;
        var      tree   = parser.program();
        DateTime after  = DateTime.Now;

        System.Console.Error.WriteLine("Time: " + (after - before));
        if (listener_lexer.had_error || listener_parser.had_error)
        {
            System.Console.Error.WriteLine("Parse failed.");
        }
        else
        {
            System.Console.Error.WriteLine("Parse succeeded.");
        }
        if (show_tree)
        {
            System.Console.Error.WriteLine(tree.ToStringTree(parser));
        }
        System.Environment.Exit(listener_lexer.had_error || listener_parser.had_error ? 1 : 0);
    }