java_cup

Class non_terminal


public class non_terminal
extends symbol

This class represents a non-terminal symbol in the grammar. Each non terminal has a textual name, an index, and a string which indicates the type of object it will be implemented with at runtime (i.e. the class of object that will be pushed on the parse stack to represent it).

Version:
last updated: 11/25/95

Author:
Scott Hudson

Field Summary

static non_terminal
START_nt
special non-terminal for start symbol
protected static Hashtable
_all
Table of all non-terminals -- elements are stored using name strings as the key
protected static Hashtable
_all_by_index
Table of all non terminals indexed by their index number.
protected terminal_set
_first_set
First set for this non-terminal.
protected boolean
_nullable
Nullability of this non terminal.
protected Hashtable
_productions
Table of all productions with this non terminal on the LHS.
boolean
is_embedded_action
flag non-terminals created to embed action productions
protected static int
next_index
Static counter to assign unique indexes.
protected static int
next_nt
Static counter for creating unique non-terminal names

Fields inherited from class java_cup.symbol

_index, _name, _stack_type, _use_count

Constructor Summary

non_terminal(String nm)
Constructor with default type.
non_terminal(String nm, String tp)
Full constructor.

Method Summary

void
add_production(production prod)
Add a production to our set of productions.
static Enumeration
all()
Access to all non-terminals.
static void
compute_first_sets()
Compute first sets for all non-terminals.
static void
compute_nullability()
Compute nullability of all non-terminals.
static non_terminal
find(String with_name)
lookup a non terminal by name string
static non_terminal
find(int indx)
Lookup a non terminal by index.
terminal_set
first_set()
First set for this non-terminal.
boolean
is_non_term()
Indicate that this symbol is a non-terminal.
protected boolean
looks_nullable()
Test to see if this non terminal currently looks nullable.
boolean
nullable()
Nullability of this non terminal.
int
num_productions()
Total number of productions with this non terminal on the LHS.
static int
number()
Total number of non-terminals.
Enumeration
productions()
Access to productions with this non terminal on the LHS.
String
toString()
convert to string

Methods inherited from class java_cup.symbol

index, is_non_term, name, note_use, stack_type, toString, use_count

Field Details

START_nt

public static final non_terminal START_nt
special non-terminal for start symbol


_all

protected static Hashtable _all
Table of all non-terminals -- elements are stored using name strings as the key


_all_by_index

protected static Hashtable _all_by_index
Table of all non terminals indexed by their index number.


_first_set

protected terminal_set _first_set
First set for this non-terminal.


_nullable

protected boolean _nullable
Nullability of this non terminal.


_productions

protected Hashtable _productions
Table of all productions with this non terminal on the LHS.


is_embedded_action

public boolean is_embedded_action
flag non-terminals created to embed action productions


next_index

protected static int next_index
Static counter to assign unique indexes.


next_nt

protected static int next_nt
Static counter for creating unique non-terminal names

Constructor Details

non_terminal

public non_terminal(String nm)
Constructor with default type.

Parameters:
nm - the name of the non terminal.


non_terminal

public non_terminal(String nm,
                    String tp)
Full constructor.

Parameters:
nm - the name of the non terminal.
tp - the type string for the non terminal.

Method Details

add_production

public void add_production(production prod)
            throws internal_error
Add a production to our set of productions.


all

public static Enumeration all()
Access to all non-terminals.


compute_first_sets

public static void compute_first_sets()
            throws internal_error
Compute first sets for all non-terminals. This assumes nullability has already computed.


compute_nullability

public static void compute_nullability()
            throws internal_error
Compute nullability of all non-terminals.


find

public static non_terminal find(String with_name)
lookup a non terminal by name string


find

public static non_terminal find(int indx)
Lookup a non terminal by index.


first_set

public terminal_set first_set()
First set for this non-terminal.


is_non_term

public boolean is_non_term()
Indicate that this symbol is a non-terminal.
Overrides:
is_non_term in interface symbol


looks_nullable

protected boolean looks_nullable()
            throws internal_error
Test to see if this non terminal currently looks nullable.


nullable

public boolean nullable()
Nullability of this non terminal.


num_productions

public int num_productions()
Total number of productions with this non terminal on the LHS.


number

public static int number()
Total number of non-terminals.


productions

public Enumeration productions()
Access to productions with this non terminal on the LHS.


toString

public String toString()
convert to string
Overrides:
toString in interface symbol