final String line = sc.next().trim();
if (!line.startsWith("#")) {
final String[] parts = line.split("\\s+");
if (parts.length < 2 || !"->".equals(parts[1]))
throw new GrammarSyntaxException("Can't understand "
+ "production '" + line + "'.");
final String lhs = parts[0];
final String[] rhs = Arrays.copyOfRange(parts, 2, parts.length);
if (rhs.length == 0)
throw new GrammarSyntaxException("Right hand side missing"
+ " in '" + line + "'.");
if (!addProduction(lhs, rhs))
throw new GrammarSyntaxException("Production '" + line
+ "' is declared more than once.");
}
}
if (productions.isEmpty())
throw new GrammarSyntaxException("There must be at least one"
+ " production.");
}