Programacion
#include <iostream.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
//using namespace std;
#defineIDENT 300
#define ENTERO 302
#define ASIG 304
#define ERROR -5
#define READ 301
#define WRITE 303
FILE *Fuente;
int EsPalabraReservada(char lexema[])
{
int token[]={READ,WRITE};char *TPR[]={"READ","WRITE"};
for(int i=0;i<2;i++)
{
if(strcmp(lexema,TPR[i])==0)
return (token[i]);
}
return 0;
}
int yylex(void)
{
intc;
c=fgetc(Fuente);
while(isspace(c)) //determina si lo leido es un espacio o un salto de linea
c=fgetc(Fuente);
if(isalpha(c))
{
int token;int i=0;
char lexema[30];
lexema[i]=c;
c=fgetc(Fuente);while(isalpha(c)||isdigit(c))
{
i++;
lexema[i]=c;
c=fgetc(Fuente);
}
i++;lexema[i]='\0';
ungetc(c,Fuente);
token=EsPalabraReservada(lexema);
if(token)
return(token);else
return (IDENT);
}
if(isdigit(c))
{
c=fgetc(Fuente);
while(isdigit(c))
c=fgetc(Fuente);ungetc(c,Fuente);
return (ENTERO);
}
if (c==':')
{
c=fgetc(Fuente);
if(c=='=')
return (ASIG);ungetc(c,Fuente);
return (ERROR);
}
if(strchr("+*();",c))
return (c);
if (c==EOF)
return (0);
return (ERROR);...
Regístrate para leer el documento completo.