// for all itemsets I in collection C
ItemSet I;
Token token;
IntegerList reduceproductions;
int highestproduction, priority;
SymbolList shiftsymbols, reducesymbols;
for (i = 0; i < _C.getSize(); i++)
{
I = _C.get(i);
shiftsymbols = I.getShiftSymbols(); // Transition symbols for shift actions
reducesymbols = I.getReduceSymbols(); // Lookahead symbols for reduce actions
for (j = 0; j < _tsymbols.getSymbolCount(); j++)
{
reduceproductions = I.getReduceProductions(_tsymbols.getSymbol(j));
priority = -1;
highestproduction = -1;
for (k = 0; k < reduceproductions.getSize(); k++)
{
/*if ((_grammar.getProductionList().getProduction(reduceproductions.get(k)).getSymbol().equals(
_grammar.getStartSymbol())) && (_tsymbols.getSymbol(j).equals(endsymbol)))
_table.setAcceptAction(i, j, reduceproductions.get(k));*/
if (_grammar.getProductionList().getProduction(reduceproductions.get(k)).getPriority()
> priority)
{
highestproduction = reduceproductions.get(k);
priority = _grammar.getProductionList().getProduction(highestproduction).getPriority();
}
}
//if (!_table.isAcceptAction(i, j))
if (shiftsymbols.contains(_tsymbols.getSymbol(j)))
{
if (reducesymbols.contains(_tsymbols.getSymbol(j)))
{
token = _grammar.getTokenList().getToken(_tsymbols.getSymbol(j));
if (token.getPriority() > priority)
{
_table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));
if (_logger!=null)
_logger.warn("Shift/Reduce Conflict State "+i+" between"+
System.getProperty(("line.separator"))+
token+System.getProperty(("line.separator"))+
_grammar.getProductionList().getProduction(highestproduction)+
System.getProperty(("line.separator"))+
"The parser will shift");
}
else if (token.getPriority() < priority)
{
/*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
_grammar.getStartSymbol()))
&& (_tsymbols.getSymbol(j).equals(endsymbol)))
_table.setAcceptAction(i, j, highestproduction);
else*/
_table.setReduceAction(i, j, highestproduction);
if (_logger!=null)
_logger.warn("Shift/Reduce Conflict State "+i+" between"+
System.getProperty(("line.separator"))+
token+System.getProperty(("line.separator"))+
_grammar.getProductionList().getProduction(highestproduction)+
System.getProperty(("line.separator"))+
"The parser will reduce");
}
else
{
if (token.getAssociativity()==Associativity.RIGHT)
{
_table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));
if (_logger!=null)
_logger.warn("Shift/Reduce Conflict State "+i+" between"+
System.getProperty(("line.separator"))+
token+System.getProperty(("line.separator"))+
_grammar.getProductionList().getProduction(highestproduction)+
System.getProperty(("line.separator"))+
"The parser will shift");
}
else if (token.getAssociativity()==Associativity.LEFT)
{
/*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
_grammar.getStartSymbol()))
&& (_tsymbols.getSymbol(j).equals(endsymbol)))
_table.setAcceptAction(i, j, highestproduction);
else*/
_table.setReduceAction(i, j, highestproduction);
if (_logger!=null)
_logger.warn("Shift/Reduce Conflict State "+i+" between"+
System.getProperty(("line.separator"))+
token+System.getProperty(("line.separator"))+
_grammar.getProductionList().getProduction(highestproduction)+
System.getProperty(("line.separator"))+
"The parser will reduce");
}
else
{
_table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));
if (_logger!=null)
_logger.info("Shift/Reduce Conflict State "+i+" between"+
System.getProperty(("line.separator"))+
token+System.getProperty(("line.separator"))+
_grammar.getProductionList().getProduction(highestproduction)+
System.getProperty(("line.separator"))+
"The parser will shift");
_conflicts.add(new ShiftReduceConflict(I, _tsymbols.getSymbol(j)));
}
}
}
else
_table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));
}
else if (reducesymbols.contains(_tsymbols.getSymbol(j)))
{
/*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
_grammar.getStartSymbol()))
&& (_tsymbols.getSymbol(j).equals(endsymbol)))
_table.setAcceptAction(i, j, highestproduction);
else*/
_table.setReduceAction(i, j, highestproduction);
}
for (k = 0; k < reduceproductions.getSize(); k++)
if ((_grammar.getProductionList().getProduction(reduceproductions.get(k)).getSymbol().equals(
_grammar.getStartSymbol())) && (_tsymbols.getSymbol(j).equals(endsymbol)))
_table.setAcceptAction(i, j, reduceproductions.get(k));
}
for (j = 0; j < _ntsymbols.getSymbolCount(); j++)
if (shiftsymbols.contains(_ntsymbols.getSymbol(j)))
_table.setTransition(i, j, I.getTransition(_ntsymbols.getSymbol(j)));
}
/*_table.setAcceptAction(_C.get(0).getTransition(_grammar.getStartSymbol()),
_ntsymbols.indexOf(_grammar.getStartSymbol()), 0);*/