Está en la página 1de 6

Analizador Lexico sentencia WHILE

#include <cstdlib>

#include <iostream>

#include <stdio.h>

#include <string.h>

using namespace std;

/* -----------------------------------------------------------------------------|

|
|

| Asignatura: Autómatas y lenguajes. |

| Autor:
|

| Codigo: 67000134 Nombre: oscar alejandro castillo caicedo |

| Codigo: 67000114 Nombre: tatiana camila beltran |

| Codigo: 67000081 Nombre: juan pablo guerra |

| Fecha: 22 arbil 2019 |

| Version: 1.0
|

| ---------------------------------------------------------------------------*/

int menu(){

int op = 0;

system("cls");

cout <<" 1. sentencia WHILE() " << endl;

cout <<" 0. Salir " << endl;

cout <<"Digite una opcion ";

cin >> op;

return op; // retorna el numero de la opcion del menu

int leerCorreo( char c ){// Los simbolos que aceptara el automata


if ( c == 'w' ) return 0;

if ( c == 'h' ) return 1;

if ( c == 'i' ) return 2;

if ( c == 'l' ) return 3;

if ( c == 'e' ) return 4;

if ( c == '(' ) return 5;

if ( c == ')' ) return 6;

if ( c == '{' ) return 7;

if ( c == '}' ) return 8;

else {

cout << endl << "error de sintaxis---------------- " << c ;

cout<<endl<<" sintaxis correcta -----while(){}---"<<endl;

exit (EXIT_FAILURE);

int reconocer_Correo( char *w ){

int i = 0; // cabeza lectora

int q = 0; // estado inicial q0

int s; // simbolo de sigma

int F [ 10 ] = { 0, 0, 1, 0, 1, 0, 1, 0, 0, 0}; // estados de aceptacion q3 q5 q7

int delta [ 10 ][ 10] = // matriz de transicion de estados

{ /* w h i l e ( ) { } /

/* qo */ { 3, 6, 6, 1, 6, 6, 6, 6, 6 },

/* q1 */ { 6, 6, 6, 2, 6, 6, 6, 6, 6 },

/* q2 */ { 6, 6, 6, 16, 6, 6, 6, 6, 6 },

/* q3 */ { 6, 6, 4, 6, 6, 6, 6, 6, 6 },

/* q4 */ { 6, 5, 6, 6, 6, 6, 6, 6, 6 },

/* q5 */ { 6, 16, 6, 6, 6, 6, 6, 6, 6 },

/* q6 */ { 6, 6, 6, 6, 6, 6, 6, 6, 6 },

/* q7 */ { 8, 8, 8, 8, 8, 16, 16, 16, 16 },

/* q8 */ { 8, 8, 8, 8, 8, 16, 16, 16, 16 },

/* q9 */ { 10, 10, 10, 10, 10, 16, 16, 16, 16 },

};

// procesa la cadena w
for ( i = 0; i < (int)strlen( w ); i++ ) {

s = leerCorreo( w[i] ); // lee el primer simbolo y verifica que sea mayuscula

q = delta[ q ][ s ]; // cambia de estado

return F[ q ]; // retorna 1 si es estado de aceptacion 0 en caso contrario

int main( int argc, char *argv[] ){

int opc=0;

do{

opc=menu(); // llama a la funcion para visualizar el menu

switch (opc){

case 1: { char w[10];

int ace=0;

cout<<"SENTENCIA WHILE "<<endl;

cout<< "-----------"<<endl;

fflush( stdin );

gets( w );

ace= reconocer_Correo( w );

if(ace==1){

cout << "sintanxis correcta" << endl;

}else{

cout << "sintaxis incorrecta" << endl;

cout<< "tal vez queria decir ______while() {}_____"<<endl;

system ("pause");

}break;

}while(opc!=0);
return 0;

CONTEXTO GRAMÁTICAL CON SENTENCIA WHILE

SENTENCIAS -> SENTENCIAS WHILE

|SENTENCIAS MENSAJE

|WHILE

|MENSAJE

MENSAJE( STRING ) -> System.out.println( STRING )

WHILE -> while ( R ) { SENTENCIAS }

R -> E < E

|E > E

|E > E

|E >= E

|E <= E

|E == E

E -> E + E

|E - E

|E * E

|E / E

| (E)

|IDENTIFICADOR

|NUMERO
3. sentencia valida

while(i < j+1){

System.out.println( STRING )

while(j == 1){

System.out.println( STRING )

while( c >j )

System.out.println( STRING )

4. sentencia no valida

while(i < j+1){

System.out.println( STRING )

while(j == 1){

while( c >j )

System.out.println( STRING )

PROGRAMA -> lista_sentencias

lista_sentencias -> lista_sentenciasista_sentencias sentencia

lista_sentencias -> sentencia

Condicion-> R;

sentencia -> E;

sentencia -> WHILE

WHILE -> while ( Condicion ) sentencia

WHILE -> while (condicion ) { lista_sentencias }


Sentencia en Backus-Naur Form

<while_stmt> ::= while <condicion de finalizacion> <expresion> < SENTENCIAS > | < STRING(stmts) >

También podría gustarte