Package java_cup
Class emit
- java.lang.Object
-
- java_cup.emit
-
public class emit extends java.lang.ObjectThis class handles emitting generated code for the resulting parser. The various parse tables must be constructed, etc. before calling any routines in this class.Three classes are produced by this code:
- symbol constant class
- this contains constant declarations for each terminal (and optionally each non-terminal).
- action class
- this non-public class contains code to invoke all the user actions that were embedded in the parser specification.
- parser class
- the specialized parser class consisting primarily of some user supplied general and initialization code, and the parse tables.
Three parse tables are created as part of the parser class:
- production table
- lists the LHS non terminal number, and the length of the RHS of each production.
- action table
- for each state of the parse machine, gives the action to be taken
(shift, reduce, or error) under each lookahead symbol.
- reduce-goto table
- when a reduce on a given production is taken, the parse stack is popped back a number of elements corresponding to the RHS of the production. This reveals a prior state, which we transition out of under the LHS non terminal symbol for the production (as if we had seen the LHS symbol rather than all the symbols matching the RHS). This table is indexed by non terminal numbers and indicates how to make these transitions.
In addition to the method interface, this class maintains a series of public global variables and flags indicating how misc. parts of the code and other output is to be produced, and counting things such as number of conflicts detected (see the source code and public variables below for more details).
This class is "static" (contains only static data and methods).
- Version:
- last update: 11/25/95
- Author:
- Scott Hudson
- See Also:
java_cup.main
-
-
Field Summary
Fields Modifier and Type Field Description protected static boolean_genericlabelsprotected static boolean_locationsprotected static boolean_lr_valuesprotected static boolean_xmlactionsstatic java.lang.Stringaction_codeUser declarations for direct inclusion in user action class.static longaction_code_timeTime to produce action code class.static longaction_table_timeTime to produce the action table.static java.lang.Stringclass_type_argumentTUM changes; proposed by Henning Niss 20050628: Type arguments for class declarationstatic longgoto_table_timeTime to produce the reduce-goto table.static java.util.Stackimport_listList of imports (Strings containing class names) to go with actions.static java.lang.Stringinit_codeUser code for user_init() which is called during parser initialization.static intnot_reducedCount of the number on non-reduced productions found.static booleannowarnDo we skip warnings?static intnum_conflictsNumber of conflict found while building tables.static java.lang.Stringpackage_namePackage that the resulting code goes into (null is used for unnamed).static java.lang.Stringparser_class_nameName of the generated parser class.static java.lang.Stringparser_codeUser declarations for direct inclusion in parser class.static longparser_timeTime to produce parser class.static java.lang.StringprefixThe prefix placed on names that pollute someone else's name space.static longproduction_table_timeTime to produce the production table.static java.lang.Stringscan_codeUser code for scan() which is called to get the next Symbol.static productionstart_productionThe start production of the grammar.static java.lang.Stringsymbol_const_class_nameName of the generated class for symbol constants.static longsymbols_timeTime to produce symbol constant class.static intunused_non_termCount of unused non terminals.static intunused_termCount of unused terminals.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclear()protected static voiddo_action_table(java.io.PrintWriter out, parse_action_table act_tab, boolean compact_reduces)Emit the action table.protected static intdo_escaped(java.io.PrintWriter out, char c)protected static intdo_newline(java.io.PrintWriter out, int nchar, int nbytes)protected static voiddo_reduce_table(java.io.PrintWriter out, parse_reduce_table red_tab)Emit the reduce-goto table.protected static voiddo_table_as_string(java.io.PrintWriter out, short[][] sa)protected static voidemit_action_code(java.io.PrintWriter out, production start_prod)Emit code for the non-public class holding the actual action code.protected static voidemit_package(java.io.PrintWriter out)Emit a package spec if the user wants one.protected static voidemit_production_table(java.io.PrintWriter out)Emit the production table.protected static voidemit_xmlaction_code(java.io.PrintWriter out, production start_prod)Emit code for generic XML parsetree output.static booleanlocations()static booleanlr_values()whether or not to emit code for left and right valuesstatic voidparser(java.io.PrintWriter out, parse_action_table action_table, parse_reduce_table reduce_table, int start_st, production start_prod, boolean compact_reduces, boolean suppress_scanner)Emit the parser subclass with embedded tables.protected static java.lang.Stringpre(java.lang.String str)Build a string with the standard prefix.protected static voidset_genericlabels(boolean b)protected static voidset_locations(boolean b)protected static voidset_lr_values(boolean b)protected static voidset_xmlactions(boolean b)static voidsymbols(java.io.PrintWriter out, boolean emit_non_terms, boolean sym_interface)Emit code for the symbol constant class, optionally including non terms, if they have been requested.protected static java.lang.StringtypeArgument()TUM changes; proposed by Henning Niss 20050628 Build a string with the specified type arguments, if present, otherwise an empty string.
-
-
-
Field Detail
-
prefix
public static java.lang.String prefix
The prefix placed on names that pollute someone else's name space.
-
package_name
public static java.lang.String package_name
Package that the resulting code goes into (null is used for unnamed).
-
symbol_const_class_name
public static java.lang.String symbol_const_class_name
Name of the generated class for symbol constants.
-
parser_class_name
public static java.lang.String parser_class_name
Name of the generated parser class.
-
class_type_argument
public static java.lang.String class_type_argument
TUM changes; proposed by Henning Niss 20050628: Type arguments for class declaration
-
action_code
public static java.lang.String action_code
User declarations for direct inclusion in user action class.
-
parser_code
public static java.lang.String parser_code
User declarations for direct inclusion in parser class.
-
init_code
public static java.lang.String init_code
User code for user_init() which is called during parser initialization.
-
scan_code
public static java.lang.String scan_code
User code for scan() which is called to get the next Symbol.
-
start_production
public static production start_production
The start production of the grammar.
-
import_list
public static java.util.Stack import_list
List of imports (Strings containing class names) to go with actions.
-
num_conflicts
public static int num_conflicts
Number of conflict found while building tables.
-
nowarn
public static boolean nowarn
Do we skip warnings?
-
not_reduced
public static int not_reduced
Count of the number on non-reduced productions found.
-
unused_term
public static int unused_term
Count of unused terminals.
-
unused_non_term
public static int unused_non_term
Count of unused non terminals.
-
symbols_time
public static long symbols_time
Time to produce symbol constant class.
-
parser_time
public static long parser_time
Time to produce parser class.
-
action_code_time
public static long action_code_time
Time to produce action code class.
-
production_table_time
public static long production_table_time
Time to produce the production table.
-
action_table_time
public static long action_table_time
Time to produce the action table.
-
goto_table_time
public static long goto_table_time
Time to produce the reduce-goto table.
-
_lr_values
protected static boolean _lr_values
-
_locations
protected static boolean _locations
-
_xmlactions
protected static boolean _xmlactions
-
_genericlabels
protected static boolean _genericlabels
-
-
Method Detail
-
lr_values
public static boolean lr_values()
whether or not to emit code for left and right values
-
locations
public static boolean locations()
-
set_lr_values
protected static void set_lr_values(boolean b)
-
set_locations
protected static void set_locations(boolean b)
-
set_genericlabels
protected static void set_genericlabels(boolean b)
-
set_xmlactions
protected static void set_xmlactions(boolean b)
-
clear
public static void clear()
-
pre
protected static java.lang.String pre(java.lang.String str)
Build a string with the standard prefix.- Parameters:
str- string to prefix.
-
typeArgument
protected static java.lang.String typeArgument()
TUM changes; proposed by Henning Niss 20050628 Build a string with the specified type arguments, if present, otherwise an empty string.
-
emit_package
protected static void emit_package(java.io.PrintWriter out)
Emit a package spec if the user wants one.- Parameters:
out- stream to produce output on.
-
symbols
public static void symbols(java.io.PrintWriter out, boolean emit_non_terms, boolean sym_interface)Emit code for the symbol constant class, optionally including non terms, if they have been requested.- Parameters:
out- stream to produce output on.emit_non_terms- do we emit constants for non terminals?sym_interface- should we emit an interface, rather than a class?
-
emit_action_code
protected static void emit_action_code(java.io.PrintWriter out, production start_prod) throws internal_errorEmit code for the non-public class holding the actual action code.- Parameters:
out- stream to produce output on.start_prod- the start production of the grammar.- Throws:
internal_error
-
emit_production_table
protected static void emit_production_table(java.io.PrintWriter out)
Emit the production table.- Parameters:
out- stream to produce output on.
-
do_action_table
protected static void do_action_table(java.io.PrintWriter out, parse_action_table act_tab, boolean compact_reduces) throws internal_errorEmit the action table.- Parameters:
out- stream to produce output on.act_tab- the internal representation of the action table.compact_reduces- do we use the most frequent reduce as default?- Throws:
internal_error
-
do_reduce_table
protected static void do_reduce_table(java.io.PrintWriter out, parse_reduce_table red_tab)Emit the reduce-goto table.- Parameters:
out- stream to produce output on.red_tab- the internal representation of the reduce-goto table.
-
do_table_as_string
protected static void do_table_as_string(java.io.PrintWriter out, short[][] sa)
-
do_newline
protected static int do_newline(java.io.PrintWriter out, int nchar, int nbytes)
-
do_escaped
protected static int do_escaped(java.io.PrintWriter out, char c)
-
parser
public static void parser(java.io.PrintWriter out, parse_action_table action_table, parse_reduce_table reduce_table, int start_st, production start_prod, boolean compact_reduces, boolean suppress_scanner) throws internal_errorEmit the parser subclass with embedded tables.- Parameters:
out- stream to produce output on.action_table- internal representation of the action table.reduce_table- internal representation of the reduce-goto table.start_st- start state of the parse machine.start_prod- start production of the grammar.compact_reduces- do we use most frequent reduce as default?suppress_scanner- should scanner be suppressed for compatibility?- Throws:
internal_error
-
emit_xmlaction_code
protected static void emit_xmlaction_code(java.io.PrintWriter out, production start_prod) throws internal_errorEmit code for generic XML parsetree output.- Parameters:
out- stream to produce output on.start_prod- the start production of the grammar.- Throws:
internal_error
-
-