IntegerList productions = _grammar.getProductionList().getProductionList(symbol);
SymbolList examined = new SymbolList(true); // List of all examined symbols
SymbolList productiondefinition, newfirstset;
boolean foundEMPTY;
int i, j, k; // index variables
Symbol newsymbol;
for (i = 0; i < productions.getSize(); i++)
{
productiondefinition = _grammar.getProductionList().getProduction(
productions.get(i)).getDefinition();
if (productiondefinition.getSymbolCount() == 0)
{
// Symbol for a empty firstset added
firstset.addSymbol(EmptySymbol.EMPTY);
}
else
{
// for every symbol in the production
j = 0;
do
{
foundEMPTY = true;
newsymbol = productiondefinition.getSymbol(j);
if (newsymbol.isTerminal())
{
// if a terminal symbol
firstset.addSymbol(newsymbol);
}
else if (!newsymbol.equals(symbol))
{
// and if a non terminal symbol
if (!examined.contains(newsymbol))
{
newfirstset = first(newsymbol, visited);
foundEMPTY = newfirstset.contains(EmptySymbol.EMPTY);
for (k = 0; k < newfirstset.getSymbolCount(); k++)
if (!newfirstset.getSymbol(k).isEmpty())
firstset.addSymbol(newfirstset.getSymbol(k));
examined.addSymbol(newsymbol);
}
}
j++;
}
while ((!newsymbol.isTerminal()) && (foundEMPTY) &&
(j < productiondefinition.getSymbolCount()) &&
(!productiondefinition.getSymbol(j - 1).equals(symbol)));
}
}
//System.out.println("Symbol="+symbol.toString()+" beendet");