return to teapro.com
----------------------------------------------------------------------
The Teapro Computer Programming Language Written in C90
A Collection of Short Articles on Teapro and OpenTea
12-APR-2008
Copyright (c) 2004-2008 by D La Pierre Ballard
Email: dlb@teapro.com
Teaquad Method is copyright (c) 2006-2007 by D La Pierre Ballard
In today's world, we need computer software that actually works.
Let's do it right, and let's do it now.
----------------------------------------------------------------------
Please feel free to quote or copy from this webpage. Also, feel free
to link to this webpage.
----------------------------------------------------------------------
The computer programming language Teapro may be used for free by
anyone, but there is no warranty of any kind whatsoever on Teapro.
----------------------------------------------------------------------
The computer program teapro.exe may be used for free by anyone, but
there is no warranty of any kind whatsoever on teapro.exe.
----------------------------------------------------------------------
The computer source code teapro.c may be used for free by anyone, but
there is no warranty of any kind whatsoever on teapro.c.
----------------------------------------------------------------------
The computer source code tinytea.cpp may be used for free by anyone,
but there is no warranty of any kind whatsoever on tinytea.cpp. The
program tinytea.cpp is the beta version of the next version of
teapro.c and has the .cpp ending because it is usually compiled on a
C++ compiler.
----------------------------------------------------------------------
The Teaquad method for testing numbers from 1E15 to 4E20 for
primeness may be used for free by anyone. There is no warranty of
any kind on the Teaquad method.
----------------------------------------------------------------------
What is teapro.exe?
The teapro.exe computer program is an interpreter for the computer
programming language Teapro. The teapro.exe program is written in C90
which is generally regarded as the most portable programming language
that is compiled. The website teapro.com has teapro.exe as a free
download. The source code for the Teapro interpretor, teapro.c, is
available for free also on the website teapro.com and may be compiled
for Windows or Linux.
On the website teapro.com, down at the bottom are links to download
the following files which have to do with Teapro.
teapro4.html: this is this webpage about the language Teapro.
teapro.c: this is the C90 source code for the Teapro interpreter
teapro.exe: 32-bit console Teapro interpreter program for Windows.
teapro4.cpp and teapro4.exe are the same as above
tinytea.cpp: source code for the beta of next Teapro interpreter
tinytea.exe: beta version of new Teapro interpreter for Windows.
c90tea.cpp: C90 source code for an old reliable Teapro interpretor
c90tea.exe: old reliable 32-bit console Teapro interpreter
oklatea.cpp: Teapro interpreter C90 public domain source code
oklatea.exe: 32-bit console Teapro interpreter from oklatea.cpp
teapro9.pas: Delphi source code for the Windows Teapro interpreter
teapro9.exe: Teapro interpreter for Windows written in Delphi
tinytea.tea: Teapro program to test out all Teapro commands.
teaprime.tea: Teapro program to find prime numbers, 5TP39, PNQ30.
fixran.tea: Teapro program used to maintain this webpage book.
teasho.tea: Teapro program with various utility capabilities.
teaword.tea: Teapro program to do certain things with words.
teatest.tea: Teapro program to test various things.
teatry.tea: Teapro program to test some things.
teamath.tea: Teapro program to do great accuracy math.
teachess.tea: Play over chess games and solve 2-move chess problems.
tea3move.tea: Teapro program that solves three move chess problems.
tea4move.tea: Teapro program that solves four move chess problems.
teabag.tea: Teapro program that plays various types of games.
----------------------------------------------------------------------
The Teapro interpreter teapro.exe was compiled as a console
application using the Borland C++ Builder 1.0 for Windows. It also
compiles using gcc on Linux and runs the same.
----------------------------------------------------------------------
The Teapro interpreter teapro9.exe was compiled as a Windows GUI
program using Borland Delphi Professional 2.0.
----------------------------------------------------------------------
Suppose you need a quick program to do some file processing or maybe
some terminal input/output with calculations all on a Windows or a
Linux computer. Teapro will do the job. A quick Teapro program is easy
to write and debug. There is a lot less to go wrong with a Teapro
program. Teapro is a no frills language which is often easier and more
solid to work with than other interpreted languages. Teapro has been
designed from the start to be simple and solid. The Teapro interpreter
is available at teapro.com. It is available in source code as teapro.c
or as a ready to run executable teapro.exe for Windows.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 001: Introduction to the Teapro Computer Programming Language
Updated 2007/06/24, 2005/11/12, 2005/11/08, 2005/11/07, 2005/09/10,
**********************************************************************
----------------------------------------------------------------------
The program teapro.exe interprets the Teapro computer programming
language. Teapro is a simple programming language which runs on
Windows or Linux. The complete C90 source code for Teapro is available
as a free download from teapro.com as teapro.c which can be compiled
for Linux, also. Teapro does have full file, decimal number and string
processing. Because Teapro is available for free there is no expense
in obtaining it. The single file teapro.exe, which is the Teapro
interpreter program for Windows, is all you need to add to your
Windows computer to allow you to run programs written in the Teapro
language. The Teapro interpreter, teapro.exe, is available for free
download from the website teapro.com.
The Teapro programming language is a simple and solid interpreted
language which runs on Windows or Linux using one single stand alone
interpreter program, teapro.exe, which is less than 200 kilobytes in
size. The Teapro interpreter, teapro.exe, can be installed in a
directory by merely copying it to that directory from a diskette, a
network or the Internet. The Teapro interpreter program can be
uninstalled merely by deleting the one file teapro.exe from your
computer. The Teapro intrepreter program, teapro.exe, is small enough
so that you can even run it off of a diskette. Since the Teapro
interpreter is written in standard C90 it can be compiled and run on
Linux in the same way.
The Teapro programming language has very powerful string, number and
file handling capabilities as well as simple control structures which
allow complex programming to be done easily. Teapro uses technologies
developed in the past which were too slow then, but which are viable
on the much faster Personal Computers of today. Teapro uses the
OpenTea technology for programming that is simple and solid.
The Teapro programming language was invented on 14-DEC-1997 by D La
Pierre Ballard. The Teapro interpreter, teapro.exe, was written by him
in C90 and is a full 32-bit Windows application. The available source
code in teapro.c can be compiled and run on Linux in exactly the same
fashion. A Teapro program is a text file with the extension .TEA and
can be coded using any word processor or text editor. If the
programmer prefers, the .TXT extension works fine too.
Teapro was developed to show that effective programming can be done
on a Windows or Linux without having a development system consisting
of hundreds of files and costing a hundred dollars or more. Teapro is
enormously simpler than any of the major languages in use today and is
slower only because it is strictly interpreted. Teapro has far fewer
gimmicks in it than do other languages. Teapro does not allow the
programmer to use any of the constructs which tend to over-complicate
so many of the modern programs. Those are the same programs which are
hard to understand, hard to fix and full of minor bugs.
Teapro uses the OpenTea technology of far greater simplicity than has
been generally used in the past for computer programming. Teapro does
not access the internet. System commands cannot be called in Teapro.
Other programs cannot be started by a Teapro program. Teapro has
definite limits to make it immune to viruses and attacks by malevolent
software. Teapro is much more solid than most other software. Teapro
does not access the computer's registry or configuration files.
The author realizes that many programmers will not find Teapro
attractive because of the limitations of the Teapro language which
require a much simpler programming style than other languages. The
author hopes to show that the current trends in programming toward the
bigger and more complicated are neither necessarily needed nor good.
Teapro greatly limits the programmer to structured programs containing
simpler constructs that are easy to understand and maintain.
Of course, Teapro does now include the GOTO, GTAG commands which can
be used for non-structured programming. Read the chapter on the GOTO,
GTAG commands.
From teapro.com is available for free download the Teapro interpreter
written in C90 for Windows as teapro.exe. Also, there is a Teapro
interpreter written in Borland Delphi 2.0 for Windows named
teapro9.exe. Additionally, the C90 source code for the Teapro
interpreter is available for free download as teapro.c which can be
compiled for Linux.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 002: Running the HELLO WORLD Program in Teapro
Updated 2005/11/12, 2005/11/08, 2002/12/30
**********************************************************************
----------------------------------------------------------------------
Traditionally, the first program that a newcomer to a programming
language does is the "HELLO WORLD" program. Let us do it in Teapro.
First, download the Teapro interpreter, teapro.exe, to your computer
from the website teapro.com. You might want to create a special folder
to hold it along with any programs in Teapro you might write.
Second, open whatever wordprocessor you prefer or even Notepad or
Wordpad that come with Windows.
Third, type into that word processor the following short seven line
program. Which is listed between the dash lines. Teapro is not
sensitive to case so you can use uppercase, lowercase, or mixed as you
prefer.
----------------------------------------------------------------------
SUB_HELLOWORLD
ENDP
SUBR SUB_HELLOWORLD
VARI S_ANY
$OUT "HELLO WORLD"
$INP S_ANY, "return"
ENDS SUB_HELLOWORLD
----------------------------------------------------------------------
Next, save the program in the same folder that contains the Teapro
interpreter program, teapro.exe. Save the HELLO WORLD program as
HELLO.TEA and save it as a text file. You can also save it as
HELLO.TXT, if you prefer.
Next, run the Teapro interpreter, teapro.exe, that is in that same
folder.
Next, type in the console command LOAD and hit return.
It will ask for the program name. Type in HELLO.TEA or HELLO.TXT,
which ever you named the small Teapro program.
Next, type in the console command RUN and hit return.
This will run the Teapro program HELLO.TEA which you have just
written. The following two lines should appear on the Teapro console
display:
HELLO WORLD
return
The word "return" is to prompt you to hit the return key on your
computer. When you do so the Teapro program HELLO.TEA will end. You
can type in an asterisk and hit return to close the Teapro console.
You have just run your first Teapro program.
In the next chapter there is a line for line explanation of the seven
line Teapro program HELLO.TEA.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 003: An Explanation of the Teapro Program HELLO.TEA
Updated 2005/11/08, 2002/12/30
**********************************************************************
----------------------------------------------------------------------
This chapter gives a line for line explanation of the Teapro program
HELLO.TEA which does HELLO WORLD. Here, again, is that seven line
program between the dash lines.
----------------------------------------------------------------------
SUB_HELLOWORLD
ENDP
SUBR SUB_HELLOWORLD
VARI S_ANY
$OUT "HELLO WORLD"
$INP S_ANY, "return"
ENDS SUB_HELLOWORLD
----------------------------------------------------------------------
Below is a line for line explanation of the above program.
----------------------------------------------------------------------
SUB_HELLOWORLD
The above line calls the subroutine SUB_HELLOWORLD.
----------------------------------------------------------------------
ENDP
The above line ends the program after the subroutine SUB_HELLOWORLD
is called and returned from.
----------------------------------------------------------------------
SUBR SUB_HELLOWORLD
The above line is the first line of the subroutine SUB_HELLOWORLD.
----------------------------------------------------------------------
VARI S_ANY
The above line defines a string variable S_ANY which can be used
within the subroutine SUB_HELLOWORLD.
----------------------------------------------------------------------
$OUT "HELLO WORLD"
The above line outputs a string to the screen. The string is "HELLO
WORLD". The quotation marks are not part of the string but only
delineate it.
----------------------------------------------------------------------
$INP S_ANY, "return"
The above line outputs the string "return" to the screen and waits
for the user to hit return or enter something in and hit return.
Whatever the user enters in is put into the string variable S_ANY.
----------------------------------------------------------------------
ENDS SUB_HELLOWORLD
The above line ends the subroutine SUB_HELLOWORLD. The next line
after calling the subroutine is then performed which ends the Teapro
program.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 004: Qualities of Teapro, the OpenTea Technology
Updated 2007/04/21, 2007/02/03, 2005/11/12, 2005/11/09, 2005/11/08,
**********************************************************************
----------------------------------------------------------------------
In Teapro, the only reserved words are the Teapro commands which are
well covered alphabetically in other chapters in this booklet.
The language Teapro has only two variable types. It has strings and
decimal numbers. Strings are strings of characters of any length up to
100,000,000, if the memory of your computer will handle them that big.
Decimals are fifteen digit accuracy floating point decimal numbers
which can be plus or minus and either quite large or quite small. Of
course, the floating point decimal numbers have the same limitations
in Teapro that they have in other languages. Sometimes decimals in
Teapro can have sixteen digit accuracy. See the chapter on Teapro
floating point decimal arithmetic.
Teapro has a fantastic assortment of commands for handling strings.
For example you can cut, delete, insert or replace characters in the
middle of a string. You can do lookups starting at any certain point
in a string that go forwards or backwards. You can sort the constant
length substrings which make up a string. You can test a string to see
if it is all one character or fits a certain pattern or is numeric.
In Teapro there are restrictions on the naming of variables which
make it obvious to the programmer which data type the variables are.
Other languages do not have this and it is often difficult to tell
reserved words from variables. Additionally, because of these
restrictions in Teapro, it is also obvious whether or not a variable
is a global variable or a local variable. Also, variable names that
overlap other variable names within the same subroutine are not
allowed in Teapro. You cannot have local variables named S_STRING and
S_STRING1 both in the same subroutine because they overlap.
In Teapro you can have global variables and local variables. This has
been one of the greatest advances of modern programming. Other
languages do this in ways far more complex than in Teapro. There are
no pointers in Teapro.
The OpenTea methods of file processing are used in Teapro. File
processing is done much simpler in Teapro than in other languages. In
Teapro there are three ways to read files and to write to files. In
each of the three ways, the file is opened and closed by each read or
write command. In this way there is no limit on the number of files
accessed. Also, a program crash has far less chance of damaging a file
this way, since most of the time no file is open. The name of the file
must be included in each read or write command in a string variable.
Because of this, it is obvious which file is being processed. Some may
say that this method is too slow. However, modern computers are so
fast that an interpreted language such as Teapro is now viable which
offers this much higher degree of simplicity and solidity.
The first of the three ways to read and write files is with the
commands FREA and FWRI. These commands read and write by byte position
in the file and by length. These commands are best for random access
of fixed length records.
The second file access method in Teapro is with the commands FSIP and
FAPP. These commands are for reading and writing lines which are
variable length records which end in a carriage return and a line
feed. These commands are used to read through a text file or to write
one.
The third method of file access in Teapro is with the commands FINP
and FOUT. These two commands read and write an entire file into or
from a single string variable all in one swoop.
All Teapro commands are four characters long. The beginning character
in many cases is either $ or D depending upon which type of variable
the command uses. The commands which do not begin with $ or D are
mostly commands used for control, file processing, array access, or to
set up variables.
Without using the GOTO and GTAG commands, it is impossible in Teapro
to write an unstructured program. You cannot exit a subroutine except
by exiting at the bottom. There is no "CONTINUE" command to go to the
top of a loop block before hitting the ENDW command. The is no "BREAK"
command to jump to the bottom of a loop block or a DIFT/$IFT block.
The GOTO and GTAG commands were added because Teapro was being used
to write a program to translate from a language in which GOTO and GTAG
equivalents were used into Teapro. In certain cases, the GOTO and GTAG
commands make for a much simpler and much faster program than using
the DIFT, $IFT, DWHI, $WHI commands even with deeply nested
subroutines.
There can be no memory leaks in Teapro because you cannot allocate
memory as in other languages in which you must then remember to
deallocate it. If you need space in which to store data, you can put a
whale of a lot in a string.
The Teapro interpreter is a single .EXE Windows file well under a
200K in size. Teapro can be put on any Windows computer by merely
copying it from a diskette. The source code in C90 for the Teapro
interpreter compiles and runs similarly well on Linux computers. The
Teapro interpreter uses a remarkably low level of resources to run so
that it can run while many other applications are running also.
To run a Teapro program on Windows you need only the Teapro
interpreter, teapro.exe, and the one Teapro program file that you want
to run. You do not need dozens of other files, and you do not need to
install anything. A standard 1.44 Meg diskette can well hold both the
Teapro interpreter and several Teapro programs with plenty of room to
spare. The Teapro interpreter can run a Teapro program just fine even
when both are on a 1.44 Meg diskette. A Teapro program file is a text
file that has the extension .TEA as the last part of the name of the
file. If you prefer, you can use the extension .TXT instead.
Interpreted languages are proving to be a major direction that
computer programming is turning to more and more often. Programs
written in them are much easier to modify and rerun. Interpreted
languages generally offer far more simplicity than compiled languages
and offer commands that accomplish much more. Some interpreted
languages are for internet use; whereas, some are for the purpose of
controlling the computer. Teapro does not do those things but is best
suited for file processing, calculations, and terminal input and
output.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 005: What makes the Teapro Programming Language so Simple
Updated 2008/03/30, 2007/06/24, 2007/02/03, 2005/11/09, 2004/04/01
**********************************************************************
----------------------------------------------------------------------
The OpenTea technology of simple and solid programming which is used
in Teapro is discussed in the following paragraphs.
Teapro does not have the graphical user interface that has taken the
world by storm. The GUI, as it is called, is often unnecessary and
just costs heavily in terms of system resources. Teapro is best for
calculations, file processing, and screen input and output. The
command line interface of Teapro offers much greater flexibility for
complex program input than does a GUI. A graphical user interface
would be of minimal value for this type of programming.
Teapro is not object oriented, but is an old fashioned procedural
language. What the object oriented languages offer is far too complex
when simple programs of just a few thousand lines are needed. One
slight disadvantage of Teapro is that it does not allow subroutines to
be defined within subroutines.
Teapro does not have multi-threading. Multi-threading is sometimes
useful for compiled commercial applications, but is otherwise more
trouble than it is worth. In application programming it is not
necessary.
In Teapro you cannot combine several commands into one command. There
are no functions and the programmer in Teapro can only write
subroutines not functions. Languages which have functions sometimes
have problems with whether or not a function is called. The languages
which have functions sometimes limit what may or may not be done
within a function.
The order of the variables following an assignment command determines
the order in which the aritmetic is done. The arithmetic is done
strictly left to right. This is far simpler for the programmer to
understand than in other languages in which the assignment command is
really an algebraic equation to be solved. This left to right method
of performing assignment commands is far simpler for the programmer
and for the interpreter. The left to right evaluation of an expression
is much more likely to give the programmer the expected answer.
In Teapro, variables must be passed to subroutines and from
subroutines using generically named global variables. By doing this in
this fashion it is obvious to the programmer whether or not the called
subroutine changes the original sent variable or not. This is more
like the way information is actually passed between subroutines in
other languages where the actual process is disguised by the complex
parameter notation.
Generically named global variables are just global variables named
with names like SG_PASS1, SG_PASS2, DG_PASS1 or DG_PASS2 which are
used for passing data to and from subroutines.
In Teapro, just prior to calling a subroutine, you must put the
non-global variables, which you want to pass to that subroutine, into
generically named global variables. At the bottom of the subroutine if
you want to pass data back to the code which called that subroutine
you must put that data into generically named global variables. Since
Teapro is a generally structured language, code in subroutines is
performed from top to bottom so that it is simple to send variable
values back to the calling subroutine using global variables. Usually
some global generically named variables of both data types are defined
at the beginning of the program to be used for this passing of
information.
In Teapro all global variables are statically allocated when the
program is prepped just prior to execution. Local variables are
dynamically allocated just as in other modern languages. Because the
local variables are dynamically allocated during execution, recursive
subroutines may be used if the programming problem requires this. It
is only necessary to remember to use global generic variables to pass
data to and from the performing subroutine.
In other interpreted languages the original code is usually compiled
into either a pseudo-code or byte codes and can only be made sense of
by the language interpreter or virtual machine. With Teapro the actual
written text code is the program that the interpreter reads in to
perform. When the Teapro interpreter begins to run a program, it goes
through and makes a few changes to the code in its own memory to make
interpretation much simpler and faster.
The fact that anyone can read through the actual text Teapro program
is both an advantage and a disadvantage. If the progammer needs to
keep his work secret it is a disadvantage. Because the source program
is also the object program. The OpenTea technology prefers open source
code.
Once the Teapro interpreter begins running a Teapro program, the
actual text file which contains the program is no longer being
accessed by the Teapro interpreter. At that time the Teapro
interpreter only needs the Teapro program which it has in memory to
continue to run that Teapro program.
Because Teapro is interpreted and has deliberately built in
limitations, it is sometimes called a scripting language. Teapro
is limited to file processing, heavy string processing, keyboard
input and output and intensive mathematical calculations. It is
these types of computer processing that Teapro is designed to do.
Teapro does not have commands that can be used to take control of
your computer. Viruses cannot be written in Teapro because
programs written in Teapro cannot call other programs or call
operating system commands.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 006: Simpler Programming with the Teapro Programming Language
Updated 2007/06/24, 2006/06/11, 2006/06/09, 2005/11/12, 2005/11/09,
**********************************************************************
----------------------------------------------------------------------
Here is further discussion of how the OpenTea technology is utilized
in Teapro.
1. Teapro programs are generally structured programs. Subroutines are
entered at the top and exited at the bottom. If absolutely necessary
the programmer can use the commands GOTO and GTAG to jump around when
absolutely needed.
2. Variable names in Teapro must utilize a hungarian type of
notation. From a variable name the programmer can tell not only the
type of the variable but also whether the variable is global or local.
4. Teapro has strongly typed variables. Teapro commands require that
the parameters be either string or decimal types. Only string
expressions will allow either type of variable.
5. String append expressions are only allowed when doing a string
assignment or with the commands $APP, $INP, $OUT, and $SHO.
6. Decimal variable expressions are allowed only when doing a decimal
variable assignment. Decimal assigment statements are performed
strictly left to right.
7. Subroutine names always begin with "SUB_". In Teapro there is no
confusion between subroutine names, Teapro command names and variable
names.
8. There are no functions in Teapro and the programmer can only write
subroutines.
9. Data is passed by generically named global variables when going
into or coming out of subroutines.
10. The conditional control commands: DWHI, DIFT, $WHI and $IFT, can
each do only one compare for each command.
11. The right side of a numeric decimal assignment command is
evaluated strictly left to right, not according to operator
precedence. It is not an algebraic expression as in other languages.
Algebraic expressions are not used in Teapro.
12. There are less than one hundred keywords in Teapro.
13. File processing using the FREA, FWRI, FINP, FOUT, FSIP, or FAPP
commands to read or write to a file has the name of the file in a
string variable as one of the parameters of those commands. The file
is opened, processed and then closed. No file is left open from one
command to another.
14. Except for $IFT or DIFT command lines followed by a colon and a
non-control command, there can never be more than one command per
line. Command lines beginning with $IFT or DIFT when followed by a
colon allow one other command on that line and do so because the
performance of that one other command is conditional. That other
command may not be a control command.
15. Blank lines, comment lines, spaces between command parameters,
indentation and uppercase/lowercase can all be used according to the
programmer's style. These things do not affect the speed or the
resources of the running program in any way.
16. Program lines may not be wrapped to the next line. The whole
command line must be on one line.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 007: Appearance of a Teapro Program
Updated 2005/11/09, 2002/12/30
**********************************************************************
----------------------------------------------------------------------
A Teapro command must be only on one line. However, spaces may be put
in between the parameters of the command to make the appearance easier
to read. These spaces do not affect the speed of the program.
Comment lines may be put anywhere and are begun with an apostrophe.
Comment lines do not affect the speed of the program.
Blank lines can be put where wanted and do not affect in any way the
use of resources or the speed of the program.
----------------------------------------------------------------------
Generally, a Teapro program starts out with some lines defining the
global variables wanted. Then may follow some lines in which some
subroutines are called. Since local variables can only be defined in
subroutines, the Teapro programmer may want the call to a subroutine
to be the only non-subroutine command other than to define some global
variables. In that way all other processing will be in subroutines
which have local variables available.
Each time a subroutine is entered all of the local variables for that
subroutine are initialized to zero for decimal variables or to a
string of zero length for string variables.
----------------------------------------------------------------------
Command names in Teapro generally have movement from left to right.
However, command parameters have movement from right to left. For
example, take the following command:
$TOD D_DECIMAL, S_STRING
The command name is: string to decimal. This command takes the value
of the string S_STRING, and it converts that value into a decimal
number value and then stores it in the decimal variable D_DECIMAL.
Movement in the command name, $TOD, is from left to right. Movement in
the parameters is right to left. This convention in Teapro, which
nearly always applies, helps the programmer to remember the commands
and the parameters of the commands.
In the assignment command there is no command named. However, the
right side of the assignment command moves to the left after it is
evaluated. For example:
D_DECIMAL1 = 5 + D_DECIMAL2 * D_DECIMAL3
We take 5 and add D_DECIMAL2 to it. Then we multiply that decimal
number by D_DECIMAL3 and store the result in D_DECIMAL1. The
evaluation of the decimal expression to the right of the equal sign is
left to right, but the movement is still right to left since the value
of that decimal expression is moved from the right to the left into
D_DECIMAL1.
Teapro programs are text files with the program name having extension
.TEA and can be written or coded using any word processor or text
editor. Some programmers may prefer to have the extension .TXT on the
Teapro program, and that will work fine, too.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 008: Security and Teapro
Updated 2007/02/03, 2005/11/09, 2005/11/08, 2004/04/25
**********************************************************************
----------------------------------------------------------------------
The aim of the OpenTea Technology which Teapro utilizes is to have a
language which is simple and solid.
Reliability and trustworthiness are the other keywords kept in mind
besides ease of use and simplicity during the development of the
language Teapro and during the writing of the Teapro interpreter.
The Teapro interpreter does not try to access the internet and does
not install software on the user's computer. Because Teapro does not
offer a means to do calls to the operating system, there is no way
that any kind of virus, worm, or trojan can be written in Teapro.
There are no problems with buffer overflow with the Teapro
interpreter like some other software. Any extreme or excessive string
sizes will cause an error condition which will end the Teapro program.
The limit on string length in Teapro is 100,000,000 bytes. For
security, the limit on the string entry size for the $INP statement is
just 100 bytes.
The number of significant digits in the decimal numbers is set at
fifteen digits, but will sometimes work with sixteen.
It is extremely important that the Teapro interpreter be absolutely
reliable and trustworthy. Please send an e-mail to dlb@teapro.com if
you find any kind of problem with the Teapro interpreter.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 009: Variable Naming in Teapro
Updated 2005/11/12, 2005/11/09, 2004/04/25
**********************************************************************
----------------------------------------------------------------------
Global variables are defined at the top of the program using the
command VARI. Local variables are defined at the top of subroutines
and again the command is VARI. Global variables can be used any where
in the program. Local variables can only be used while the processing
is in the subroutine in which they are defined.
If a variable is a string variable the name must begin with an "S".
If a variable is a decimal variable the name must begin with a "D".
Then, if the variable is a local variable defined in a subroutine, the
first letter is followed by an underline "_" and then letters and
numbers. However, if the variable is a global variable defined at the
top of the program rather than in a subroutine, then the second
character in the name is a "G" followed by a underline and then
letters and numbers. The minimum length for a variable name is five
characters and the maximum length is sixty-four characters.
An important restriction is that variable names in the same scope
must not overlap. In other words, in a subroutine one cannot have the
variables "D_BYTES" and "D_BYTE" both, since they overlap. Also,
"SG_NUM" and "SG_NUMBER" are not allowed. Also, "S_NUM" and "S_NUM1"
are not allowed. By in the same scope, is meant that both variables
are available in the same subroutine, or both variables are global
variables.
Subroutine names must begin with the characters "SUB_". Like variable
names they can be upto sixty-four characters long. The remaining
characters must be letters, numbers or underlines. In subroutine names
only are additional underlines permitted beyond the first one in byte
4.
In other languages there are lists of reserved words which must be
avoided as names for variables and subroutines. Sometimes there are
hundreds of reserved words in other languages. In Teapro there is no
need for for such concern for reserved words because variables and
subroutines cannot be named the same as commands. Likewise, variables
cannot be named the same as subroutines. Furthermore, local variables
and global variables cannot have the same names.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 010: Definitions of Teapro Terminology
Updated 2006/06/11, 2006/06/09, 2005/12/09, 2005/12/08, 2005/11/12,
**********************************************************************
----------------------------------------------------------------------
Assignment operator: in Teapro the assignment operator is the equal
sign ie.
D_DECIMAL1 = D_DECIMAL2 + 1
The above Teapro language program line means to find the value of the
variable D_DECIMAL2 and to add 1 to that value; then, to store that
value in the variable D_DECIMAL1.
S_STRING1 = "hello" + S_STRING2 + D_DECIMAL1
The above program line means to take the string "hello" and to
concatenate to it the string in the variable S_STRING2, and then to
concatenate to that the string value of the decimal number in the
variable D_DECIMAL1. Finally, this resultant string is stored in the
variable S_STRING1.
----------------------------------------------------------------------
Control commands: They control the flow of the program. They are:
DIFT, DWHI, $IFT, $WHI, ENDI, ENDW, ELSE, SUBR, ENDS, ENDP.
----------------------------------------------------------------------
Generic global variables: global variables which a programmer can set
up to pass information to and from subroutines. Usually names of these
are like: SG_PASS1, SG_PASS2, DG_PASS1, DG_PASS2. Of course these
are simply global variables like any other global variables except
that the programmer uses them only for passing information into or out
of a subroutine. Of course, you may any legal global variable names
which you care to use.
----------------------------------------------------------------------
A numeric literal can be any whole number, or it can be any decimal
number if there is at least one digit, even just a zero, to the
left of the decimal. Numeric literals may have a + or a - sign in
front of them.
D_ANY = 1234.56789 * - 2 / + 1.7 % + 4 / 0.987654321
Begin with 1234.56789 and multiply by -2, then divide by a +1.7, then
find mod 4 and divide by 0.987654321.
----------------------------------------------------------------------
String literal: a string of characters inclosed by either double
quotation marks or by number signs ie. "hello" or "1234567890" or
"!@#_tui672" or #"xyz#.
----------------------------------------------------------------------
String append expression: what is to the right of the assignment
operator in a string assignment command ie.
S_STRING1 = S_STRING2 + "1234" + D_DECIMAL1
A string append expression evalutes to a string. You can use
string append expressions also in the Teapro commands: $APP, $INP,
$OUT, and $SHO.
----------------------------------------------------------------------
**********************************************************************
CHAP: 011: The String Assignment Command & String Append Expressions
Updated 2006/06/11, 2005/11/12, 2005/11/09, 2005/11/07, 2004/06/09
**********************************************************************
----------------------------------------------------------------------
Here is an example which shows the string assignment command.
S_STR1 = S_STR2 + "Hello World" + #16.3# + S_STR3 + D_DEC1
S_STR1 = S_STR2 + #Hello World# + "16.3" + S_STR3 + D_DEC1
$SET S_STR1 = S_STR2 + #Hello World# + "16.3" + S_STR3 + D_DEC1
The three above lines produce the same result. A string literal
may be enclosed in either double quotes, i.e. "hello" or in number
signs, i.e. #hello#.
The first thing to notice is that the string assignment
command does not have a command in front! If you must put
a command in front, you can use $SET, but it is preferred
to omit it as it is not needed. The characteristic of the
string assignment command is a variable of type string
followed by an equal sign and then more variables with
plus signs between them. The part to the right of the
equal sign is called a string append expression. A string
append expression can also be used with $APP, $INP, $OUT,
and $SHO.
The string assignment command merely concatenates string literals and
variables together into one string. Decimal variables can be
concatenated into the string also. Decimal variables are changed to
strings before they are concatenated into the string.
The other assignment command, the decimal assignment command, begins
with a decimal variable. It is covered in another chapter.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 012: The Decimal Assignment Command and Teapro Operators
Updated 2007/07/23, 2007/07/08, 2006/11/13, 2005/12/09, 2005/11/12,
**********************************************************************
----------------------------------------------------------------------
Here is an example which shows the decimal assignment command.
----------------------------------------------------------------------
D_NUM = - D_DEC1 * -412.71 / D_DEC2 + D_DEC3 % D_DEC4 + 86 ^ 2
DSET D_NUM = - D_DEC1 * -412.71 / D_DEC2 + D_DEC3 % D_DEC4 + 86 ^ 2
Set D_NUM to zero, subtract D_DEC1, multiply by -412.71, divide
by D_DEC2, add D_DEC3, find mod D_DEC4, add 86, raise to power 2.
See command DPOW for how exponentiation works.
----------------------------------------------------------------------
The answer is the decimal variable to the left of the equal sign.
= means to set the answer to zero.
+ means to add the next number to the answer.
- means to subtract the next number from the answer.
* means to multiply the next number times the answer.
/ means to divide the answer by the next number.
% means to round both to integers and find the modulus or mod.
The sign of a mod is the same as the sign of the mod of term.
\ means to round both to integers and do an integer divide.
^ means to raise to a power.
@ means to round to a number of decimal places.
? means to truncate to a number of decimal places.
----------------------------------------------------------------------
The first thing to notice is that the decimal assignment command does
not have a command in front! If you must have a command you may use
DSET, but it is not needed and it is preferred to be omitted. The
defining characteristic of the decimal assignment command is that a
variable of type decimal is followed by an equal sign and then more
decimal variables and decimal literals with operators between them.
Notice the -412.71 which is a numeric literal which is a negative
number. Numeric literals may have a plus + or a minus - sign in from
of them to make them either positive or negative numbers. If both the
positive and negative signs are not there, then the number is
positive. The 86 does not have a sign and is positive.
A numeric literal can be any whole number, or it can be any decimal
number if there is at least one digit, even just a zero, to the
left of the decimal. Numeric literals may have a + or a - sign in
front of them.
The decimal assignment command does various mathematical decimal
operations in a strictly left to right order using both decimal
variables and decimal literals. A zero divide or a mod zero will cause
an error which will cause your Teapro program to end.
Decimal numbers have fifteen significant figures. The placing of
the decimal point in the decimal numbers can be almost anywhere.
Decimals can be any number that one should conceivably ever need
because of the tremendous range of values that they cover.
Sometimes, decimal numbers can be sixteen digits long.
The strict left to right evaluation of the decimal assignment command
has two good reasons to justify it. First, the programmer will make
far fewer errors if she/he is required to put the variables in the
order of evaluation. Secondly, a zero divide or a mod zero cannot
arise unless the variable going into a decimal assignment command is
already zero. That variable can be tested on a line just prior to the
decimal assinment line. A third reason for the left to right method is
that the interpreter is much simpler.
Notice that mod "%" and integer divide "\" both round the two numbers
before doing the operation. This is a banker's round which is what is
most commonly used in floating point arithmetic. In floating point
arithmetic calculated numbers are often a tiny tiny bit off from an
integer. Doing % or \ without first rounding the two numbers would
give an answer quite different from what one would expect. Both of
these operators return an integer result. The sign of the mod result
is the same as the sign of the mod of term.
D_NUMBER = D_TERM1 % D_TERM2
In the above the sign of D_NUMBER will be the sign of D_TERM1. If one
considers how modulus works in algebra, this is true, also.
If you want to round such that an ending decimal of .5 is rounded
away from zero use the command DROU. Also, if you want to truncate
such that the result is an integer closer to zero than your beginning
non-integer decimal number use the command DTRU.
In other languages, the decimal or numerical assignment command
appears to be an algebraic expression for the computer to evaluate. In
these other languages, operator precedence determines which operations
are done first very similarly as they are done in algebra. In these
other languages, however, the truth of the matter is that when the
operators have the same precedence then a left to right evaluation
order is done just as the language Teapro does all of the time for all
operators in decimal assignment statements.
Teapro greatly simplifies this situation and throws the decision of
order of evaluation to the programmer without the complications of
operator precedence. It is important when doing floating point math
combined with integer math that the programmer definitely determine
the exact order for the operations to be done in a straight forward
manner. The language Teapro is at this time one of the very few
available languages which offers to the programmer what the programmer
needs and deserves in this respect.
If the first term to the right of the equal sign has no operator in
front of it then a plus sign is understood to be there.
The string assignment command begins with a variable of type string
and is covered in another chapter.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 013: String Commands Alphabetically
Updated 2008/02/06, 2007/02/03, 2006/10/14, 2006/06/11, 2006/06/09,
**********************************************************************
----------------------------------------------------------------------
In the following the Teapro commands are in uppercase for greater
clarity. Most Teapro programmers prefer to use lower case for the
Teapro commands and variables in their programs.
----------------------------------------------------------------------
ARRB
Blank the string array. The string array holds 2000 strings with the
index ranging from 1 to 2000. Use ARRZ to zero the decimal array.
Other string array commands are $TOI and ITO$.
----------------------------------------------------------------------
$APP S_STRING1, S_STRING2
String append. Put S_STRING1 + S_STRING2 into S_STRING1. The string
S_STRING2 can be a string append expression. Creating a string longer
than 100,000,000 bytes will cause an error.
----------------------------------------------------------------------
$BAK D_BYTE, S_LOOKIN, D_START, S_LOOKFOR
Back lookup. Using S_LOOKIN starting at byte D_START backwardly
search or look for S_LOOKFOR. If it is found put the number of the
first byte into D_BYTE and if it is not found put zero into D_BYTE.
----------------------------------------------------------------------
$BES S_NEW, S_OLD
Blank escape characters in S_OLD and store the string in S_NEW. An
escape character is one whose number is less than 32.
----------------------------------------------------------------------
$CH$ S_NEW, S_CHAR, D_LONG
String character to string. Make S_NEW of length D_LONG of the first
character of S_CHAR. Creating a string longer than 100,000,000 bytes
will cause an error.
----------------------------------------------------------------------
$CHD D_CHAR, S_CHAR
String character to decimal. Find the character number of the first
character of S_CHAR and put that number into D_CHAR.
----------------------------------------------------------------------
$CLO S_NEW, S_OLD
Make case lower. Make S_OLD lower case and store in S_NEW.
----------------------------------------------------------------------
$CNT D_COUNT, S_STRING, S_FIND
Put count of occurrences of S_FIND in S_STRING into D_COUNT.
Occurrences cannot overlap.
----------------------------------------------------------------------
$COD S_NEW, S_OLD
Code S_OLD into S_NEW. Code and decode are the same operation.
This is an entirely different type of encryption than done by $TOE.
----------------------------------------------------------------------
$CUP S_NEW, S_OLD
Case make upper. Make S_OLD uppercase and store in S_NEW.
----------------------------------------------------------------------
$CUT S_PARTSTRING, S_WHOLESTRING, D_BYTE, D_LONG
Cut string from string. Put into S_PARTSTRING a portion of
S_WHOLESTRING starting at byte D_BYTE for length D_LONG.
----------------------------------------------------------------------
$DAT S_DATE
Put the date as a string into S_DATE. The date string contains the
date and time in two formats:
"22-MAR-2002 21:28:16 20020322212816".
----------------------------------------------------------------------
$DEL S_STRING, D_BEG, D_LONG
String delete. In string S_STRING starting at D_BEG delete the bytes
for a length of D_LONG.
----------------------------------------------------------------------
$DOT D_DOT, S_STRING1, S_STRING2, D_WHICH
Find certain string occurrence and put location in d_dot. Find
occurrence d_which of s_string2 in s_string1 and put the number of
the first byte of that occurrence into d_dot. Occurrences of
s_string2 cannot overlap a previous occurrence. If the wanted
occurrence of the wanted string is not found then put zero into
D_DOT.
----------------------------------------------------------------------
$HSH D_HASH, S_STRING
String hash. Create a hash number D_HASH that is fairly unique for
the string S_STRING. The hash decimal number D_HASH can be 15 digits
long. The first 9 are merely a total of the char numbers of the bytes
in the file. The last six represent a total of the char numbers times
the positions in records which are 701 bytes long. 701 is prime.
Char numbers run from 1 to 256 for these calculations.
----------------------------------------------------------------------
$IFT S_STRING1 = S_STRING2
$IFT S_STRING1 = S_STRING2: $OUT "hello world"
If S_STRING1 equals S_STRING2 then perform all of the command lines
down to the matching ELSE or ENDI command. If they do not equal then
jump down to the appropriate ELSE or ENDI command.
If the command line beginning with $IFT ends with a colon and another
command line, then only that other command line is conditioned by the
$IFT. That other command line must not be a control command.
You may use any of the following compare options with $IFT:
= is equal to
< is less than
<= is less than or equal to
<> is not equal to
> is greater than
>= is greater than or equal to
----------------------------------------------------------------------
$INP S_INPUT, S_OUTPUT
Output S_OUTPUT to screen and input from the keyboard S_INPUT.
S_OUTPUT can be a string expression. For security, the maximum length
of S_INPUT for $INP is 100 bytes for security.
----------------------------------------------------------------------
$INS S_WHOLESTRING, D_BYTE, S_PARTSTRING
Insert string into string. Insert into S_WHOLESTRING starting at byte
D_BYTE the string S_PARTSTRING. If D_BYTE is the length of
S_WHOLESTRING plus one then S_PARTSTRING is appended at the end.
Creating a string longer than 100,000,000 bytes will cause an error.
----------------------------------------------------------------------
$ISC D_YESNO, S_STRING, S_CHAR
String is a string of characters S_CHAR? If S_STRING is a string of
the first character of S_CHAR then put 1 in D_YESNO else 2.
----------------------------------------------------------------------
$ISD D_YESNO, S_STRING
String is decimal. If string S_STRING is a decimal number then put 1
in D_YESNO otherwise put 2 in D_YESNO.
----------------------------------------------------------------------
$ISP D_YESNO, S_STRING, S_PATTERN
String S_STRING is a type pattern match with string S_PATTERN.
Compare S_STRING and S_PATTERN to see if the pattern of types match.
If yes then put a 1 in D_YESNO. If not put a 2 in D_YESNO. Types of
characters are: escapes, blanks, punctuation, numbers, uppers, lowers,
and char greater than #126. The two strings must also be the same
length.
----------------------------------------------------------------------
$IST D_YESNO, S_STRING, S_TYPE
String S_STRING is made up of characters of the same type as the
first character of S_TYPE. If yes then put 1 in D_YESNO. If no then
put 2 in D_YESNO. Types of characters are: escapes, blanks,
punctuation, numbers, uppers, lowers, and char greater than #126.
----------------------------------------------------------------------
$LEN D_LONG, S_STRING
String length. Put length of string S_STRING into D_LONG.
----------------------------------------------------------------------
$LOK D_BYTE, S_WHOLESTRING, D_START, S_PARTSTRING
Look for S_PARTSTRING in S_WHOLESTRING starting at byte D_START. If
it is found put the beginning byte number in D_BYTE. If it is not
found put zero in D_BYTE.
----------------------------------------------------------------------
$OFF S_RESULT, S_STRING, D_LONG
Cut off end of string S_STRING for D_LONG bytes and store it in
S_RESULT.
----------------------------------------------------------------------
$OUT S_OUTPUT
String out. Output to the screen S_OUTPUT. S_OUTPUT can be a string
expression made up of string variables and literals as well as decimal
variables. $OUT does a carriage return and line feed at the end to
move the line up.
----------------------------------------------------------------------
$PAR S_TOEXTRACT, S_CSV, S_CHAR, D_WHICH
Parse a string. Extract string S_TOEXTRACT from the character
separated value string S_CSV indicated by number D_WHICH. Strings in
S_CSV are separated by occurrences of S_CHAR. The length of S_CHAR
must be 1. If D_WHICH=1 then return the string ending with the first
occurrence of S_CHAR. If D_WHICH=6 return the string ending with the
sixth occurrence of S_CHAR.
----------------------------------------------------------------------
$PKD D_YESNO, D_DECIMAL, S_STRING
String in packed format to decimal. Convert the packed format number
in S_STRING into a whole number decimal D_DECIMAL. Packed decimal
format is also called BCD or binary coded decimal. If S_STRING can be
converted to a decimal number put 1 in D_YESNO otherwise put 2 in
D_YESNO.
----------------------------------------------------------------------
$REP S_WHOLESTRING, D_BYTE, S_PARTSTRING
Replace part of a string with another string. In S_WHOLESTRING
starting at byte D_BYTE replace the bytes with S_PARTSTRING. The
length of S_WHOLESTRING is never changed by this command.
----------------------------------------------------------------------
$SET S_STRING1 = S_STRING2 + " hello there " + S_STRING3 + # WOW #
String set. This is the string assignment command in Teapro. It is
actually preferred to omit the $SET command at the beginning. Notice
that string literals may be enclosed in double quotes or pound signs.
----------------------------------------------------------------------
$SHO S_OUTPUT
String show. Output to the screen S_OUTPUT. S_OUTPUT can be a string
expression made up of string variables and literals as well as decimal
variables. $SHO does not do a carriage return and a newline
afterwards.
----------------------------------------------------------------------
$SOR S_NEW, S_OLD, D_LONG
Sort string. Sort the string S_OLD into string S_NEW by sections each
D_LONG in length.
----------------------------------------------------------------------
$SWP S_STRING, S_OLD, S_NEW
String swap. In S_STRING replace each occurrence of S_OLD with S_NEW.
----------------------------------------------------------------------
$SYS S_INFO, D_WHICH
System or program information to S_INFO depending on D_WHICH.
1 = path and filename of this running Teapro Interpreter
2 = current subroutine name of Teapro program
3 = version of current Teapro program
----------------------------------------------------------------------
$TLO S_NEW, S_OLD
String trim low. Trim string S_NEW and make lower case. Then put it
into S_OLD.
----------------------------------------------------------------------
$TOD D_DECIMAL, S_STRING
String to decimal. Convert the string in S_STRING to a decimal number
and store it in decimal variable D_DECIMAL. If S_STRING cannot be
converted to a decimal number an error occurs. Usually, one should use
$ISD to test S_STRING first to see if it can be converted to a
decimal.
----------------------------------------------------------------------
$TOE S_NEW, S_OLD, S_KEY, D_WHICH
String to encoded. Code S_OLD into S_NEW using key S_KEY. If
D_WHICH=1 encode. If D_WHICH=2 then decode. S_KEY must be letters
and numbers, and is not case sensitive. This encryption is about
26 bit in strength which makes it pretty weak. There are only
61,000,001 possible keys. This is an entirely different type of
encryption from $COD. This encryption is called Old Toe.
----------------------------------------------------------------------
$TOI D_INDEX, S_STRING
String to index. Put the string S_STRING in the array of strings at
index D_INDEX. The array of strings has 2000 strings with the index
ranging from 1 to 2000. If the index D_INDEX is outside of this range
an error will occur which will cause the running Teapro program to
end. S_STRING cannot be a string append expression.
----------------------------------------------------------------------
$TRB S_NEW, S_OLD
Trim the blanks and escape characters from both ends of S_OLD and put
the string in S_NEW.
----------------------------------------------------------------------
$TRL S_NEW, S_OLD
Trim the blanks and escape characters from the left end of S_OLD and
put the string in S_NEW.
----------------------------------------------------------------------
$TRR S_NEW, S_OLD
Trim the blanks and escape characters from the right end of S_OLD and
put the string in S_NEW.
----------------------------------------------------------------------
$TUP S_NEW, S_OLD
Trim string S_OLD and make it upper case. Then put it in S_NEW.
----------------------------------------------------------------------
$WHI S_STRING1 > S_STRING2
String while command beginning a while block which ends with ENDW.
The comparison can be >,=,<,>=,<=, or <>. If the comparison is true
the while loop continues. If the comparison is not true the block is
skipped over and the line under the ENDW is processesed next.
----------------------------------------------------------------------
ITO$ S_STRING, D_INDEX
Index to string. Get the string that is in the array of strings
at index D_INDEX and put that string in S_STRING. The array of
strings has 2000 strings with the index ranging from 1 to 2000. If
the index D_INDEX is outside of this range an error will occur
which will end the running Teapro program.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 014: Decimal Commands Alphabetically
Updated 2008/03/30, 2007/10/15, 2007/07/23, 2007/07/08, 2007/03/04,
**********************************************************************
In the following the Teapro commands are in uppercase for greater
clarity. Most Teapro programmers prefer to use lower case for the
Teapro commands in their programs.
----------------------------------------------------------------------
ADDI D_INDEX, D_DECIMAL
Add to decimal array at index. Add decimal D_DECIMAL to decimal array
value at D_INDEX and put total back in decimal array at D_INDEX. The
decimal array index D_INDEX cannot be less than 1 or greater than
10000. Other decimal array commands are ARRZ,DTOI,ITOD.
----------------------------------------------------------------------
ARRZ
Zero the decimal array. The decimal array holds 2000 decimal values
with the index value ranging from 1 to 2000. Use ARRB to blank the
string array.
----------------------------------------------------------------------
DABS D_RESULT, D_NUMBER
Absolute value. Put the absolute value of D_NUMBER into D_RESULT.
----------------------------------------------------------------------
DARC D_RADIANS, D_SIN
Get the arcsine of a number. Put the arcsine of sine D_SIN into
D_RADIANS. D_SIN is made to be 1 if greater than 1 and is made to be
-1 if less than -1.
----------------------------------------------------------------------
DBAD D_NUMBER1 >= D_NUMBER2
Bad decimal variable test. If the condition is true, then we have
an error and the running Teapro program will end. DBAD is quick
and is to be used only for testing for near disaster situations.
Any of the standard tests can be used ie. <, >, =, <=, >=, <>.
----------------------------------------------------------------------
DBUG
The teapro command DBUG toggles debug mode. By rights it should be
EBUG instead since it is more of a control command. The opportunity to
name a command DBUG was just too much to resist.
----------------------------------------------------------------------
DCH$ S_STRING, D_CHAR, D_LONG
Decimal character to string. Make a string S_STRING of the character
corresponding to D_CHAR of length D_LONG.
----------------------------------------------------------------------
DDEC D_DECIMAL
Decrement D_DECIMAL by 1.
----------------------------------------------------------------------
DED$ S_STRING, D_DECIMAL, D_LONG, D_PLACES
Decimal edit to string. Change D_DECIMAL into string S_STRING, and
give it a length of at least D_LONG, right justified. Show the number
of decimal positions in D_PLACES. Separate 1000's with commas. The
command DTO$ is the same but does not put in commas. If D_LONG and
D_PLACES are both zero then the number will be its natural length with
no leading zeros and no trailing zeros to the right of the decimal.
----------------------------------------------------------------------
DFAC D_FACTOR, D_NUMBER
Find the lowest integer factor of D_NUMBER greater than one and put
it in D_FACTOR. If there are none greater than one put one in
D_FACTOR. If D_FACTOR ends up with one then D_NUMBER is prime.
DFAC only works for numbers less than 2^53 or 9,007,199,254,740,992.
For numbers greater than that upto 4E20 use DFAK.
----------------------------------------------------------------------
DFAK D_FACTOR, D_1QUADPART, D_1QUADMULT
Find the lowest factor of a test number such that D_1QUADPART is the
part of the test number less than 1E15 and D_1QUADMULT is the number
of quadrillions, ie. 1E15, of the test number. For example, suppose
the test number is 123,456,789,012,345,678,901. The part below 1E15 is
789,012,345,678,901 and this would be put into D_1QUADPART as it is
the PART below 1E15. Into D_1QUADMULT we would need to put 123,456 as
it is the number of quadrillions, ie 1E15. This test number has a
D_FACTOR of 11. Another test number is 108,000,000,000,000,001. Into
D_1QUADPART we put 1. Into D_1QUADMULT we put 108. DFAK gives 1 for
D_FACTOR meaning that this test number is prime. DFAK will work for
sure only if D_1QUADMULT is 400,000 or less.
This is the Teaquad method of testing large numbers for primeness.
----------------------------------------------------------------------
DIFT D_DECIMAL1 = D_DECIMAL2
DIFT D_DECIMAL1 = D_DECIMAL2: $OUT "hello there"
If D_DECIMAL1 equals D_DECIMAL2 then perform all of the command lines
down to the matching ELSE or ENDI command. If they do not equal then
jump down to the appropriate ELSE or ENDI command.
If the DIFT command line is followed with a colon and another command
line, then the DIFT command line conditions only that other command
line. That other command line may not be a control command.
You may use any of the following compare options with DIFT:
=, >, >=, <, <= or <>.
----------------------------------------------------------------------
DINC D_DECIMAL
Decimal increment. Increment D_DECIMAL by one.
----------------------------------------------------------------------
DLOG D_LOG, D_NUMBER
Logarithm of base 10. Put the common or base 10 logarithm of D_NUMBER
into D_LOG. D_NUMBER is made positive if negative and D_LOG is zero
if D_NUMBER is zero.
----------------------------------------------------------------------
DPK$ S_STRING, D_DECIMAL, D_LONG
Decimal number to a packed format string. Round D_DECIMAL to a whole
number and then change it into a string of packed format of length
D_LONG. Packed decimal format is also called binary coded decimal or
BCD.
----------------------------------------------------------------------
DPOW D_RESULT, D_NUMBER, D_POWER
Raise D_NUMBER to power D_POWER and put into D_RESULT. D_NUMBER
must be greater than zero. If D_NUMBER is negative and D_POWER is
not an integer then make D_NUMBER positive first.
----------------------------------------------------------------------
DRAN D_RANDOM
Put a decimal random number between 0 and 1 in D_RANDOM.
----------------------------------------------------------------------
DROU D_NEW, D_OLD
Round decimal number to integer. Round decimal number D_OLD and put
the result in D_NEW. A decimal amount of 0.5 is rounded away from
zero.
----------------------------------------------------------------------
DSEC D_SECONDS
Put seconds in D_SECONDS. This is used to time various events. The
difference between two calls of this command will be the time in
seconds that has passed.
----------------------------------------------------------------------
DSIN D_SIN, D_RADIANS
Sine of a number. Put the sine of number D_RADIANS which is an angle
in radians into D_SIN. If D_RADIANS > 2*PI then D_RADIANS is made to
be 2*PI. If D_RADIANS < -2*PI then D_RADIANS is made to be -2*PI.
----------------------------------------------------------------------
D_RESULT = -D_NUM1 * D_NUM2 - D_NUM3 / D_NUM3 % D_NUM4 \ D_NUM5
DSET D_RESULT = -D_NUM1 * D_NUM2 - D_NUM3 / D_NUM3 % D_NUM4 \ D_NUM5
Decimal set. The right side is evaluated strictly left to right. It
is preferred here to omit the DSET command altogether. The operators
are:
+ is add
- is subtract
* is multiply
/ is divide
% is round both to an integer and find the mod.
The sign of a mod result is the same as the mod of term.
\ round both to an integer and do an integer divide.
^ means to raise to a power.
@ means to round to a number of decimal places.
? means to truncate to a number of decimal places.
Literal numbers can be used as the decimal variables are used if the
numbers are -99999 to +99999 with no decimal places.
----------------------------------------------------------------------
DSYS D_AMOUNT, D_NUMBER
Decimal system info.
D_NUMBER=1 means put total string length in D_AMOUNT.
D_NUMBER=2 means put lines of Teapro done in D_AMOUNT.
----------------------------------------------------------------------
DTO$ S_STRING, D_DECIMAL, D_LONG, D_PLACES
Decimal to string. Change D_DECIMAL into string S_STRING, and give it
a length of at least D_LONG, right justified. Show the number of
decimal positions in D_PLACES. Do not put in commas as in DED$. If
D_LONG and D_PLACES are both zero then the number will be its natural
length with no leading zeros and no trailing zeros to the right of the
decimal.
----------------------------------------------------------------------
DTOF S_STRING, D_DECIMAL, D_LONG
Decimal to field. Change decimal D_DECIMAL into a string S_STRING of
length D_LONG such that S_STRING begins with + or -, is right
justified and zero filled. This format is needed many times for a
field in a record. The decimal D_DECIMAL is rounded to a whole number.
----------------------------------------------------------------------
DTOI D_INDEX, D_DECIMAL
Decimal to index. Put the decimal D_DECIMAL into the array of
decimals at index D_INDEX. The array of decimals has 10000
decimals with the index ranging from 1 to 10000. If the index
D_INDEX is outside of this range an error will occur and the
running Teapro program will end.
----------------------------------------------------------------------
DTRU D_NEW, D_OLD
Truncate decimal number. Truncate decimal number D_OLD and put the
result in D_NEW. If D_OLD is not an integer, D_NEW will be closer to
zero than D_OLD.
----------------------------------------------------------------------
DWHI D_DECIMAL1 < D_DECIMAL2
Decimal while. While D_DECIMAL1 is less than D_DECIMAL2 perform
the lines of commands down to the matching ENDW;
otherwise, jump to line right after the ENDW. The
following compares can be use: =, >, >=, <, <= and <>.
----------------------------------------------------------------------
ITOD D_DECIMAL, D_INDEX
Index to decimal. Get the decimal that is in the array of decimals at
index D_INDEX and put that decimal in D_DECIMAL. The array of decimals
has 2000 decimals with the index ranging from 1 to 2000. If the index
D_INDEX is outside of this range an error will occur and the running
Teapro program will end.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 015: Array Commands Alphabetically
Updated 2008/03/30, 2007/10/15, 2006/06/11, 2006/06/09, 2006/04/29,
**********************************************************************
----------------------------------------------------------------------
ADDI D_INDEX, D_DECIMAL
Add to decimal array at index. Add decimal D_DECIMAL to decimal array
value at D_INDEX and put total back in decimal array at D_INDEX. The
decimal array index D_INDEX cannot be less than 1 or greater than
10000. Other decimal array commands are ARRZ,DTOI,ITOD.
----------------------------------------------------------------------
ARRB
Blank the string array. The string array holds 2000 strings with the
index ranging from 1 to 2000. Use ARRZ to zero the decimal array.
----------------------------------------------------------------------
ARRZ
Zero the decimal array. The decimal array holds 2000 decimal values
with the index value ranging from 1 to 2000. Use ARRB to blank the
string array.
----------------------------------------------------------------------
DTOI D_INDEX, D_DECIMAL
Decimal to index. Put the decimal D_DECIMAL into the array of
decimals at index D_INDEX. The array of decimals has 10000
decimals with the index ranging from 1 to 10000. If the index
D_INDEX is outside of this range an error will occur and the
running Teapro program will end.
----------------------------------------------------------------------
ITOD D_DECIMAL, D_INDEX
Index to decimal. Get the decimal that is in the array of decimals at
index D_INDEX and put that decimal in D_DECIMAL. The array of decimals
has 2000 decimals with the index ranging from 1 to 2000. If the index
D_INDEX is outside of this range an error will occur and the running
Teapro program will end.
----------------------------------------------------------------------
ITO$ S_STRING, D_INDEX
Index to string. Get the string that is in the array of strings at
index D_INDEX and put that string in S_STRING. The array of strings
has 2000 strings with the index ranging from 1 to 2000. If the index
D_INDEX is outside of this range an error will occur and the running
Teapro program will end.
----------------------------------------------------------------------
$TOI D_INDEX, S_STRING
String to index. Put the string S_STRING in the array of strings at
index D_INDEX. The array of strings has 2000 strings with the index
ranging from 1 to 2000. If the index D_INDEX is outside of this range
an error will occur and the running Teapro program will end. S_STRING
cannot be a string append expression.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 016: Control Commands Alphabetically
Updated 2007/04/15, 2007/04/14, 2006/04/29, 2005/11/13, 2005/11/09,
**********************************************************************
In the following, the Teapro commands are in uppercase for greater
clarity. Most Teapro programmers prefer to use lower case for the
Teapro commands in their programs.
----------------------------------------------------------------------
$IFT S_STRING1 = S_STRING2
$IFT S_STRING1 = S_STRING2: $OUT "hello world"
If S_STRING1 equals S_STRING2 then perform all of the command lines
down to the matching ELSE or ENDI command. If they do not equal then
jump down to the appropriate ELSE or ENDI command. If the command line
beginning with $IFT ends with a colon and another command line, then
only that other command line is conditioned by the $IFT. That other
command line must not be a control command. You may use any of the
following compare options with $IFT: =, >, >=, <, <= or <>.
----------------------------------------------------------------------
DIFT D_DECIMAL1 = D_DECIMAL2
DIFT D_DECIMAL1 = D_DECIMAL2: $OUT "hello world"
If D_DECIMAL1 equals D_DECIMAL2 then perform all of the command lines
down to the matching ELSE or ENDI command. If they do not equal then
jump down to the appropriate ELSE or ENDI command. If the DIFT command
line is followed with a colon and another command line, then the DIFT
command line conditions only that other command line. That other
command line may not be a control command. You may use any of the
following compare options with DIFT: =, >, >=, <, <= or <>.
----------------------------------------------------------------------
DWHI D_DECIMAL1 = D_DECIMAL2
While D_DECIMAL1 equals D_DECIMAL2 perform the lines of commands down
to the matching ENDW. The following compares can be use: =, >, >=, <,
<= and <>.
----------------------------------------------------------------------
ELSE
The command ELSE is the middle part of the $IFT or DIFT, ELSE, ENDI
block. Program lines between the $IFT or DIFT and the ELSE are
performed if the condition is true. If the condition is not true then
the program lines between ELSE and the matching ENDI are performed
instead. An $IFT or DIFT and ENDI block does not have to have an ELSE
part.
----------------------------------------------------------------------
ENDI
End of if block. The command ENDI is the end command of the $IFT or
DIFT, ELSE, ENDI block. Every one of these blocks must have an ENDI
command. Without the ELSE command, this blocks allows performance of
the commands between the top part and the bottom ENDI part only if the
condition is true. See the ELSE command for how it works.
----------------------------------------------------------------------
ENDP
End program. The ENDP command ends the program.
----------------------------------------------------------------------
ENDS
The command ENDS is the ending line to subroutines.
----------------------------------------------------------------------
ENDW
The command ENDW is at the ending line of the while loop block of
lines, which began with DWHI or $WHI. While the condition of the DWHI
or $WHI command is true the loop will continue looping.
----------------------------------------------------------------------
GTAG tag_top1
This is the tag that the command "GOTO tag_top1" goes to. Both have
to be in the same subroutine. GTAG names begin with "tag_" and are
local to the subroutine they are in.
----------------------------------------------------------------------
GOTO tag_top1
Go to the line which has "GTAG tag_top1" on it. Both have to be in the
same subroutine. Each GTAG line can have many corresponding GOTO
lines.
----------------------------------------------------------------------
SUB_SOME_SUBROUTINE
Exit to subroutine SUB_some_subroutine. The name of the subroutine
must begin with "SUB_" and be no more than sixty-four characters in
total length. Exiting to a subroutine is what is meant by "calling"
it.
----------------------------------------------------------------------
SUBR SUB_SOME_SUBROUTINE
Subroutine. The command SUBR followed by a subroutine name forms the
top line in a subroutine block. The bottom line in a subroutine block
is the ENDS command. A subroutine must be called for the commands in
it to be performed. Call a subroutine using the name of it in
calculations.
----------------------------------------------------------------------
VARI D_DECIMAL1, S_STRING2, S_STRING3, S_STRING4, D_DECIMAL5
Variable declaration. Use the VARI command to declare variables which
can be in any order or of any of the two types.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 017: File Commands Alphabetically
Updated 2007/02/03, 2006/05/23, 2005/11/14, 2004/05/08
**********************************************************************
----------------------------------------------------------------------
FADD D_LONG, S_FILE, S_RECORD
File add. Add a record S_RECORD to the end of file S_FILE and put a
line feed character on the end. Put the total length added to the file
in D_LONG. The maximum length of the data that can be written is 4096.
If the command succeeds, the length written, D_LONG, to the file will
be one more than the length of S_RECORD. Use the command FAPP to add a
record to the file with a carriage return and a line feed added to the
end.
----------------------------------------------------------------------
FAPP D_LONG, S_FILE, S_RECORD
File append. Append a record S_RECORD to the end of file S_FILE and
put a carriage return and a line feed character on the end. Put the
total length added to the file in D_LONG. The maximum length of the
data that can be written is 4096. If the command succeeds, the length
written, D_LONG, to the file will be two more than the length of
S_RECORD. Use the command FADD to add a record to the file with just a
line feed on the end.
----------------------------------------------------------------------
FDEL D_YES, S_FILE
File delete. Delete the file named in S_FILE.
If the file is deleted put 1 in D_YES else put 2 in D_YES.
----------------------------------------------------------------------
FINP S_RECORD, S_FILE
File input. The file name is in S_FILE. Input that entire file into
the string S_RECORD. If the length of the file is greater than
100,000,000 bytes an error will occur.
----------------------------------------------------------------------
FLEN D_LONG, S_FILE
File length. Find the length in bytes of the file named in S_FILE and
put it into D_LONG. If the file cannot be accessed or cannot be
found put -1 in D_LONG.
----------------------------------------------------------------------
FOUT D_BYTES, S_FILE, S_RECORD
File output. The string to be outputted is in S_RECORD. Output the
entire string into the file whose name is in S_FILE. The total number
of bytes written goes in D_BYTES. The entire file will consist of what
was in S_RECORD.
----------------------------------------------------------------------
FREA S_RECORD, S_FILE, D_BYTE, D_LONG
File read. Read from the file named in S_FILE starting at byte D_BYTE
for length D_LONG and put that record into S_RECORD. In Teapro the
first byte of a file is byte 1. If the file read fails for some reason
the resulting string will have less length than hoped for. The maximum
length of the data read can be 4096 bytes.
----------------------------------------------------------------------
FREN D_YES, S_FILE2, S_FILE1
File rename. Rename the file named in S_FILE1 to the name in S_FILE2.
If the file is renamed put 1 in D_YES else put 2 in D_YES.
----------------------------------------------------------------------
FSIP S_RECORD, S_FILE, D_FILEBYTE
File sip. Sip or read a variable length record S_RECORD starting at
D_BYTE and ending in a line feed from file S_FILE and remove the line
feed. Put the beginning of the next record into D_FILEBYTE. If no
record was read put zero in D_FILEBYTE. Zero length records are
possible. You must put 1 in D_FILEBYTE for the first read. The maximum
length of the data read is 4096 bytes. Variable length records in
files end with a line feed which means they end with character = 10.
The command FSIP blanks escape characters in S_RECORD.
----------------------------------------------------------------------
FWRI D_LENGTH, S_FILE, D_BYTE, S_RECORD
File write. Write to the file named in S_FILE starting at byte D_BYTE
the string in S_RECORD. The number of bytes written goes in D_LENGTH.
In Teapro the first byte of a file is byte 1. The maximum length of
the data written can be 4096 bytes.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 018: Reading Through a File in Teapro with the Command FREA
Updated 2005/11/15, 2004/12/03
**********************************************************************
Here is a short Teapro program to show how one can read through a
file using the command FREA and to output the records to the screen.
If we were writing a program to be used for reading through files we
would add to it lines to take care of various problems which might
arise.
Comment lines explain the program line just under them. The
commands and variables are in uppercase and the comments are mostly
in lower. This is just for easy following of the program. A
programmer can use either or both cases for either or both.
----------------------------------------------------------------------
'there are no global variables in this program if there were
'some they would be defined here with the VARI command
'call the subroutine SUB_READFILE
SUB_READFILE
'the ENDP command ends the program
ENDP
'the following code is for the subroutine SUB_READFILE
SUBR SUB_READFILE
'the next two lines define the variables local to this subroutine
VARI D_RECORD, S_RECORD, S_FILENAME, D_BYTE, S_INP
VARI D_RECLENGTH, D_LONG, D_LOOP
'prompt user to enter the filename into the variable S_FILENAME
$INP S_FILENAME, "enter the file name"
'prompt the use to enter the record length into S_INP
$INP S_INP, "enter the record length"
'change S_INP to a decimal variable D_RECLENGTH
$TOD D_RECLENGTH, S_INP
'initialize D_RECORD to one for the record number
D_RECORD = 1
'set decimal variable D_LOOP to one
D_LOOP = 1
'while D_LOOP is one keep looping
DWHI D_LOOP = 1
'find the byte number to read from to get record D_RECORD
D_BYTE = D_RECORD - 1 * D_RECLENGTH + 1
'read file S_FILENAME beginning at byte D_BYTE for length
'D_RECLENGTH and put the record into S_RECORD
FREA S_RECORD, S_FILENAME, D_BYTE, D_RECLENGTH
'find length of S_RECORD and put into D_LONG
$LEN D_LONG, S_RECORD
'if D_LONG = D_RECLENGTH the do the following lines
DIFT D_LONG = D_RECLENGTH
'output S_RECORD to the screen
$OUT S_RECORD
'increment D_RECORD by one
DINC D_RECORD
'ELSE is the control command to do else in DIFT/$IFT
ELSE
'use DINC to increment D_LOOP by one
DINC D_LOOP
'ENDI is the command to end a DIFT or $IFT control command
ENDI
'ENDW is the control command to end the loop begun with DWHI
ENDW
'prompt user to hit return
$INP S_INP, "return"
'ENDS is the control command for ending a subroutine
ENDS SUB_READFILE
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 019: Reading Through a File in Teapro Using FSIP
Updated 2005/04/20
**********************************************************************
----------------------------------------------------------------------
This is similar to the chapter on reading through a file using the
FSIP command. FSIP is better suited for files with variable length
records than is the command FREA.
----------------------------------------------------------------------
'call the subroutine SUB_READFILE
SUB_READFILE
'the ENDP command ends the program
ENDP
'the following code is for the subroutine SUB_READFILE
SUBR SUB_READFILE
'the next two lines define the variables local to this subroutine
VARI S_RECORD, S_FILENAME, D_FILEBYTE, S_INP
VARI D_LONG, D_LOOP
'prompt user to enter the filename into the variable S_FILENAME
$INP S_FILENAME, "enter the file name"
'set the variable D_FILEBYTE to 1 to begin at the beginning
D_FILEBYTE = 1
'set decimal variable D_LOOP to one
D_LOOP = 1
'while D_LOOP is one keep looping
DWHI D_LOOP = 1
'read a record from S_FILENAME beginning at byte D_FILEBYTE
FSIP S_RECORD, S_FILENAME, D_FILEBYTE
'we have a good record if D_FILEBYTE is not zero
DIFT D_FILEBYTE > 0
'output S_RECORD to the screen
$OUT S_RECORD
'ELSE is the control command to do else in DIFT/$IFT
ELSE
'use DINC to increment D_LOOP by one to end the loop
DINC D_LOOP
'end the DIFT command block
ENDI
'ENDW is the control command to end the loop begun with DWHI
ENDW
'prompt user to hit return
$INP S_INP, "return"
'ENDS is the control command for ending a subroutine
ENDS SUB_READFILE
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 020: Teapro Decimal Number Arithmetic
Updated 2005/11/15, 2004/10/16
**********************************************************************
----------------------------------------------------------------------
In Teapro, numbers are called decimal numbers because they can have
digits to the right of the decimal point. They are actually binary
floating point numbers which have fifteen digit accuracy as decimal
numbers.
The accuracy is actually a little better than fifteen digits. For
example, suppose you are working with positive numbers that have no
digits to the right of the decimal. Such numbers are usually called
integers if they are all there over the applicable range and if they
can be converted to strings. The applicable range of such Teapro
decimal numbers is from 1 to 9.007E15. What this means is 9.007
times 10 raised to the 15th power. This is commonly called scientific
notation. Written out exactly this number is: 9,007,199,254,740,991.
It is actually two raised to the fifty-third power minus one.
If you begin adding one to say 9.00715E, you will shortly get a
situation such that adding one does not change the number. When this
happens you have slightly exceeded the maximum range of accuracy of
the Teapro decimal numbers. That maximum is the two raised to the
fifty-third power minus one. All of this applies similarly to negative
Teapro decimal numbers.
For business programming which does lots of addition with two decimal
money amounts, the Teapro decimal numbers should be used as whole
numbers representing the amount of money in cents. Since Teapro does
all of its arithmetic using floating point arithmetic, the only way to
guarantee the accuracy of the cents is to do all of the arithmetic
using cents instead of dollars. Binary floating point arithmetic works
best with whole integer numbers when exact accuracy is required when
adding quantities of numbers together.
The decimal number 0.10 representing ten cents is not exactly 0.10
using floating point arithmetic. This is why the addition of several
hundreds of values which have two decimal places will sometimes be off
by 0.01 or possibly more. If you divide 1 by 10 what you will get with
Teapro is the number: 0.10000000000000000555. This is using teapro.exe
compiled with Borland's C++ Builder 1.0 for Windows.
This is the reason that the two packed commands, $pkd and dpk$, use
whole numbers only. Packed decimal numbers are also called binary
coded decimal or BCD.
if you need to round a number to an integer, you can do this by doing
the command DROU which rounds away from zero as is usually used in the
business world.
If you want to truncate your non-integer decimal number to an integer
which is less than it is use the command DTRU.
If you are doing money and are using cents as your unit in order to
use whole numbers, you can output the number in dollars by doing the
following.
----------------------------------------------------------------------
D_DOLLARS = D_CENTS / 100
DED$ S_DOLLARS, D_DOLLARS, 10, 2
$OUT "The amount in dollars = " + S_DOLLARS
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 021: A Sample Teapro Program
Updated 2005/11/15
**********************************************************************
----------------------------------------------------------------------
Here is a sample program written in Teapro. Following the program is
a line by line explanation of it. Generally, a program should have
lots of comment lines. In the following program these have been
omitted to make reading the program easier. This is a rather trivial
program, but it is just a sample program for show. Blank lines are
added to make the program more readable. When you program in Teapro
use blank lines and comment lines as much as you think best, since
they do not hurt the performance of the program. Also, notice the
indentation. Indentation does not hurt performance at all and makes
the control blocks much easier to follow.
----------------------------------------------------------------------
VARI DG_PASS1
SUB_MAIN
ENDP
SUBR SUB_MAIN
VARI D_COUNT
D_COUNT = 0
DWHI D_COUNT < 5
DG_PASS1 = D_COUNT
SUB_DECIMAL_OUT
D_COUNT = DG_PASS1
ENDW
ENDS SUB_MAIN
SUBR SUB_DECIMAL_OUT
VARI D_DECIMAL, S_STRING
D_DECIMAL = DG_PASS1 + 1
DTO$ S_STRING, D_DECIMAL, 10, 0
$OUT S_STRING
DG_PASS1 = D_DECIMAL
ENDS SUB_DECIMAL_OUT
----------------------------------------------------------------------
The following is a line by line explanation of the above sample
program.
----------------------------------------------------------------------
VARI DG_PASS1
The above line defines a global decimal variable to be used to pass a
decimal from one subroutine to the other. It is also used to pass a
decimal from the second subroutine back to the subroutine calling it.
----------------------------------------------------------------------
SUB_MAIN
This line calls the subroutine SUB_MAIN.
----------------------------------------------------------------------
ENDP
This line marks the end of a Teapro program. The Teapro interpreter
stops at this line.
----------------------------------------------------------------------
SUBR SUB_MAIN
This line is the first line of the subroutine SUB_MAIN.
----------------------------------------------------------------------
VARI D_COUNT
This line creates a local decimal variable D_COUNT which is only
visible in the subroutine SUB_MAIN. It will be used as a counter to
count the number of times the subroutine SUB_DECIMAL_OUT is called.
----------------------------------------------------------------------
D_COUNT = 0
This line assigns the value zero to the local decimal variable
D_COUNT.
----------------------------------------------------------------------
DWHI D_COUNT < 5
This is the first line of a while loop which ends with the line ENDW
a few lines on down. The lines within this loop are performed while
the decimal variable D_COUNT is less than five. At that point the
control of the program falls out of the loop.
----------------------------------------------------------------------
DG_PASS1 = D_COUNT
This line puts the local decimal variable D_COUNT into the global
decimal variable DG_PASS1 to send the value of D_COUNT to the
subroutine SUB_DECIMAL_OUT which is then called on the next line.
----------------------------------------------------------------------
SUB_DECIMAL_OUT
This line calls the subroutine SUB_DECIMAL_OUT.
----------------------------------------------------------------------
D_COUNT = DG_PASS1
This line assigns the decimal value sent back by the subroutine to
the local decimal variable D_COUNT.
----------------------------------------------------------------------
ENDW
This line marks the bottom of the while loop begun earlier.
----------------------------------------------------------------------
ENDS SUB_MAIN
This line is the end of the SUB_MAIN subroutine. The name of the
subroutine is not required but makes the program more readable.
----------------------------------------------------------------------
SUBR SUB_DECIMAL_OUT
The above line is the first line of a subroutine named
SUB_DECIMAL_OUT. The name of a subroutine must begin with "sub_" and
must be no more than 20 characters. Other underline characters may be
used in names of subroutines but not in variable names.
----------------------------------------------------------------------
VARI D_DECIMAL, S_STRING
The above line defines two local variables to this subroutine. One is
a decimal named: D_DECIMAL. The other is a string named S_STRING.
Variable names must be no more than 20 characters and must have one
underline character but no more. Local variable names begin with D_ or
S_ depending upon which type of variable they are. Global variables
which are defined at the top of the program and are not in a
subroutine must begin with DG_ or SG_.
----------------------------------------------------------------------
D_DECIMAL = DG_PASS1 + 1
The above is a decimal assignment command. Take the part to the right
of the equal sign and evaluate is strictly left to right using the
operators to determine whether to add, subtract, multiply, divide, mod
or do integer division. In this case take the global decimal variable
DG_PASS1, add 1 to it and put that into the local decimal variable
D_DECIMAL. The global decimal variable DG_PASS1 is bringing a decimal
value into this subroutine as though the calling of the subroutine had
a parameter.
----------------------------------------------------------------------
DTO$ S_STRING, D_DECIMAL, 10, 0
The above command is called decimal to string. It changes the local
decimal variable D_DECIMAL into a string of minimum length 10 and puts
the string into local string variable S_STRING. The decimal in the
string of minimum length 10 is right justified. The fourth parameter
of 0 means to truncate to 0 decimal positions.
----------------------------------------------------------------------
$OUT S_STRING
The above command is the string out command. It outputs the local
string variable S_STRING to the output window bottom line of the
Teapro interpreter.
----------------------------------------------------------------------
DG_PASS1 = D_DECIMAL
The above command is a decimal assignment command. It assigns the
decimal in D_DECIMAL to the global variable DG_PASS1 in order to send
it back to the subroutine that called this subroutine. The decimal
variable D_DECIMAL is a local variable which can only be used in this
subroutine. In other places this variable cannot even be seen to exist
at all. In order to get the value of D_DECIMAL out of this subroutine
it is necessary to assign that value to a global variable to get it
back to the subroutine which called this subroutine.
----------------------------------------------------------------------
ENDS SUB_DECIMAL_OUT
The above is the end subroutine command. It marks the end of the
subroutine SUB_DECIMAL_OUT. It is not necessary to have the name of
the subroutine follow the command but it helps to make the listing
more readable.
----------------------------------------------------------------------
The output of this sample program would look like the following.
----------------------------------------------------------------------
1
2
3
4
5
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 022: The OpenTea Technology Used in Teapro
Updated 2005/11/16, 2005/11/15, 2004/04/01
**********************************************************************
----------------------------------------------------------------------
The following are the specific constructs which make up the OpenTea
Programming Language Technology. The OpenTea Technology is what makes
the interpreted language Teapro so simple, so useful and so much
different from other modern computer programming languages. All of
this information is discussed earlier but is here summarized.
----------------------------------------------------------------------
1. File processing commands have the file name as a parameter in a
string variable so that those commands can both open and then close
the file. No file is ever left open from one command to another.
----------------------------------------------------------------------
2. Order of operation in assignment commands is done strictly left to
right for greatly improved simplicity. The part to the right of the
equal sign is not an algebraic expression as in other languages which
has to be solved algebraically. Decimal expressions are not allowed in
other commands in Teapro. A number to divide by cannot become zero
during the evaluation of the decimal assignment command.
----------------------------------------------------------------------
3. There are only two kinds of variables. All Teapro variables are
either strings or decimal numbers. Most other languages have a half
dozen or more types of variables. Each of the variable types can
either be a variable or a constant of that variable type. Each of the
variable types can be a global variable or a local variable.
----------------------------------------------------------------------
4. The programmer can only write subroutines and not functions. There
are no functions in Teapro. Commands cannot be combined together on
one line as is done in languages which have functions.
----------------------------------------------------------------------
5. Values are passed from subroutine to subroutine using generic
global variables rather than with parameters.
----------------------------------------------------------------------
6. Teapro programs are generally structured. While there are the
commands GOTO and GTAG, without using them programs must be strictly
structured.
----------------------------------------------------------------------
7. The program which is the Teapro interpreter is small, uses few
resources and requires no .DLL files other than those in the operating
system. The Teapro interpreter can be copied from computer to computer
by using a diskette. Since it is so small it does not need a multi
diskette installation. In fact, it does not need to be installed at
all. The Teapro interpreter and the Teapro program to be run can be
run off of a diskette.
----------------------------------------------------------------------
8. The string handling commands do insert, delete and replace. Other
languages do not have each of these three. The two string search
commands in Teapro allow the programmer to search both forwards and
backwards in a string starting at any particular byte. Strings can
also be sorted not only as length one strings but also as length
greater than one strings.
----------------------------------------------------------------------
9. Compares are single compares in the control commands DIFT, DWHI,
$IFT, and $WHI. In Teapro compares may not be strung together with
"and" or "or" as in other languages. Use nesting to accomplish the
same thing as multiple compares. Nesting of compares is much easier to
understand, and is much more straightforward.
----------------------------------------------------------------------
10. Teapro has two commands $pkd and dpk$ for turning decimal numbers
into strings of packed format and for the same reversed. Older
business languages such as COBOL and RPG store numbers in records
using this packed format. Packed decimal format is also called binary
coded decimal or BCD.
----------------------------------------------------------------------
11. Expressions are generally not allowed in Teapro. Expressions are
algebraic problems which must be evaluated to obtain the value needed.
In Teapro you cannot use 3 * 8 to mean 24. The minus sign is an
operator used only in the assignment command.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 023: Teapro Console Commands for teapro.exe
Updated 2005/09/10, 2005/07/31, 2005/06/15, 2005/04/21, 2005/04/09,
**********************************************************************
----------------------------------------------------------------------
Before getting into the console commands for the program teapro.exe,
the command line parameter needs to be explained. On the command line
after the program teapro.exe a parameter may be placed, for example:
C:\TEST\teapro.exe tinytea.tea
What this will do is to load and run the program tinytea.tea after
the teapro.exe has started. Then, when the program tinytea.tea has
ended the teapro.exe interpreter will also end.
The Teapro program tinytea.tea is used for testing all of the Teapro
commands and for heavy prime number testing. It is used for finding
the prime numbers 5TP39, ie. 10 twin primes in 39 numbers.
It is not necessary to put the name of the Teapro program as a
parameter on the command line. If there is not parameter, the
interpreter teapro.exe will come up as a console application in which
case the following console commands may be performed.
----------------------------------------------------------------------
DEBUG
This command is used to turn DEBUG on. In a teapro program debug can
be toggled with the DBUG program command.
----------------------------------------------------------------------
INFO
This command gives information about some of the limitations of a
teapro program such as total maximum program lines.
----------------------------------------------------------------------
LOAD
Use this command to get the Teapro interpreter to ask for a Teapro
program name to be loaded.
----------------------------------------------------------------------
RUN
This command runs the program that has just been loaded.
----------------------------------------------------------------------
SHOW
This command allows you to show the loaded program to see how the
teapro prep has changed the original program in preparation to having
it ready to run. When in SHOW mode you can enter a line number to
begin listing at that line. You can enter SUBR to list only the Teapro
program subroutines.
----------------------------------------------------------------------
STEP
This command turns on STEP so that the program stops before each
Teapro program line and shows the line. The user can then hit return
to continue the Teapro program.
----------------------------------------------------------------------
SUBR
This command causes the Teapro interpreter to show each Teapro
program subroutine line on the console when it is called.
----------------------------------------------------------------------
TRACE
This command causes the teapro interpreter to show each program line
before performing it.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 024: Variables and How They are Named
Updated 2007/02/03, 2005/09/10, 2005/09/03, 2005/07/31, 2005/07/27,
**********************************************************************
----------------------------------------------------------------------
In Teapro there are two kinds of variables. There are decimal
variables which are fifteen digit floating point variables. There are
strings which can be as long as 100,000,000 characters.
Variables can be global or local. Global variables can be seen by all
parts of the running Teapro program. Local variables can be seen only
within the subroutine in which they are defined.
Global decimal variables have names which begin with DG_ with the
rest of the variable name made up of letters and numbers. Local
decimal variables have names which begin with D_ with the rest of the
variable name made up of letters and numbers. Either upper or lower
case is OK. Variable names must be at least five characters long but
may be upto about sixty long.
Global string variables have names which begin with SG_ with the rest
of the variable name made up of letters and numbers. Local string
variables have names which begin with S_ with the rest of the variable
name made up of letters and numbers. Either upper or lower case is OK.
Variable names must be at least five characters long but may be upto
about sixty long.
Case of commands and variable names does not matter in Teapro. Names
such as D_ANY, D_ANY, d_Any, D_aNy, etc. are all the same in Teapro.
Literal numbers can only have upto five digits with no decimal. They
may have a + or - sign in front of them that does not count towards
the length of 5.
"hello world" is a string literal.
Also, #hello world# is a string literal.
In this booklet, variables and commands will generally be given in
uppercase so they will stand out.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 025: Decimal and String Expressions in Teapro
Updated 2007/08/01, 2007/07/23, 2007/07/08, 2007/05/04, 2007/04/14,
**********************************************************************
----------------------------------------------------------------------
The decimal assignment expression:
D_NUMBER = - D_TOTAL * 3 + D_ANY / -14 % 2 \ D_DOT
The above is a decimal assignment command expression. In Teapro
only the decimal assignment command can have a decimal expression.
Only the operators +, -, *, /, %, \, @, ? can be used. These
operators have the following meanings:
+ means to add term1 and term2
- means to subtract term2 from term1
* means to multiply term1 and term2
/ means to divide term1 by term2
% means round and find modulus of term1 using absolute of term2.
The sign of a mod result is the same as the mod of term.
\ means round both and do an integer divide term1 by term2
^ means raise term1 to power term2.
@ means to round term1 to number of decimal positions in term2.
? means to truncate term1 to number of decimal positions in term2.
A decimal assignment expression may be upto 200 bytes in length.
The operations are done strictly left to right. Here is an
example:
$TOD D_NUMBER, "-123,456,789.012345"
D_ANSWER = D_NUMBER * -45218
You cannot use a number like -123,456,789.012345 in a decimal
assignment expression, so you must put it into a decimal variable and
then use that variable in the decimal assignment expression.
Note that there is no command in the decimal assignment command line.
When the program is running it puts DSET in front of the decimal
assignment command line. You can use DSET as the command in front of
your decimal assignment expressions but it is not needed. For example:
DSET D_ANSWER = D_NUMBER * -45218
----------------------------------------------------------------------
The string expression:
S_STRING = "Count=" + D_COUNT + ", string=" + S_ANY
The above is the string assigment command with a string append
expression. A string append expression can be used as the last
parameter with five Teapro commands. These are $APP,$INP,$OUT,$SHO and
the string assignment command.
Note that in the string assignment command that there is no actual
command. The program automatically puts $SET in front of the string
assignment command when preparing a Teapro program to run. You can use
$SET but it is not needed. For example:
$SET S_ANY = S_DOT + " HELLO THERE " + # AGAIN # + " 123.45"
Note here that you can enclose literal strings in either " or #. In
this way if you need either of them in a literal string you can use
the other one to enclose the string.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 026: Teapro D-Commands Alphabetically
Updated 2008/03/30, 2007/10/15, 2007/07/23, 2007/07/08, 2007/03/04,
**********************************************************************
----------------------------------------------------------------------
DABS D_RESULT, D_NUMBER
Absolute value. Put the absolute value of D_NUMBER into D_RESULT.
----------------------------------------------------------------------
DARC D_RADIANS, D_SIN
Get the arcsine of a number. Put the arcsine of sine D_SIN into
D_RADIANS. D_SIN is made to be 1 if greater than 1 and is made to be
-1 if less than -1.
----------------------------------------------------------------------
DBAD D_NUMBER1 >= D_NUMBER2
Bad decimal variable test. If the condition is true, then we have
an error and the running Teapro program will end. DBAD is quick
and is to be used only for testing for near disaster situations.
Any of the standard tests can be used ie. <, >, =, <=, >=, <>.
----------------------------------------------------------------------
DBUG
The teapro command DBUG toggles debug mode. By rights it should be
EBUG instead since it is more of a control command. The opportunity to
name a command DBUG was just too much to resist.
----------------------------------------------------------------------
DCH$ S_STRING, D_CHAR, D_LONG
Decimal character to string. Make a string S_STRING of the character
corresponding to D_CHAR of length D_LONG.
----------------------------------------------------------------------
DDEC D_DECIMAL
Decrement D_DECIMAL by 1.
----------------------------------------------------------------------
DED$ S_STRING, D_DECIMAL, D_LONG, D_PLACES
Decimal edit to string. Change D_DECIMAL into string S_STRING, and
give it a length of at least D_LONG, right justified. Show the number
of decimal positions in D_PLACES. Separate 1000's with commas. The
command DTO$ is the same but does not put in commas. If D_LONG and
D_PLACES are both zero then the number will be its natural length with
no leading zeros and no trailing zeros to the right of the decimal.
----------------------------------------------------------------------
DFAC D_FACTOR, D_NUMBER
Find the lowest integer factor of D_NUMBER greater than one and put
it in D_FACTOR. If there are none greater than one put one in
D_FACTOR. If D_FACTOR ends up with one then D_NUMBER is prime.
DFAC only works for numbers less than 2^53 or 9,007,199,254,740,992.
For large numbers upto 4E20 use the Teapro command DFAK.
----------------------------------------------------------------------
DFAK D_FACTOR, D_1QUADPART, D_1QUADMULT
Find the lowest factor of a test number such that D_1QUADPART is the
part of the test number less than 1E15 and D_1QUADMULT is the number
of quadrillions, ie. 1E15, of the test number. For example, suppose
the test number is 123,456,789,012,345,678,901. The part below 1E15 is
789,012,345,678,901 and this would be put into D_1QUADPART as it is
the PART below 1E15. Into D_1QUADMULT we would need to put 123,456 as
it is the number of quadrillions, ie 1E15. This test number has a
D_FACTOR of 11. Another test number is 108,000,000,000,000,001. Into
D_1QUADPART we put 1. Into D_1QUADMULT we put 108. DFAK gives 1 for
D_FACTOR meaning that this test number is prime. DFAK will work for
sure only if D_1QUADMULT is 400,000 or less.
This is the Teaquad method of testing large numbers for primeness.
----------------------------------------------------------------------
DIFT D_DECIMAL1 = D_DECIMAL2
DIFT D_DECIMAL1 = D_DECIMAL2: $OUT "hello there"
If D_DECIMAL1 equals D_DECIMAL2 then perform all of the command lines
down to the matching ELSE or ENDI command. If they do not equal then
jump down to the appropriate ELSE or ENDI command.
If the DIFT command line is followed with a colon and another command
line, then the DIFT command line conditions only that other command
line. That other command line may not be a control command.
You may use any of the following compare options with DIFT:
=, >, >=, <, <= or <>.
----------------------------------------------------------------------
DINC D_DECIMAL
Decimal increment. Increment D_DECIMAL by one.
----------------------------------------------------------------------
DLOG D_LOG, D_NUMBER
Logarithm of base 10. Put the common or base 10 logarithm of D_NUMBER
into D_LOG. D_NUMBER is made positive if negative and D_LOG is zero
if D_NUMBER is zero.
----------------------------------------------------------------------
DPK$ S_STRING, D_DECIMAL, D_LONG
Decimal number to a packed format string. Round D_DECIMAL to a whole
number and then change it into a string of packed format of length
D_LONG. Packed decimal format is also called binary coded decimal or
BCD.
----------------------------------------------------------------------
DPOW D_RESULT, D_NUMBER, D_POWER
Raise D_NUMBER to power D_POWER and put into D_RESULT. D_NUMBER
must be greater than zero. If D_NUMBER is negative and D_POWER is
not an integer then make D_NUMBER positive first.
----------------------------------------------------------------------
DRAN D_RANDOM
Put a decimal random number between 0 and 1 in D_RANDOM.
----------------------------------------------------------------------
DROU D_NEW, D_OLD
Round decimal number to integer. Round decimal number D_OLD and put
the result in D_NEW. A decimal amount of 0.5 is rounded away from
zero.
----------------------------------------------------------------------
DSEC D_SECONDS
Put seconds in D_SECONDS. This is used to time various events. The
difference between two calls of this command will be the time in
seconds that has passed.
----------------------------------------------------------------------
DSIN D_SIN, D_RADIANS
Sine of a number. Put the sine of number D_RADIANS which is an angle
in radians into D_SIN. If D_RADIANS > 2*PI then D_RADIANS is made to
be 2*PI. If D_RADIANS < -2*PI then D_RADIANS is made to be -2*PI.
----------------------------------------------------------------------
D_RESULT = -D_NUM1 * D_NUM2 - D_NUM3 / D_NUM3 % D_NUM4 \ D_NUM5
DSET D_RESULT = -D_NUM1 * D_NUM2 - D_NUM3 / D_NUM3 % D_NUM4 \ D_NUM5
Decimal set. The right side is evaluated strictly left to right. It
is preferred here to omit the DSET command altogether. The operators
are:
+ is add
- is subtract
* is multiply
/ is divide
% is round both to an integer and find the mod.
The sign of a mod result is the same as the mod of term.
\ round both to an integer and do an integer divide.
^ means to raise to a power.
@ means to round to a number of decimal places.
? means to truncate to a number of decimal places.
Literal numbers can be used as the decimal variables are used if the
numbers are -99999 to +99999 with no decimal places.
----------------------------------------------------------------------
DSYS D_AMOUNT, D_NUMBER
Decimal system info.
D_NUMBER=1 means put total string length in D_AMOUNT.
D_NUMBER=2 means put lines of Teapro done in D_AMOUNT.
----------------------------------------------------------------------
DTO$ S_STRING, D_DECIMAL, D_LONG, D_PLACES
Decimal to string. Change D_DECIMAL into string S_STRING, and give it
a length of at least D_LONG, right justified. Show the number of
decimal positions in D_PLACES. Do not put in commas as in DED$. If
D_LONG and D_PLACES are both zero then the number will be its natural
length with no leading zeros and no trailing zeros to the right of the
decimal.
----------------------------------------------------------------------
DTOF S_STRING, D_DECIMAL, D_LONG
Decimal to field. Change decimal D_DECIMAL into a string S_STRING of
length D_LONG such that S_STRING begins with + or -, is right
justified and zero filled. This format is needed many times for a
field in a record. The decimal D_DECIMAL is rounded to a whole number.
----------------------------------------------------------------------
DTOI D_INDEX, D_DECIMAL
Decimal to index. Put the decimal D_DECIMAL into the array of
decimals at index D_INDEX. The array of decimals has 10000
decimals with the index ranging from 1 to 10000. If the index
D_INDEX is outside of this range an error will occur and the
running Teapro program will end.
----------------------------------------------------------------------
DTRU D_NEW, D_OLD
Truncate decimal number. Truncate decimal number D_OLD and put the
result in D_NEW. If D_OLD is not an integer, D_NEW will be closer to
zero than D_OLD.
----------------------------------------------------------------------
DWHI D_DECIMAL1 < D_DECIMAL2
Decimal while. While D_DECIMAL1 is less than D_DECIMAL2 perform
the lines of commands down to the matching ENDW;
otherwise, jump to line right after the ENDW. The
following compares can be use: =, >, >=, <, <= and <>.
----------------------------------------------------------------------
**********************************************************************
CHAPTER: 027: Teapro $-Commands Alphabetically
Updated 2008/02/06, 2007/02/03, 2006/06/11, 2006/06/02, 2006/06/01,
**********************************************************************
----------------------------------------------------------------------
$APP S_STRING1, S_STRING2
String append. Put S_STRING1 + S_STRING2 into S_STRING1. The string
S_STRING2 can be a string append expression. Creating a string longer
than 100,000,000 bytes will cause an error.
----------------------------------------------------------------------
$BAK D_BYTE, S_LOOKIN, D_START, S_LOOKFOR
Back lookup. Using S_LOOKIN starting at byte D_START backwardly
search or look for S_LOOKFOR. If it is found put the number of the
first byte into D_BYTE and if it is not found put zero into D_BYTE.
----------------------------------------------------------------------
$BES S_NEW, S_OLD
Blank escape characters in S_OLD and store the string in S_NEW. An
escape character is one whose number is less than 32.
----------------------------------------------------------------------
$CH$ S_NEW, S_CHAR, D_LONG
String character to string. Make S_NEW of length D_LONG of the first
character of S_CHAR. Creating a string longer than 100,000,000 bytes
will cause an error.
----------------------------------------------------------------------
$CHD D_CHAR, S_CHAR
String character to decimal. Find the character number of the first
character of S_CHAR and put that number into D_CHAR.
----------------------------------------------------------------------
$CLO S_NEW, S_OLD
Make case lower. Make S_OLD lower case and store in S_NEW.
----------------------------------------------------------------------
$CNT D_COUNT, S_STRING, S_FIND
Put count of occurrences of S_FIND in S_STRING into D_COUNT.
Occurrences cannot overlap.
----------------------------------------------------------------------
$COD S_NEW, S_OLD
Code S_OLD into S_NEW. Code and decode are the same operation.
This is an entirely different type of encryption from $TOE.
----------------------------------------------------------------------
$CUP S_NEW, S_OLD
Case make upper. Make S_OLD uppercase and store in S_NEW.
----------------------------------------------------------------------
$CUT S_PARTSTRING, S_WHOLESTRING, D_BYTE, D_LONG
Cut string from string. Put into S_PARTSTRING a portion of
S_WHOLESTRING starting at byte D_BYTE for length D_LONG.
----------------------------------------------------------------------
$DAT S_DATE
Put the date as a string into S_DATE. The date string contains the
date and time in two formats:
"22-MAR-2002 21:28:16 20020322212816".
----------------------------------------------------------------------
$DEL S_STRING, D_BEG, D_LONG
String delete. In string S_STRING starting at D_BEG delete the bytes
for a length of D_LONG.
----------------------------------------------------------------------
$DOT D_DOT, S_STRING1, S_STRING2, D_WHICH
Find certain string occurrence and put location in d_dot. Find
occurrence d_which of s_string2 in s_string1 and put the number of
the first byte of that occurrence into d_dot. Occurrences of
s_string2 cannot overlap a previous occurrence. If the wanted
occurrence of the wanted string is not found then put zero into
D_DOT.
----------------------------------------------------------------------
$HSH D_HASH, S_STRING
String hash. Create a hash number D_HASH that is fairly unique for
the string S_STRING. The hash decimal number D_HASH can be 15 digits
long. The first 9 are merely a total of the char numbers of the bytes
in the file. The last six represent a total of the char numbers times
the positions in records which are 701 bytes long. 701 is prime.
Char numbers run from 1 to 256 for these calculations.
----------------------------------------------------------------------
$IFT S_STRING1 = S_STRING2
$IFT S_STRING1 = S_STRING2: $OUT "hello world"
If S_STRING1 equals S_STRING2 then perform all of the command lines
down to the matching ELSE or ENDI command. If they do not equal then
jump down to the appropriate ELSE or ENDI command.
If the command line beginning with $IFT ends with a colon and another
command line, then only that other command line is conditioned by the
$IFT. That other command line must not be a control command.
You may use any of the following compare options with $IFT:
= is equal to
< is less than
<= is less than or equal to
<> is not equal to
> is greater than
>= is greater than or equal to
----------------------------------------------------------------------
$INP S_INPUT, S_OUTPUT
Output S_OUTPUT to screen and input from the keyboard S_INPUT.
S_OUTPUT can be a string expression. For security, the maximum length
of S_INPUT for $INP is 100 bytes for security.
----------------------------------------------------------------------
$INS S_WHOLESTRING, D_BYTE, S_PARTSTRING
Insert string into string. Insert into S_WHOLESTRING starting at byte
D_BYTE the string S_PARTSTRING. If D_BYTE is the length of
S_WHOLESTRING plus one then S_PARTSTRING is appended at the end.
Creating a string longer than 100,000,000 bytes will cause an error.
----------------------------------------------------------------------
$ISC D_YESNO, S_STRING, S_CHAR
String is a string of characters S_CHAR? If S_STRING is a string of
the first character of S_CHAR then put 1 in D_YESNO else 2.
----------------------------------------------------------------------
$ISD D_YESNO, S_STRING
String is decimal. If string S_STRING is a decimal number then put 1
in D_YESNO otherwise put 2 in D_YESNO.
----------------------------------------------------------------------
$ISP D_YESNO, S_STRING, S_PATTERN
String S_STRING is a type pattern match with string S_PATTERN.
Compare S_STRING and S_PATTERN to see if the pattern of types match.
If yes then put a 1 in D_YESNO. If not put a 2 in D_YESNO. Types of
characters are: escapes, blanks, punctuation, numbers, uppers, lowers,
and char greater than #126. The two strings must also be the same
length.
----------------------------------------------------------------------
$IST D_YESNO, S_STRING, S_TYPE
String S_STRING is made up of characters of the same type as the
first character of S_TYPE. If yes then put 1 in D_YESNO. If no then
put 2 in D_YESNO. Types of characters are: escapes, blanks,
punctuation, numbers, uppers, lowers, and char greater than #126.
----------------------------------------------------------------------
$LEN D_LONG, S_STRING
String length. Put length of string S_STRING into D_LONG.
----------------------------------------------------------------------
$LOK D_BYTE, S_WHOLESTRING, D_START, S_PARTSTRING
Look for S_PARTSTRING in S_WHOLESTRING starting at byte D_START. If
it is found put the beginning byte number in D_BYTE. If it is not
found put zero in D_BYTE.
----------------------------------------------------------------------
$OFF S_RESULT, S_STRING, D_LONG
Cut off end of string S_STRING for D_LONG bytes and store it in
S_RESULT.
----------------------------------------------------------------------
$OUT S_OUTPUT
String out. Output to the screen S_OUTPUT. S_OUTPUT can be a string
expression made up of string variables and literals as well as decimal
variables. $OUT does a carriage return and line feed at the end to
move the line up.
----------------------------------------------------------------------
$PAR S_TOEXTRACT, S_CSV, S_CHAR, D_WHICH
Parse a string. Extract string S_TOEXTRACT from the character
separated value string S_CSV indicated by number D_WHICH. Strings in
S_CSV are separated by occurrences of S_CHAR. The length of S_CHAR
must be 1. If D_WHICH=1 then return the string ending with the first
occurrence of S_CHAR. If D_WHICH=6 return the string ending with the
sixth occurrence of S_CHAR.
----------------------------------------------------------------------
$PKD D_YESNO, D_DECIMAL, S_STRING
String in packed format to decimal. Convert the packed format number
in S_STRING into a whole number decimal D_DECIMAL. Packed decimal
format is also called BCD or binary coded decimal. If S_STRING can be
converted to a decimal number put 1 in D_YESNO otherwise put 2 in
D_YESNO.
----------------------------------------------------------------------
$REP S_WHOLESTRING, D_BYTE, S_PARTSTRING
Replace part of a string with another string. In S_WHOLESTRING
starting at byte D_BYTE replace the bytes with S_PARTSTRING. The
length of S_WHOLESTRING is never changed by this command.
----------------------------------------------------------------------
$SET S_STRING1 = S_STRING2 + " hello there " + S_STRING3 + # WOW #
String set. This is the string assignment command in Teapro. It is
actually preferred to omit the $SET command at the beginning. Notice
that string literals may be enclosed in double quotes or pound signs.
----------------------------------------------------------------------
$SHO S_OUTPUT
String show. Output to the screen S_OUTPUT. S_OUTPUT can be a string
expression made up of string variables and literals as well as decimal
variables. $SHO does not do a carriage return and a newline
afterwards.
----------------------------------------------------------------------
$SOR S_NEW, S_OLD, D_LONG
Sort string. Sort the string S_OLD into string S_NEW by sections each
D_LONG in length.
----------------------------------------------------------------------
$SWP S_STRING, S_OLD, S_NEW
String swap. In S_STRING replace each occurrence of S_OLD with S_NEW.
----------------------------------------------------------------------
$SYS S_INFO, D_WHICH
System or program information to S_INFO depending on D_WHICH.
1 = path and filename of this running Teapro Interpreter
2 = current subroutine name of Teapro program
3 = version of current Teapro program
----------------------------------------------------------------------
$TLO S_NEW, S_OLD
String trim low. Trim string S_NEW and make lower case. Then put it
into S_OLD.
----------------------------------------------------------------------
$TOD D_DECIMAL, S_STRING
String to decimal. Convert the string in S_STRING to a decimal number
and store it in decimal variable D_DECIMAL. If S_STRING cannot be
converted to a decimal number an error occurs. Usually, one should use
$ISD to test S_STRING first to see if it can be converted to a
decimal.
----------------------------------------------------------------------
$TOE S_NEW, S_OLD, S_KEY, D_WHICH
String to encoded. Code S_OLD into S_NEW using key S_KEY. If
D_WHICH=1 encode. If D_WHICH=2 then decode. S_KEY must be letters
and numbers, and is not case sensitive. This encryption is about
26 bit in strength which makes it pretty weak. There are only
61,000,001 possible keys. This is an entirely different type of
encryption from $COD.
----------------------------------------------------------------------
$TOI D_INDEX, S_STRING
String to index. Put the string S_STRING in the array of strings at
index D_INDEX. The array of strings has 2000 strings with the index
ranging from 1 to 2000. If the index D_INDEX is outside of this range
an error will occur which will cause the running Teapro program to
end. S_STRING cannot be a string append expression.
----------------------------------------------------------------------
$TRB S_NEW, S_OLD
Trim the blanks and escape characters from both ends of S_OLD and put
the string in S_NEW.
----------------------------------------------------------------------
$TRL S_NEW, S_OLD
Trim the blanks and escape characters from the left end of S_OLD and
put the string in