Etapa 2

Código de la Segunda Fase

 

AbrirArch:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chmaquina;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
*
* @author Luis Carlos
*/
public class AbrirArch extends Thread
{
javax.swing.JTextArea jTextAreaUno;
javax.swing.JTextField jTextFieldUno;
javax.swing.JTable jTableUno;
javax.swing.JFileChooser dlgAbrirUno;
NewJFrame frame=new NewJFrame();
File nombArchivo2=new File («»);
BufferedReader entrada;
int opcionUno;

public AbrirArch(javax.swing.JTextArea jTextArea, javax.swing.JTextField jTextField, javax.swing.JTable jTable, javax.swing.JFileChooser dlgAbrir, int opcion)
{
jTextAreaUno=jTextArea;
jTextFieldUno=jTextField;
jTableUno=jTable;
dlgAbrirUno=dlgAbrir;
opcionUno=opcion;
}

public void run ()
{
if (opcionUno==javax.swing.JFileChooser.APPROVE_OPTION)
{
nombArchivo2=dlgAbrirUno.getSelectedFile();
frame.setNombProg(nombArchivo2.getName());
String texto=new String ();
try
{
FileReader fr=new FileReader(nombArchivo2.toString());
entrada=new BufferedReader(fr);
String doc;

while((doc=entrada.readLine())!=null)
{
jTextAreaUno.append(doc+»\n»);
texto += doc + «\n»;
}

entrada.close();
}
catch(java.io.FileNotFoundException fnfex)
{
jTextAreaUno.append(«El archivo no ha sido encontrado\n»);
}

catch(java.io.IOException ioex)
{
jTextAreaUno.append(«El archivo no ha sido encontrado\n»);
}
}
else if (jTextAreaUno.getText().equals(«»))
javax.swing.JOptionPane.showMessageDialog(null, «Para continuar, debe abrir un archivo .ch»);
}
}

 

Abrir:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chmaquina;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
*
* @author Luis Carlos
*/
public class Abrir extends Thread
{
javax.swing.JTextArea jTextAreaUno;
javax.swing.JTextField jTextFieldDos;
javax.swing.JTable jTableUno;
javax.swing.JFileChooser dlgAbrirUno;
File nombArchivo2=new File («»);
BufferedReader entrada;
int opcionUno;

public Abrir(javax.swing.JTextArea jTextArea, javax.swing.JTextField jTextField, javax.swing.JTable jTable, javax.swing.JFileChooser dlgAbrir, int opcion)
{
jTextAreaUno=jTextArea;
jTextFieldDos=jTextField;
jTableUno=jTable;
dlgAbrirUno=dlgAbrir;
opcionUno=opcion;
}

public void run ()
{
if (opcionUno==javax.swing.JFileChooser.APPROVE_OPTION)
{
nombArchivo2=dlgAbrirUno.getSelectedFile();
String texto=new String ();
try
{
FileReader fr=new FileReader(nombArchivo2.toString());
entrada=new BufferedReader(fr);
String doc;

while((doc=entrada.readLine())!=null)
{
jTextAreaUno.append(doc+»\n»);
texto += doc + «\n»;
}

jTextFieldDos.setText(nombArchivo2.getName());
jTableUno.setValueAt(nombArchivo2.getName(),0,0);
entrada.close();
}
catch(java.io.FileNotFoundException fnfex)
{
jTextAreaUno.append(«El archivo no ha sido encontrado\n»);
}

catch(java.io.IOException ioex)
{
jTextAreaUno.append(«El archivo no ha sido encontrado\n»);
}
}
else if (jTextAreaUno.getText().equals(«»))
javax.swing.JOptionPane.showMessageDialog(null, «Para continuar, debe abrir un archivo .ch»);
}
}

 

NewJFrame:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chmaquina;
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;

/**
*
* @author Luis Carlos
*/
public class NewJFrame extends javax.swing.JFrame
{
AbrirArch cargar;
AbrirMem memoria;
Compilar compilar;
CorrerCodigo ejecutar;
CorrerPasoAPaso ejecutarP;

static String acumulador=»0″;
BufferedReader entrada;
File nombArchivo2=new File («»);
static int a=0;
static String vecMem[]=new String[759];
static int nucleoSist=95;
static int memPrincipal=759;
static int numProg=0; //ojo
ListaDoble ld=new ListaDoble();
ListaDoble ldd=new ListaDoble(); // instrucciones temporales
ListaDoble ldVariable=new ListaDoble(); //variables
ListaDoble ldEjecutar=new ListaDoble(); //instr a ejecutar
ListaDoble ldTemporal=new ListaDoble(); // instr temp para mostrar
static ListaDoble ldVarVector=new ListaDoble(); //almacena la variable y la posicion que ocupa en la memoria

static int posTablaA=0;
static int posTablaB=0;
static Nodo IntTemporal;
static int indVector=1;
static int contVariable=0;
static int ultLinea=0;
static int linProgBor=0;
static int numProgEjec=1;
String nombArch=»»;

public NewJFrame()
{
initComponents();
jTable1.setEnabled(false);
}

// <editor-fold defaultstate=»collapsed» desc=»Generated Code»>//GEN-BEGIN:initComponents
private void initComponents() {

jFrame1 = new javax.swing.JFrame();
jPopupMenu1 = new javax.swing.JPopupMenu();
jFrame2 = new javax.swing.JFrame();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jScrollPane5 = new javax.swing.JScrollPane();
jTable2 = new javax.swing.JTable();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jLayeredPane1 = new javax.swing.JLayeredPane();
jLabel4 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jTextField1 = new javax.swing.JTextField();
jScrollPane3 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
jTextArea3 = new javax.swing.JTextArea();
jLabel7 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
Abrir = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem8 = new javax.swing.JMenuItem();

org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);

org.jdesktop.layout.GroupLayout jFrame2Layout = new org.jdesktop.layout.GroupLayout(jFrame2.getContentPane());
jFrame2.getContentPane().setLayout(jFrame2Layout);
jFrame2Layout.setHorizontalGroup(
jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame2Layout.setVerticalGroup(
jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(60, 20, 100, 100));
setName(«CH-MÁQUINA – 2° SEMESTRE DE 2012»); // NOI18N
setPreferredSize(new java.awt.Dimension(895, 680));
setResizable(false);
getContentPane().setLayout(null);

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(20, 50, 220, 210);

jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField2.setText(«100»);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(410, 270, 40, 20);

jTextField3.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField3.setText(«69»);
jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});
getContentPane().add(jTextField3);
jTextField3.setBounds(410, 290, 40, 20);

jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{«Nombre», null},
{«Acumulador», null},
{«Computador», null}
},
new String [] {
«», «»
}
));
jTable2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jScrollPane5.setViewportView(jTable2);

getContentPane().add(jScrollPane5);
jScrollPane5.setBounds(10, 490, 250, 60);

jTextField4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField4.setDisabledTextColor(new java.awt.Color(0, 0, 0));
jTextField4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField4ActionPerformed(evt);
}
});
getContentPane().add(jTextField4);
jTextField4.setBounds(260, 50, 280, 160);

jTextField5.setBackground(new java.awt.Color(204, 204, 204));
jTextField5.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
getContentPane().add(jTextField5);
jTextField5.setBounds(360, 470, 110, 80);
getContentPane().add(jLayeredPane1);
jLayeredPane1.setBounds(0, 0, 0, 0);

jLabel4.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText(«KERNEL»);
getContentPane().add(jLabel4);
jLabel4.setBounds(330, 290, 90, 20);

jLabel8.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel8.setText(«INFORMACION DEL PROGRAMA»);
getContentPane().add(jLabel8);
jLabel8.setBounds(580, 30, 240, 20);

jLabel9.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel9.setForeground(new java.awt.Color(255, 255, 255));
jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel9.setText(«CODIGO CH»);
getContentPane().add(jLabel9);
jLabel9.setBounds(40, 20, 170, 20);

jLabel3.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText(«EJECUCION»);
getContentPane().add(jLabel3);
jLabel3.setBounds(50, 470, 150, 15);

jTextArea2.setEditable(false);
jTextArea2.setColumns(20);
jTextArea2.setForeground(new java.awt.Color(0, 0, 255));
jTextArea2.setRows(5);
jScrollPane2.setViewportView(jTextArea2);

getContentPane().add(jScrollPane2);
jScrollPane2.setBounds(20, 300, 220, 100);

jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
getContentPane().add(jTextField1);
jTextField1.setBounds(20, 400, 220, 50);

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
«Nombre», «Base», «Limite Cod.», «Limite Prog.»
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false
};

public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}

public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
jScrollPane3.setViewportView(jTable1);

getContentPane().add(jScrollPane3);
jScrollPane3.setBounds(560, 60, 320, 260);

jLabel5.setIcon(new javax.swing.ImageIcon(«C:\\Users\\Luis Carlos\\Downloads\\Sistemas Operativos\\CHMAQUINA III\\ch-maquina (fase1)\\Código\\src\\Imagenes\\Monitor.png»)); // NOI18N
getContentPane().add(jLabel5);
jLabel5.setBounds(250, 20, 300, 240);

jLabel6.setBackground(new java.awt.Color(0, 102, 153));
jLabel6.setForeground(new java.awt.Color(0, 102, 153));
jLabel6.setIcon(new javax.swing.ImageIcon(«C:\\Users\\Luis Carlos\\Downloads\\Sistemas Operativos\\CHMAQUINA III\\ch-maquina (fase1)\\Código\\src\\Imagenes\\Impresora.jpg»)); // NOI18N
getContentPane().add(jLabel6);
jLabel6.setBounds(290, 340, 250, 180);

jPanel1.setBackground(new java.awt.Color(0, 102, 153));
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

jLabel2.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText(«ERRORES»);

jButton3.setText(«OK»);
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
cargarMem(evt);
}
});
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jLabel1.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText(«MEMORIA»);

jTextArea3.setColumns(20);
jTextArea3.setRows(5);
jTextArea3.setSelectionColor(new java.awt.Color(0, 0, 0));
jScrollPane4.setViewportView(jTextArea3);

jLabel7.setFont(new java.awt.Font(«Verdana», 1, 11)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel7.setText(«USUARIO»);

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(30, 30, 30)
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(133, 133, 133)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(55, 55, 55)
.add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(352, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 220, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(69, 69, 69))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(jLabel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(110, 110, 110))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(271, 271, 271)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 32, Short.MAX_VALUE)
.add(jLabel7)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 199, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(27, 27, 27))
);

getContentPane().add(jPanel1);
jPanel1.setBounds(0, 0, 900, 590);

jMenuBar1.setBackground(new java.awt.Color(204, 204, 204));
jMenuBar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jMenuBar1.setFont(new java.awt.Font(«Tahoma», 0, 12)); // NOI18N
jMenuBar1.setRequestFocusEnabled(false);

Abrir.setBackground(new java.awt.Color(204, 204, 255));
Abrir.setText(«Archivo»);

jMenuItem1.setText(«Abrir»);
jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
abrir(evt);
}
});
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
Abrir.add(jMenuItem1);

jMenuItem2.setText(«Guardar»);
jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
guardar(evt);
}
});
Abrir.add(jMenuItem2);

jMenuBar1.add(Abrir);

jMenu1.setBackground(new java.awt.Color(204, 204, 255));
jMenu1.setText(«Cargar»);
jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
compilar(evt);
}
});
jMenuBar1.add(jMenu1);

jMenu3.setBackground(new java.awt.Color(204, 204, 255));
jMenu3.setText(«Ver»);
jMenu3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
verMemoria(evt);
}
});
jMenuBar1.add(jMenu3);

jMenu4.setBackground(new java.awt.Color(204, 204, 255));
jMenu4.setText(«Edición»);

jMenuItem3.setText(«Ejecutar»);
jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
ejecutarPaso(evt);
}
});
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu4.add(jMenuItem3);

jMenuItem4.setText(«Detener»);
jMenuItem4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
pararPasos(evt);
}
});
jMenu4.add(jMenuItem4);

jMenuItem8.setText(«Reanudar»);
jMenuItem8.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
reanudarPasos(evt);
}
});
jMenu4.add(jMenuItem8);

jMenuBar1.add(jMenu4);

setJMenuBar(jMenuBar1);

pack();
}// </editor-fold>//GEN-END:initComponents

private void reanudarPasos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reanudarPasos
ejecutarP.reanudarP=0;
}//GEN-LAST:event_reanudarPasos

private void pararPasos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pararPasos
ejecutarP.reanudarP=1;
}//GEN-LAST:event_pararPasos

private void ejecutarPaso(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ejecutarPaso
modoKernel();
ejecutarP=new CorrerPasoAPaso(ldEjecutar, ldVariable, jTable2, ldVarVector, jTextArea3, jTextField4, jTextField5);
ejecutarP.start();
}//GEN-LAST:event_ejecutarPaso

private void verMemoria(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verMemoria
modoKernel();
mostrarMem();
}//GEN-LAST:event_verMemoria

private void guardar(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_guardar

modoUsuario();
javax.swing.JFileChooser dlgGuardar=new javax.swing.JFileChooser();
int opcion=dlgGuardar.showSaveDialog(this);
File nombArchG=new File(«»);

if(opcion==javax.swing.JFileChooser.APPROVE_OPTION)
{
try
{
nombArchG=dlgGuardar.getSelectedFile();
String texto=jTextArea1.getText();
FileOutputStream mf=new FileOutputStream(nombArchG);
DataOutputStream as=new DataOutputStream(mf);

StringTokenizer sent1=new StringTokenizer(texto,»\r\n»);
int numTok = sent1.countTokens();
int tam=texto.length();

String sent2=»»;

for (int i=0; i<numTok; i++)
{
sent2=sent1.nextToken();
as.writeBytes(sent2+»\r\n»);
}
}
catch(IOException e)
{
javax.swing.JOptionPane.showMessageDialog(null, «Hay una anomalía en el flujo de salida\n»+e);
}
}
else
javax.swing.JOptionPane.showMessageDialog(null, «Operación cancelada»);
}//GEN-LAST:event_guardar

private void abrir(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_abrir
desactivar();
modoUsuario();
javax.swing.JFileChooser dlgAbrir = new javax.swing.JFileChooser();
int opcion=dlgAbrir.showOpenDialog(this);
cargar=new AbrirArch(jTextArea1, jTextField1, jTable1, dlgAbrir, opcion);
cargar.start();
}//GEN-LAST:event_abrir

private void compilar(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_compilar
try
{
modoKernel();
tokenizar();
compilar=new Compilar(ldd, jTextArea2, ldVariable, ldEjecutar, jTextArea1, ldTemporal, jTextArea3, jTable1);
compilar.start();
}
catch(Exception e)
{
javax.swing.JOptionPane.showMessageDialog(null,»Programa sin cargar»+e);
}

}//GEN-LAST:event_compilar

public void mostrarMem()
{
jTextArea3.setText(«»);
int val=0;
vecMem[0]=»acumulador 0″;

for(int i=0; i<memPrincipal; i++)
{
if (vecMem[i]==null)
{
if (i<10)
jTextArea3.append(«D0x0000″+val+» «+»\n»);
else if(i<100)
jTextArea3.append(«D0x000″+val+» «+»\n»);
else if(i<1000)
jTextArea3.append(«D0x00″+val+» «+»\n»);
else if(i<10000)
jTextArea3.append(«D0x0″+val+» «+»\n»);
else
jTextArea3.append(«D0x»+val+» «+»\n»);
}
else if (i<10)
jTextArea3.append(«D0x0000″+val+» «+vecMem[i]+»\n»);
else if(i<100)
jTextArea3.append(«D0x000″+val+» «+vecMem[i]+»\n»);
else if(i<1000)
jTextArea3.append(«D0x00″+val+» «+vecMem[i]+»\n»);
else if(i<10000)
jTextArea3.append(«D0x0″+val+» «+vecMem[i]+»\n»);
else
jTextArea3.append(«D0x»+val+» «+vecMem[i]+»\n»);

val=val+1;
}
}

public void desactivar ()
{
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jButton3.setEnabled(false);
}

private void cargarMem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cargarMem
memoria=new AbrirMem(jTextField2, jTextField3);
memoria.start();
}//GEN-LAST:event_cargarMem

private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField3ActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField2ActionPerformed

private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField4ActionPerformed

private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField5ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton3ActionPerformed

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenuItem3ActionPerformed

public void tokenizar()
{
ld=new ListaDoble ();
ldd=new ListaDoble ();

String t=jTextArea1.getText();
StringTokenizer sent1=new StringTokenizer(t,»\n»);
int numTok = sent1.countTokens();
int tam=t.length();

String sent2=»»;

for (int i=0; i<numTok; i++)
{
sent2=sent1.nextToken();
ld.ingrUlt(new Nodo (sent2,» «,i, «», «»));
}

Nodo temp=ld.p;

while (temp!=null)
{
StringTokenizer sent3=new StringTokenizer(temp.getInfo(),» \n\0\t»);
int numTok2 = sent3.countTokens();

String sent4=»»;
for(int j=0; j<numTok2; j++)
{
sent4=sent3.nextToken();
ldd.ingrUlt(new Nodo (sent4, » «, temp.getNumLine(), «», «»));
}
temp=temp.getSig();
}
}

public int capacMem(Nodo prim, Nodo ult, int numProg)
{
int ab=0;

try
{
Nodo b=prim;
int numVar=0;

while (b!=ult)
{
if (b.getInfo().equals(«//»))
{
Nodo tempNueva=b;

while(tempNueva!=null)
{
if(tempNueva.getNumLine()==tempNueva.getSig().getNumLine())
{
tempNueva=tempNueva.getSig();
}
else
{
b=tempNueva.getSig();
tempNueva=null;
}
}
}
else if (b.getInfo().equals(«nueva»))
{
numVar++;
b=b.getSig();
}
else
b=b.getSig();
}

contVariable=contVariable+numVar;
Nodo temp=prim;
int numLinProg=ult.getNumLine()-prim.getNumLine();
jTextArea3.append(Integer.valueOf(contVariable).toString());
String a=Integer.valueOf(ultLinea).toString();

if ((numLinProg+contVariable+nucleoSist+ultLinea)>(vecMem.length-2))
{
javax.swing.JOptionPane.showMessageDialog(null,»El programa «+numProg+» sobrepasa los límites de memoria»);
jTextArea2.setText(«»);
contVariable=contVariable-numVar;
ab=0;
}
else
{
ultLinea=ultLinea+ult.getNumLine()+1;
ab=1;
}
}
catch(Exception e)
{
javax.swing.JOptionPane.showMessageDialog(null,»PRINCIPAL»);
}
return ab;
}

public String getAcum ()
{
return acumulador;
}

public void setAcum(String acum)
{
acumulador=acum;
}

public void setTamMem(int num)
{
memPrincipal=num;
vecMem=new String[num];
}

public void setTamSist(int sist)
{
nucleoSist=sist;
}

public void setNombProgTabla()
{
String dato=jTextField1.getText();
jTable1.setValueAt(dato,1,1);
}

public int getTamMem()
{
return memPrincipal;
}

public void setNombProg(String dato)
{
nombArch=dato;
jTextField1.setText(dato);
}

public String getNombArch()
{
return nombArch;
}

public void borrarPrin()
{
jTextArea1.setText(«»);
jTextArea2.setText(«»);
}

public int compVar(Nodo temp)
{
if(temp!=null)
{
if ((temp.getInfo().equals(«cargue»))||(temp.getInfo().equals(«almacene»))||(temp.getInfo().equals(«vaya»))||
(temp.getInfo().equals(«vayasi»))||(temp.getInfo().equals(«nueva»))||(temp.getInfo().equals(«etiqueta»))||
(temp.getInfo().equals(«lea»))||(temp.getInfo().equals(«sume»))||(temp.getInfo().equals(«reste»))||
(temp.getInfo().equals(«multiplique»))||(temp.getInfo().equals(«divida»))||(temp.getInfo().equals(«potencia»))||
(temp.getInfo().equals(«modulo»))||(temp.getInfo().equals(«muestre»))||(temp.getInfo().equals(«imprima»))||
(temp.getInfo().equals(«retorne»)))
return -1;
else
return 1;
}
else
return -1;
}

public void ingValorVec(String dato)
{
vecMem[indVector]=dato;
indVector++;
}

public void setVariabPosc(String dato, String tipo, String valor)
{
//se almacena la variable(info) y la posicion que ocupa
//en la memoria (numLine)
ldVarVector.ingrUlt(new Nodo(dato,»»,indVector,tipo, valor));
}

public String getInfoVec(int ind)
{
return vecMem[ind];
}

public void setInfoVec(String dato, int ind)
{
vecMem[ind]=dato;
}

public void modifNum()
{
compilar.num=0;
}

public void modoKernel()
{
jLabel7.setText(«Modo Usuario»);
}

public void modoUsuario()
{
jLabel7.setText(«Modo Usuario»);
}

public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new NewJFrame().setVisible(true);
}
});
}

// Variables declaration – do not modify//GEN-BEGIN:variables
private javax.swing.JMenu Abrir;
private javax.swing.JButton jButton3;
private javax.swing.JFrame jFrame1;
private javax.swing.JFrame jFrame2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JLayeredPane jLayeredPane1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTable jTable1;
private javax.swing.JTable jTable2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
// End of variables declaration//GEN-END:variables
}

 

Nodo:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chmaquina;

/**
*
* @author Luis Carlos
*/
public class Nodo
{
Nodo anterior;
Nodo siguiente;
String informacion;
String nomEtiqueta;
int numLinea;
String valorVariable;
String tipoVariable;

public Nodo(String dato, String etiq, int line, String tipoV, String valV)
{
anterior=null;
siguiente=null;
informacion=dato;
nomEtiqueta=etiq;
numLinea=line;
tipoVariable=tipoV;
valorVariable=valV;
}

public void setAnt(Nodo a)
{
anterior=a;
}

public void setSig(Nodo s)
{
siguiente=s;
}

public void setInfo(String f)
{
informacion=f;
}

public void setNombEtiq(String e)
{
nomEtiqueta=e;
}

public void setNumLine(int l)
{
numLinea=l;
}

public void setValVar(String valV)
{
valorVariable=valV;
}

public void setTipoVar(String tipoV)
{
tipoVariable=tipoV;
}

public Nodo getAnt()
{
return anterior;
}

public Nodo getSig()
{
return this.siguiente;
}

public String getInfo()
{
return informacion;
}

public String getNombEtiq ()
{
return nomEtiqueta;
}

public int getNumLine()
{
return numLinea;
}

public String getValorVar()
{
return valorVariable;
}

public String getTipoVar()
{
return tipoVariable;
}
}