1 # Copyright (C) 2006-2009, Parrot Foundation.
6 tgc.pir - The TGE rules compiler
10 > ./parrot compilers/tge/tgc.pir [OPTIONS] FILE
14 This program takes a tree grammar, specified in B<FILE>, and compiles it
15 into the PIR code needed to execute that grammar. This PIR code is then
16 suitable for inclusion or compilation into other larger programs.
22 =item --output OUTFILE
24 Send the output to OUTFILE. By default, output is directed to STDOUT.
33 .local string infile, outfile
35 load_bytecode "TGE.pbc"
36 load_bytecode "Getopt/Obj.pbc"
38 # Grab program name for error reporting
41 # Sanity check parameters
43 unless $I0 >= 1 goto ERR_TOO_FEW_ARGS
45 # Grab the final argument
49 # Process command line options
51 getopts = new ["Getopt";"Obj"]
52 getopts."notOptStop"(1)
53 push getopts, "output|o=s"
54 push getopts, "help|h"
56 opts = getopts."get_options"( args )
65 ck_output = exists opts['output']
66 if ck_output goto OUTPUT_FILE
70 outfh = $P0.'stdhandle'(.PIO_STDOUT_FILENO)
74 outfile = opts['output']
75 outfh = new ['FileHandle']
76 outfh.'open'(outfile, 'w')
77 unless outfh goto ERR_NO_OUTFILE
81 # Read grammar file and compile here
83 infh = new ['FileHandle']
84 infh.'open'(infile, 'r')
85 unless infh goto ERR_NO_INFILE
88 source = infh.'read'(65535)
92 grammar = new ['TGE';'Compiler']
94 .local string compiled_source
95 compiled_source = grammar.'precompile'(source, infile)
96 print outfh, compiled_source
97 unless ck_output goto END
99 # Close the output file and check result
100 $I0 = outfh.'close'()
102 die 'Error: close output failed'
108 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
109 $P1.'print'("Usage: ")
111 $P1.'print'(" [OPTIONS] FILE\n")
112 $P1.'print'(<<"OPTIONS")
114 --output=OUTFILE -- redirect output to OUTFILE
115 --help -- print this message
121 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
122 $P1.'print'("Error: too few arguments\n\n")
127 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
128 $P1.'print'("Error: file not found: ")
135 $P1 = $P0.'stdhandle'(.PIO_STDERR_FILENO)
136 $P1.'print'("Error: file not found: ")
148 # vim: expandtab shiftwidth=4 ft=pir: