Reputation: 434
Is there a way in flex to reference definition names in the action part of a matched pattern, similar to how you reference to the pattern itself? I would like something similar to
%{
#include<stdio.h>
}%
DIGIT [0-9]
%%
{DIGIT} printf("%s is a %s", yytext, yydefinition)
%%
int main(){
yylex(); return 0;
}
I can imagine that the problem with this might be when you have multiple definitions in a rule such as {DIGIT} | {STRING}
.
Upvotes: 1
Views: 315
Reputation: 54563
No: lex
(and flex
) compile the contents of named patterns into tables without providing a way to refer to their names in the lexer.
There is not a lot of help with states (aka start conditions). lex/flex simply generate #define
statements for those names.
flex
has a debug switch, but the generated tables for that still do not include the information you want.
yacc
and bison
, on the other hand, have tables which can be used to help with error messages. The cproto
program uses that feature, adjusting for several variations of yacc
and bison
.
Upvotes: 2