[cfe-dev] Lookahead vs. Tentative Parsing
akyrtzi at gmail.com
Wed Jul 6 23:51:21 PDT 2011
On Jul 6, 2011, at 2:10 PM, Douglas Gregor wrote:
> 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.
Actually there's not much difference in efficiency, they use the same preprocessor cache. The important thing is how many tokens you are going ahead, it doesn't matter what way you are using to get the tokens.
> 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
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
More information about the cfe-dev