public static void generateSyntaxImpl(
		Syntax syntax,
		String className,
		String pkgName,
		List initialNonterminals)
		throws IOException
	{
		String origClsName = className;
		className = className+"Syntax";
		String fileName = (pkgName != null ? pkgName+"."+className : className);
		fileName = fileName.replace('.', File.separatorChar)+".java";
		Writer f = new BufferedWriter(new FileWriter(fileName));
		
		if (pkgName != null)
			fwrite("package "+pkgName+";\n\n", f);

		fwrite("/**\n", f);
		fwrite(" * DO NOT EDIT - Syntax generated from "+origClsName+".syntax\n", f);
		fwrite(" * at "+new Date()+"\n", f);
		fwrite(" * by fri.patterns.interpreter.parsergenerator.util.SourceGenerator.\n", f);
		fwrite(" */\n\n", f);

		fwrite("import fri.patterns.interpreter.parsergenerator.syntax.*;\n\n", f);
		fwrite("public final class "+className+" extends Syntax\n", f);	// class definition
		fwrite("{\n", f);
		
		for (int i = 0; i < initialNonterminals.size(); i++)	// define String constants for every nonterminal
			fwrite("	public static final String "+initialNonterminals.get(i)+" = \""+initialNonterminals.get(i)+"\";\n", f);
		fwrite("\n", f);
		
		fwrite("	public "+className+"()	{\n", f);	// constructor
		fwrite("		super("+syntax.size()+");\n\n", f);
		fwrite("		Rule rule;\n", f);

		for (int i = 0; i < syntax.size(); i++)	{
			Rule rule = syntax.getRule(i);
			String nt = rule.getNonterminal();
			if (initialNonterminals.indexOf(nt) < 0)	// have not been defined as String constant
				nt = "\""+nt+"\"";
			fwrite("\n		rule = new Rule("+nt+", "+rule.rightSize()+");	// "+i+"\n", f);
			
			for (int j = 0; j < rule.rightSize(); j++)	{
				String rightSymbol = rule.getRightSymbol(j);
				if (Token.isTerminal(rightSymbol))
					fwrite("		rule.addRightSymbol(\""+SyntaxUtil.maskQuoteAndBackslash(rightSymbol)+"\");\n", f);
				else
					if (initialNonterminals.indexOf(rightSymbol) >= 0)	// have been defined as String constants
						fwrite("		rule.addRightSymbol("+rightSymbol+");\n", f);
					else
						fwrite("		rule.addRightSymbol(\""+rightSymbol+"\");\n", f);
			}
			fwrite("		addRule(rule);\n", f);
		}
		fwrite("	}\n", f);
		fwrite("}\n", f);

		f.close();
		System.err.println("Generated Syntax source file: "+fileName);
	}