Exemple #1
0
        private static void RunProgram()
        {
            // Scanner
            Scanner scan = null;

            try
            {
                scan = new Scanner(inputFile);
                scan.Scan();
            }
            catch (IOException)
            {
                Console.WriteLine("The specified input file {0} was not found.", inputFile);
                return;
            }
            catch (XmlException e)
            {
                Console.WriteLine("The specified input file is not well-formed Xaml.");
                Console.WriteLine();

                if (debugMode)
                {
                    Console.WriteLine("Debug: {0}", e.Message);
                    Console.WriteLine();
                }
                return;
            }

            // Parser
            IActivity ast = null;

            try
            {
                Parser pars = new Parser(scan.Token());
                // ModuleFactory
                IModuleFactory modules = ModuleFactory.Instance;
                pars.ModuleFactory = modules;
                ast = pars.Parse();
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine("Error: {0}", e.Message);
                return;
            }
            catch (ParseException e)
            {
                Console.WriteLine("Error while parsing the Xaml:");
                Console.WriteLine(e.Message);
                if (debugMode)
                {
                    Console.WriteLine("Debug: activity '{0}', queue element near or at '{1}', ", e.Activity, e.ElementNumber);
                    Console.WriteLine();
                }
                return;
            }

            // Generation
            try
            {
                Generation gen = new Generation(ast);
                gen.Compile();

                // Format
                string format = formatFile.ToString();

                if (Path.GetFileNameWithoutExtension(outputFile).Equals(String.Empty))
                {
                    gen.WriteOutput(Path.ChangeExtension(inputFile, format), format);
                    if (File.Exists(Path.ChangeExtension(inputFile, format)))
                    {
                        Console.WriteLine("Output file '{0}' sucessfully written", Path.GetFileNameWithoutExtension(inputFile) + "." + format);
                    }
                }
                else
                {
                    gen.WriteOutput(Path.ChangeExtension(outputFile, format), format);
                    if (File.Exists(Path.ChangeExtension(outputFile, format)))
                    {
                        Console.WriteLine("Output file '{0}' sucessfully written", Path.GetFileNameWithoutExtension(outputFile) + "." + format);
                    }
                }
            }
            catch (SecurityException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Win32Exception e)
            {
                Console.WriteLine(e.Message);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }
        }