static private void writeParserActionsArray(Grammar grammar, Options opts, Writer out) throws IOException
{
for (int i = 0, last_i = grammar.rules.length - 1; i < grammar.rules.length; i++)
{
Production rule = grammar.rules[i];
out.write("\n\t\t\t");
if (rule.code == null)
{
if (rule.rhs.size() == 0)
{
out.write("Action.NONE");
if (i != last_i) out.write(", ");
out.write("\t// [");
out.write(String.valueOf(rule.id));
out.write("] ");
out.write(rule.toString());
}
else if (rule.rhs.size() == 1)
{
out.write("Action.RETURN");
if (i != last_i) out.write(',');
out.write("\t// [");
out.write(String.valueOf(rule.id));
out.write("] ");
out.write(rule.toString());
}
else
{
int n = indexOfLastReferencedSymbol(rule.rhs);
if (n == 0)
{
out.write("Action.RETURN");
}
else if (n > 0)
{
out.write("RETURN");
out.write(String.valueOf(n + 1));
}
else
{
out.write("RETURN");
out.write(String.valueOf(rule.rhs.size()));
}
if (i != last_i) out.write(',');
out.write("\t// [");
out.write(String.valueOf(rule.id));
out.write("] ");
out.write(rule.toString());
if (n < 0)
{
out.write("; returns '");
out.write(rule.rhs.items[rule.rhs.size() - 1].symbol.name);
out.write("' although none is marked");
}
else if (countReferencedSymbols(rule.rhs) > 1)
{
out.write("; returns '");
out.write(rule.rhs.items[n].alias);
out.write("' although more are marked");
}
}
}
else
{
out.write("new Action");
if (opts.name_action_classes)
{
out.write(String.valueOf(rule.id));
out.write("()");
if (i != last_i) out.write(',');
out.write("\t// [");
out.write(String.valueOf(rule.id));
out.write("] ");
out.write(rule.toString());
}
else
{
out.write("() {\t// [");
out.write(String.valueOf(rule.id));
out.write("] ");
out.write(rule.toString());
out.write('\n');
out.write("\t\t\t\tpublic Symbol reduce(Symbol[] _symbols, int offset) {\n");
writeReduceActionCode(rule, out);
out.write("\t\t\t\t}");
out.write("\n\t\t\t}");