[cfe-dev] What's the best way to...?

Alexei Svitkine alexei.svitkine at gmail.com
Thu Jan 29 10:31:55 PST 2009


> Very wild idea, and probably not practicable: put a layer between lexer
> and parser. Usually it just forwards tokens, but when the lexer runs out
> of tokens, you do a stack trace to find out what part of the parser
> called you. Then you know what the parser would now expect.

Hmm.. Perhaps if the Parser was made to pass a constant that says what
type of thing is being parsed to the Lexer when asking for the next
token, the stack trace voodoo can be avoided. The Lexer would then
need to be decoupled from the Parser to make this possible... perhaps
the Parser would use a LexerProvider or something which just wraps the
Lexer and takes the extra parameter. Then I could derive from
LexerProvider and intercept that...

Seems like it would require a lot of (small) changes to the Parser to
do this... and I can understand that there might be resistance against
this approach since it would add a level of indirection and thus
decrease performance (though a smart compiler/linker could optimize
that out?).

-Alexei



More information about the cfe-dev mailing list