public class production extends Object
I addition to construction and manipulation operations, productions provide methods for factoring out actions (see remove_embedded_actions()), for computing the nullability of the production (i.e., can it derive the empty string, see check_nullable()), and operations for computing its first set (i.e., the set of terminals that could appear at the beginning of some string derived from the production, see check_first_set()).
production_part, 
symbol_part, 
action_part| Modifier and Type | Field and Description | 
|---|---|
| protected action_part | _actionAn action_part containing code for the action to be performed when we
 reduce with this production. | 
| protected static Hashtable<Integer,production> | _allTable of all productions. | 
| protected terminal_set | _first_setFirst set of the production. | 
| protected int | _indexIndex number of the production. | 
| protected symbol_part | _lhsThe left hand side non-terminal. | 
| protected boolean | _nullableNullability of the production (can it derive the empty string). | 
| protected boolean | _nullable_knownIs the nullability of the production known or unknown? | 
| protected int | _num_reductionsCount of number of reductions using this production. | 
| protected production_part[] | _rhsA collection of parts for the right hand side. | 
| protected int | _rhs_assoc | 
| protected int | _rhs_lengthHow much of the right hand side array we are presently using. | 
| protected int | _rhs_precThe precedence of the rule | 
| protected static int | next_indexStatic counter for assigning unique index numbers. | 
| Constructor and Description | 
|---|
| production(non_terminal lhs_sym,
          production_part[] rhs_parts,
          int rhs_l)Constructor with no action string. | 
| production(non_terminal lhs_sym,
          production_part[] rhs_parts,
          int rhs_l,
          int prec_num,
          int prec_side) | 
| production(non_terminal lhs_sym,
          production_part[] rhs_parts,
          int rhs_l,
          String action_str)Full constructor. | 
| production(non_terminal lhs_sym,
          production_part[] rhs_parts,
          int rhs_l,
          String action_str,
          int prec_num,
          int prec_side) | 
| Modifier and Type | Method and Description | 
|---|---|
| action_part | action()An action_part containing code for the action to be performed when we
 reduce with this production. | 
| static Enumeration<production> | all()Access to all productions. | 
| terminal_set | check_first_set()Update (and return) the first set based on current NT firsts. | 
| boolean | check_nullable()Check to see if the production (now) appears to be nullable. | 
| static void | clear() | 
| protected String | declare_labels(production_part[] rhs,
              int rhs_len,
              String final_action)Declare label names as valid variables within the action string | 
| boolean | equals(Object other)Generic equality comparison. | 
| boolean | equals(production other)Equality comparison. | 
| static production | find(int indx)Lookup a production by index. | 
| terminal_set | first_set()First set of the production. | 
| int | hashCode()Produce a hash code. | 
| int | index()Index number of the production. | 
| protected static boolean | is_id_char(char c)Determine if a character can be in a label id. | 
| protected static boolean | is_id_start(char c)Determine if a given character can be a label id starter. | 
| symbol_part | lhs()The left hand side non-terminal. | 
| protected String | make_declaration(String labelname,
                String stack_type,
                int offset)Return label declaration code | 
| protected int | merge_adjacent_actions(production_part[] rhs_parts,
                      int len)Helper routine to merge adjacent actions in a set of RHS parts | 
| void | note_reduction_use()Increment the count of reductions with this non-terminal | 
| boolean | nullable_known()Is the nullability of the production known or unknown? | 
| boolean | nullable()Nullability of the production (can it derive the empty string). | 
| int | num_reductions()Count of number of reductions using this production. | 
| static int | number()Total number of productions. | 
| int | precedence_num()Access to the precedence of the rule | 
| int | precedence_side() | 
| protected void | remove_embedded_actions()Remove all embedded actions from a production by factoring them out into
 individual action production using new non terminals. | 
| int | rhs_length()How much of the right hand side array we are presently using. | 
| production_part | rhs(int indx)Access to the collection of parts for the right hand side. | 
| void | set_precedence_num(int prec_num)Setting the precedence of a rule | 
| void | set_precedence_side(int prec_side) | 
| protected action_part | strip_trailing_action(production_part[] rhs_parts,
                     int len)Helper routine to strip a trailing action off rhs and return it | 
| String | to_simple_string()Convert to a simpler string. | 
| String | toString()Convert to a string. | 
protected static Hashtable<Integer,production> _all
protected static int next_index
protected symbol_part _lhs
protected int _rhs_prec
protected int _rhs_assoc
protected production_part[] _rhs
protected int _rhs_length
protected action_part _action
protected int _index
protected int _num_reductions
protected boolean _nullable_known
protected boolean _nullable
protected terminal_set _first_set
public production(non_terminal lhs_sym, production_part[] rhs_parts, int rhs_l, String action_str) throws internal_error
Factoring out of actions is accomplished by creating new "hidden" non terminals. For example if the production was originally:
    A ::= B {action} C D
 
 
 then it is factored into two productions:
 
 
    A ::= B X C D
    X ::= {action}
 
 
 (where X is a unique new non terminal). This has the effect of placing
 all actions at the end where they can be handled as part of a reduce by
 the parser.internal_errorpublic production(non_terminal lhs_sym, production_part[] rhs_parts, int rhs_l) throws internal_error
internal_errorpublic production(non_terminal lhs_sym, production_part[] rhs_parts, int rhs_l, String action_str, int prec_num, int prec_side) throws internal_error
internal_errorpublic production(non_terminal lhs_sym, production_part[] rhs_parts, int rhs_l, int prec_num, int prec_side) throws internal_error
internal_errorpublic static Enumeration<production> all()
public static production find(int indx)
public static void clear()
public static int number()
public symbol_part lhs()
public int precedence_num()
public int precedence_side()
public void set_precedence_num(int prec_num)
public void set_precedence_side(int prec_side)
public production_part rhs(int indx) throws internal_error
internal_errorpublic int rhs_length()
public action_part action()
public int index()
public int num_reductions()
public void note_reduction_use()
public boolean nullable_known()
public boolean nullable()
public terminal_set first_set()
protected static boolean is_id_start(char c)
c - the character in question.protected static boolean is_id_char(char c)
c - the character in question.protected String make_declaration(String labelname, String stack_type, int offset)
labelname - the label namestack_type - the stack type of label?protected String declare_labels(production_part[] rhs, int rhs_len, String final_action)
rhs - array of RHS parts.rhs_len - how much of rhs to consider valid.final_action - the final action string of the production.lhs_type - the object type associated with the LHS symbol.protected int merge_adjacent_actions(production_part[] rhs_parts, int len)
rhs_parts - array of RHS parts.len - amount of that array that is valid.protected action_part strip_trailing_action(production_part[] rhs_parts, int len)
rhs_parts - array of RHS parts.len - how many of those are valid.protected void remove_embedded_actions()
                                throws internal_error
    A ::= B {action1} C {action2} D
 
 
 then it will be factored into:
 
 
    A ::= B NT$1 C NT$2 D
    NT$1 ::= {action1}
    NT$2 ::= {action2}
 
 
 where NT$1 and NT$2 are new system created non terminals.internal_errorpublic boolean check_nullable()
                       throws internal_error
internal_errorpublic terminal_set check_first_set() throws internal_error
internal_errorpublic boolean equals(production other)
public boolean equals(Object other)
public String to_simple_string() throws internal_error
internal_errorCopyright © 2003–2016 Community Z Tools Project. All rights reserved.