I'm writing a recursive decent parser for an imaginary programming language. It's a C-style language with common operators like ==, <, >, <=, and >=, and it also features generic functions (like those in C#).
In languages like C#, to call a generic function, you write:
someFunction<T>(x);
My question is, how does the parser differentiate the generic parameters from comparison operators (< and >).
From my perspective, the code above could have either of these two meanings:
- call 'someFunction' with a generic parameter 'T', and with a regular parameter 'x'
- evaluate the expression '(someFunction < T) > x', treating 'someFunction', 'T', and 'x' as regular variables
How would the parser know which interpretation is intended?