| 1 | #!/usr/local/bin/perl -w | ||
| 2 | # #################################################################################### # | ||
| 3 | # Program parseg4grammarfromfile # | ||
| 4 | # # | ||
| 5 | # Author Axel Zuber # | ||
| 6 | # Created 29.05.2022 # | ||
| 7 | # # | ||
| 8 | # Description read an ANTLR4 grammar file, convert it to Marpa syntax # | ||
| 9 | # and write it to the output file # | ||
| 10 | # # | ||
| 11 | # ------------------------------------------------------------------------------------ # | ||
| 12 | # # | ||
| 13 | # Input ANTLR4 grammar # | ||
| 14 | # # | ||
| 15 | # ------------------------------------------------------------------------------------ # | ||
| 16 | # # | ||
| 17 | # Output Marpa grammar file # | ||
| 18 | # # | ||
| 19 | # ------------------------------------------------------------------------------------ # | ||
| 20 | # # | ||
| 21 | # Exit code # | ||
| 22 | # 0 : Successful # | ||
| 23 | # 4 : Warnings # | ||
| 24 | # 8 : Errors # | ||
| 25 | # # | ||
| 26 | # ------------------------------------------------------------------------------------ # | ||
| 27 | # # | ||
| 28 | # History # | ||
| 29 | # Ver Date Name Description # | ||
| 30 | # 0.9 29.05.2022 A. Zuber Initial version # | ||
| 31 | # # | ||
| 32 | # #################################################################################### # | ||
| 33 | |||
| 34 | package MAIN; | ||
| 35 | |||
| 36 | use strict; | ||
| 37 | use warnings; | ||
| 38 | use open ":std", ":encoding(UTF-8)"; | ||
| 39 | |||
| 40 | use lib 'lib'; | ||
| 41 | use Data::Dumper; | ||
| 42 | use File::Basename; | ||
| 43 | use Getopt::Std; | ||
| 44 | use MarpaX::G4; | ||
| 45 | |||
| 46 | use vars qw($scriptName); | ||
| 47 | |||
| 48 | # ------------------------------------------------------------------------------------ # | ||
| 49 | # MAIN # | ||
| 50 | # ------------------------------------------------------------------------------------ # | ||
| 51 | |||
| 52 | BEGIN { $scriptName = basename($0); } | ||
| 53 | |||
| 54 | my $options = {}; | ||
| 55 | |||
| 56 | die 'Invalid option(s) given' if !getopts( $MarpaX::G4::optstr, $options ); | ||
| 57 | MarpaX::G4::printHelpScreen($scriptName) if exists $options->{h}; | ||
| 58 | |||
| 59 | ## ----------------------------------------------------------------------- | ||
| 60 | # process all input files | ||
| 61 | # (if more than 1 file is specified, they are usually Lexer and Parser) | ||
| 62 | ## ----------------------------------------------------------------------- | ||
| 63 | |||
| 64 | my $translator = MarpaX::G4->new(); | ||
| 65 | $translator->translatefiles( \@ARGV, $options ); | ||
| 66 | |||
| 67 | exit 0 |