3 ms·
> convert the tokens around the damage back into text, re-lex that text, and then work from front and back of the new partial stream I haven't tried it and I'm
by vorg 12y ago
> convert the tokens around the damage back into text, re-lex that text, and then work from front and back of the new partial stream
I haven't tried it and I'm no parsing expert but it seems when a rule is specified "forwards" (i.e. beginning-to-end) then it can be used for lexing (or parsing) forwards but there'd be problems using it to lex (or parse) backwards. Hence the first "L" in "LL" and "LR" parsing.
Maybe an algorithm could use both directions running in parallel and create 2 structures/memoizations, one for the forward parse and one for the backward, hence a dual LL/RL or LR/RR parse, and access both structures to repair "damage". However, there could be another problem: if the lookahead for some lex or parse rule is 1, couldn't that translate to any lookbehind value when lexing or parsing backwards? An LL(1) grammar might require an equivalent RL(k) grammar for some very high k. Of course you'd also need to avoid right recursion as well as left recursion for topdown parsing.
I haven't tried any of this but these are the things that cross my mind whenever I think of incremental parsing!