Hi, I'm trying to parse words but I can't doing it. I read the manual, but I still can't parse something like this: KEYWORD word word, Here is my code:
%{ #include <stdio.h> %} %union { char *string; } %token <string> KEYWORD DATA %type <string> expr expresion %% input : /* empty */ | input line ; line : '\n' | expr '\n' { printf( "%s\n", $1 ); } ; expr : KEYWORD expresion { $$ = $2; } ; expresion : DATA { $$ = $1; } ; %% #include <stdio.h> #include <ctype.h> main(){ yyparse(); } yyerror(char *str){ printf("error= %s \n",str); } yylex(){ int c; while((c=getchar())==' ' || c == '\t'); if (c==EOF) return 0; if (isalpha (c)) { static char *symbuf = 0; static int length = 0; int i; if (length == 0) length = 40, symbuf = (char *)malloc (length + 1); i = 0; do { if (i == length) { length *= 2; symbuf = (char *)realloc (symbuf, length + 1); } symbuf[i++] = c; c = getchar (); } while (c != EOF && isalnum (c)); ungetc (c, stdin); symbuf[i] = '\0'; yylval.string=symbuf; printf("%s \n",yylval.string); return KEYWORD; } return c; } thanks for any help. _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison