Ejemplo n.º 1
0
        public static int Main(string[] args)
        {
            Dictionary <string, string> arguments = LoadParameters(args);

            if (inputPath == null)
            {
                Console.WriteLine();
                Console.WriteLine("No .vge source file indicated");
                PrintHelp();
                return(INVALID_PARAMETER);
            }

            if (arguments.ContainsKey("/h") || arguments.ContainsKey("/?"))
            {
                PrintHelp();
                return(0);
            }

            if (arguments.ContainsKey("/d"))
            {
                _debugMode = true;
            }

            if (arguments.ContainsKey("/m"))
            {
                float mutRate = 0;

                try
                {
                    mutRate = Convert.ToSingle(arguments["/m"]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid mutation rate provided");
                    PrintHelp();
                    return(-1);
                }
                if (mutRate < Real.MinMutation || mutRate > Real.MaxMutation)
                {
                    Console.WriteLine("Mutation rate must be between " + Real.MinMutation.ToString() + " and " + Real.MaxMutation.ToString());
                    PrintHelp();
                    return(-2);
                }
                Rottytooth.Esolang.Entropy.Real.MutationRate = mutRate;
            }

            EntropyGrammar grammar = new EntropyGrammar();

            Parser parser = new Parser(grammar);


            try
            {
                TextReader         reader      = new StreamReader(inputPath);
                System.IO.FileInfo file        = new FileInfo(inputPath);
                string             fileName    = Path.GetFileNameWithoutExtension(file.FullName);
                ParseTree          programTree = parser.Parse(reader.ReadToEnd());

                if (CheckForErrors(programTree, parser))
                {
                    return(-1);
                }

                if (_debugMode)
                {
                    PrintTree(programTree);
                    return(0);
                }
                else
                {
                    CodeConverter converter = new CodeConverter(programTree);
                    string        program   = converter.ToCSharp();
                    Console.WriteLine(program);
                    CodeGenerator.Compile(program, fileName + ".exe");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.GetType() + " error thrown: " + ex.Message);
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static int Main(string[] args)
        {
            Dictionary<string, string> arguments = LoadParameters(args);

            if (inputPath == null)
            {
                Console.WriteLine();
                Console.WriteLine("No .vge source file indicated");
                PrintHelp();
                return INVALID_PARAMETER;
            }

            if (arguments.ContainsKey("/h") || arguments.ContainsKey("/?"))
            {
                PrintHelp();
                return 0;
            }

            if (arguments.ContainsKey("/d"))
            {
                _debugMode = true;
            }

            if (arguments.ContainsKey("/m"))
            {
                float mutRate = 0;

                try
                {
                    mutRate = Convert.ToSingle(arguments["/m"]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid mutation rate provided");
                    PrintHelp();
                    return -1;
                }
                if (mutRate < Real.MinMutation || mutRate > Real.MaxMutation)
                {
                    Console.WriteLine("Mutation rate must be between " + Real.MinMutation.ToString() + " and " + Real.MaxMutation.ToString());
                    PrintHelp();
                    return -2;
                }
                Rottytooth.Esolang.Entropy.Real.MutationRate = mutRate;
            }

            EntropyGrammar grammar = new EntropyGrammar();

            Parser parser = new Parser(grammar);

            try
            {
                TextReader reader = new StreamReader(inputPath);
                System.IO.FileInfo file = new FileInfo(inputPath);
                string fileName = Path.GetFileNameWithoutExtension(file.FullName);
                ParseTree programTree = parser.Parse(reader.ReadToEnd());

                if (CheckForErrors(programTree, parser))
                {
                    return -1;
                }

                if (_debugMode)
                {
                    PrintTree(programTree);
                    return 0;
                }
                else
                {
                    CodeConverter converter = new CodeConverter(programTree);
                    string program = converter.ToCSharp();
                    Console.WriteLine(program);
                    CodeGenerator.Compile(program, fileName + ".exe");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.GetType() + " error thrown: " + ex.Message);
            }
            return 0;
        }