Ejemplo - norman-ipn/Errores GitHub Wiki
/* Codigo C*/ %{ #include "diccionario.h" /* definiciones de insertar_tabla(), buscar_tabla()*/ DICCIONARIO *diccionario; %} //DECLARACION EN BISON
%union { int valor_entero; double valor_real; char * texto; } %token <valor_real> CONSTANTE_REAL %token <valor_entero> CONSTANTE_ENTERA %token IDENTIFICADOR
%left β-β β+β
%left ββ β/β
%type <valor_real> expresion
%% / Gramatica /
input: / cadena vacia /
| input linea
;
linea: β\nβ
| IDENTIFICADOR β=β expresion β\nβ { insertar_tabla(diccionario, $1, $3); }
| expresion β\nβ { printf ("\t%d\n", $1); }
;
expresion: CONSTANTE_REAL { $$ = $1; }
| CONSTANTE_ENTERA { $$ = (double) $1; }
| IDENTIFICADOR { $$ = buscar_tabla(diccionario,$1); }
| expresion β+β expresion { $$ = $1 + $3; }
| expresion β-β expresion { $$ = $1 - $3; }
| expresion ββ expresion { $$ = $1 *
/ejemplo.l ESTO CODI9FICADO EN FLEX/
%{ #include <stdlib.h> #include <malloc.h> #include <string.h> #include "ejemplo.tab.h" %} NUM [0-9]+ %% {NUM} { yylval.valor_entero = atoi(yytext); return (CONSTANTE_ENTERA); } {NUM}.{NUM} { yylval.valor_real = atof(yytext); return (CONSTANTE_REAL); } "+"|"-"|""|"/" { return (yytext[0]); } "\n" { return (yytext[0]); } [A-Za-z] { yylval.texto = (char *) malloc (strlen(yytext) + 1); strcpy(yytext, yylval.texto); return (IDENTIFICADOR); } . ; %%
//un sencillo ejemplo en la pagina adjunta para comprender un poco el post de algunos compaΓ±eros y tambn para la compilacion
Compilacion $ bison -d ejemplo.y $ flex ejemplo.l $ gcc -o ejemplo ejemplo.tab.c lex.yy.c diccionario.c