I am making a compiler using Flex-Yacc and I am currently trying to make a buffer system to help me implement the for and while loops. I have read the Flex manual
(here) and when I use the YY_CURRENT_BUFFER in my yacc file and I compile it, I get
undefined reference to YY_CURRENT_BUFFER
. How can I declare/include this in my code? I have searched a lot but I cannot seem to find it.
"YY_CURRENT_BUFFER" is not a variable, but a macro local to the lexer (it's not exported in the header generated by lex --header-file
, and it expands to an expression using static variables (ie variables that are local to lex.yy.c, not global, not accessible from other source files).
You should wrap all the code making use of "YY_CURRENT_BUFFER" in a function in the lexer (*.l) file, put its definition in a header included in the parser (*.y) file, and use that function instead of "YY_CURRENT_BUFFER" directly.