Ambiguity: Lexer rules

How to handle ambiguous rules?

Remember the “The following token definitions can never be matched because prior tokens match the same input”.

If you’ll like to match “INT” as a token and a bunch of other chars as another token.

WRONG!

ID 	:	('a'..'z'|'A'..'Z')+;
TYPE 	:	'INT';

RIGHT!

TYPE 	:	'INT';
ID 	:	('a'..'z'|'A'..'Z')+;

But this comes with consequences. There is NO WAY ID could be matched with ‘INT’ as a value, since that will match to the TYPE rule.

Now here is why that may not matter…
a function header in C# :

public int int (string string, object object)

“,.. well if you know C# or JAVA,, you’ll see that this is not a problem…

But it just might be a problem for you.

I’m a C# developer,.. and C# solves this ambiguity with a ‘@‘.
like so:

public static void @static(int @int, object @new, float @const)

This is of course not the final word on this topic.. I’ll post more here.. I’t would help if you’ll post a comment like hurry up already.. 🙂

cheers.

Leave a Reply