A yacc scanner will normally get tokens via a lexer, calling a function named yylex
.
The lexer is what normally reads characters from an input file (or buffer, in your case). Assuming you're using Flex to generate the lexer, the usual "hook" for modifying how input is read is to re-define the YY_INPUT
macro.
As @dietrich Epp mentioned, however, there are also yy_scan_string, yy_scan_buffer, and yy_scan_bytes. Whether these are more suitable for your purposes than defining your own YY_INPUT may be open to some question. Although I can't remember any of the details, my recollection is of having avoided them at times due to (at least perceived) lack of efficiency (or maybe it was just that it seemed to me that defining YY_INPUT was easier -- can't remember for sure).