コード例 #1
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (!Form1.uml.claseActual.esNula())
     {
         string nombreFun, visiFun, tipoFunc;
         nombreFun = textBox3.Text;
         visiFun   = comboBox5.Text;
         tipoFunc  = comboBox4.Text;
         comboBox7.Items.Clear();
         Funcion nueva = new Funcion(Form1.uml.claseActual.getNombre(), nombreFun, tipoFunc, this.lParametros, visiFun, null);
         if (Form1.uml.claseActual.addFuncion(nueva))
         {
             MessageBox.Show("Funcion creada exitosamente");
         }
         else
         {
             MessageBox.Show("La funcion no ha sido creada, existe una igual", "Error");
         }
         textBox3.Text = "";
         lParametros   = new ListaParametro();
     }
     else
     {
         MessageBox.Show("Debe seleccionar una clase actual", "Error");
     }
 }
コード例 #2
0
        private Funcion getconstructor(ParseTreeNode nodoConstructor, string nombreClase)
        {
            //CONSTRUCTOR.Rule = ToTerm("__constructor") + "[" + PARAMETROS + "]" + ":" + Eos + CUERPO;
            Cuerpo         instr;
            ListaParametro parametros = getParametros(nodoConstructor.ChildNodes[0]);
            string         nombre     = nodoConstructor.ChildNodes[0].Token.Value.ToString();
            Funcion        nueva      = new Funcion(nombreClase, Constantes.constructor, Constantes.tipoVoid, parametros, Constantes.publico, nodoConstructor.ChildNodes[1]);

            if (nombre.Equals(nombreClase, StringComparison.OrdinalIgnoreCase))
            {
                nueva = new Funcion(nombreClase, nombre, Constantes.tipoVoid, parametros, Constantes.publico, nodoConstructor.ChildNodes[1]);
                nueva.setConstructor(true);
                // instr = getCuerpo(nodoConstructor.ChildNodes[1]);
                // nueva.setCuerpo(instr);
                return(nueva);
            }
            else
            {
                ErrorA nuevo = new ErrorA(Constantes.errorSemantico, nodoConstructor.ChildNodes[0].Token.Location.Line,
                                          nodoConstructor.ChildNodes[0].Token.Location.Position, nodoConstructor.ChildNodes[0].Token.Location.Column,
                                          "El nombre de " + nombre + ", no coincide con el nombre de clase, " + nombreClase);
                Form1.errores.addError(nuevo);
                return(null);
                //error semantico
            }
        }
コード例 #3
0
 private void iniciarValores()
 {
     lParametros = new ListaParametro();
     cargarAtributos();
     cargarClases();
     actualizarTipos();
 }
コード例 #4
0
        private ListaParametro getParametros(ParseTreeNode nodoParametros)
        {
            ListaParametro parametros = new ListaParametro();
            string         tipo, nombre;
            variable       nuevoParametro;

            foreach (ParseTreeNode item in nodoParametros.ChildNodes)
            {
                tipo           = item.ChildNodes[0].ChildNodes[0].Token.Value.ToString();
                nombre         = item.ChildNodes[1].Token.Value.ToString();
                nuevoParametro = new variable(nombre, tipo);
                parametros.addParametro(nuevoParametro);
            }

            return(parametros);
        }
コード例 #5
0
/*
 *      private List<Atributo> generarAtributos(ParseTreeNode nodoAtributo)
 *      {
 *
 *            ATRIBUTO.Rule = VISIBILIDAD + TIPO + L_IDS + ToTerm(";")3,4,2,3
 | VISIBILIDAD + TIPO + identificador + ToTerm("=") + EXPRESION + ToTerm(";")
 | TIPO + L_IDS + ToTerm(";")
 | TIPO + identificador + ToTerm("=") + EXPRESION + ToTerm(";");
 |
 |
 |          List<Atributo> lista = new List<Atributo>();
 |          Atributo nuevo;
 |          int noHijos = nodoAtributo.ChildNodes.Count;
 |          string tipo, nombre, visibilidad;
 |          if (noHijos == 2)
 |          {
 |              visibilidad = Constantes.publico;
 |              tipo = nodoAtributo.ChildNodes[0].ChildNodes[0].Token.Value.ToString();
 |              foreach (ParseTreeNode item in nodoAtributo.ChildNodes[1].ChildNodes)
 |              {
 |                  nombre = item.Token.Value.ToString();
 |                  nuevo = new Atributo(visibilidad, nombre, tipo);
 |                  lista.Add(nuevo);
 |              }
 |              return lista;
 |
 |          }
 |          else if (noHijos == 4)
 |          {
 |              visibilidad = nodoAtributo.ChildNodes[0].ChildNodes[0].Token.Value.ToString();
 |              tipo = nodoAtributo.ChildNodes[1].ChildNodes[0].Token.Value.ToString();
 |              nombre = nodoAtributo.ChildNodes[2].Token.Value.ToString();
 |              nuevo = new Atributo(visibilidad, nombre, tipo);
 |              lista.Add(nuevo);
 |              return lista;
 |          }
 |          else
 |          {//posee tres hijos
 |              if (nodoAtributo.ChildNodes[0].Term.Name.Equals(Constantes.visibilidad))
 |              {
 |
 |                  visibilidad =nodoAtributo.ChildNodes[0].ChildNodes[0].Token.Value.ToString();
 |                  tipo = nodoAtributo.ChildNodes[1].ChildNodes[0].Token.Value.ToString();
 |                  foreach (ParseTreeNode item in nodoAtributo.ChildNodes[2].ChildNodes)
 |                  {
 |                      nombre = item.Token.Value.ToString();
 |                      nuevo = new Atributo(visibilidad, nombre, tipo);
 |                      lista.Add(nuevo);
 |                  }
 |                  return lista;
 |
 |              }
 |              else
 |              {
 |                  visibilidad = Constantes.publico;
 |                  tipo = nodoAtributo.ChildNodes[0].ChildNodes[0].Token.Value.ToString();
 |                  nombre = nodoAtributo.ChildNodes[1].Token.Value.ToString();
 |                  nuevo = new Atributo(visibilidad, nombre, tipo);
 |                  lista.Add(nuevo);
 |                  return lista;
 |
 |
 |              }
 |
 |          }
 |
 |      }
 */

        private Funcion getConstructor(ParseTreeNode nodoConstructor, string nombreClase)
        {
            /* CONSTRUCTOR.Rule = identificador + ToTerm("(") + L_PARAMETRO + ToTerm(")") + CUERPO;*/
            Funcion constructor;
            string  nombre = nodoConstructor.ChildNodes[0].Token.Value.ToString();

            if (nombre.ToUpper().Equals(nombreClase.ToUpper()))
            {
                ListaParametro parametros = getParametros(nodoConstructor.ChildNodes[1]);
                constructor = new Funcion(nombreClase, nombre, Constantes.tipoVoid, parametros, Constantes.publico, nodoConstructor.ChildNodes[2]);
                constructor.setConstructor(true);
                return(constructor);
            }
            else
            {
                ErrorA nuevo = new ErrorA(Constantes.errorSemantico, nodoConstructor.ChildNodes[0].Token.Location.Line,
                                          nodoConstructor.ChildNodes[0].Token.Location.Position, nodoConstructor.ChildNodes[0].Token.Location.Column,
                                          "El nombre de " + nombre + ", no coincide con el nombre de clase, " + nombreClase);
                Form1.errores.addError(nuevo);
                return(null);
                //error semantico
            }
        }