*
* @return Return a list of violations, if this object isn't valid.
*/
public Violations validate()
{
Violations violations = new Violations();
if (startsymbol==null)
violations.addViolation("Start symbol is not defined", location);
else if (!contains(startsymbol))
violations.addViolation("Start symbol \""+startsymbol+"\""+
"is not defined through a production", location);
if (getProductionCount()<=0)
violations.addViolation("No productions are defined", location);
for (Enumeration e = productions.elements(); e.hasMoreElements();)
violations.addViolations(((Production)e.nextElement()).validate());
SymbolSet ntsymbols = getSymbols().getNonterminals();
for (int i = 0; i<ntsymbols.getSymbolCount(); i++)
{
if (!contains(ntsymbols.getSymbol(i)))
violations.addViolation("Nonterminal symbol \""+ntsymbols.getSymbol(i)+"\""+
"is not defined through a production", location);
if (ntsymbols.getSymbol(i).getName().equals("error"))
violations.addViolation("Nonterminal symbol with name \"error\" is not allowed", location);
}
SymbolSet tsymbols = getSymbols().getTerminals();
for (int i = 0; i<tsymbols.getSymbolCount(); i++)
{
if ((!(tsymbols.getSymbol(i) instanceof Error)) &&
(tsymbols.getSymbol(i).getName().equals("error")))
violations.addViolation("Terminal symbol with name \"error\" is not allowed", location);
}
return violations;
}