So if I understand correctly, in C++ we have a bit-shift operator:
int a = 1024; a = a >> 1; And we can also have two > tokens in a row in some contexts, i.e. in a template:
Foo<Bar<int>> x = ... How do C++ parsers differentiate between those cases? Do C++ lexers need to have context information when they're parsing tokens to know whether they're parsing a pair of angle braces or something?
>>is truly ambiguous.Foo!(Bar!int)but that ship has long since sailed.>>is never ambiguous. The problem is that it's not always easy to know whether a<is a less-than operator or the start of a template argument list. Although that determination requires resolving the name which precedes the<, a task which goes far beyond what lexers are generally responsible for, the answer is always clear. And once that determination is made, the decision about>>is very simple -- if a>can close a template argument list, then it does so. See this brief answer.