%{ #include "hello.tab.h" #define YY_USER_ACTION \ yylloc->first_line = yylloc->last_line; \ yylloc->first_column = yylloc->last_column; \ for(int i = 0; yytext[i] != '\0'; i++) { \ if(yytext[i] == '\n') { \ yylloc->last_line++; \ yylloc->last_column = 0; \ } \ else { \ yylloc->last_column++; \ } \ } /* definitions section */ %} SPACE [ ] %option noyywrap %option yylineno %option bison-locations /* rules below here */ %% \( { return round_open; } \) { return round_close; } \* { return multiply; } [0-9] { yylval->integer = atoi(yytext); return single_digit_integer; } [1-9][0-9]+ { yylval->integer = atoi(yytext); return multi_digit_integer; } {SPACE} { return space; } [^()[:space:]]+ { printf("%d:%d - %d:%d invalid: '%s'\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column, yytext); return invalid; } %%