I have a parser generated using Flex/Bison – it parses each line of a file and returns some output for that line. My input data is a little corrupt, and what I’d like to do is add a special character (like a #) to the beginning of lines that I’d like bison to ignore, and merely echo the line to the output.
So if my input looked like
apples 3 ate
oranges 4 consumed
# rhino ten
my output after parsing the lines might be
I ate three apples
I consumed four oranges
# rhino ten
Is there some easy way to do this ?
You can do this lexically in the flex scanner.
Something like:
Or in the parser:
In the parser just generate from your top level grammar a production for this:
Not sure about including that newline; I have no idea how you’re handling those. So it may not be appropriate.