コード例 #1
0
        public bool Ensamblar()
        {
            if (asm_code != null)
            {
                string errors_path = Environment.CurrentDirectory + @"\Files\errors.s";
                Directory.CreateDirectory(Environment.CurrentDirectory + @"\Files\");
                FileStream intermediary_file = new FileStream(Environment.CurrentDirectory + @"\Files\intermediary.s", FileMode.Create);
                FileStream tabsim_file       = new FileStream(Environment.CurrentDirectory + @"\Files\tabsim.s", FileMode.Create);
                FileStream object_program    = new FileStream(Environment.CurrentDirectory + @"\Files\object.o", FileMode.Create);
                FileStream error_program     = new FileStream(errors_path, FileMode.Create);
                error_program.Close();

                string            temp_code = string.Join("\n", asm_code);
                SICLexer          lex       = new SICLexer(new AntlrInputStream(temp_code));
                CommonTokenStream tokens    = new CommonTokenStream(lex);
                SICParser         parser    = new SICParser(tokens);

                parser.ErrorHandler = new CustomErrorHandler();

                parser.programa();

                WriteTabSim(parser.tabsim, tabsim_file, parser.PC);
                symbol_table = parser.tabsim;

                List <Tuple <string, string> > programa_objeto =
                    WriteObjectProgram(intermediary_file, asm_code, parser.programa_objeto, parser.tabsim);
                intermediary_code = programa_objeto;

                registers = new List <string>();
                registers.Add(WriteHeaderRegister(object_program, parser.name, parser.first_PC, parser.PC));

                List <string> temp_registers = WriteTextRegisters(object_program, programa_objeto, parser.tabsim);
                registers.AddRange(temp_registers);

                registers.Add(WriteEndRegister(object_program, parser.tabsim, parser.last_sim, parser.first_PC));

                errors = GetErrors(errors_path, parser.duplicated_sim);

                tabsim_file.Close();
                intermediary_file.Close();
                object_program.Close();

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        private void ventanaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openWindowsEnsamblar();

            string line = "", prog;

            prog = "";
            line = filePath;
            //SE ALMACENA LA CADENA DE ENTRADA

            string linea, error;

            System.IO.StreamReader file = null;

            try
            {
                file = new System.IO.StreamReader(@line);
                while ((linea = file.ReadLine()) != null)
                {
                    prog += linea + '\n';
                }
                error = line.Substring(0, line.Length - 1);
                if (extendido)
                {
                    using (FileStream fs = File.Create(error + "tx"))
                    {
                    }
                }
                else
                {
                    using (FileStream fs = File.Create(error + "ts"))
                    {
                    }
                }
                using (FileStream fs = File.Create(error + 'i'))
                {
                }
                prog = prog.Substring(0, prog.Length - 1);
                file.Close();
                SICLexer lex = new SICLexer(new AntlrInputStream(prog + Environment.NewLine));
                //CREAMOS UN LEXER CON LA CADENA QUE ESCRIBIO EL USUARIO
                CommonTokenStream tokens = new CommonTokenStream(lex);
                //CREAMOS LOS TOKENS SEGUN EL LEXER CREADO
                SICParser parser = new SICParser(tokens);
                //CREAMOS EL PARSER CON LOS TOKENS CREADOS

                if (extendido)
                {
                    parser.go(error + "tx", error + 'i');
                }
                else
                {
                    parser.go(error + "ts", error + 'i');
                }
                printErrors();
                mostrarIntermedio();
            }
            catch (RecognitionException ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Archivo inexistente");
            }
        }