/* PRUEBAS DE ALGUNAS EXPRESIONES REGULARES COMPILAR CON: flex NOMBRE.l gcc lex.yy.c .o NOMBRE -lfl */ %{ #include <string.h> void muestra(); void otro(); int copia(char*); int num_lineas= 0, num_caracteres= 0; struct mia { int num; char *x; }; %} DIGITO [0-9] REAL {DIGITO}+"."{DIGITO}+ ESPACIO [ ] TAB [\t] %% {DIGITO} { printf("DIGITO:%s (%d)\n",yytext, atoi(yytext) ); } [0-9]+ { printf("NUMERO:%s (%d)\n",yytext, atoi(yytext) ); } {REAL} { printf("REAL:%s \n",yytext ); copia(yytext); printf("REAL_NEW:%s \n",yytext ); } \n { ++num_lineas; ++num_caracteres; muestra(); } "hola" { printf("HOLA: %s \n",yytext ); } {ESPACIO} { printf("ESPACIO\n"); } {TAB} { printf("TABULADOR\n"); } %% int copia(char *x) { char *y = (char*)malloc(sizeof(char)*80); y=x; strcpy(y, "hola"); printf("LONGITUD= %i\n", yyleng); return 1; } void muestra() { printf("# de lineas= %d, # de caracteres.= %d\n",num_lineas,num_caracteres); } void otro() { printf("hola\n"); } int main(int N, char **Args) { yylex(); }