{"id":1855,"date":"2019-03-08T19:15:39","date_gmt":"2019-03-09T00:15:39","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=1855"},"modified":"2019-04-12T18:27:57","modified_gmt":"2019-04-12T22:27:57","slug":"rewriting-the-tree-regular-expression-engine","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2019\/03\/08\/rewriting-the-tree-regular-expression-engine\/","title":{"rendered":"Rewriting the pattern matching engine &#8212; part 1"},"content":{"rendered":"\n<p>For the last two weeks, I&#8217;ve trying to write Piggy patterns to construct a symbol table from a Java AST. Patch after patch, I&#8217;d change the pattern matching code to &#8220;fix&#8221; something that wasn&#8217;t working. Unfortunately, I finally wrote a pattern that broke the camel&#8217;s back, &#8220;&lt; classBodyDeclaration &lt; modifier >* &lt; <g class=\"gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"5\" data-gr-id=\"5\"><g class=\"gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"5\" data-gr-id=\"5\">memberDeclaration<\/g><\/g> &lt; <g class=\"gr_ gr_6 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"6\" data-gr-id=\"6\"><g class=\"gr_ gr_6 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"6\" data-gr-id=\"6\">methodDeclaration<\/g><\/g> > > >&#8221;, which looks for methods within a class.<\/p>\n\n\n\n<p>So, I decided to rewrite the engine the way it should have been done: using an NFA. It&#8217;s so far taken a week or so, but it turns that the pattern matcher is much cleaner, and likely faster. In addition, the output engine&#8211;which executes the code blocks in the pattern&#8211;is also much cleaner. I&#8217;ll try to see if I can combine the patterns together in one automaton.<\/p>\n\n\n\n<p>I really should have known better than to approach the tree regular expression matching problem following what other people did, using a top-down recursive recognizer. Live and learn. Always follow a clean, clear theory instead of just hacking.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the last two weeks, I&#8217;ve trying to write Piggy patterns to construct a symbol table from a Java AST. Patch after patch, I&#8217;d change the pattern matching code to &#8220;fix&#8221; something that wasn&#8217;t working. Unfortunately, I finally wrote a pattern that broke the camel&#8217;s back, &#8220;&lt; classBodyDeclaration &lt; modifier >* &lt; memberDeclaration &lt; methodDeclaration &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/165.227.223.229\/index.php\/2019\/03\/08\/rewriting-the-tree-regular-expression-engine\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Rewriting the pattern matching engine &#8212; part 1&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1855"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=1855"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1855\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=1855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=1855"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=1855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}