{"id":256,"date":"2009-11-10T21:27:11","date_gmt":"2009-11-10T20:27:11","guid":{"rendered":"http:\/\/floris.briolas.nl\/floris\/?p=256"},"modified":"2009-11-10T21:28:20","modified_gmt":"2009-11-10T20:28:20","slug":"ambiguity-lexer-rules","status":"publish","type":"post","link":"https:\/\/floris.briolas.nl\/floris\/2009\/11\/ambiguity-lexer-rules\/","title":{"rendered":"Ambiguity: Lexer rules"},"content":{"rendered":"<p>How to handle ambiguous rules?<\/p>\n<p>Remember the <a href=\"http:\/\/floris.briolas.nl\/floris\/?p=46\">&#8220;The following token definitions can never be matched because prior tokens match the same input&#8221;<\/a>. <\/p>\n<p>If you&#8217;ll like to match &#8220;INT&#8221; as a token and a bunch of other chars as another token. <\/p>\n<p>WRONG!<\/p>\n<pre name=\"code\"  class=\"antlr\">\r\nID \t:\t('a'..'z'|'A'..'Z')+;\r\nTYPE \t:\t'INT';\r\n<\/pre>\n<p>RIGHT!<\/p>\n<pre name=\"code\" class=\"antlr\">\r\nTYPE \t:\t'INT';\r\nID \t:\t('a'..'z'|'A'..'Z')+;\r\n<\/pre>\n<p>But this comes with consequences. There is NO WAY ID could be matched with &#8216;INT&#8217; as a value, since that will match to the TYPE rule. <\/p>\n<p>Now here is why that may not matter&#8230;<br \/>\na function header in C# :<\/p>\n<blockquote><p>public int int (string string, object object)<\/p><\/blockquote>\n<p>&#8220;,.. well if you know C# or JAVA,, you&#8217;ll see that this is not a problem&#8230;<\/p>\n<p>But it just might be a problem for you.<\/p>\n<p>I&#8217;m a C# developer,.. and C# solves this ambiguity with a &#8216;<strong>@<\/strong>&#8216;.<br \/>\nlike so:<\/p>\n<blockquote><p>public static void @static(int @int, object @new, float @const)<\/p><\/blockquote>\n<p>This is of course not the final word on this topic..  I&#8217;ll post more here.. I&#8217;t would help if you&#8217;ll post a comment like hurry up already.. \ud83d\ude42<\/p>\n<p>cheers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to handle ambiguous rules? Remember the &#8220;The following token definitions can never be matched because prior tokens match the same input&#8221;. If you&#8217;ll like to match &#8220;INT&#8221; as a token and a bunch of other chars as another token. WRONG! ID : (&#8216;a&#8217;..&#8217;z&#8217;|&#8217;A&#8217;..&#8217;Z&#8217;)+; TYPE : &#8216;INT&#8217;; RIGHT! TYPE : &#8216;INT&#8217;; ID : (&#8216;a&#8217;..&#8217;z&#8217;|&#8217;A&#8217;..&#8217;Z&#8217;)+; But [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3],"tags":[6],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p61yPs-48","_links":{"self":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/256"}],"collection":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":10,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/256\/revisions\/315"}],"wp:attachment":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}