Exemple #1
0
        private void primeraPasadaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SicAsm asm     = new SicAsm();
            string program = editor.Text.ToUpper();

            if (editor.Text == "")
            {
                MessageBox.Show("No hay instrucciones a compilar.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            StreamReader     inputStream = new StreamReader(Console.OpenStandardInput());
            AntlrInputStream input       = new AntlrInputStream(program);
            SicAsmLexer      lexer       = new SicAsmLexer(input);

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SicAsmParser      parser = new SicAsmParser(tokens);
            IParseTree        tree   = parser.program();
            //Console.WriteLine(tree.ToStringTree(parser));
            String res = "" + asm.Assemble(program);

            List <String> lines = new List <string>();

            for (int i = 0; i < editor.Lines.Count; i++)
            {
                lines.Add(editor.Lines[i].ToUpper());
            }

            String text = asm.SaveIntermediateFile(lines, filepath + "\\" + filename + ".lst");

            if (asm.Erros.Count != 0)
            {
                text = "";
                for (int i = 0; i < lines.Count; i++)
                {
                    if (asm.Erros.ContainsKey(i))
                    {
                        text += "Linea " + i + ": " + (string)asm.Erros[i] + "\r\n";
                    }
                }
            }
            asm.SaveErrorFile(lines, filepath + "\\" + filename + ".t");
            asm.SaveSymbolTable(filepath + "\\" + filename + ".sym");
            //if (asm.Erros.Count == 0)
            asm.SaveObjectProgram(filepath + "\\" + filename + ".obj");
            textBoxMensajes.Text = text;
            MessageBox.Show(res);
        }
Exemple #2
0
        /// <summary>
        /// Realiza el paso 1 del ensamblado, genera el archivo de errores
        /// y la tabla de simbolos.
        /// </summary>
        /// <param name="tree">Arbol de análisis sintáctico generado con ANTLR</param>
        /// <returns></returns>
        public string Pass1(String ProgramText)
        {
            StreamReader     inputStream = new StreamReader(Console.OpenStandardInput());
            AntlrInputStream input       = new AntlrInputStream(ProgramText);
            SicAsmLexer      lexer       = new SicAsmLexer(input);

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SicAsmParser      parser = new SicAsmParser(tokens);
            IParseTree        tree   = parser.program();

            // Bandera indica primera pasada.
            _is_first_pass = true;
            _line_count    = 0;
            string result = this.Visit(tree);

            if (!result.Contains("Error"))
            {
                result = "OK! Primera pasada completa";
            }

            return(result);
        }