Ben Bacarisse said:Fine. I do it the other way unless there is a compelling reason not to,
but that is because pretty much all the parsers I've written want to
ignore newlines -- they operate on token streams. Reading lines would
just add an irrelevant detail.
(The parsers I write now tend to read an entire file into memory (although
even that is apparently also fraught with problems if you read this
newsgroup too much).
Newlines are significant in the source syntax, but have a more indirect
affect on the resulting token stream. This kind of parser (for language
source) is for a stricter, more precise syntax than might be used for
processing command-line input.
A few years I might have pulled in the source code a line at a time, but now
the largest file I might typically want to process would occupy around
0.0025% of the installed ram I happen to have in my PC.
Of course you can't read a file-at-a-time for interactive input;
line-at-a-time is the next best thing, which exactly matches the
line-buffering used by the language runtime.)