1#!perl
2
3use strict;
4use warnings;
5
6use ANTLR::Runtime::ANTLRFileStream;
7use ANTLR::Runtime::CommonTokenStream;
8use ANTLR::Runtime::RecognitionException;
9use SimpleCalcLexer;
10use SimpleCalcParser;
11
12my $input = ANTLR::Runtime::ANTLRFileStream->new({ file_name => $ARGV[0] });
13my $lexer = SimpleCalcLexer->new({ input => $input });
14my $tokens = ANTLR::Runtime::CommonTokenStream->new({ token_source => $lexer });
15my $parser = SimpleCalcParser->new({ input => $tokens });
16eval {
17    $parser->expr();
18    print "ok\n";
19    print "errors: ", $parser->get_number_of_syntax_errors(), "\n";
20    print "failed: ", $parser->failed(), "\n";
21};
22if (my $ex = ANTLR::Runtime::RecognitionException->caught()) {
23    print $ex->trace, "\n";
24}
25elsif ($ex = $@) {
26    die $ex;
27}
28