tsymbols = symbols.getTerminals();
ntsymbols = symbols.getNonterminals();
// C = closure( [S'=^S,EOF] )
IntegerList changedState = new IntegerList(); // 0=not changed 1=changed
addItemSet(getStartItemSet());
changedState.add(CHANGED);
boolean mustrepeat = false;
for (int i = 0; i<getItemSetCount(); i++)
{
changedState.set(i, NOTCHANGED);
ItemSet I = getItemSet(i);
// J = goto(I,X) add to C, for all nonterminal and terminal symbols X
// for the non terminal symbols
SymbolSet nextnonterminals = I.getNextNonterminals();
for (int j = 0; j<nextnonterminals.getSymbolCount(); j++)
{
ItemSet J = I.jump(nextnonterminals.getSymbol(j));
if (!J.isEmpty())
{
int index = indexOfCore(J);
if (index<0) // if C doesn't contain J
{
index = addItemSet(J);
changedState.add(CHANGED);
}
else // otherwise the found state extends through J
{
if (getItemSet(index).addItemSet(J)) // if the found state change
{
if (index<changedState.getCount())
changedState.set(index, CHANGED);
else
changedState.add(CHANGED);
if (index<=i) // if J before I, and J
// was changed then must the loop repeat
mustrepeat = true;
}
}
I.setTransition(nextnonterminals.getSymbol(j), index); // stores the transition for this symbol
}
}
// and for the terminal symbols
SymbolSet nextterminals = I.getNextTerminals();
for (int j = 0; j<nextterminals.getSymbolCount(); j++)
{
ItemSet J = I.jump(nextterminals.getSymbol(j));
if (!J.isEmpty())
{
int index = indexOfCore(J);
if (index<0) // if C doesn't contain J
{
index = addItemSet(J);
changedState.add(CHANGED);
}
else // otherwise the found state extends through J
{
if (getItemSet(index).addItemSet(J)) // if the found state change
{
if (index<changedState.getCount())
changedState.set(index, CHANGED);
else
changedState.add(CHANGED);
if (index<=i) // if J before I, and J
// was changed then must the loop repeat
mustrepeat = true;
}
}
I.setTransition(nextterminals.getSymbol(j), index); // stores the transition for this symbol
}
}
}
do
{
mustrepeat = false;
for (int i = 0; i<getItemSetCount(); i++)
if (changedState.get(i)==CHANGED)
{
changedState.set(i, NOTCHANGED);
ItemSet I = getItemSet(i);
symbols = I.getShiftSymbols();
for (int j = 0; j<symbols.getSymbolCount(); j++)
{
ItemSet J = I.jump(symbols.getSymbol(j));
int index = I.getTransition(symbols.getSymbol(j));
if (getItemSet(index).addItemSet(J)) // if the found state change
{
if (index<changedState.getCount())
changedState.set(index, CHANGED);
else
changedState.add(CHANGED);
if (index<=i) // if J before I, and J
// was changed then must the loop repeat