Top Description Fields Constructors Methods
java_cup

public Class lalr_item

extends lr_item_core
Class Inheritance
Imports
java.util.Stack, .Enumeration

This class represents an LALR item. Each LALR item consists of a production, a "dot" at a position within that production, and a set of lookahead symbols (terminal). (The first two of these parts are provide by the super class). An item is designed to represent a configuration that the parser may be in. For example, an item of the form:
   [A ::= B * C d E  , {a,b,c}]
 
indicates that the parser is in the middle of parsing the production
   A ::= B C d E
 
that B has already been parsed, and that we will expect to see a lookahead of either a, b, or c once the complete RHS of this production has been found.

Items may initially be missing some items from their lookahead sets. Links are maintained from each item to the set of items that would need to be updated if symbols are added to its lookahead set. During "lookahead propagation", we add symbols to various lookahead sets and propagate these changes across these dependency links as needed.

Author
Scott Hudson
Version
last updated: 11/25/95
See Also
java_cup.lalr_item_set, java_cup.lalr_state

Field Summary

Modifier and TypeField and Description
protected terminal_set
_lookahead

The lookahead symbols of the item.

protected Stack<E>
_propagate_items

Links to items that the lookahead needs to be propagated to.

protected boolean
needs_propagation

Flag to indicate that this item needs to propagate its lookahead (whether it has changed or not).

Inherited from java_cup.lr_item_core:
_core_hash_cache_dot_pos_symbol_after_dot_the_production

Constructor Summary

AccessConstructor and Description
public
lalr_item(production
the production for the item.
prod
,
int
the position of the "dot" within the production.
pos
,
terminal_set
the set of lookahead symbols.
look
)

Full constructor.

public
lalr_item(production
the production for the item.
prod
,
terminal_set
the set of lookahead symbols.
look
)

Constructor with default position (dot at start).

public
lalr_item(production
the production for the item.
prod
)

Constructor with default position and empty lookahead set.

Method Summary

Modifier and TypeMethod and Description
public void
add_propagate(lalr_item prop_to)

Add a new item to the set of items we propagate to.

public terminal_set
calc_lookahead(terminal_set lookahead_after)

Calculate lookahead representing symbols that could appear after the symbol that the dot is currently in front of.

public boolean
equals(lalr_item other)

Equality comparison -- here we only require the cores to be equal since we need to do sets of items based only on core equality (ignoring lookahead sets).

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java_cup.lr_item_core.equals.

Generic equality comparison.
public int
hashCode()

Overrides java_cup.lr_item_core.hashCode.

Return a hash code -- here we only hash the core since we only test core matching in LALR items.
public terminal_set
lookahead()

The lookahead symbols of the item.

public boolean
lookahead_visible()

Determine if everything from the symbol one beyond the dot all the way to the end of the right hand side is nullable.

public Stack<E>
propagate_items()

Links to items that the lookahead needs to be propagated to

public void
propagate_lookaheads(terminal_set
symbols to potentially be added to lookahead of this item.
incoming
)

Propagate incoming lookaheads through this item to others need to be changed.

public lalr_item
shift()

Produce the new lalr_item that results from shifting the dot one position to the right.

public String
toString()

Overrides java_cup.lr_item_core.toString.

Convert to string.
Inherited from java_cup.lr_item_core:
core_equalscore_hashCodedot_at_enddot_before_ntdot_posequalsobj_hashshift_coresymbol_after_dotthe_productionto_simple_string

Field Detail

_lookaheadback to summary
protected terminal_set _lookahead

The lookahead symbols of the item.

_propagate_itemsback to summary
protected Stack<E> _propagate_items

Links to items that the lookahead needs to be propagated to.

needs_propagationback to summary
protected boolean needs_propagation

Flag to indicate that this item needs to propagate its lookahead (whether it has changed or not).

Constructor Detail

lalr_itemback to summary
public lalr_item(production prod, int pos, terminal_set look) throws internal_error

Full constructor.

Parameters
prod:production

the production for the item.

pos:int

the position of the "dot" within the production.

look:terminal_set

the set of lookahead symbols.

lalr_itemback to summary
public lalr_item(production prod, terminal_set look) throws internal_error

Constructor with default position (dot at start).

Parameters
prod:production

the production for the item.

look:terminal_set

the set of lookahead symbols.

lalr_itemback to summary
public lalr_item(production prod) throws internal_error

Constructor with default position and empty lookahead set.

Parameters
prod:production

the production for the item.

Method Detail

add_propagateback to summary
public void add_propagate(lalr_item prop_to)

Add a new item to the set of items we propagate to.

calc_lookaheadback to summary
public terminal_set calc_lookahead(terminal_set lookahead_after) throws internal_error

Calculate lookahead representing symbols that could appear after the symbol that the dot is currently in front of.

Note

this routine must not be invoked before first sets and nullability has been calculated for all non terminals.

equalsback to summary
public boolean equals(lalr_item other)

Equality comparison -- here we only require the cores to be equal since we need to do sets of items based only on core equality (ignoring lookahead sets).

equalsback to summary
public boolean equals(Object other)

Overrides java_cup.lr_item_core.equals.

Generic equality comparison.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

hashCodeback to summary
public int hashCode()

Overrides java_cup.lr_item_core.hashCode.

Return a hash code -- here we only hash the core since we only test core matching in LALR items.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

lookaheadback to summary
public terminal_set lookahead()

The lookahead symbols of the item.

lookahead_visibleback to summary
public boolean lookahead_visible() throws internal_error

Determine if everything from the symbol one beyond the dot all the way to the end of the right hand side is nullable. This would indicate that the lookahead of this item must be included in the lookaheads of all items produced as a closure of this item.

Note

this routine should not be invoked until after first sets and nullability have been calculated for all non terminals.

propagate_itemsback to summary
public Stack<E> propagate_items()

Links to items that the lookahead needs to be propagated to

propagate_lookaheadsback to summary
public void propagate_lookaheads(terminal_set incoming) throws internal_error

Propagate incoming lookaheads through this item to others need to be changed.

Parameters
incoming:terminal_set

symbols to potentially be added to lookahead of this item.

shiftback to summary
public lalr_item shift() throws internal_error

Produce the new lalr_item that results from shifting the dot one position to the right.

toStringback to summary
public String toString()

Overrides java_cup.lr_item_core.toString.

Convert to string.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.