aboutsummaryrefslogtreecommitdiff
path: root/antlr-3.4/runtime/Perl5/examples/simplecalc/simplecalc.pl
blob: e6176ef3d48cbeaeee99edfc68cf8ee144f98224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!perl

use strict;
use warnings;

use ANTLR::Runtime::ANTLRFileStream;
use ANTLR::Runtime::CommonTokenStream;
use ANTLR::Runtime::RecognitionException;
use SimpleCalcLexer;
use SimpleCalcParser;

my $input = ANTLR::Runtime::ANTLRFileStream->new({ file_name => $ARGV[0] });
my $lexer = SimpleCalcLexer->new({ input => $input });
my $tokens = ANTLR::Runtime::CommonTokenStream->new({ token_source => $lexer });
my $parser = SimpleCalcParser->new({ input => $tokens });
eval {
    $parser->expr();
    print "ok\n";
    print "errors: ", $parser->get_number_of_syntax_errors(), "\n";
    print "failed: ", $parser->failed(), "\n";
};
if (my $ex = ANTLR::Runtime::RecognitionException->caught()) {
    print $ex->trace, "\n";
}
elsif ($ex = $@) {
    die $ex;
}