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