{"id":2646,"date":"2020-03-30T08:54:06","date_gmt":"2020-03-30T12:54:06","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=2646"},"modified":"2020-04-03T07:50:15","modified_gmt":"2020-04-03T11:50:15","slug":"flex-vs-bison-import","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2020\/03\/30\/flex-vs-bison-import\/","title":{"rendered":"Flex vs Bison import"},"content":{"rendered":"\n<p>I&#8217;ve written a basic Bison import for Antlrvsix, and now I&#8217;m in the guts of writing a Flex import. While writing the Bison import, I soon realized a problem that I could not deal with immediately. Many people write Bison code that is very undisciplined. Often the code contains driver code (<a href=\"https:\/\/github.com\/akimd\/bison\/blob\/master\/examples\/java\/calc\/Calc.y\" class=\"ek-link\">calc.y<\/a> from the official Gnu repository), The static semantics is often wrapped up with the tree construction. While this is ok, this means the grammar contains target-language code, which is not a great way to write grammars. If you really want an abstract syntax tree instead of a parse tree for semantic checks, you should discipline the semantic checks outside of tree construction. For now, I do not copy code blocks to the generated Antlr grammar.<\/p>\n\n\n\n<p>For Flex, the problem is that the embedded code exclusively performs semantic checks at the lexer phase. So this code must be included in a generated Antlr lexer grammar. The good news is that it&#8217;s not too difficult to convert the patterns in Flex into Antlr lexer rules and modes. You can then convert the code blocks in a Flex rule into your target language. Whether this works or not, I will find out&#8211;I&#8217;m translating line-by-line the Flex lexical grammar into an Antlr lexer grammar, and so far, it looks good.<\/p>\n\n\n\n<p>Aside, I&#8217;ve been using Antlrvsix quite a bit myself to write the Flex grammars. I added a refactoring to sort lexer modes alphabetically since the original Flex &#8220;scan.l&#8221; code defined the start states in a haphazard order. And, since I&#8217;ve switch to the &#8220;Dark mode&#8221; theme in Visual Studio 2019, I added to the options color selections for grammar symbols so I can see the symbol text more clearly.<\/p>\n\n\n\n<p>&#8211;Ken<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve written a basic Bison import for Antlrvsix, and now I&#8217;m in the guts of writing a Flex import. While writing the Bison import, I soon realized a problem that I could not deal with immediately. Many people write Bison code that is very undisciplined. Often the code contains driver code (calc.y from the official &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/165.227.223.229\/index.php\/2020\/03\/30\/flex-vs-bison-import\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Flex vs Bison import&#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\/2646"}],"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=2646"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/2646\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=2646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=2646"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=2646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}