I'm writing my own programming language and have arrived at parsing tuples/lambda expressions after having gotten most of the other stuff out the way. The syntax is very similar to C# with some little differences. I was wondering does C# look-ahead to determine whether or not to produce a simple parenthesised expression, a tuple or a lambda, seems unlikely because the look-ahead (k) is indeterminate.
Right now I'm kind of hacking the solution together by peeking ahead for certain indicators that should give the parser a clue as to what it's trying to parse. i.e. check for an identifier @1 then check for an '=', ',' or ':' (colon is used to annotate identifiers with type information) at @2.
My lambda syntax is a little more flexible than what is available in C#, so guess in it you could just parse the list of identifiers up until there are no more commas and check the next 2 tokens for ')' and '=>'.
Is there some sort of trick I'm missing?