{"id":100,"date":"2022-01-29T15:03:26","date_gmt":"2022-01-29T06:03:26","guid":{"rendered":"http:\/\/blogs.harvard.edu\/adamnoto\/?p=100"},"modified":"2022-01-30T23:26:15","modified_gmt":"2022-01-30T14:26:15","slug":"the-best-ide-for-working-with-lex-and-yacc-bison","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/2022\/01\/29\/the-best-ide-for-working-with-lex-and-yacc-bison\/","title":{"rendered":"(The Best) IDE for working with Lex and Yacc\/Bison"},"content":{"rendered":"<p>It&#8217;s painful to code something without an adequate IDE isn&#8217;t it? If you have been searching for the best IDE for Yacc\/Lex, I think we faced the same challenges. But just to save your time: for Linux\/macOS users: try Vim. I personally use CLion and Xcode, though.<\/p>\n<p><!--more--><\/p>\n<p>It seems like there&#8217;s no IDE offering proper syntax highlighting, indentation, and code intellisense for editing\u00a0<em>both<\/em> Lex and Yacc. It might be because not many people edit Yacc and Lex day-to-day as part of their work. I myself won&#8217;t be coding them if it&#8217;s not for the <a href=\"https:\/\/sites.fas.harvard.edu\/~libe295\/spring2018\/index.html#onlinedocs-problemsets\">compiler class<\/a> I am taking this semester.<\/p>\n<p>Or, maybe, it&#8217;s just difficult if not bordering impossible to come up with the perfect grammar\u00a0<em>thingy<\/em>\u00a0(like, <a href=\"https:\/\/github.com\/microsoft\/vscode\/blob\/main\/extensions\/javascript\/syntaxes\/JavaScript.tmLanguage.json\">tmLanguage JSON file<\/a>) so that color highlighter, indentation and so on would just work\u2122, considering that Lex and Yacc each use a host language such as C in addition to their own constructs, effectively making them to be just <a href=\"https:\/\/stackoverflow.com\/a\/1732454\">as difficult as HTML<\/a> to be parsed with <em>regular<\/em> expressions.<\/p>\n<p>Anyway, anything is better than Notepad certainly, no!?<\/p>\n<p>I have tried Vim, NeoVIM, Textmate, Emacs\/Spacemacs, Visual Studio Code, Sublime, XCode, <em>the<\/em>\u00a0Visual Studio, Atom, and CLion. I&#8217;d say: Vim is probably the best overall, albeit there are some irritating issues in Vim. <em>So<\/em>, be prepared \ud83d\ude42<\/p>\n<div id=\"attachment_106\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-106\" class=\"size-large wp-image-106\" src=\"http:\/\/blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.36.00-1024x391.png\" alt=\"Editing Yacc and Lex in Vim\" width=\"1024\" height=\"391\" srcset=\"https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.36.00-1024x391.png 1024w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.36.00-300x115.png 300w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.36.00-768x293.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><p id=\"caption-attachment-106\" class=\"wp-caption-text\">Editing Yacc and Lex in Vim<\/p><\/div>\n<p>Especially when editing Yacc files. Vim is inconvenient as the indentation just didn&#8217;t work. For example, when I type\u00a0<code>if<\/code>\u00a0something something, and then pressed enter, I thought the cursor would be indented but it didn&#8217;t. Strangely <em>tho<\/em>, Lex did not exhibit this problem at all. It was smooth sailing with Lex files.<\/p>\n<p>For other IDEs, you may skip CLion and the macOS version of Visual Studio as they do not recognize Lex and Yacc files at all. <a href=\"https:\/\/www.youtube.com\/watch?v=ca0UTVoWCpU\">Maybe, Visual Studio will behave differently on Windows<\/a>, but I couldn&#8217;t verify. The\u00a0<a href=\"https:\/\/social.msdn.microsoft.com\/Forums\/en-US\/ef99e9f5-2a48-423b-b6c0-fa5617d7c63d\/how-do-i-get-c-to-work-on-visual-studio-for-mac?forum=visualstudiogeneral\">macOS version of Visual Studio does not support C\/C++<\/a>\u00a0; only C# and mobile.<\/p>\n<div id=\"attachment_114\" style=\"width: 688px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-114\" class=\"size-full wp-image-114\" src=\"http:\/\/blogs.harvard.edu\/adamnoto\/files\/2022\/02\/Screen-Shot-2022-01-21-at-19.29.40.png\" alt=\"Editing a Lex file like a Text file on macOS Visual Studio\" width=\"678\" height=\"192\" srcset=\"https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/02\/Screen-Shot-2022-01-21-at-19.29.40.png 678w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/02\/Screen-Shot-2022-01-21-at-19.29.40-300x85.png 300w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><p id=\"caption-attachment-114\" class=\"wp-caption-text\">Editing a Lex file like a Text file on macOS Visual Studio<\/p><\/div>\n<p><a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEABKL-7544\">A JetBrains user<\/a>\u00a09 years ago has asked for the much-needed Lex and Yacc support. But&#8230; their representative couldn&#8217;t do much as &#8220;there is pretty small interest in the topic.&#8221;<\/p>\n<p>It&#8217;s rather surprising. No doubt. Many would expect CLion and other paid JetBrains IDEs to have some kind of support, at least syntax highlighting and proper indentation if nothing else, since those products are aimed for professionals. I hope someday they&#8217;ll support Yacc and Lex.<\/p>\n<p>Anyway. Yeah, we can simply cross them out for now. But I still use CLion nevertheless, please continue reading.<\/p>\n<div id=\"attachment_116\" style=\"width: 687px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-116\" class=\"size-full wp-image-116\" src=\"http:\/\/blogs.harvard.edu\/adamnoto\/files\/2022\/02\/Screen-Shot-2022-01-21-at-20.10.03.png\" alt=\"Inconsistent syntax highlighting on Emacs\" width=\"677\" height=\"200\" srcset=\"https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/02\/Screen-Shot-2022-01-21-at-20.10.03.png 677w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/02\/Screen-Shot-2022-01-21-at-20.10.03-300x89.png 300w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><p id=\"caption-attachment-116\" class=\"wp-caption-text\">Inconsistent syntax highlighting on Emacs<\/p><\/div>\n<p>Now, between VSCode, Sublime, Textmate, Emacs\/Spacemacs and Atom, I really can&#8217;t choose. All of them offered only nominal support. They all have serious issues with syntax highlighting, issues which Vim has none. Sad.<\/p>\n<p>Onto XCode&#8230; surprisingly, it checked the decent syntax highlighting requirement. And, <del>this one not surprisingly<\/del>, it has the most pleasing user interface to edit those Lex\/Yacc files with. Although, I find the fact that I can&#8217;t have access to the terminal from within the IDE a rather painful experience.<\/p>\n<div id=\"attachment_108\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-108\" class=\"size-large wp-image-108\" src=\"http:\/\/blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.52.33-1024x563.png\" alt=\"Editing a Lex file in XCode\" width=\"1024\" height=\"563\" srcset=\"https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.52.33-1024x563.png 1024w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.52.33-300x165.png 300w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-15.52.33-768x422.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><p id=\"caption-attachment-108\" class=\"wp-caption-text\">Editing a Lex file in XCode<\/p><\/div>\n<p>But, I still admire this IDE&#8217;s look and feel.<\/p>\n<div id=\"attachment_109\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-109\" class=\"size-large wp-image-109\" src=\"http:\/\/blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-16.22.51-1024x482.png\" alt=\"Editing Yacc on XCode\" width=\"1024\" height=\"482\" srcset=\"https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-16.22.51-1024x482.png 1024w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-16.22.51-300x141.png 300w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-16.22.51-768x362.png 768w, https:\/\/archive.blogs.harvard.edu\/adamnoto\/files\/2022\/01\/Screen-Shot-2022-01-21-at-16.22.51.png 1716w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><p id=\"caption-attachment-109\" class=\"wp-caption-text\">Editing Yacc on XCode<\/p><\/div>\n<p>Pretty UI asides, the experience of editing Yacc files in XCode warrant some betterment.\u00a0For example, let&#8217;s consider we have the following rules:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nscreens: \/* empty *\/\r\n       | screens screen\r\n       ;\r\n<\/pre>\n<p>If I wanted to add an action next to the <code>screen<\/code>\u00a0non-terminal on the second line, Xcode will indent the whole line incorrectly upon seeing the opening brace (<code>{<\/code>) &#8230;to be:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nscreens: \/* empty *\/\r\n| screens screen {\r\n       ;\r\n<\/pre>\n<p>Not only that,\u00a0the syntax highlighter for C (within Yacc files) is buggy. I noticed how some function calls were highlighted with blue while others did not. It happened occasionally, and when I overwrite the function with the same name, it&#8217;s highlighted correctly.\u00a0I also could not replicate this kind of issue after restarting the IDE.<\/p>\n<p>So yeah, Vim is generally the most sensible choice overall. If it&#8217;s the only choice available.<\/p>\n<p>But indeed, there&#8217;s no single\u00a0best IDE.<\/p>\n<p>Xcode exhibited issues with rules\/productions indentation, as does Vim with the subroutines part. Personally, I simply turned off XCode&#8217;s automatic indentation to <em>help<\/em> it stop from being that much annoying. In that way, XCode has supplanted Vim for me.<\/p>\n<p>I&#8217;d then use CLion to edit C files as it has the best-in-class intellisense for my C files.<\/p>\n<p>If I were a Windows user, however, I&#8217;ll not miss giving Visual Studio a try. It seems Visual Studio on Windows has excellent support for C\/C++ in addition to Lex and Yacc.<\/p>\n<p>In any case, they are all better than Notepad.<\/p>\n<p>Good luck.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s painful to code something without an adequate IDE isn&#8217;t it? If you have been searching for the best IDE for Yacc\/Lex, I think we faced the same challenges. But just to save your time: for Linux\/macOS users: try Vim. I personally use CLion and Xcode, though.<\/p>\n","protected":false},"author":10207,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6317],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-engineering"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/users\/10207"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":29,"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/posts\/100\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/adamnoto\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}