Top Description Fields Constructors Methods
java_cup

public Class Main

extends Object
Class Inheritance
Imports
java.util.Enumeration, java.io.*

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: Options to the main program include:
-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
-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.
Author
Frank Flannery
Version
last updated: 7/3/96

Field Summary

Modifier and TypeField and Description
protected static parse_action_table
action_table

Resulting parse action table.

protected static long
build_end

Timing data -- when did we end state and table building

protected static long
check_end

Timing data -- when did we end checking

protected static long
dump_end

Timing data -- when did we end dumping

protected static long
emit_end

Timing data -- when did we finish emitting code

protected static int
expect_conflicts

User option -- number of conflicts to expect

protected static long
final_time

Timing data -- when were we completely done

protected static long
first_end

Timing data -- when did we end first set calculation

protected static boolean
include_non_terms

User option -- should we include non terminal symbol numbers in the symbol constant class.

protected static BufferedInputStream
input_file

Input file.

protected static boolean
lr_values

User option -- should generator generate code for left/right values?

protected static long
machine_end

Timing data -- when did we end state machine construction

protected static boolean
no_summary

User option -- do not print a summary.

protected static long
nullability_end

Timing data -- when did we end nullability calculation

protected static boolean
opt_compact_red

User option -- do we compact tables by making most common reduce the default action

protected static boolean
opt_do_debug

User option -- do we run produce extra debugging messages

protected static boolean
opt_dump_grammar

User option -- do we produce a dump of the grammar

protected static boolean
opt_dump_states

User option -- do we produce a dump of the state machine

protected static boolean
opt_dump_tables

User option -- do we produce a dump of the parse tables

protected static boolean
opt_show_timing

User option -- do we show timing information as a part of the summary

protected static long
parse_end

Timing data -- when did we end parsing

protected static PrintWriter
parser_class_file

Output file for the parser class.

protected static long
prelim_end

Timing data -- when did we end preliminaries

protected static long
reduce_check_end

Timing data -- when did we end checking for non-reduced productions

protected static parse_reduce_table
reduce_table

Resulting reduce-goto table.

protected static lalr_state
start_state

Start state in the overall state machine.

protected static long
start_time

Timing data -- when did we start

protected static boolean
suppress_scanner

User option -- should generator suppress references to java_cup.runtime.Scanner for compatibility with old runtimes?

protected static boolean
sym_interface

User option -- should symbols be put in a class or an interface?

protected static PrintWriter
symbol_class_file

Output file for the symbol constant class.

protected static long
table_end

Timing data -- when did we end table construction

Constructor Summary

AccessConstructor and Description
private
Main()

Only constructor is private, so we do not allocate any instances of this class.

Method Summary

Modifier and TypeMethod and Description
protected static void
build_parser()

Build the (internal) parser from the previously parsed specification.

protected static void
check_unused()

Check for unused symbols.

protected static void
close_files()

Close various files used by the system.

public static void
dump_grammar()

Produce a human readable dump of the grammar.

public static void
dump_machine()

Produce a (semi-) human readable dump of the complete viable prefix recognition state machine.

public static void
dump_tables()

Produce a (semi-) human readable dumps of the parse tables

protected static void
emit_parser()

Call the emit routines necessary to write out the generated parser.

protected static void
emit_summary(boolean
did the system get far enough to generate code.
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.

public static void
main(String[]
an array of strings containing command line arguments.
argv
)

The main driver for the system.

protected static void
open_files()

Open various files used by the system.

protected static void
parse_args(String[]
the command line arguments to be parsed.
argv
)

Parse command line options and arguments to set various user-option flags and variables.

protected static void
parse_grammar_spec()

Parse the grammar specification from standard input.

protected static String
plural(int
the numerical value determining plurality.
val
)

Helper routine to optionally return a plural or non-plural ending.

protected static void
show_times()

Produce the optional timing summary as part of an overall summary.

protected static String
timestr(long
the value being formatted (in ms).
time_val
,
long
total time percentages are calculated against (in ms).
total_time
)

Helper routine to format a decimal based display of seconds and percentage of total time given counts of milliseconds.

protected static void
usage(String
a specific error message to preface the usage message by.
message
)

Print a "usage message" that described possible command line options, then exit.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

action_tableback to summary
protected static parse_action_table action_table

Resulting parse action table.

build_endback to summary
protected static long build_end

Timing data -- when did we end state and table building

check_endback to summary
protected static long check_end

Timing data -- when did we end checking

dump_endback to summary
protected static long dump_end

Timing data -- when did we end dumping

emit_endback to summary
protected static long emit_end

Timing data -- when did we finish emitting code

expect_conflictsback to summary
protected static int expect_conflicts

User option -- number of conflicts to expect

final_timeback to summary
protected static long final_time

Timing data -- when were we completely done

first_endback to summary
protected static long first_end

Timing data -- when did we end first set calculation

include_non_termsback to summary
protected static boolean include_non_terms

User option -- should we include non terminal symbol numbers in the symbol constant class.

input_fileback to summary
protected static BufferedInputStream input_file

Input file. This is a buffered version of System.in.

lr_valuesback to summary
protected static boolean lr_values

User option -- should generator generate code for left/right values?

machine_endback to summary
protected static long machine_end

Timing data -- when did we end state machine construction

no_summaryback to summary
protected static boolean no_summary

User option -- do not print a summary.

nullability_endback to summary
protected static long nullability_end

Timing data -- when did we end nullability calculation

opt_compact_redback to summary
protected static boolean opt_compact_red

User option -- do we compact tables by making most common reduce the default action

opt_do_debugback to summary
protected static boolean opt_do_debug

User option -- do we run produce extra debugging messages

opt_dump_grammarback to summary
protected static boolean opt_dump_grammar

User option -- do we produce a dump of the grammar

opt_dump_statesback to summary
protected static boolean opt_dump_states

User option -- do we produce a dump of the state machine

opt_dump_tablesback to summary
protected static boolean opt_dump_tables

User option -- do we produce a dump of the parse tables

opt_show_timingback to summary
protected static boolean opt_show_timing

User option -- do we show timing information as a part of the summary

parse_endback to summary
protected static long parse_end

Timing data -- when did we end parsing

parser_class_fileback to summary
protected static PrintWriter parser_class_file

Output file for the parser class.

prelim_endback to summary
protected static long prelim_end

Timing data -- when did we end preliminaries

reduce_check_endback to summary
protected static long reduce_check_end

Timing data -- when did we end checking for non-reduced productions

reduce_tableback to summary
protected static parse_reduce_table reduce_table

Resulting reduce-goto table.

start_stateback to summary
protected static lalr_state start_state

Start state in the overall state machine.

start_timeback to summary
protected static long start_time

Timing data -- when did we start

suppress_scannerback to summary
protected static boolean suppress_scanner

User option -- should generator suppress references to java_cup.runtime.Scanner for compatibility with old runtimes?

sym_interfaceback to summary
protected static boolean sym_interface

User option -- should symbols be put in a class or an interface? [CSA]

symbol_class_fileback to summary
protected static PrintWriter symbol_class_file

Output file for the symbol constant class.

table_endback to summary
protected static long table_end

Timing data -- when did we end table construction

Constructor Detail

Mainback to summary
private Main()

Only constructor is private, so we do not allocate any instances of this class.

Method Detail

build_parserback to summary
protected static void build_parser() throws internal_error

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.
check_unusedback to summary
protected static void check_unused()

Check for unused symbols. Unreduced productions get checked when tables are created.

close_filesback to summary
protected static void close_files() throws IOException

Close various files used by the system.

dump_grammarback to summary
public static void dump_grammar() throws internal_error

Produce a human readable dump of the grammar.

dump_machineback to summary
public static void dump_machine()

Produce a (semi-) human readable dump of the complete viable prefix recognition state machine.

dump_tablesback to summary
public static void dump_tables()

Produce a (semi-) human readable dumps of the parse tables

emit_parserback to summary
protected static void emit_parser() throws internal_error

Call the emit routines necessary to write out the generated parser.

emit_summaryback to 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:boolean

did the system get far enough to generate code.

mainback to summary
public static void main(String[] argv) throws internal_error, IOException, Exception

The main driver for the system.

Parameters
argv:String[]

an array of strings containing command line arguments.

open_filesback to summary
protected static void open_files()

Open various files used by the system.

parse_argsback to summary
protected static void parse_args(String[] argv)

Parse command line options and arguments to set various user-option flags and variables.

Parameters
argv:String[]

the command line arguments to be parsed.

parse_grammar_specback to summary
protected static void parse_grammar_spec() throws Exception

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.

pluralback to summary
protected static String plural(int val)

Helper routine to optionally return a plural or non-plural ending.

Parameters
val:int

the numerical value determining plurality.

show_timesback to summary
protected static void show_times()

Produce the optional timing summary as part of an overall summary.

timestrback to summary
protected static String timestr(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.

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:long

the value being formatted (in ms).

total_time:long

total time percentages are calculated against (in ms).

usageback to summary
protected static void usage(String message)

Print a "usage message" that described possible command line options, then exit.

Parameters
message:String

a specific error message to preface the usage message by.