https://wiki.ccarh.org/index.php?title=Zbex_conditional_compiles_and_other_features&feed=atom&action=historyZbex conditional compiles and other features - Revision history2024-03-28T23:09:58ZRevision history for this page on the wikiMediaWiki 1.33.0https://wiki.ccarh.org/index.php?title=Zbex_conditional_compiles_and_other_features&diff=797&oldid=prevCraig: added chapter navigator at top and bottom of page2010-10-20T05:22:19Z<p>added chapter navigator at top and bottom of page</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 05:22, 20 October 2010</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>__TOC__</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">{{ZbexChap</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"> | before = [[Zbex debugging instructions|Instructions for debugging]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"> | after = [[Zbex Controlling the text display with putc|Controlling the text display with putc]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">}}</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline"><center></ins>__TOC__<ins class="diffchange diffchange-inline"></center></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Zbex provides you with some compile time features that can add flexibility and readability to your programs. The following commands must start in column one. </div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Zbex provides you with some compile time features that can add flexibility and readability to your programs. The following commands must start in column one. </div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l156" >Line 156:</td>
<td colspan="2" class="diff-lineno">Line 160:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> i >>= 3 i = i >> 3 " " </div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> i >>= 3 i = i >> 3 " " </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> i <<= 4 + j i = i << (4 + j) " "</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> i <<= 4 + j i = i << (4 + j) " "</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{ZbexChap</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> | before = [[Zbex debugging instructions|Instructions for debugging]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> | after = [[Zbex Controlling the text display with putc|Controlling the text display with putc]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">}}</ins></div></td></tr>
</table>Craighttps://wiki.ccarh.org/index.php?title=Zbex_conditional_compiles_and_other_features&diff=684&oldid=prevCraig: created page2010-10-15T03:31:17Z<p>created page</p>
<p><b>New page</b></p><div>__TOC__<br />
<br />
Zbex provides you with some compile time features that can add flexibility and readability to your programs. The following commands must start in column one. <br />
<br />
== #define ==<br />
<br />
The #define command has two fields, separated by one more blanks. The second field is defined as a compile time replacement for the first field. The effect during compilation is that whenever the compiler finds a string of characters (outside a put statement) that matches the first field, it substitutes the string of characters in the second field. This feature allows you to identify arbitrary constants (sometimes called "magic numbers") with a name, so that these can later be easily found and changed. It also allows you to identify program parameters by name (e.g., the size of arrays) so that these can be easily changed. The #define command is also used to set the value of boolean variables used in conditional compiles. The variable is identified in the first field, and its value is set by the second field. The value is 1, if and only if the second field is a "1". Example: <br />
<br />
Program <br />
--------------------- <br />
#define LIMIT 40 <br />
<br />
int h,i,j(LIMIT) <br />
j(1) = 1 <br />
j(2) = 1 <br />
loop for i = 3 to LIMIT <br />
j(i) = j(i-1) + j(i-2) <br />
repeat <br />
loop for i = 1 to LIMIT <br />
putc ~j(i) ... <br />
h = i / 5 <br />
if rem = 0 <br />
putc <br />
end <br />
repeat <br />
putc <br />
run <br />
<br />
Execution <br />
------------------------------------- <br />
** S=15, P=57, L=243, M=450 ** <br />
1 1 2 3 5 <br />
8 13 21 34 55 <br />
89 144 233 377 610 <br />
987 1597 2584 4181 6765 <br />
10946 17711 28657 46368 75025 <br />
121393 196418 317811 514229 832040 <br />
1346269 2178309 3524578 5702887 9227465 <br />
14930352 24157817 39088169 63245986 102334155 <br />
<br />
Ready for program <br />
<br />
<br />
== #if, #else, #endif == <br />
<br />
This group of commands works much like the if/else/end group in Zbex, except that the effect is to tell the compiler which lines of code to compile. The #if command requires a boolean variable, whose value must be set by a #define command (see above). If the value of the variable is 1, the lines following the #if will be compiled, up to the #else (which is optional) or the #endif of the group. It is possible to have nested #if-#else-#endif groups. Example: <br />
<br />
Program <br />
--------------------- <br />
#define OPTION_1 1 <br />
#define OPTION_2 0 <br />
<br />
str name.30,subname.10(3) <br />
int i <br />
<br />
name = "Ronald Wilson Reagan" <br />
<br />
mpt = 0 <br />
loop for i = 1 to 3 <br />
subname(i) = txt(name,[' ']) <br />
repeat <br />
<br />
putc The candidate's name is ... <br />
#if OPTION_1 <br />
putc ~subname(1) ... <br />
<br />
#if OPTION_2 <br />
putc ~subname(2) ... <br />
#else <br />
putc ~subname(2){1} . ... <br />
#endif <br />
<br />
#endif <br />
putc ~subname(3) <br />
run <br />
<br />
Execution <br />
------------------------------------- <br />
** S=12, P=56, L=263, M=431 ** <br />
The candidate's name is Ronald W. Reagan <br />
Ready for program <br />
<br />
<br />
== #process ==<br />
<br />
This command allows you to identify groups of lines that you want included in a compile. Groups of lines are identified by letters, caps and small (52 groups total). The compiler will include all groups identied by letters found on #process command line. You may use the #process command more than once. Program lines belonging to a group are identified by an ampersand "&" in column one, followed by a single letter in column two and a blank space in column three. Example: <br />
<br />
Program <br />
--------------------- <br />
#process A b D <br />
<br />
&A putc Option A <br />
&b putc Option B <br />
&c putc Option C <br />
&D putc Option D <br />
&E putc Option E <br />
&F putc Option F <br />
run <br />
<br />
Execution <br />
------------------------------------- <br />
** S=4, P=17, L=231, M=410 ** <br />
Option A <br />
Option B <br />
Option D <br />
Ready for program <br />
<br />
The #process command is very useful for removing debug statements from the compile process after your program is running properly. I have found it helpful to keep debug statements available in case something goes wrong with one of my programs later on. The advantage is that I don't have to rethink the debugging process from scratch. By using the %<letter> method for removing these lines, I can turn them back on in an instant by simply including the proper process statement at the top my program. In the small example below, I can turn on the dputc statement by replacing the "*" in front of process with a "#". <br />
<br />
Program <br />
--------------------- <br />
*process A <br />
int i <br />
loop for i = 1 to 10 <br />
&A dputc ~i <br />
repeat <br />
run <br />
<br />
== #autodef ==<br />
<br />
If you are writing a short program and you are feeling too lazy to declare your variables, you may be able to use the #autodef command. #autodef automatically declares the letters 'a'..'t' to be integers and the letters 'u'..'z' to be real numbers. All other symbols will be declared as strings with maximum length of 160. Example: <br />
<br />
Program <br />
--------------------- <br />
#autodef <br />
A = "" <br />
loop for i = 1 to 1000 <br />
A = A // "x" <br />
repeat <br />
run <br />
<br />
Execution <br />
------------------------------------- <br />
** S=5, P=16, L=237, M=451 ** <br />
Run-time error: maximum length of string variable: A <br />
has been exceeded at line = 4 <br />
attempted length = 161, maximum length = 160 <br />
Ready for program <br />
<br />
== Abbreviations ==<br />
<br />
The Zbex compiler recognizes a few abbreviations that have become standard in other programing languages. These are listed below, along with what they represent. <br />
<br />
Abbreviation Expanded to ... <br />
-------------- ------------------------- <br />
++i i = i + 1 (integer only) <br />
--i i = i - 1 (integer only) <br />
<br />
x += 1.0 x = x + 1.0 (integer and real) <br />
i -= 10 i = i - 10 " " " <br />
y *= x + 3.0 y = y * (x + 3.0) " " " <br />
k /= 4 k = k / 4 " " " <br />
<br />
i &= 0x01 i = i & 0x01 (integer only) <br />
i |= 0x04 i = i | 0x04 " " <br />
i >>= 3 i = i >> 3 " " <br />
i <<= 4 + j i = i << (4 + j) " "</div>Craig