So, I have created a .l file for my lexical analysis. I have defined one pattern as follows
<str,chars,comment,text_block,text_block_chars><<EOF>> {printf("%d", yy_top_state()); showError("", EOF_ERROR); return(0);}
Here I want to give the error depending on what state it was. I know that there is yy_top_state() and yy_current_buffer() functions in my lex.yy.c file which stores the current state. However I cant access those function.
Can someone tell me if there are any other way I can access my current state through .l file only.
(Here str, chars, etc. are the states and showError() is some other function that I have defined)
Thank you.
The current state is available through the macro YY_START
(and also YYSTATE
). The value is a small integer, with INITIAL
having the value 0.
As far as I know, there is no way of getting the symbolic name of the start condition at runtime. State names are preprocessor macros, so they're long gone before the lexer is compiled, and they are not available outside of the generated lexer. But it would be easy enough to build a lookup table (in the lexer).