production

Overview | Package | Class | Tree | Deprecated | Index | Help | Weka's home

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## weka.core.parser.java_cup
Class production

    java.lang.Object
      weka.core.parser.java_cup.production

Direct Known Subclasses:
  action_production

    public class production

extends java.lang.Object

This class represents a production in the grammar. It contains a LHS non terminal, and an array of RHS symbols. As various transformations are done on the RHS of the production, it may shrink. As a result a separate length is always maintained to indicate how much of the RHS array is still valid.

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()).

Version:
  last updated: 7/3/96
Author:
  Frank Flannery
See Also:
  `production_part`, `symbol_part`, `action_part`

Constructor Summary
`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, java.lang.String action_str)` Full constructor.
`production(non_terminal lhs_sym, production_part[] rhs_parts, int rhs_l, java.lang.String action_str, int prec_num, int prec_side)`

Method Summary
`action_part` | `action()` An action_part containing code for the action to be performed when we reduce with this production.
`static java.util.Enumeration` | `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()`
`boolean` | `equals(java.lang.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.
`symbol_part` | `lhs()` The left hand side non-terminal.
`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()`
`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)`
`java.lang.String` | `to_simple_string()` Convert to a simpler string.
`java.lang.String` | `toString()` Convert to a string.

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### production

    public production(non_terminal lhs_sym,
                      production_part[] rhs_parts,
                      int rhs_l,
                      java.lang.String action_str)
               throws internal_error

  Full constructor. This constructor accepts a LHS non terminal, an array of RHS parts (including terminals, non terminals, and actions), and a string for a final reduce action. It does several manipulations in the process of creating a production object. After some validity checking it translates labels that appear in actions into code for accessing objects on the runtime parse stack. It them merges adjacent actions if they appear and moves any trailing action into the final reduce actions string. Next it removes any embedded actions by factoring them out with new action productions. Finally it assigns a unique index to the production.

  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.

  Throws:
    `internal_error`

### production

    public production(non_terminal lhs_sym,
                      production_part[] rhs_parts,
                      int rhs_l)
               throws internal_error

  Constructor with no action string.

  Throws:
    `internal_error`

### production

    public production(non_terminal lhs_sym,
                      production_part[] rhs_parts,
                      int rhs_l,
                      java.lang.String action_str,
                      int prec_num,
                      int prec_side)
               throws internal_error

Throws:
  `internal_error`

### production

    public production(non_terminal lhs_sym,
                      production_part[] rhs_parts,
                      int rhs_l,
                      int prec_num,
                      int prec_side)
               throws internal_error

Throws:
  `internal_error`

Method Detail

### all

    public static java.util.Enumeration all()

  Access to all productions.

### find

    public static production find(int indx)

  Lookup a production by index.

### clear

    public static void clear()

### number

    public static int number()

  Total number of productions.

### lhs

    public symbol_part lhs()

  The left hand side non-terminal.

### precedence_num

    public int precedence_num()

  Access to the precedence of the rule

### precedence_side

    public int precedence_side()

### set_precedence_num

    public void set_precedence_num(int prec_num)

  Setting the precedence of a rule

### set_precedence_side

    public void set_precedence_side(int prec_side)

### rhs

    public production_part rhs(int indx)
                        throws internal_error

  Access to the collection of parts for the right hand side.

  Throws:
    `internal_error`

### rhs_length

    public int rhs_length()

  How much of the right hand side array we are presently using.

### action

    public action_part action()

  An action_part containing code for the action to be performed when we reduce with this production.

### index

    public int index()

  Index number of the production.

### num_reductions

    public int num_reductions()

  Count of number of reductions using this production.

### note_reduction_use

    public void note_reduction_use()

  Increment the count of reductions with this non-terminal

### nullable_known

    public boolean nullable_known()

  Is the nullability of the production known or unknown?

### nullable

    public boolean nullable()

  Nullability of the production (can it derive the empty string).

### first_set

    public terminal_set first_set()

  First set of the production. This is the set of terminals that could appear at the front of some string derived from this production.

### check_nullable

    public boolean check_nullable()
                           throws internal_error

  Check to see if the production (now) appears to be nullable. A production is nullable if its RHS could derive the empty string. This results when the RHS is empty or contains only non terminals which themselves are nullable.

  Throws:
    `internal_error`

### check_first_set

    public terminal_set check_first_set()
                                 throws internal_error

  Update (and return) the first set based on current NT firsts. This assumes that nullability has already been computed for all non terminals and productions.

  Throws:
    `internal_error`

### equals

    public boolean equals(production other)

  Equality comparison.

### equals

    public boolean equals(java.lang.Object other)

  Generic equality comparison.

  Overrides:
    `equals` in class `java.lang.Object`

### hashCode

    public int hashCode()

  Produce a hash code.

  Overrides:
    `hashCode` in class `java.lang.Object`

### toString

    public java.lang.String toString()

  Convert to a string.

  Overrides:
    `toString` in class `java.lang.Object`

### to_simple_string

    public java.lang.String to_simple_string()
                                      throws internal_error

  Convert to a simpler string.

  Throws:
    `internal_error`

Overview | Package | Class | Tree | Deprecated | Index | Help | Weka's home

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD