buffered input

Nick Sabalausky a at a.a
Sat Feb 5 18:33:56 PST 2011


"spir" <denis.spir at gmail.com> wrote in message 
news:mailman.1321.1296950957.4748.digitalmars-d at puremagic.com...
> On 02/05/2011 11:00 PM, Nick Sabalausky wrote:
>>> Transparent buffering sounds sensible but in fact it robs you of 
>>> important
>>> >  capabilities. It essentially forces you to use grammars with 
>>> > lookahead 1
>>> >  for all input operations. Being able to peek forward into the stream
>>> >  without committing to read from it allows you to e.g. do operations 
>>> > like
>>> >  "does this stream start with a specific word" etc. As soon
>>> >
>> That shouldn't be a problem for the cases where a lookahead of 1 is all
>> that's needed. So both types can exist (with the traditional/automatic 
>> type
>> most likely built on top of Andrei's type). Thus, I think the only 
>> question
>> is "Are the appropriate use-cases for the traditional/automatic type 
>> minor
>> enough and infrequent enough to actively discourage it by not providing 
>> it?"
>> That I can't answer.
>
> And what about backtracking (eg for parsing the source)?
>

Like I said, there are certainly cases where a lookahead of 1 isn't 
sufficient, and for those, something more like Andrei's proposal can be 
used.

(FWIW, LR doesn't usually need backtracking. That's more typically an LL 
thing. Not that LL is any less important, though. Of course, if the lexical 
grammer supports non-consuming lookahead, then you'd still need lookahead >1 
no matter what parsing algorithm is used.)




More information about the Digitalmars-d mailing list