Package java_cup
Class Main
java.lang.Object
java_cup.Main
This class serves as the main driver for the JavaCup system.
It accepts user options and coordinates overall control flow.
The main flow of control includes the following activities:
- Parse user supplied arguments and options.
- Open output files.
- Parse the specification from standard input.
- Check for unused terminals, non-terminals, and productions.
- Build the state machine, tables, etc.
- Output the generated code.
- Close output files.
- Print a summary if requested.
- -package name
- specify package generated classes go in [default none]
- -parser name
- specify parser class name [default "parser"]
- -symbols name
- specify name for symbol constant class [default "sym"]
- -interface
- emit symbol constant interface, rather than class
- -nonterms
- put non terminals in symbol constant class
- -expect #
- number of conflicts expected/allowed [default 0]
- -compact_red
- compact tables by defaulting to most frequent reduce
- -nowarn
- don't warn about useless productions, etc.
- -nosummary
- don't print the usual summary of parse states, etc.
- -progress
- print messages to indicate progress of the system
- -time
- print time usage summary
- -dump_grammar
- produce a dump of the symbols and grammar
- -dump_states
- produce a dump of parse state machine
- -dump_tables
- produce a dump of the parse tables
- -dump
- produce a dump of all of the above
- -debug
- turn on debugging messages within JavaCup
- -nopositions
- don't generate the positions code
- -locations
- generate handles xleft/xright for symbol positions in actions
- -noscanner
- don't refer to java_cup.runtime.Scanner in the parser (for compatibility with old runtimes)
- -version
- print version information for JavaCUP and halt.
- Version:
- last updated: 7/3/96
- Author:
- Frank Flannery
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static parse_action_tableResulting parse action table.protected static longTiming data -- when did we end state and table buildingprotected static longTiming data -- when did we end checkingprotected static FileOutput directory.protected static longTiming data -- when did we end dumpingprotected static longTiming data -- when did we finish emitting codeprotected static intUser option -- number of conflicts to expectprotected static longTiming data -- when were we completely doneprotected static longTiming data -- when did we end first set calculationprotected static booleanprotected static booleanUser option -- should we include non terminal symbol numbers in the symbol constant class.protected static BufferedInputStreamInput file.protected static booleanprotected static booleanUser option -- should generator generate code for left/right values?protected static longTiming data -- when did we end state machine constructionprotected static booleanUser option -- do not print a summary.protected static longTiming data -- when did we end nullability calculationprotected static booleanUser option -- do we compact tables by making most common reduce the default actionprotected static booleanUser option -- do we run produce extra debugging messagesprotected static booleanUser option -- do eclipse debug symbolsprotected static booleanUser option -- do we produce a dump of the grammarprotected static booleanUser option -- do we produce a dump of the state machineprotected static booleanUser option -- do we produce a dump of the parse tablesprotected static booleanUser option -- do we show timing information as a part of the summaryprotected static longTiming data -- when did we end parsingprotected static PrintWriterOutput file for the parser class.protected static longTiming data -- when did we end preliminariesprotected static booleanUser option -- do we print progress messages.protected static longTiming data -- when did we end checking for non-reduced productionsprotected static parse_reduce_tableResulting reduce-goto table.protected static lalr_stateStart state in the overall state machine.protected static longTiming data -- when did we startprotected static booleanUser option -- should generator suppress references to java_cup.runtime.Scanner for compatibility with old runtimes?protected static booleanUser option -- should symbols be put in a class or an interface? [CSA]protected static PrintWriterOutput file for the symbol constant class.protected static longTiming data -- when did we end table constructionprotected static boolean -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidBuild the (internal) parser from the previously parsed specification.protected static voidCheck for unused symbols.protected static voidClose various files used by the system.static voidProduce a human readable dump of the grammar.static voidProduce a (semi-) human readable dump of the complete viable prefix recognition state machine.static voidProduce a (semi-) human readable dumps of the parse tablesprotected static voidCall the emit routines necessary to write out the generated parser.protected static voidemit_summary(boolean output_produced) Emit a long summary message to standard error (System.err) which summarizes what was found in the specification, how many states were produced, how many conflicts were found, etc.static voidThe main driver for the system.protected static voidOpen various files used by the system.protected static voidparse_args(String[] argv) Parse command line options and arguments to set various user-option flags and variables.protected static voidParse the grammar specification from standard input.protected static Stringplural(int val) Helper routine to optionally return a plural or non-plural ending.protected static voidProduce the optional timing summary as part of an overall summary.protected static Stringtimestr(long time_val, long total_time) Helper routine to format a decimal based display of seconds and percentage of total time given counts of milliseconds.protected static voidPrint a "usage message" that described possible command line options, then exit.
-
Field Details
-
print_progress
protected static boolean print_progressUser option -- do we print progress messages. -
opt_dump_states
protected static boolean opt_dump_statesUser option -- do we produce a dump of the state machine -
opt_dump_tables
protected static boolean opt_dump_tablesUser option -- do we produce a dump of the parse tables -
opt_dump_grammar
protected static boolean opt_dump_grammarUser option -- do we produce a dump of the grammar -
opt_show_timing
protected static boolean opt_show_timingUser option -- do we show timing information as a part of the summary -
opt_do_debug
protected static boolean opt_do_debugUser option -- do we run produce extra debugging messages -
opt_do_debugsymbols
protected static boolean opt_do_debugsymbolsUser option -- do eclipse debug symbols -
opt_compact_red
protected static boolean opt_compact_redUser option -- do we compact tables by making most common reduce the default action -
include_non_terms
protected static boolean include_non_termsUser option -- should we include non terminal symbol numbers in the symbol constant class. -
no_summary
protected static boolean no_summaryUser option -- do not print a summary. -
expect_conflicts
protected static int expect_conflictsUser option -- number of conflicts to expect -
lr_values
protected static boolean lr_valuesUser option -- should generator generate code for left/right values? -
locations
protected static boolean locations -
xmlactions
protected static boolean xmlactions -
genericlabels
protected static boolean genericlabels -
sym_interface
protected static boolean sym_interfaceUser option -- should symbols be put in a class or an interface? [CSA] -
suppress_scanner
protected static boolean suppress_scannerUser option -- should generator suppress references to java_cup.runtime.Scanner for compatibility with old runtimes? -
start_time
protected static long start_timeTiming data -- when did we start -
prelim_end
protected static long prelim_endTiming data -- when did we end preliminaries -
parse_end
protected static long parse_endTiming data -- when did we end parsing -
check_end
protected static long check_endTiming data -- when did we end checking -
dump_end
protected static long dump_endTiming data -- when did we end dumping -
build_end
protected static long build_endTiming data -- when did we end state and table building -
nullability_end
protected static long nullability_endTiming data -- when did we end nullability calculation -
first_end
protected static long first_endTiming data -- when did we end first set calculation -
machine_end
protected static long machine_endTiming data -- when did we end state machine construction -
table_end
protected static long table_endTiming data -- when did we end table construction -
reduce_check_end
protected static long reduce_check_endTiming data -- when did we end checking for non-reduced productions -
emit_end
protected static long emit_endTiming data -- when did we finish emitting code -
final_time
protected static long final_timeTiming data -- when were we completely done -
input_file
Input file. This is a buffered version of System.in. -
parser_class_file
Output file for the parser class. -
symbol_class_file
Output file for the symbol constant class. -
dest_dir
Output directory. -
start_state
Start state in the overall state machine. -
action_table
Resulting parse action table. -
reduce_table
Resulting reduce-goto table.
-
-
Method Details
-
main
The main driver for the system.- Parameters:
argv- an array of strings containing command line arguments.- Throws:
internal_errorIOExceptionException
-
usage
Print a "usage message" that described possible command line options, then exit.- Parameters:
message- a specific error message to preface the usage message by.
-
parse_args
Parse command line options and arguments to set various user-option flags and variables.- Parameters:
argv- the command line arguments to be parsed.
-
open_files
protected static void open_files()Open various files used by the system. -
close_files
Close various files used by the system.- Throws:
IOException
-
parse_grammar_spec
Parse the grammar specification from standard input. This produces sets of terminal, non-terminals, and productions which can be accessed via static variables of the respective classes, as well as the setting of various variables (mostly in the emit class) for small user supplied items such as the code to scan with.- Throws:
Exception
-
check_unused
protected static void check_unused()Check for unused symbols. Unreduced productions get checked when tables are created. -
build_parser
Build the (internal) parser from the previously parsed specification. This includes:- Computing nullability of non-terminals.
- Computing first sets of non-terminals and productions.
- Building the viable prefix recognizer machine.
- Filling in the (internal) parse tables.
- Checking for unreduced productions.
- Throws:
internal_error
-
emit_parser
Call the emit routines necessary to write out the generated parser.- Throws:
internal_error
-
plural
Helper routine to optionally return a plural or non-plural ending.- Parameters:
val- the numerical value determining plurality.
-
emit_summary
protected static void emit_summary(boolean output_produced) Emit a long summary message to standard error (System.err) which summarizes what was found in the specification, how many states were produced, how many conflicts were found, etc. A detailed timing summary is also produced if it was requested by the user.- Parameters:
output_produced- did the system get far enough to generate code.
-
show_times
protected static void show_times()Produce the optional timing summary as part of an overall summary. -
timestr
Helper routine to format a decimal based display of seconds and percentage of total time given counts of milliseconds. Note: this is broken for use with some instances of negative time (since we don't use any negative time here, we let if be for now).- Parameters:
time_val- the value being formatted (in ms).total_time- total time percentages are calculated against (in ms).
-
dump_grammar
Produce a human readable dump of the grammar.- Throws:
internal_error
-
dump_machine
public static void dump_machine()Produce a (semi-) human readable dump of the complete viable prefix recognition state machine. -
dump_tables
public static void dump_tables()Produce a (semi-) human readable dumps of the parse tables
-