static int Main(string[] args) { String command = null; List <String> scriptFilename = new List <String>(); bool showUsage = false; bool nonDebugNonGuiExitOnError = false; bool showIncludes = false; int errorCode = 0; // 0==success, the return value PrintVersion(); ParseArguments(args, out command, out scriptFilename, out showUsage, out nonDebugNonGuiExitOnError, out showIncludes, out errorCode); if (showUsage) { PrintUsage(); return(errorCode); } TextReader reader; bool showPrompt; bool readFromConsole; errorCode = DetermineAndOpenInputSource(command, scriptFilename, out reader, out showPrompt, out readFromConsole); if (errorCode != 0) { return(errorCode); } GrShell shell = new GrShell(reader); GrShellImpl shellImpl = new GrShellImpl(); IGrShellImplForDriver impl = shellImpl; GrShellDriver driver = new GrShellDriver(shell, impl); shell.SetImpl(shellImpl); shell.SetDriver(driver); driver.tokenSources.Push(shell.token_source); driver.showIncludes = showIncludes; impl.nonDebugNonGuiExitOnError = nonDebugNonGuiExitOnError; try { driver.conditionalEvaluationResults.Push(true); while (!driver.Quitting && !driver.Eof) { driver.ShowPromptAsNeeded(showPrompt); bool success = shell.ParseShellCommand(); errorCode = HandleEofOrErrorIfNonConsoleShell(scriptFilename, success, nonDebugNonGuiExitOnError, shell, driver, ref reader, ref showPrompt, ref readFromConsole); if (errorCode != 0) { return(errorCode); } } driver.conditionalEvaluationResults.Pop(); } catch (Exception e) { Console.WriteLine("exit due to " + e.Message); errorCode = -2; } finally { impl.Cleanup(); } return(errorCode); }