The yacc scanner usually receives tokens through the lexer, calling a function called yylex .
A lexer is what usually reads characters from an input file (or buffer, in your case). Assuming you are using Flex to generate lexer, the usual “hook” to change the way you read is to override the YY_INPUT macro.
However, as @dietrich Epp noted, there are also yy_scan_string, yy_scan_buffer and yy_scan_bytes. Whether they are more suitable for your purposes than defining your own YY_INPUT may be open to some kind of question. Although I cannot recall a single detail, my recollection is that from time to time they avoided them because of (at least the sensation) lack of effectiveness (or maybe it seemed to me that the definition of YY_INPUT was simpler - t remember for sure).
source share