예제 #1
0
        // System.IO.Path.GetTempFileName()

        private static void Main()
        {
            var args       = Environment.GetCommandLineArgs();
            var parameters = Parameters.parse(args);

            if (parameters == null)
            {
                printHelp(args);
                return;
            }
            if (parameters.outputFile == null)
            {
                parameters.outputFile = System.IO.Path.GetTempFileName();
            }

            var inputFile = new FileOrigin(args[1]);

            try
            {
                var parseTree = CSTBuilder.Build(inputFile);
                Console.WriteLine(parseTree.ToString());

                var backendFunctions = new Frontend().FromParseTreeToBackend(parseTree);

                var    backend      = new Backend.Backend();
                string assemblyFile = parameters.outputFile;
                if (!parameters.onlyAssembly)
                {
                    assemblyFile = System.IO.Path.GetTempFileName();
                }
                generateAssemblyFile(assemblyFile, backend.FromFunctionsToNasm(backendFunctions));
                if (!parameters.onlyAssembly)
                {
                    // TODO invoke NASM (using parameters)
                    var nasm = new Process();
                    nasm.StartInfo.FileName  = "nasm";  // take $PATH into account
                    nasm.StartInfo.Arguments = assemblyFile + " -o " + parameters.outputFile;
                    nasm.Start();
                    nasm.WaitForExit();
                }
            }
            catch (CSTBuilder.LexerFailure ex)
            {
                Console.WriteLine("Syntax error:");
                var diagnostics = new SourceDiagnostic();
                diagnostics.PrintFragmentInLine(ex.Fragment);
            }
        }
예제 #2
0
        //[Test()]
        public void Sample01Test() // bad test -> strings not implemented
        {
            var s = new StringBuilder();

            s.AppendLine("main(int x) -> void");
            s.AppendLine("{");
            s.AppendLine("    print(\"Hello, World!\\n\");");
            s.AppendLine("}");
            var inputFile        = new StringOrigin(s.ToString());
            var parseTree        = CSTBuilder.Build(inputFile);
            var backendFunctions = new Frontend().FromParseTreeToBackend(parseTree);

            foreach (var f in backendFunctions)
            {
                Console.WriteLine(f);
            }
        }