📄 yabasic.1
字号:
.TH yabasic 1.SH NAMEyabasic - yet another Basic.SH SYNOPSISyabasic [options] [filename [arguments]].SH DESCRIPTIONYabasic is a simple, old fashioned basic interpreter withsome additional features like subroutines and libraries.Graphics and printing are limited but very easy to use.Yabasic is documented within the file yabasic.htm, whichmay or may not be present on your system; in any case thisdocument can be found on www.yabasic.de.However, this html-document has been inserted as a preformatted text into this man page. Note, that you will at least need an eighty-column terminal to read this text without ugly wrapped lines.Moreover, this man-page contains some chapters, that are specific for windows and do not directly apply to your system.Finally note, that this man-page (unlike the html-document it is based upon) does not contain hyperlinks. In fact due to its large number of hyperlinks the html-document is much easier to read, understand and navigate than this man-page. However if you are determined to read this man-page, there are three especially useful ways to navigate; each works by searching for specific strings:.IP \(bu 4To go to a specific chapter (e.g. Chapter 5, "All commands and functions of yabasic"), you may look up the number of this chapter in the table of contents and search for the string "\fBChapter 5.\fR"; please note the uppercase "C" and the dot..IP \(bu 4To go to the description of a specific command (e.g. the \fBfor\fR-command), you may search for its name followed by a single space and a double hyphen. In the example this would be "\fBfor --\fR"..IP \(bu 4The description of functions contain the name of the function followed by parens ("\fB()\fR"). Therefore, to find the description of the sine-function, you should search for "\fBsin\\(\\) --\fR". Note, that you will probably need to escape those parens by prepending them with a backslash ("\fB\\\fR")..in 1vBut now for the documentation itself: .nfYabasic _________________________________________________________________ Table of Contents 1. Introduction About this document About yabasic 2. The yabasic-program under Windows Starting yabasic Options The context Menu 3. The yabasic-program under Unix Starting yabasic Options Setting defaults 4. Some features of yabasic, explained by topic print, input and others Control statements: loops, if and switch Drawing and painting Reading from and writing to files Subroutines and Libraries String processing Arithmetic Data and such Other interesting commands. 5. All commands and functions of yabasic listed by topic Number processing and conversion Conditions and control structures Data keeping and processing String processing File operations and printing Subroutines and libraries Other commands Graphics and printing 6. All commands and functions of yabasic grouped alphabetically A B C D E F G H I L M N O P R S T U V W X Special characters Reserved Words 7. A grab-bag of some general concepts and terms Logical shortcuts Conditions and expressions References on arrays Specifying Filenames under Windows Escape-sequences Creating a standalone program from your yabasic-program 8. A few example programs A very simple program The demo of yabasic 9. The Copyright of yabasicChapter 1. Introduction About this document About yabasicAbout this document 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 (which is, of course, a sort of basic) itself. This document applies to version 2.760 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.About yabasic 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,100open printercircle 50,50,40text 10,50,"Press any key to get a printout"clear screeninkey$close printerclose 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.Chapter 2. The yabasic-program under Windows Starting yabasic Options The context MenuStarting yabasic Once, yabasic has been set up correctly, there are three ways to start it: 1. 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. 2. 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. 3. 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.Note 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.Options 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 ambiguous. For example, you may write -e instead of -execute. -help or -? Prints a short help message, which itself describes two further help-options. -version Prints the version of yabasic. -geometry +X-POSITION+Y-POSITION 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. -font NAME-OF-FONT 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. -bind NAME-OF-STANDALONE-PROGRAM 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. -execute A-PROGRAM-AS-A-SINGLE-STRING 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. -infolevel INFOLEVEL 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. -doc NAME-OF-A-PROGRAM 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. -librarypath DIRECTORY-WITH-LIBRARIES 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.The context Menu 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. Execute This will invoke yabasic to execute your program. The same happens, if you doubleclick on the icon. Edit notepad will be invoked, allowing you to edit your program. View docu This will present the embedded documentation of your program. Embedded documentation is created with the special comment doc.Chapter 3. The yabasic-program under Unix Starting yabasic Options Setting defaultsStarting yabasic If your system administrator (vulgo root) has installed yabasic correctly, there are three ways to start it: 1. 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). 2. 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. 3. 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.Note 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.Options 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. -help or -? Prints a short help message, which itself describes two further help-options. -version Prints the version of yabasic. -fg FOREGROUND-COLOR or -foreground FOREGROUND-COLOR 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. -bg BACKGROUND-COLOR or -background BACKGROUND-COLOR Define the background color for the graphics-window. The usual X11 colornames are accepted. This value cannot be changed, once yabasic has been started. -geometry +X-POSITION+Y-POSITION 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. -display BACKGROUND-COLOR Specify the display, where the graphics window of yabasic should appear. Normally, however this value will be already present within the environment variable DISPLAY. -font NAME-OF-FONT Name of the font, which will be used for text within the graphics window. -execute A-PROGRAM-AS-A-SINGLE-STRING 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. -bind NAME-OF-STANDALONE-PROGRAM 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. -infolevel INFOLEVEL 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. -doc NAME-OF-A-PROGRAM 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. -librarypath DIRECTORY-WITH-LIBRARIES 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.Setting defaults 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: blueyabasic*background: goldyabasic*geometry: +10+10yabasic*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.Chapter 4. Some features of yabasic, explained by topic print, input and others Control statements: loops, if and switch Drawing and painting Reading from and writing to files Subroutines and Libraries String processing Arithmetic Data and such Other interesting commands. 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.print, input and others 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.Control statements: loops, if and switch 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.Drawing and painting You need to call open window before you may draw anything with either line, circle, rectangle or triangle; all of these statements may be decorated with clear or fill. If you want to change the colour for drawing, use colour. Note however, that there can only be a single window open at any given moment in time. Everything 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.Reading from and writing to files 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -