Documente Academic
Documente Profesional
Documente Cultură
TEORIA DE LENGUAJES
TEORIA DE LENGUAJES
TEORIA DE LENGUAJES
TEORIA DE LENGUAJES
TEORIA DE LENGUAJES
3. LENGUAJE DE DESARROLLO
El lenguaje de desarrollo que utilizaremos es el LENGUAJE c#. A continuacin
se presenta las lneas de cdigo para la creacin de las ventanas:
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
namespace Teoria_de_Lenguajes
{
public partial class AnalizadorLexico : Form
{
string error = "";
string lexema = ""; string caracter = "";
public AnalizadorLexico()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{ //Limpiar cuadro de caracteres y mensaje para nueva ejecucuion
lista_Token.Items.Clear();
lbxSecuencia.Items.Clear();
lbxErrores.Items.Clear();
string a = cuadro_Codigo.Text;
if (cuadro_Codigo.Text != "")
{
int fila = 1, columna = 1;
int verificador=0;
for (int i = 0; i < cuadro_Codigo.Text.Length; i++)
{
//Compara caracter con Palabras reservas
if (a.Substring(i, 1) == "M" || a.Substring(i, 1) == "R" || a.Substring(i,1)=="W")
{
if (a.Substring(i, 1) == "M")
{
lexema = "PROG PRINCIPAL";
AgregaSecuencia();
}
else if (a.Substring(i, 1) == "R")
{
lexema = " LECTURA";
AgregaSecuencia();
}
else
TEORIA DE LENGUAJES
lexema = "ESCRITURA";
AgregaSecuencia();
}
}
//Compara Caracter con elementos Desconocidos
else if (a.Substring(i, 1) == "A" || a.Substring(i, 1) == "B"||
a.Substring(i, 1) == "C" || a.Substring(i, 1) == "D"||
a.Substring(i, 1) == "E" || a.Substring(i, 1) == "F"||
a.Substring(i, 1) == "G" || a.Substring(i, 1) == "H"||
a.Substring(i, 1) == "I" || a.Substring(i, 1) == "J"||
a.Substring(i, 1) == "K" || a.Substring(i, 1) == "L"||
a.Substring(i, 1) == "N" || a.Substring(i, 1) == ""||
a.Substring(i, 1) == "O" || a.Substring(i, 1) == "P"||
a.Substring(i, 1) == "Q" || a.Substring(i, 1) == "S"||
a.Substring(i, 1) == "T" || a.Substring(i, 1) == "U"||
a.Substring(i, 1) == "V" || a.Substring(i, 1) == "X"||
a.Substring(i, 1) == "Y" || a.Substring(i, 1) == "Z")
{
lexema = "DESCONOCIDO";
//Poner la secuencia en rojo como advertencia
lbxSecuencia.Items.Add("<" + lexema + ">");
//Mostrando Los Mensajes de error
error = "Elemento desconocido en la fila "+fila+" columna "+columna;
lbxErrores.Items.Add(error);
lbxErrores.ForeColor = System.Drawing.Color.Red;
}
///Compara el Caracter con Operadores
else if (a.Substring(i, 1) == "+" || a.Substring(i, 1) == "-" || a.Substring(i, 1) == "*" ||
a.Substring(i, 1) == "/" || a.Substring(i, 1) == "%")
{
if (a.Substring(i, 1) == "+")
{
lexema = "OPER SUMA";
AgregaSecuencia();
}
else if (a.Substring(i, 1) == "-")
{
lexema = "OPER RESTA";
AgregaSecuencia();
}
else if (a.Substring(i, 1) == "*")
{
lexema = "OPER MULTIPLIC";
AgregaSecuencia();
}
else if (a.Substring(i, 1) == "/")
{
lexema = "OPER COCIENTE";
AgregaSecuencia();
}
else
{
lexema = "OPER RESIDUO";
AgregaSecuencia();
TEORIA DE LENGUAJES
TEORIA DE LENGUAJES
+"
}
}
}
TEORIA DE LENGUAJES
4. DISEO DE PANTALLAS
El diseo de pantalla quedaria de la siguiente manera:
TABLA: Servir para mostrar la tabla que contienen los tokens y
lexemas.
TABLA DE SIMBOLOS : Servir para mostrar la tabla de smbolos
y las veces en que aparecen en el programa.
TEORIA DE LENGUAJES