How to parse a C string with Bison

Bison parsers don't read input at all. They simply obtains a series of tokens by repeatedly calling yylex. (Or, with modern bison, you can create a "push parser" which is given tokens in successive calls.) So whatever implements yylex is responsible for the input.

If you use flex to create a lexical scanner, you can use yy_scan_string (or yy_scan_bytes if you know how long the string is) to scan a string instead of scanning from a file. See the Flex manual for details on these functions.

For a simple example, you could put the following two functions at the end of your flex definition file, after the second %%: