//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
using System;
using System.IO;
using Ilog.Language.Tools;
using Ilog.Language.Syntax;
/**
* Jacc is just another compiler-compiler (or rather, more than just
* that). It is a yacc-compatible C# compiler generator, augmented with
* many features, not the least of which being its ability to
* accommodate dynamic operators à la Prolog. For details,
* consult the documentation on the Jacc system and grammar format.
*
* @version Last modified on Sun May 22 20:53:53 2005 by hak
* @author Hassan Aït-Kaci
* @copyright © 2000 ILOG, S.A.
*
* @see Options
* @see Grammar
* @see GenericParser
* @see ParserGenerator
*/
public class Jacc : Command
{
public static void Main (string[] args)
{
DefineOption("p",
Options.ParserPrefix,
"parser name (default: grammar=\"Foo.grm\" => parser=\"Foo"
+Options.ParserPrefix+".cs\")");
DefineOption("v",
Options.Verbosity.ToString(),
"information verbosity (number between 0 and 4)");
DefineOption("m",
Options.InitMethodSize.ToString(),
"max number of instructions in parser initialization method");
DefineOption("amb",
"",
"allow ambiguous actions (for dynamic parsing)");
DefineOption("trail",
Options.TrailHistory.ToString(),
"max size of trail history (for dynamic parsing)");
DefineOption("choices",
Options.ChoiceHistory.ToString(),
"max size of choice history (for dynamic parsing)");
DefineOption("n",
"",
"do not generate the parser");
DefineOption("rrp",
"",
"resolve R/R conflicts based on precedence (dangerous!)");
DefineOption("doc",
"",
"generate only the grammar documentation");
DefineOption("i",
"",
"tolerate an incomplete grammar (no parser is generated)");
DefineOption("o",
"System.Console.Out",
"redirect the log to the specified file");
DefineOption("e",
"System.Console.Error",
"redirect errors to the specified file");
OptionalArgument(Options.GrammarPrefix);
SetUsage("\nUsage: jacc [options] grammar_file(s)\n");
if (args.Length == 0)
{
PrintHelp();
Environment.Exit(1); // exit with a non-zero status code...
}
if (ParseCommandLine(args))
{
String arg = GetArgument();
String pre = FullFileNamePrefix(arg);
String suf = FileNameSuffix(arg);
String par = GetOption("p");
if (ArgumentIsPresent && !OptionIsPresent("p"))
par = pre+par;
Options.GrammarPrefix = pre;
if (suf.Length > 0)
Options.GrammarSuffix = suf;
Options.ParserPrefix = par;
Options.Verbosity = int.Parse(GetOption("v"));
Options.InitMethodSize = int.Parse(GetOption("m"));
Options.TrailHistory = int.Parse(GetOption("trail"));
Options.ChoiceHistory = int.Parse(GetOption("choices"));
Options.ResolveRRsWithPrecedence = OptionIsPresent("rrp");
Options.AllowChoiceActions = OptionIsPresent("amb");
Options.DocOnly = OptionIsPresent("doc");
Options.NoParser = OptionIsPresent("n");
Options.IsPermissible = OptionIsPresent("i");
String outFile = GetOption("o");
if (!outFile.Equals("System.Console.Out"))
{
try
{
Options.Out = new StreamWriter(outFile);
}
catch (Exception e)
{
Console.Error.WriteLine(e);
Console.Error.WriteLine("*** Couldn't create file "+outFile);
Environment.Exit(1); // exit with a non-zero status code...
}
}
String errFile = GetOption("e");
if (!errFile.Equals("System.Console.Error"))
{
try
{
Options.Error = new StreamWriter(errFile);
}
catch (Exception e)
{
Console.Error.WriteLine(e);
Console.Error.WriteLine("*** Couldn't create file "+errFile);
Environment.Exit(1); // exit with a non-zero status code...
}
}
new ParserGenerator();
}
}
}