Package org.acplt.oncrpc.apps.jrpcgen.cup_runtime

# Class virtual_parse_stack

java.lang.Object
org.acplt.oncrpc.apps.jrpcgen.cup_runtime.virtual_parse_stack

public class virtual_parse_stack extends Object
This class implements a temporary or "virtual" parse stack that replaces the top portion of the actual parse stack (the part that has been changed by some set of operations) while maintaining its original contents. This data structure is used when the parse needs to "parse ahead" to determine if a given error recovery attempt will allow the parse to continue far enough to consider it successful. Once success or failure of parse ahead is determined the system then reverts to the original parse stack (which has not actually been modified). Since parse ahead does not execute actions, only parse state is maintained on the virtual stack, not full Symbol objects.

Version:
  last updated: 7/3/96
Author:
  Frank Flannery
See Also:
  - `lr_parser`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected int`
`real_next`
Top of stack indicator for where we leave off in the real stack.
`protected Stack`
`real_stack`
The real stack that we shadow.
`protected Stack`
`vstack`
The virtual top portion of the stack.

## Constructor Summary

Constructors
Constructor
Description
`virtual_parse_stack(Stack shadowing_stack)`
Constructor to build a virtual stack out of a real stack.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`empty()`
Indicate whether the stack is empty.
`protected void`
`get_from_real()`
Transfer an element from the real to the virtual stack.
`void`
`pop()`
Pop the stack.
`void`
`push(int state_num)`
Push a state number onto the stack.
`int`
`top()`
Return value on the top of the stack (without popping it).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### real_stack

protected Stack real_stack
The real stack that we shadow. This is accessed when we move off the bottom of the virtual portion of the stack, but is always left unmodified.

### real_next

protected int real_next
Top of stack indicator for where we leave off in the real stack. This is measured from top of stack, so 0 would indicate that no elements have been "moved" from the real to virtual stack.

### vstack

protected Stack vstack
The virtual top portion of the stack. This stack contains Integer objects with state numbers. This stack shadows the top portion of the real stack within the area that has been modified (via operations on the virtual stack). When this portion of the stack becomes empty we transfer elements from the underlying stack onto this stack.

## Constructor Details

### virtual_parse_stack

public virtual_parse_stack(Stack shadowing_stack) throws Exception
Constructor to build a virtual stack out of a real stack.

Parameters:
  `shadowing_stack` - The real stack.
Throws:
  `Exception` - if any error occurs.

## Method Details

### get_from_real

protected void get_from_real()
Transfer an element from the real to the virtual stack. This assumes that the virtual stack is currently empty.

### empty

public boolean empty()
Indicate whether the stack is empty.

Returns:
  True if the stack is empty, false otherwise.

### top

public int top() throws Exception
Return value on the top of the stack (without popping it).

Returns:
  The value on the top of the stack.
Throws:
  `Exception` - if this method has been called on an empty stack.

### pop

public void pop() throws Exception
Pop the stack.

Throws:
  `Exception` - if the stack is empty.

### push

public void push(int state_num)
Push a state number onto the stack.

Parameters:
  `state_num` - The state that shall e pushed on the stack.