I\'m trying to use flex and bison to create a filter, because I want get certain grammar elements from a complex language. My plan is to use flex + bison to recognise the gr
I think I managed to make it work ( credit goes to the writer of the bison manual ltcalc lexical analyzer). By default, bison creates yylloc that contains
{ first_line, first_column , last_line , last_column }
We only need to update those values in our lexical analyzer. Ex :
[ \t] { ++yylloc.last_column; }
[\n] { yyloc.last_column = 0; return EOL; }
[a-zA-Z]+ {
yylloc.last_column += strlen(yytext);
return IDENTIFIER;
}
Now in bison, to retrieve those fields:
statement : IDENTIFIER '=' expression
{ printf("%d - %d\n", @1.last_line, @1.last_column); }
By default these fields are initialized to one, we should initialize the column fields to zero otherwise they will report the wrong column.