{"id":221,"date":"2009-09-22T21:21:14","date_gmt":"2009-09-22T19:21:14","guid":{"rendered":"http:\/\/www.coolbasic.com\/blog\/?p=221"},"modified":"2009-09-22T21:21:14","modified_gmt":"2009-09-22T19:21:14","slug":"the-new-parser-is-underway","status":"publish","type":"post","link":"https:\/\/www.coolbasic.com\/blog\/2009\/09\/22\/the-new-parser-is-underway\/","title":{"rendered":"The new parser is underway!"},"content":{"rendered":"<p>It\u2019s been a bit silent ever since I finished the V3 compiler \u2013 oh well, kind of. Even thought the compiler was fully functional, I realized that it had to be re-written in order to gain more performance. Due to drastic syntax changes of the key elements I can\u2019t copy-paste the previous code much at all. And, writing basically the same old code again is \u2013 big surprise \u2013 boring. I also finished my thesis so I felt complete, and wanted to take a few weeks off. I\u2019ve been working hard one year straight after all.<\/p>\n<p>So things have progressed a little slowly for the past few weeks, but at least they have. I didn\u2019t want to blog until I had finished a certain feature, and that\u2019s the support for conditional compiling. I demoed the feature in <a href=\"http:\/\/www.assembly.org\">Assembly Summer 2009<\/a>, but it has now been enhanced! Conditional compilation practically means that the programmer can affect at compile time which parts of the source code will or will not be compiled. Because CoolBasic V3 compiler optimizes all conditional branches, including <code>If<\/code>, <code>While<\/code>, and <code>Until<\/code>, by stripping constant expressions that evaluate to <code>False<\/code>, from the final Intermediate Language, the <code>#If<\/code> and <code>If<\/code> statements were essentially identical. However, conditional compilation now gets evaluated immediately after lexical analysis so that <code>False<\/code> branches don\u2019t get processed in Pass#1 or Pass#2 at all!<\/p>\n<p>These so-called <em>directive expressions<\/em> must evaluate to a constant value. Because the directive expressions will be evaluated before statement parsing, regular constant variables can\u2019t be resolved. Thus, there will be no name resolution (as we understand it in OOP), but instead, CoolBasic introduces <em>directive constants<\/em> which can be declared via the <code>#Const<\/code> statement. These constants are separate from the regular ones you\u2019d declare via the standard <code>Const<\/code> statement, and they will not conflict by name. Directive constants are always <code>Private<\/code> to the file they are declared in. In addition, it\u2019s possible to define global directive constants at project level, but that will be a feature of the code editor.<\/p>\n<p>In contrast to regular constants, directive constants can be declared multiple times with the same name, and it\u2019s possible to assign a different value to them each time. You can use existing directive constants in directive expressions when declaring other directive constants. Imagine the possibilities for implementing different sound engines, for example. The following example will shed some light about the concept:<\/p>\n<pre name=\"code\" class=\"cbv3\">#Const DEBUG = True\n#If DEBUG\n    \/\/ This will get compiled, and is available in program\n    Function A() \n    EndFunction\n#Else\n    \/\/ This is unavailable in program \u2013 unless #Const DEBUG = False\n    Function B() \n    EndFunction\n#EndIf\n#Const DEBUG = Not DEBUG \/\/ Redefine the DEBUG directive constant<\/pre>\n<p>As directive expressions are processed so early, I had to write yet another postfix converter and calculator for the purpose. God that was boring. At least now it\u2019s done. Next, I should be able to start writing statement specific parsers and general-purpose parsers.<\/p>\n<p>I <strong>may<\/strong> (or may not) have a mega surprise next time. Stay tuned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s been a bit silent ever since I finished the V3 compiler \u2013 oh well, kind of. Even thought the compiler was fully functional, I realized that it had to be re-written in order to gain more performance. Due to drastic syntax changes of the key elements I can\u2019t copy-paste the previous code much at [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[5,8,10],"_links":{"self":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/221"}],"collection":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":0,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}