curimit / SugarCpp

SugarCpp is a language which can compile to C++11.
135 stars 13 forks source link

Fix the ambiguity of generic type parameters <...> #33

Closed curimit closed 9 years ago

curimit commented 9 years ago

Consider the following two cases:

a = T<B>D
a = T < B > D

There are two posible explanations:

  1. T is a type
  2. T is a variable Since we didn't do the type inferance, it is impossible to select the correct rule in parsing time.

Luckly, there do exist a way to distinguish these two kind of possibilities. We can use spaces to distinguish them:

  1. If we want something like a < b, we must add at least one space after a.
  2. if we want sometine like vector<int>, it is not allowed to add extra spaces between vector and <.

Here is a test case:

int main()
    a = f<int>(1,2)
    a = T<B>() > C < D