[cfe-dev] Lookahead vs. Tentative Parsing

Douglas Gregor dgregor at apple.com
Wed Jul 6 14:10:19 PDT 2011

On Jul 5, 2011, at 8:56 PM, John Freeman wrote:

> Since C++ lambda expressions and Objective-C message expressions can 
> each start with the same two tokens (l_square followed by identifier), 
> it can take a lookahead of three tokens to differentiate the two cases. 
> There are other instances, especially in C++, where further lookahead, 
> or even semantic analysis, may be required. In the case above, I guess 
> that lookahead is enough to decide which parsing path to take, but in 
> general, what are the criteria for deciding to use lookahead vs. 
> tentative parsing?

Lookahead ahead is more efficient than tentative parsing. Typically, do lookahead if possible, to to catch all of the common cases. Then, fall back to tentative parsing if it's a tricky case.

> With tentative parsing, are diagnostics suppressed until the parsing has 
> been committed?

No. Make sure that tentative parsing doesn't generate any diagnostics or perform any semantic analysis.

	- Doug

More information about the cfe-dev mailing list