public static void Main(string[] args)
        {
            if (args.Length == 0) // check on correct parameter usage
            {
                Console.WriteLine("Usage: ASSEM source [ immediate ]");
            }
            else
            {
                string sourceName = args[0];
                bool   immediate  = args.Length > 1;
                string codeName   = newFileName(sourceName, ".cod");
                PVM.Init();

                bool assembledOK = PVMAsm.Assemble(sourceName);
                int  codeLength  = PVMAsm.CodeLength();
                int  initSP      = PVMAsm.StackBase();
                PVM.ListCode(codeName, codeLength);
                if (!assembledOK || codeLength == 0)
                {
                    Console.WriteLine("Unable to interpret code");
                }
                else
                {
                    if (immediate)
                    {
                        PVM.QuickInterpret(codeLength, initSP);
                    }
                    char reply = 'n';
                    do
                    {
                        Console.Write("\n\nInterpret [y/N]? ");
                        reply = (Console.ReadLine() + " ").ToUpper()[0];
                        if (reply == 'Y')
                        {
                            PVM.Interpret(codeLength, initSP);
                        }
                    } while (reply == 'Y');
                }
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            bool   mergeErrors = false;
            bool   immediate   = false;
            string inputName   = null;

            // ------------------------ process command line parameters:

            Console.WriteLine("Assem compiler 1.00");

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].ToLower().Equals("-l"))
                {
                    mergeErrors = true;
                }
                else if (args[i].ToLower().Equals("-i"))
                {
                    immediate = true;
                }
                else
                {
                    inputName = args[i];
                }
            }
            if (inputName == null)
            {
                Console.WriteLine("No input file specified");
                Console.WriteLine("Usage: Parva [-l] source.pav [-l]");
                Console.WriteLine("-l directs source listing to listing.txt");
                Console.WriteLine("-i proceeds directly to interpreter");
                System.Environment.Exit(1);
            }

            // ------------------------ parser and scanner initialization

            int pos = inputName.LastIndexOf('/');

            if (pos < 0)
            {
                pos = inputName.LastIndexOf('\\');
            }
            string dir = inputName.Substring(0, pos + 1);

            string outputName = null;

            pos = inputName.LastIndexOf('.');
            if (pos < 0)
            {
                outputName = inputName + ".pretty";
            }
            else
            {
                outputName = inputName.Substring(0, pos) + ".pretty";
            }
            Parser.pretty = new OutFile(outputName);
            if (Parser.pretty.OpenError())
            {
                Console.WriteLine("cannot open " + outputName);
                System.Environment.Exit(1);
            }

            Scanner.Init(inputName);
            Errors.Init(inputName, dir, mergeErrors);
            PVM.Init();
//      Table.Init();

            // ------------------------ compilation

            Parser.Parse();
            Errors.Summarize();

            // ------------------------ interpretation

            bool   assembledOK = Parser.Successful();
            int    initSP      = CodeGen.GetInitSP();
            string codeName    = newFileName(inputName, ".cod");
            int    codeLength  = CodeGen.GetCodeLength();

            PVM.ListCode(codeName, codeLength);
            if (!assembledOK || codeLength == 0)
            {
                Console.WriteLine("Unable to interpret code");
                System.Environment.Exit(1);
            }
            else
            {
                if (immediate)
                {
                    PVM.QuickInterpret(codeLength, initSP);
                }
                char reply;
                do
                {
                    Console.Write("\n\nInterpret [y/N]? ");
                    reply = (Console.ReadLine() + " ").ToUpper()[0];
                    if (reply == 'Y')
                    {
                        PVM.Interpret(codeLength, initSP);
                    }
                } while (reply == 'Y');
            }
        }