home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Samples / BOZOL2 / BOZOL2.ZIP / TEST.BOZ < prev    next >
Encoding:
Text File  |  1994-02-08  |  35.1 KB  |  721 lines

  1. goto start
  2.  
  3. ====================================================================
  4. October 21, 1993 - Erik Lee Olson, PowerBASIC Tech Support
  5. Port Charlotte, Florida
  6.  
  7. This is a test program for BozoL.  See BOZOL.DOC and BOZOL.REF for a
  8. complete description of how to use and customize BozoL.
  9.  
  10. BozoL and the PowerBASIC interpreter source code are public domain
  11. =====================================================================
  12.  
  13. start (this is the beginning of the program)
  14.  
  15. color 14,1:cls
  16. locate 2,5:print "BozoL test program"
  17. print            "==================" at locate 3,5
  18. color 15,1  print chr 7
  19.  
  20. print        "1. WHAT IS BOZOL?"                              at locate 7,15
  21. print        "2. BOZOL COMMANDS AND FUNCTIONS - STARTER SET"  at locate 8,15
  22. print        "3. BOZOL PROGRAMMING RULES"                     at locate 9,15
  23. print        "4. HOW TO ADD COMMANDS AND FUNCTIONS"           at locate 10,15
  24. print        "5. CALLING BOZOL FROM YOUR OWN PROGRAMS"        at locate 11,15
  25.  
  26. print           "Or type Q to quit"   at locate 13,18  in color 14,1
  27. color 15,1:locate 15,18:input  "Enter a selection --> ",Pick
  28. if eval len pick=0: print chr 7:goto start
  29.  
  30.         goto one   if eval Pick=1
  31.          goto two   if eval Pick=2
  32.           goto three if eval Pick=3
  33.            goto four  if eval Pick=4
  34.             goto five  if eval Pick=5
  35.  
  36. if same upper Pick,"Q": color 7,0: Print "Goodbye!": end
  37. print chr 7:goto start
  38.  
  39. one:
  40. cls with color 1,7
  41. print "        1. WHAT IS BOZOL?"
  42. print ""
  43. print "        BozoL (The Bozo Language) is an extremely simple interpretive"
  44. print "        language written in PowerBASIC.  It is designed to be easy to"
  45. print "        use, easy to modify, and to run as fast as possible."
  46. print ""
  47. print "        Some of the rules in BozoL may seem a bit wierd, but there is a"
  48. print "        reason for this.  After writing a BASIC interpreter (EBASIC.ZIP)"
  49. print "        I discovered that the fundamental design of BASIC makes it"
  50. print "        extremely difficult to parse and interpret with any sort of"
  51. print "        reasonable speed.  BozoL is purposely designed to run as fast"
  52. print "        as possible as an interpreted language."
  53. print ""
  54. gosub pause
  55. print "        Why BozoL?"
  56. print ""
  57. print "        Every now and then a situation may arise where you will want to"
  58. print "        incorporate a command language into your programs.  BozoL can be"
  59. print "        easily modified to do things relevant to your program's needs."
  60. print "        Suppose you have a database program and you want to allow your"
  61. print "        users to program their own custom procedures without having to"
  62. print "        go back to the original source code and add them in."
  63. print ""
  64. print "        BozoL is a language skeleton.  All of the dirty work has been"
  65. print "        done already.  BozoL already contains expression parsing, program"
  66. print "        flow control, basic logic, and other fundamental building blocks"
  67. print "        of a programming language (print, input, variables, etc)."
  68. print ""
  69. gosub pause
  70. print "        BozoL is simple.  There are not a lot of rules, punctuation, or"
  71. print "        wierd symbols in the language.  It is a real beginner's language."
  72. print ""
  73. print "        All you need to do now is add your own custom commands and key-"
  74. print "        words to the language.  See section 4, " CHR 34 "How to add commands and"
  75. print "        functions" CHR 34 " for the exact details on how to do this."
  76. print ""
  77. gosub pause
  78. print "        Prototypes and Applications"
  79. print ""
  80. print "        Suppose you have a library of routines that pop up boxes, print"
  81. print "        menus, display pictures, etc.  You can take these routines and"
  82. print "        make BozoL commands out of them.  For instance, if you have a"
  83. print "        PowerBASIC subroutine that displays a message inside a red box"
  84. print "        on the center of the screen, you can make a BozoL command which"
  85. print "        calls this subroutine.  So now in BozoL you can say"
  86. print ""
  87. print "                REDBOX " CHR 34 "press any key to continue!" CHR 34
  88. print ""
  89. print "        and BozoL will call your subroutine.  Using this technique, you"
  90. print "        can take an entire library, or many libraries, and make BozoL"
  91. print "        commands out of all of those subroutines."
  92. print ""
  93. gosub pause
  94. print "        I'll give you a more advanced example.  Suppose you have a Power-"
  95. print "        BASIC library that features pull-down menus, dialog boxes, list"
  96. print "        boxes, a text editor, and data entry screens.  If you took every"
  97. print "        callable SUB and FUNCTION in this library and made BozoL commands"
  98. print "        out of them, then you could use the BozoL language to write"
  99. print "        really neat user-interface programs, prototypes, or even finished"
  100. print "        products.  Instead of shipping an EXE, you can ship the BozoL"
  101. print "        interpreter along with an interpreted BozoL program that can"
  102. print "        be easily modified by your customers without ever having to"
  103. print "        give them the source code or customizing the program yourself."
  104. print ""
  105. print "        Software upgrades could be faxed to your customers or even"
  106. print "        dictated over the phone."
  107. print ""
  108. gosub pause
  109. print "        Process Control"
  110. print ""
  111. print "        You could use BozoL to control machinery.  You could add commands"
  112. print "        like TURN EVERYTHING OFF or DISPLAY STATUS OF MIXER 1.  By inventing"
  113. print "        commands and adding them to the language you could turn BozoL into"
  114. print "        a high level language that does almost anything, for any purpose."
  115. print "        Users could enter direct statements or run programs that display"
  116. print "        menus and perform certain tasks, and easily add to or modify the"
  117. print "        system without a lot of complicated programming.  Consider these"
  118. print "        possible additions to the language:"
  119. print ""
  120. print "                DISPLAY SCHEMATIC"
  121. print "                BLOCK PHONES"
  122. print "                ELECTRIC FENCES OFF"
  123. print "                DISENGAGE SECURITY IN DINOSAUR EMBRYO LAB"
  124. print ""
  125. gosub pause
  126. print "        With the fundamental building blocks of the language already in"
  127. print "        place (like GOTO, GOSUB, IF, LOAD, RUN, SAVE, PRINT, INPUT, LOCATE,"
  128. print "        COLOR, LET, etc) you can easily build a custom language that works"
  129. print "        well, runs fast, can handle almost any programming task, and can"
  130. print "        call subroutines written in BASIC, C, Assembler, or BozoL.  Since"
  131. print "        most of the nitty gritty is compiled in (like what do do when the"
  132. print "        command BLOCK PHONES is issued) it will almost always seem to"
  133. print "        run just as fast as a compiled program."
  134. print ""
  135. gosub pause
  136. goto start
  137.  
  138.  
  139. two:
  140. cls with color 1,7
  141. print "        2. BOZOL COMMANDS AND FUNCTIONS - STARTER SET"
  142. print ""
  143. print "        As I mentioned in part 1, all of the fundamental building blocks"
  144. print "        of the language, its structure, variable handling and flow control"
  145. print "        have already been built in.  All you need to do is add new key"
  146. print "        words and the code that is executed when BozoL sees the key word."
  147. print ""
  148. print "        These are the key words that are built in to BozoL already:"
  149. print ""
  150. print ""
  151. print "         ASC       ASCII     BE        CALC      CASE      CHR       CLS"
  152. print "         COLOR     CR        EQUAL     EQUALS    EVAL      FALSE     GOSUB"
  153. print "         GOTO      IF        IN        INKEY     INPUT     IS        LCASE"
  154. print "         LEFT      LEN       LET       LIST      LOAD      LOCATE    LOWER"
  155. print "         LTRIM     MID       NOT       PRINT     PROMPT    QUIT      RETURN"
  156. print "         RIGHT     RTRIM     RUN       SAME      SAVE      SET       SUBSTR"
  157. print "         TAB       TO        TRUE      UCASE     UNTIL     UPPER     WHAT"
  158. print "         WHILE     WITH"
  159. print ""
  160. gosub pause
  161. print "        (... and added since this writing...)"
  162. print ""
  163. print "        END, CWAIT"
  164. print ""
  165. print "        See the file BOZOL.REF for a complete description of each command"
  166. print "        and examples of how to use them in your programs."
  167. print ""
  168. gosub pause
  169. goto start
  170.  
  171. three:
  172. cls with color 1,7
  173. print "        3. BOZOL PROGRAMMING RULES"
  174. print ""
  175. print "        BozoL is funny for a couple of reasons.  First, the syntax is"
  176. print "        probably unlike any language you have ever seen.  As I mentioned"
  177. print "        earlier, this is to make it easier for the interpreter to"
  178. print "        parse and execute its statements.  Easier means faster."
  179. print ""
  180. print "        BozoL also has keywords which don't do anything.  The reason for"
  181. print "        these keywords is to make the awkward syntax a bit easier to"
  182. print "        stomach.  Remember these keywords when adding your own commands"
  183. print "        to BozoL.  They can come in handy."
  184. print ""
  185. print "        Keywords that don't do anything:"
  186. print ""
  187. print "                TO, IN, WITH, IS, BE, EQUAL, OF, THE, AT"
  188. print ""
  189. gosub pause
  190. print "        You will see me using these in program examples every once in a while."
  191. print "        For instance, to assign a value to a variable you could say"
  192. print ""
  193. print "                SET A TO 1"
  194. print ""
  195. print "        Although the word " CHR 34 "TO" CHR 34 " is not really necessary.  You could also"
  196. print "        say"
  197. print ""
  198. print "                SET A 1"
  199. print ""
  200. print "        but that looks silly and its meaning would not be clear to someone"
  201. print "        who does not know all about BozoL (like anyone does but me!)."
  202. print ""
  203. gosub pause
  204. print "        Which brings up another rule:  BozoL statements are parsed with"
  205. print "        spaces, commas, or semicolons.  It does not matter which you use"
  206. print "        and it does not matter how you mix them.  For instance, these"
  207. print "        expressions are all the same:"
  208. print ""
  209. print "                SET A TO 1"
  210. print "                SET A,1"
  211. print "                SET;A;1"
  212. print "                SET   A   TO   1"
  213. print ""
  214. print "        Also, multiple statements can be on the same line.  In fact, it"
  215. print "        is necessary to put multiple statements on the same line in some"
  216. print "        cases.  Multiple statements are separated by colons, just like"
  217. print "        BASIC."
  218. print ""
  219. print "                SET A TO 1: PRINT A: PRINT " CHR 34 "GoodBye!" CHR 34 ":END"
  220. print ""
  221. gosub pause
  222. print "        Now here's another bit of silliness:  BozoL will also allow"
  223. print "        you to place multiple statements on a line without using colons"
  224. print "        to separate them, BUT if you do not use colons the statements will"
  225. print "        be executed in REVERSE ORDER."
  226. print ""
  227. print "        For example, if you said"
  228. print ""
  229. print "                PRINT 1: PRINT 2: PRINT 3"
  230. print ""
  231. print "        BozoL would display this on the screen:"
  232. print ""
  233. print "                1"
  234. print "                2"
  235. print "                3"
  236. print ""
  237. gosub pause
  238. print "        But if you said"
  239. print ""
  240. print "                PRINT 1 PRINT 2 PRINT 3"
  241. print ""
  242. print "        then BozoL would print this:"
  243. print ""
  244. print "                3"
  245. print "                2"
  246. print "                1"
  247. print ""
  248. print "        This is the magic of 'stack parsing', which is how BozoL processes"
  249. print "        statements and functions.  For more info on stack parsing, read"
  250. print "        the comments in the source code."
  251. print ""
  252. gosub pause
  253. print "        This is not mean't to be funny or wierd.  It is very useful.  For"
  254. print "        example, you could say"
  255. print ""
  256. print "        WHILE NOT LEN INKEY: NEXT RECORD: PRINT NAME,ADDRESS,PHONE"
  257. print ""
  258. print "        or you could also say it like this:"
  259. print ""
  260. print "        PRINT NAME,ADDRESS,PHONE OF THE NEXT RECORD WHILE NOT LEN INKEY"
  261. print ""
  262. print "        Do you see the difference between the two lines?  There is none."
  263. print "        In the first line we broke up the sentence with colons to indicate"
  264. print "        a specific order of the actions.  In the second line we said"
  265. print "        everything we wanted to do and with the help of a couple of"
  266. print "        placeholder keywords (OF and THE) which do nothing, and without"
  267. print "        the colons it almost seems like english!"
  268. print ""
  269. gosub pause
  270. print "        So to review, we have 'placeholder' commands which do nothing but"
  271. print "        make the syntax more readable, and we have a language syntax which"
  272. print "        goes forwards or backwards depending on whether or not you use"
  273. print "        colons to separate multiple statements.  If you follow me this"
  274. print "        far then we'll go on.  If not, go back a few pages."
  275. print ""
  276. print "        Bozol, as it is right now, leaves out some basic language functions"
  277. print "        which may be considered important.  Particularly file I/O.  There"
  278. print "        are no facilities to open, read, write, or append any sort of"
  279. print "        file except for LOAD and SAVE.  Most of the major string handling"
  280. print "        and arithmetic is included, as well as basic user interface"
  281. print "        primatives: INPUT, PRINT, PROMPT, and INKEY."
  282. print ""
  283. gosub pause
  284. print "        BozoL variable names can be any letter or word which does not"
  285. print "        have a numeric value and is not already defined as a keyword."
  286. print "        A BozoL variable can be of any data type.  BozoL does not"
  287. print "        distinguish between strings and numeric data.  If a BozoL variable"
  288. print "        contains alphabetic characters it is treated as 0 in arithmetic"
  289. print "        functions or functions which require a numeric parameter."
  290. print "        Variables which contain numeric data (like the number 100) can"
  291. print "        be treated as strings in string functions like LEFT, RIGHT and"
  292. print "        MID, etc."
  293. print ""
  294. print "        BozoL programs are limited to 256 defined variables and all"
  295. print "        variables are retained when a new program is RUN.  A BozoL"
  296. print "        program can be no more than 1000 lines in length.  There is"
  297. print "        no effective limit to how many statements can occur on a single"
  298. print "        line."
  299. print ""
  300. gosub pause
  301. print "        A line of code in BozoL can contain multiple statements which"
  302. print "        are separated by colons, but it may also contain statements"
  303. print "        separated by carriage return-line feed pairs.  Each line in"
  304. print "        the program can contain up to 32K of statements.  The entire"
  305. print "        BozoL program cannot exceed 64K in size, unless, of course,"
  306. print "        you modify the source code and DIM HUGE the array which contains"
  307. print "        the program."
  308. print ""
  309. print "        Error checking is done by the PowerBASIC compiler except where"
  310. print "        necessary.  If an error occurs, BozoL will display an error"
  311. print "        message and ask if you wish to continue the program or exit to"
  312. print "        DOS.  In the BozoL program, only the subroutine PROGRUN terminates."
  313. print "        If you called PROGRUN from another program your program will"
  314. print "        simply resume."
  315. print ""
  316. gosub pause
  317. print "        Entering Statements"
  318. print ""
  319. print "        By default, BozoL begins in command line mode, like GWBASIC.  You"
  320. print "        can enter direct statements, LOAD, or RUN a program.  When the"
  321. print "        program ends BozoL will return you to the command line unless the"
  322. print "        program is terminated with END or QUIT."
  323. print ""
  324. print "        If you preceed a direct statement with a line number from 1 to"
  325. print "        1000, the statement will not be executed.  Instead it will be"
  326. print "        entered into memory.  You can then type LIST to see all of the"
  327. print "        lines currently in memory.  Any blank lines will not be displayed."
  328. print ""
  329. print "        To try it out, run BozoL and type these three lines:"
  330. print ""
  331. print "                1 PRINT " CHR 34 "This is the beginning!" CHR 34
  332. print "                2 BE UNTIL LEN INKEY"
  333. print "                3 PRINT " CHR 34 "This is the end!" CHR 34
  334. print ""
  335. gosub pause
  336. print "        Then type LIST.  BozoL will re-display the lines that you entered."
  337. print "        Then type the command RUN.  BozoL will print 'This is the beginning!'"
  338. print "        and will wait for you to press any key.  After you press any key"
  339. print "        BozoL will print 'This is the end!' and the program will terminate,"
  340. print "        leaving you at the BozoL command prompt."
  341. print ""
  342. print "        Notice line 2, where we could have just said UNTIL LEN INKEY we"
  343. print "        added the dummy word BE in front of it just because it makes the"
  344. print "        purpose of the line a little more descriptive."
  345. print ""
  346. gosub pause
  347. print "        Now if you typed SAVE " CHR 34 "PROG1" CHR 34 ", BozoL would write these three"
  348. print "        lines to a file called " CHR 34 "PROG1" CHR 34 " in the current directory.  At any"
  349. print "        time in the future you can type LOAD " CHR 34 "PROG1" CHR 34 " to reload the"
  350. print "        program into memory, and then LIST or RUN, or you can just type"
  351. print "        RUN " CHR 34 "PROG1" CHR 34 " to load and run the program.  You may have already"
  352. print "        decided that it will be much less of a chore to write your"
  353. print "        programs in an external text editor.  I thought about adding a"
  354. print "        fullscreen editor to BozoL, but the best editor I have (PBWRITE)"
  355. print "        is almost four times larger than all of BozoL by itself.  If"
  356. print "        you want to add a text editor, do it yourself."
  357. print ""
  358. gosub pause
  359. print "        You must remember that when you create a program using an editor"
  360. print "        you may not use line numbers.  Line numbers can only be used to"
  361. print "        enter a program at the BozoL command line.  Line numbers are"
  362. print "        not retained by BozoL when a program is saved to disk."
  363. print ""
  364. print "        Assigning variables"
  365. print ""
  366. print "        To assign a value to a variable you can use the SET or LET"
  367. print "        statements.  They both work the same way.  You can use either"
  368. print "        depending on your favorite syntax."
  369. print ""
  370. print "                LET A BE EQUAL TO 1"
  371. print "                SET NAME TO " CHR 34 "ERIK" CHR 34
  372. print ""
  373. print "        Notice the use of the " CHR 34 "dummy" CHR 34 " keywords BE EQUAL TO and TO in these"
  374. print "        statements.  They are not necessary but can be used to provide"
  375. print "        additional readablility in your source code."
  376. print ""
  377. gosub pause
  378. print "        Using functions"
  379. print ""
  380. print "        Functions (like CHR, LEN, or UCASE) may require variables as"
  381. print "        arguments. Since BozoL does not distinguish between numeric and"
  382. print "        character data types you can use any kind of variable as an"
  383. print "        argument to a function.  Unlike BASIC or any other language,"
  384. print "        arguments to a function are not included in parenthesis."
  385. print ""
  386. print "        For example, to print ASCII code 1 in BASIC you would say"
  387. print ""
  388. print "                PRINT CHR$(1)"
  389. print ""
  390. print "        However in BozoL you would say"
  391. print ""
  392. print "                PRINT CHR 1"
  393. print ""
  394. gosub pause
  395. print "        A statement like this in BASIC:"
  396. print ""
  397. print "                PRINT LTRIM$(RTRIM$(UCASE$(A$)))"
  398. print ""
  399. print "        Would look like this in BozoL:"
  400. print ""
  401. print "                PRINT LTRIM RTRIM UCASE A"
  402. print ""
  403. print "        Evaluating expressions"
  404. print ""
  405. print "        Unlike languages which employ recursive descent parsing, BozoL"
  406. print "        does not naturally incorporate arithmetic into its syntax.  To"
  407. print "        trigger an arithmetic evaluation you must use the CALC keyword."
  408. print "        CALC has some synonyms which do the exact same thing but may"
  409. print "        be preferred for better language readability.  The keywords"
  410. print "        CALC, EVAL, WHAT, and CASE all do the same thing."
  411. print ""
  412. gosub pause
  413. print "        If you want to use arithmetic (+-/*^<> or =) to evaluate an"
  414. print "        expression you must tell BozoL to do so.  For example, if you"
  415. print "        wanted to print 1+1, you must say"
  416. print ""
  417. print "                PRINT CALC 1+1"
  418. print ""
  419. print "        you could also say"
  420. print ""
  421. print "                PRINT EVAL 1+1  or PRINT WHAT 1+1 or PRINT CASE 1+1"
  422. print ""
  423. print "        in which case BozoL would print the number 2 on the screen.  If"
  424. print "        you were to say"
  425. print ""
  426. print "                PRINT 1+1"
  427. print ""
  428. print "        then BozoL would print '1+1' on the screen.  The reason for doing"
  429. print "        it this way greatly increases the speed of the interpreter.  It"
  430. print "        also greatly reduces its complexity."
  431. print ""
  432. gosub pause
  433. print "        Again, having four synonyms for CALC may seem unnecessary but they"
  434. print "        come in handy when writing different kinds of statements.  For"
  435. print "        example you could use the dummy word IS to make a statment that"
  436. print "        goes like this"
  437. print ""
  438. print "                PRINT WHAT 1+1 IS"
  439. print ""
  440. print "        or you could make your source code more readable by using CASE"
  441. print "        in conjunction with the IF statement, like"
  442. print ""
  443. print "                IF CASE A=B: PRINT " CHR 34 "They Match" CHR 34
  444. print ""
  445. gosub pause
  446. print "        Program Logic"
  447. print ""
  448. print "        BozoL features the statements IF, WHILE, and UNTIL to embody its"
  449. print "        logic.  You can add others if you like.  It's easy."
  450. print ""
  451. print "        When a WHILE or UNTIL statement is executed, the expression which"
  452. print "        follows it is immediately evaluated.  If the expression is true,"
  453. print "        UNTIL will cause BozoL to immediately abort the current line and"
  454. print "        go on to the next one, or end the program if there are no more"
  455. print "        statements.  WHILE is the exact opposite of UNTIL.  For example,"
  456. print ""
  457. print "                PRINT " CHR 34 "Hi There!" CHR 34 " UNTIL LEN INKEY"
  458. print ""
  459. print "        This statement will print 'Hi There!' over and over again on the"
  460. print "        screen until the function INKEY returns something with a length."
  461. print "        That is, until a key is pressed."
  462. print ""
  463. gosub pause
  464. print "                PRINT " CHR 34 "Hi There!" CHR 34 " WHILE NOT LEN INKEY"
  465. print ""
  466. print "        will do the same thing.  As long as the expression remains true,"
  467. print "        WHILE and UNTIL will continue to execute the entire line over"
  468. print "        and over again."
  469. print ""
  470. print "        IF is similar.  When BozoL gets to the IF, the expression following"
  471. print "        IF will be evaluated.  If the expression returns a non-zero value,"
  472. print "        the remainder of the line will be executed.  If you are using"
  473. print "        colons to delimit the individual statements on the line, this"
  474. print "        means the remainder of the line following the IF statement.  If"
  475. print "        you are not using colons to delimit the statements on the line"
  476. print "        this refers to the statements which preceed the IF statements."
  477. print ""
  478. gosub pause
  479. print "        In other words, the statement"
  480. print ""
  481. print "                IF EVAL A=B: PRINT " CHR 34 "They Match" CHR 34
  482. print ""
  483. print "        Will print " CHR 34 "They Match" CHR 34 "on the screen if A is equal to B.  Also,"
  484. print "        the line"
  485. print ""
  486. print "                PRINT " CHR 34 "They Match" CHR 34 " IF EVAL A=B"
  487. print ""
  488. print "        will do the same thing."
  489. print ""
  490. gosub pause
  491. print "        Program flow control"
  492. print ""
  493. print "        All of the program flow control in native BozoL is contained within"
  494. print "        the simple GOTO and GOSUB...RETURN command sets.  At any point in"
  495. print "        your program you may include a label which is on a line by itself"
  496. print "        and is not a BozoL keyword.  Labels can be any word or words as long"
  497. print "        as they are unique.  To jump to a label, just say GOTO ABC, where"
  498. print "        ABC would be the label name."
  499. print ""
  500. print "        GOSUB works the same way, except BozoL remembers the line number"
  501. print "        where you GOSUBed from.  At any later point you may execute a"
  502. print "        RETURN statement and BozoL will resume program execution at the"
  503. print "        next line following the GOSUB, unlike BASIC which will resume"
  504. print "        execution at the next statement, which may be on the same line."
  505. print ""
  506. gosub pause
  507. print "        You can GOSUB up to 32 times until you must return.  If you try"
  508. print "        to GOSUB more than 32 times without ever returning BozoL will"
  509. print "        give you an overflow error.  You can increase the size of the"
  510. print "        GOSUB stack by modifying the source code, although it will"
  511. print "        probably never be necessary."
  512. print ""
  513. print "        You can also GOTO or GOSUB to a line number, but this is not"
  514. print "        advisable.  If you write BozoL programs in a text editor you"
  515. print "        must not include line numbers.  If you have a GOTO 10 in your"
  516. print "        program and then insert a line before line 10, GOTO 10 will"
  517. print "        then go to the wrong line."
  518. print ""
  519. print "        Finally, you may GOTO or GOSUB to a line number which is"
  520. print "        contained in a variable.  For example, you could say"
  521. print ""
  522. print "                SET A TO 100"
  523. print "                GOTO A"
  524. print ""
  525. print ""
  526. gosub pause
  527. goto start
  528.  
  529. four:
  530. cls with color 1,7
  531. print "        4. HOW TO ADD COMMANDS AND FUNCTIONS"
  532. print ""
  533. print ""
  534. print "        BozoL is kind of useless unless you intend to add your own"
  535. print "        custom commands and functions.  That is, after all, the whole"
  536. print "        point to having an interpreted language written in PowerBASIC."
  537. print ""
  538. print "        Adding commands and functions is easy.  You must be aware of"
  539. print "        the difference between a command and a function.  A command"
  540. print "        is a keyword which actually does something, like PRINT or"
  541. print "        INPUT or LAUNCH THE MISSILES.  A function is a keyword which"
  542. print "        may have parameters, operate on those parameters, and then"
  543. print "        leave behind a return value to be acted on by another function"
  544. print "        or a command."
  545. print ""
  546. gosub pause
  547. print "        For example, CHR is a function.  CHR does not execute anything,"
  548. print "        rather, it looks at the parameter which follows it and pushes"
  549. print "        a new parameter onto the stack."
  550. print ""
  551. print "                CHR 1"
  552. print ""
  553. print "        This will do nothing."
  554. print ""
  555. print "                PRINT CHR 1"
  556. print ""
  557. print "        BozoL will look at the 1 and push it onto a special stack.  Then"
  558. print "        it will look at CHR.  CHR will read the 1 off of the stack and"
  559. print "        push a happy face back onto the stack.  PRINT will then see the"
  560. print "        happy face on the stack and print it."
  561. print ""
  562. print "        Read that paragraph again and again if you didn't understand it."
  563. print "        It can take a while to sink in if you're not familiar with the"
  564. print "        concepts."
  565. print ""
  566. gosub pause
  567. print "        To add a custom keyword you first need to think up a name for"
  568. print "        the keyword, and then what it does.  Gee, that's kind of like"
  569. print "        creating a new SUB or FUNCTION in PowerBASIC, isn't it?  It"
  570. print "        is very similar."
  571. print ""
  572. print "        Lets start with an example.  BozoL does not have a NEW command,"
  573. print "        which would erase the current program in memory and stop"
  574. print "        execution.  Adding NEW to BozoL is easy."
  575. print ""
  576. print "        All of the commands in BozoL are broken up into a handful of"
  577. print "        include files which have a .CMD extension.  These include"
  578. print "        LOGIC.CMD, which contains IF, WHILE, and UNTIL, FUNCTION.CMD"
  579. print "        which contains many rudamentary functions like ASC, CHR,"
  580. print "        UCASE, LEFT, RIGHT, and MID, and others."
  581. print ""
  582. print "        LOAD, RUN, and other related commands are in the include file"
  583. print "        LOADRUN.CMD.  If you look at this file you can see where the"
  584. print "        guts of these commands are defined.  Each commands starts out"
  585. print "        with a CASE statement (remember, we are in PowerBASIC now)."
  586. print ""
  587. gosub pause
  588. print "        These files are included in the middle of a big SELECT CASE"
  589. print "        loop which is in the subroutine EXEC in the file BOZOL.BAS."
  590. print "        If you look at this file and sub you can see where all of the"
  591. print "        *.CMD files are included."
  592. print ""
  593. print "        NEW would belong with the other commands in LOADRUN.CMD, although,"
  594. print "        of course, you could put them anywhere.  Pull LOADRUN.CMD up into"
  595. print "        the PowerBASIC editor and page down to the end of the file."
  596. print ""
  597. print "        Add a new item to this CASE structure.  Add a few spaces to the"
  598. print "        end of the file and type in the line"
  599. print ""
  600. print "                CASE " CHR 34 "NEW" CHR 34
  601. print ""
  602. gosub pause
  603. print "        This officially defines a new command in the BozoL language.  Now"
  604. print "        all you need to do is enter some code to carry out what you want"
  605. print "        the NEW command to do.  We want to erase the program and stop"
  606. print "        execution of the program.  The program is stored in a shared array"
  607. print "        called PROGRAM$(), so the next line would be this:"
  608. print ""
  609. print "                REDIM PROGRAM$(1000)"
  610. print ""
  611. print "        This would effectively erase the contents of the program array."
  612. print "        Next you need to make sure the program stops.  BozoL thinks"
  613. print "        that the program is running as long as the shared variable"
  614. print "        PROG% is true.  Add the statement"
  615. print ""
  616. print "                PROG%=0"
  617. print ""
  618. print "        Now all you need to do is recompile BOZOL.BAS.  Try it out!"
  619. print "        Enter a small program and type LIST.  Then type NEW.  Then"
  620. print "        type LIST.  Voila!  It's gone!  You just added a new command"
  621. print "        to BozoL!"
  622. print ""
  623. gosub pause
  624. print "        Commands that use arguments"
  625. print ""
  626. print "        By the time BozoL gets to a command, all possible arguments are"
  627. print "        on a special stack called the Argument Stack.  This is actually"
  628. print "        a string array that can store up to 16 arguments at a time.  Since"
  629. print "        mose functions and commands only require one or two arguments this"
  630. print "        is quite adequate."
  631. print ""
  632. print "        You can ask for these arguments one at a time by using the"
  633. print "        PowerBASIC function POPARG$.  For example, the print command"
  634. print "        keeps printing whatever is returned by POPARG$ until it runs"
  635. print "        out of arguments.  The shared variable ArgPtr% contains the"
  636. print "        number of arguments currently on the stack.  You may find this"
  637. print "        variable useful if you want to create commands and functions that"
  638. print "        accept a variable number of arguments."
  639. print ""
  640. gosub pause
  641. print "        Lets try adding a new command.  Fund the place in BOZOL.BAS"
  642. print "        where all of the *.CMD files are included.  Add a new include"
  643. print "        file called CUSTOM.CMD"
  644. print ""
  645. print "        Next, create CUSTOM.CMD."
  646. print ""
  647. print "        The first line of CUSTOM.CMD should be CASE something, where"
  648. print "        something is the new command you want to add.  Lets add a"
  649. print "        special purpose function which returns the entire contents of"
  650. print "        a file.  this function does not really do anything by itself,"
  651. print "        but it will be a keyword you can use in other expressions."
  652. print ""
  653. print "                CASE " CHR 34 "GETFILE" CHR 34
  654. print "                        Buf% = FREEFILE"
  655. print "                        OPEN POPARG$ FOR BINARY AS #Buf%"
  656. print "                        GET #Buf%, LOF(Buf%), A$"
  657. print "                        PUSHARG A$"
  658. print "                        CLOSE #Buf%"
  659. print ""
  660. gosub pause
  661. print "        After you have added these lines, recompile BozoL and run it."
  662. print "        Try out this new command by typing in this direct statement"
  663. print ""
  664. print "                PRINT GETFILE " CHR 34 "\AUTOEXEC.BAT" CHR 34
  665. print ""
  666. print "        Your whole AUTOEXEC.BAT file should print out on the screen!"
  667. print ""
  668. print "        Notice that we used POPARG and PUSHARG to manipulate the BozoL"
  669. print "        argument stack.  We didn't want to print " CHR 34 "GETFILE" CHR 34 ", we wanted"
  670. print "        GETFILE to literally return the entire contents of a file,"
  671. print "        so use used POPARG$ to find out what file name followed the"
  672. print "        GETFILE keyword, opened the file, read the whole file into a"
  673. print "        single variable, and then pushed the whole file onto the argument"
  674. print "        stack.  Then PRINT looked at the argument stack to see what was"
  675. print "        there and finds the entire contents of your AUTOEXEC.BAT.  PRINT"
  676. print "        then prints it on the screen."
  677. print ""
  678. print ""
  679. gosub pause
  680. goto start
  681.  
  682.  
  683. five:
  684. cls with color 1,7
  685. print "        5. CALLING BOZOL FROM YOUR OWN PROGRAMS"
  686. print ""
  687. print "        In addition to being able to custom the language, you will also"
  688. print "        want to call the BozoL interpreter from your own programs.  BozoL"
  689. print "        requires the DIM and SHARED statements which exist at the top of"
  690. print "        BOZOL.BAS to be already defined in your own program.  Once you"
  691. print "        have done this all you need to do is call the subroutine PROGRUN."
  692. print "        PROGRUN requires an array as a parameter, preferably PROGRAM$(),"
  693. print "        although you can pass it any other string array if you like.  You"
  694. print "        must also specify whether or not you want BozoL to actually start"
  695. print "        running the program in PROGRAM$ or to display a command prompt"
  696. print "        and wait for someone to type RUN.  This is done by placing a"
  697. print "        true or false value into the shared variable PROG%. If PROG% is"
  698. print "        true then the program will run.  If it is false then PROGRUN"
  699. print "        will just display an OK prompt and wait for a command to be"
  700. print "        entered at the keyboard.  If you simply want to invoke the"
  701. print "        interpeter, just call PROGRUN with prog% set to 0."
  702. print ""
  703. gosub pause
  704. print "        If the program contained in PROGRAM$ ends without and explicit"
  705. print "        END or QUIT statement, the user will be returned to a command"
  706. print "        prompt.  END or QUIT exits the PROGRUN sub completely, returning"
  707. print "        control to your program, or to DOS, depending on how you may"
  708. print "        have it set up"
  709. gosub pause
  710. goto start
  711.  
  712.  
  713. pause:
  714. prompt "        ■ press ESC to quit or any other key to continue" in color 15,7 at locate 24,1
  715. set temp to cwait
  716. end if what ascii of temp is = 27
  717. cls with color 1,7
  718. locate 2,5:print "BozoL text file" in color 10,7
  719. print            "===============" at locate 3,5
  720. locate 5,1 in color 1,7:return
  721.