Table of Contents
Table of Contents
This document describes yabasic. You will find information about the yabasic interpreter (the program yabasic under Unix or yabasic.exe under Windows) as well as the language itself.
This document applies to version 2.750 of yabasic
However, this document does not contain the latest news about yabasic or a FAQ. As such information tends to change rapidly, it is presented online only at www.yabasic.de.
Although basic has its reputation as a language for beginning programmers, this is not an introduction to programming at large. Rather this text assumes, that the reader has some (moderate) experience with writing and starting computer programs.
yabasic is a traditional basic interpreter. It understands most of the typical basic-constructs, like goto, gosub, line numbers, read, data or string-variables with a trailing '$'. But on the other hand, yabasic implements some more advanced programming-constructs like subroutines or libraries (but not objects). yabasic works much the same under Unix and Windows.
yabasic puts emphasis on giving results quickly and easily; therefore simple commands are provided to open a graphic window, print the graphics or control the console screen and get keyboard or mouse information. The example below opens a window, draws a circle and prints the graphic:
open window 100,100 open printer circle 50,50,40 text 10,50,"Press any key to get a printout" clear screen inkey$ close printer close window
This example has fewer lines, than it would have in many other programming languages. In the end however yabasic lacks behind more advanced and modern programming languages like C++ or Java. But as far as it goes it tends to give you results more quickly and easily.
Table of Contents
Once, yabasic has been set up correctly, there are three ways to start it:
Rightclick on your desktop: The desktop menu appears with a submenu named new. From this submenu choose yabasic. This will create a new icon on your desktop. If you rightclick on this icon, its context menu will appear; choose Execute to execute the program.
As a variant of the way described above, you may simply create a file with the ending .yab (e.g. with your favorite editor). Everything else then works as described above.
From the start-menu: Choose yabasic from your start-menu. A console-window will open and you will be asked to type in your program. Once you are finished, you need to type return twice, and yabasic will parse and execute your program.
This is not the preferred way of starting yabasic ! Simply because the program, that you have typed, can not be saved and will be lost inevitably ! There is no such thing as a save-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs.
Under Windows yabasic will mostly be invoked by double-clicking on an appropriate icon; this way you do not have a chance to specify any of the commandline options below. However, advanced users may add some of those options to the appropriate entries in the registry.
All the options below may be abbreviated, as long as the abbreviation does not become ambigous. For example, you may write -e instead of -execute.
Prints a short help message, which itself describes two further help-options.
Prints the version of yabasic.
Sets the position of the graphic window, that is opened by open window (the size of this window, of course, is specified within the open window-command). An example would be -geometry +20+10, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. This value cannot be changed, once yabasic has been started.
Name of the font, which will be used for graphic-text; can be any of decorative, dontcare, modern, roman, script, swiss. You may append a fontsize (measured in pixels) to any of those fontnames; for example -font swiss30 chooses a swiss-type font with a size of 30 pixels.
Create a standalone program (whose name is specified by NAME-OF-STANDALONE-PROGRAM) from the yabasic-program, that is specified on the commandline. See the section about creating a standalone-program for details.
With this option you may specify some yabasic-code to be executed rigth away.This is useful for very short programs, which you do not want to save within a file. If this option is given, yabasic will not read any code from a file. Let's say, you have forgotten some of the square numbers between 1 and 10; in this case the command yabasic -e 'for a=1 to 10:print a*a:next a' will give you the answer immediately.
Change the infolevel of yabasic, where INFOLEVEL can be one of debug, note, warning, error and fatal (the default is warning). This option changes the amount of debugging-information yabasic produces. However, normally only the author of yabasic (me !) would want to change this.
Print the embedded documentation of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword doc. This documentation can also be seen by choosing the corresponding entry from the context-menu of any yabasic-program.
Change the directory, wherein libraries will be searched and imported (with the import-command). See also this entry for more information about the way, libraries are searched.
Like every other icon under Windows, the icon of every yabasic-program has a context menu offering the most frequent operations, that may be applied to a yabasic-program.
This will invoke yabasic to execute your program. The same happens, if you doubleclick on the icon.
notepad will be invoked, allowing you to edit your program.
This will present the embedded documentation of your program. Embedded documentation is created with the special comment doc.
Table of Contents
If your system administrator (vulgo root) has installed yabasic correctly, there are three ways to start it:
You may use your favorite editor (emacs, vi ?) to put your program into a file (e.g. foo). Make sure that the very first line starts with the characters '#!' followed by the full pathname of yabasic (e.g. '#!/usr/local/bin/yabasic'). This she-bang-line ensures, that your Unix will invoke yabasic to execute your program (see also the entry for the hash-character). Moreover, you will need to change the permissions of your yabasic-program foo, e.g. chmod u+x foo. After that you may invoke yabasic to invoke your program by simply typing foo (without even mentioning yabasic). However, if your PATH-variable does not contain a single dot ('.') you will have to type the full pathname of your program: e.g. /home/ihm/foo (or at least ./foo).
Save your program into a file (e.g. foo) and type yabasic foo. This assumes, that the directory, where yabasic resides, is contained within your PATH-variable.
Finally your may simply type yabasic (maybe it will be necessary to include its full pathname). This will make yabasic come up and you will be asked to type in your program. Once you are finished, you need to type return twice, and yabasic will parse and execute your program.
This is not the preferred way of starting yabasic ! Simply because the program, that you have typed, can not be saved and will be lost inevitably ! There is no such thing as a save-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs, i.e. for using yabasic as some sort of fancy desktop calculator.
yabasic accepts a number of options on the commandline. All these options below may be abbreviated, as long as the abbreviation does not become ambigous. For example you may write -e instead of -execute.
Prints a short help message, which itself describes two further help-options.
Prints the version of yabasic.
Define the foreground color for the graphics-window (that will be opened with open window). The usual X11 colornames, like red, green, … are accepted. This value cannot be changed, once yabasic has been started.
Define the background color for the graphics-window. The usual X11 colornames are accepted. This value cannot be changed, once yabasic has been started.
Sets the position of the graphic window, that is opened by open window (the size of this window, of course, is specified with the open window-command). An example would be +20+10, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. Note, that the size of the window may not be specified here (well it may, but it will be ignored anyway). This value cannot be changed, once yabasic has been started.
Specify the display, where the graphics window of yabasic should appear. Normally, however this value will be already present within the environment variable DISPLAY.
Name of the font, which will be used for text within the graphics window.
With this option you may specify some yabasic-code to be executed rigth away.This is useful for very short programs, which you do not want to save to a file. If this option is given, yabasic will not read any code from a file. E.g.
yabasic -e 'for a=1 to 10:print a*a:next a'prints the square numbers from 1 to 10.
Create a standalone program (whose name is specified by NAME-OF-STANDALONE-PROGRAM) from the yabasic-program, that is specified on the commandline. See the section about creating a standalone-program for details.
Change the infolevel of yabasic where INFOLEVEL can be one of debug, note, warning, error and fatal (the default is warning). This option changes the amount of debugging-information yabasic produces. However, normally only the author of yabasic (me !) would want to change this.
Print the embedded documentation of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword doc.
Change the directory from which libraries will be imported (with the import-command). See also this entry for more information about the way, libraries will be searched.
If you want to set some options once for all, you may put them into your X-Windows resource file. This is usually the file .Xresources or some such within your home directory (type man X for details).
Here is a sample section, which may appear within this file:
yabasic*foreground: blue yabasic*background: gold yabasic*geometry: +10+10 yabasic*font: 9x15
This will set the foreground color of the graphic-window to blue and the background color to gold. The window will appear at position 10,10 and the text font will be 9x15.
Table of Contents
This chapter has sections for some of the major features of yabasic and names a few commands related with each area. So, depending on your interest, you find the most important commands of this area named; the other commands from this area may then be discovered through the links in the see also-section.
The print-command is used to put text on the text screen. Here, the term text screen stands for your terminal (under Unix) or the console window (under Windows).
At the bottom line, print simply outputs its argument to the text window. However, once you have called clear screen you may use advanced features like printing colors or copying areas of text with getscreen$ or putscreen.
You may ask the user for input with the input-command; use inkey$ to get each key as soon as it is pressed.
Of course, yabasic has the goto- and gosub-statements; you may go to a label or a line number (which is just a special kind of label). goto, despite its bad reputation ([goto considered harmful]), has still its good uses; however in many cases you are probably better off with loops like repeat-until, while-wend or do-loop; you may leave any of these loops with the break-statement or start the next iteration immediately with continue.
Decisions can be made with the if-statement, which comes either in a short and a long form. The short form has no then-keyword and extends up to the end of the line. The long form extends up to the final endif and may use some of the keywords then (which introduces the long form), else or elsif.
If you want to test the result of an expression against many different values, you should probably use the switch-statement.
You need to call open window before you may draw anything with either line, circle or rectangle; all of these statements may be decorated with clear or fill. Note however, that all graphics in yabasic is monochrome ("black on white"). Moreover, there can only be a single window open at any given moment in time.
Evyerything you have drawn can be send to your printer too, if you use the open printer command.
To allow for some (very) limited version of animated graphics, yabasic offers the commands getbit$ and putbit, which retrieve rectangular regions from the graphics-window into a string or vice versa.
If you want to sense mouse-clicks, you may use the inkey$-function.
Before you may read or write a file, you need to open it; once you are done, you should close it. Each open file is designated by a simple number, which might be stored within a variable and must be supplied if you want to access the file. This is simply done by putting a hash ('#') followd by the number of the file after the keyword input (for reading from) or print (for writing to a file) respectively.
If you need more control, you may consider reading and writing one byte at a time, using the multi-purpose commands peek and poke.
The best way to break any yabasic-program into smaller, more manageable chunks are subroutines and libraries. They are yabasic's most advanced means of structuring a program.
Subroutines are created with the command sub. they accept parameters and may return a value. Subroutines can be called much like any builtin function of yabasic; therefore they allow to extend the language itself.
Once you have created a set of related subroutines and you feel that they could be useful in other programs too, you may collect them into a library. Such a library is contained within a separate file and may be included in any of your programs, using the keyword import.
yabasic has the usual functions to extract parts from a string: left$, mid$ and right$. Note, that all of them can be assigned to, i.e. they may change part of a string.
If you want to split a string into tokens you should use the functions token or split.
There is quite a bunch of other string-processing functions like upper$ (converting to upper case), instr (finding one string within the other), chr$ (converting an ascii-code into a character), glob (testing a string against a pattern) and more. Just follow the links.
Yabasic handles numbers and arithmetic: You may calculate trigonometric functions like sin or atan, or logarithms (with log). Bitwise operations, like and or or are available as well min or max (calculate the minimum or maximum of its argument) or mod or int (reminder of a division or integer part or a number).
You may store data within your program within data-statements; during execution you will probably want to read it into arrays, which must have been dimed before.
Table of Contents