Ejemplo n.º 1
0
        unsafe static void Main(string[] args)
        {
            //Because my computer is european, and we use , and not . for numbers!
            CultureInfo.DefaultThreadCurrentCulture   = new CultureInfo("us-US");
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("us-US");

            //variables
            string fileName;

            //if not two arguments
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: \"program name\".exe, \"filename\"");
                Console.ReadLine();
            }
            else
            {
                try
                {
                    //Create file
                    fileName = args[0];
                    string   path    = fileName;
                    string[] tacPath = path.Split('.');
                    path = tacPath[0] + ".tac";

                    //File.Create(path);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    SymTab st = new SymTab();

                    StreamWriter sw = new StreamWriter(path, true); //Write to .tac
                    StreamReader sr = new StreamReader(fileName);   //read from .ada

                    lexicalScanner.Token token = new lexicalScanner.Token();
                    lexicalScanner       lx    = new lexicalScanner(fileName, sr);
                    rdp rdp = new rdp(token, lx, sr, st, sw);

                    lx.createDictionary();

                    //While NOT eoft
                    while (token.token != lexicalScanner.SYMBOL.eoft)
                    {
                        //Get the first token
                        token = lx.getNextToken();
                        //Start the parser
                        token = rdp.parse(token);

                        if (rdp.error != true)
                        {
                            Console.WriteLine("Program is Valid!");
                            rdp.emit("start proc " + rdp.mainProc);
                            Console.WriteLine();
                            sw.Close();                                  // close writing .tac
                            StreamReader tacSr = new StreamReader(path); //read from .tac
                            Assembler586 asm   = new Assembler586(path, rdp, tacSr, st);

                            asm.buildDataSeg();
                            asm.addCodeAndIncludes();
                            asm.genAssembly();
                        }
                    }// end while NOT eoft
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("Error!!! File not found")
                }
            }
        }
Ejemplo n.º 2
0
 public Assembler(string path, rdp rdp, StreamReader tacSr, SymTab st) : this(path, rdp, tacSr)
 {
     this.st = st;
 }