Example #1
0
		public void CreateFakeDfa(string className, string namespace1, string marksPath, string suppressWarningPath)
		{
			LoadMarks(marksPath);
			LoadSuppressWarngin(suppressWarningPath);

			var generator = new Generator(OptimizationMode.NoOptimization);
			generator.ParseDeclaration(_marks);
			generator.Generate(className, className, namespace1, null, true);
		}
Example #2
0
		public void CreateDfa(string className, string namespace1, string marksPath, string suppressWarningPath)
		{
			LoadMarks(marksPath);
			LoadSuppressWarngin(suppressWarningPath);

			var dfa = CompileDfa();

			var generator1 = new Generator(OptimizationMode.NoOptimization);
			generator1.Generate(className, className, namespace1, dfa, true);
			var generator2 = new Generator(OptimizationMode.SingleStatic);
			generator2.Generate(className + "Optimized", className, namespace1, dfa, false);
			var generator3 = new Generator(OptimizationMode.IndexedArray);
			generator3.Generate(className + "Optimized2", className, namespace1, dfa, false);
		}
Example #3
0
		static void Main(string[] args)
		{
			if (args.Length < 3)
			{
				WriteUsage();
			}
			else
			{
				var dfaXml = args[0];
				var nameSpace = args[1];
				var className = args[2];

				Console.WriteLine("Load DFA");
				var dfa = Read(dfaXml);

				Console.WriteLine("Generate C# Source Code");
				var generator1 = new Generator(OptimizationMode.NoOptimization);
				generator1.Generate(className, className, nameSpace, dfa.Start, true);
				var generator2 = new Generator(OptimizationMode.SingleStatic);
				generator2.Generate(className + "Optimized", className, nameSpace, dfa.Start, false);
				var generator3 = new Generator(OptimizationMode.IndexedArray);
				generator3.Generate(className + "Optimized2", className, nameSpace, dfa.Start, false);
			}
		}
Example #4
0
        static int Main(string[] args)
        {
            try
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("Usage: DfaToCSharp.exe dfa_file_name.xml c#_namespace c#_class_name [optimization]");
                    Console.WriteLine("   Optimization: --WO  - without optimization");
                    Console.WriteLine("                 --O1  - optimization #1");
                    Console.WriteLine("                 --O2  - optimization #2");
                    return -1;
                }

                var dfaXml = args[0];
                var nameSpace = args[1];
                var className = args[2];
                var optimization = (args.Length >= 4) ? args[3] : "--WO";

                Console.WriteLine("Load DFA file: {0}", dfaXml);
                var dfa = Read(dfaXml);

                Console.WriteLine("Generate C# Source Code");

                Console.WriteLine(" DFA Table file: {0}.dfa", nameSpace);
                Console.WriteLine(" Source file: {0}.cs", className);

                if (optimization == "--WO")
                {
                    Console.WriteLine(" Not Optimized Version");
                    var generator1 = new Generator(OptimizationMode.NoOptimization);
                    generator1.Generate(className, className, nameSpace, dfa.Start, true);
                }
                else if (optimization == "--O1")
                {
                    Console.WriteLine(" Optimization: Version #1");
                    var generator2 = new Generator(OptimizationMode.SingleStatic);
                    generator2.Generate(className, className, nameSpace, dfa.Start, false);

                }
                else if (optimization == "--O2")
                {
                    Console.WriteLine(" Optimization: Version #2");
                    var generator3 = new Generator(OptimizationMode.IndexedArray);
                    generator3.Generate(className, className, nameSpace, dfa.Start, false);
                }
                else
                {
                    throw new Exception("Unknow optimization mode selected: " + optimization);
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine();
                Console.WriteLine("Error {0}", ex.Message);
                Console.ResetColor();
                return -1;
            }

            return 0;
        }