Copyright (C) 1998-2005 MKTMK Moscow, Russia

http://www.mktmk.narod.ru.

e-mail: mktmk <at> narod.ru

 

 

Interpreter Open Basic.

Users Guide.

Version 1.50.

 

Summary

 

 

Open Basic (OB) is realization of the interpreter of language Basic.

OB is developed for embed to user application as a script language.

User may attach (connect) user function to Open Basic execution system.

The user functions can be written on C/C++, assembler or others

languages.

The user functions can receive parameters from the Basic-program and return results to Basic-program.

Program interface of user functions allows determine type and order of parameters at run-time.

OB realizes a subset of commands of language Basic.

OB it is written completely on C++ and it is realized as a class with a name ob_obasic.

OB supports data of three types: floating point, signed integer, and string and arrays of these types.

OB has multithread-safe code.

 

In this document is described:

- How to use interpreter Open Basic

- Syntax of operators Open Basic

- The interface to data Open Basic from user functions

- Rules of attach of user functions

- Types of data Open Basic

- Debugging tools

 

OB does not use any graphic libraries.

OB does not use any system calls of any OS.

 

The Manufacturer

 

Copyright (C) 1998-2005 MKTMK Moscow, Russia

http://www.mktmk.narod.ru.

e-mail: mktmk <at> narod.ru

 

MKTMK software company. Moscow, Russia

Feedback

 

If you use interpreter, and want to know about new versions and about changes, please write on e-mail.

 

MKTMK software company is interested in experience of application of the interpreter:

- For what you apply the interpreter

- Your compiler and number of it version

- Error in the program

- Quality of the documentation and error in the documentation

- Whether you connected the user functions

- What remarks to the interface of the user functions

- What is your OS

- Whence you found out about the interpreter

 

These data will help us at support of the program.

 

Guarantees

 

The interpreter and the documentation provide "as is" without warranty of any kind.

 

We shall be grateful for all errors found in the program.

 

Trademarks

 

Company names and product names, which appear in this Users Guide, are the trademarks or registered trademarks of the respective companies.

 

List of files

 

Documentation

 

.\htm

read_rus.htm users guide in Russian

read_eng.htm - users guide in English

shortrus.htm - brief users guide of methods of class ob_obasic in Russian

shorteng.htm - brief users guide of methods of class ob_obasic in English

 

Libraries

 

.\lib

ob15_1.lib - library Open Basic for Borland C ++ Builder v6.0

ob15_2.lib - library Open Basic for MSVC v7.0

libob15.a - library Open Basic for GCC v3.2.2 for Linux i386

 

Examples use Open Basic as console application

 

.\exe

ob15_1.exe - console application Open Basic Borland C ++ Builder v6.0

for more help use ? switch.

ob15_2.exe - console application Open Basic MSVS v7.0

ob15_3 - console application Open Basic GCC v3.2.2 for Linux i386

 

Source code of console application

 

.\example

ob.cpp - main() of example ob15_*.exe, user

functions, examples of their connection

comline.cpp - functions for analysis of the command line

comline.h - functions for analysis of the command line

 

Source code

 

.\include

mstore.h - policy

mvect.h - vector

mlist.h - list

mstack.h - stack

mhash.h - hash-table

ob.h - main header file of Open Basic

 

.\source

ob1.cpp - realization of the interpreter

ob2.cpp - realization of the interpreter

ob3.cpp - realization of the interpreter

ob4.cpp - realization of the interpreter

ob5.cpp - realization of the interpreter

ob6.cpp - realization of the interpreter

ob7.cpp - realization of the interpreter

ob8.cpp - realization of the interpreter

ob9.cpp - realization of the interpreter

ob10.cpp - realization of the interpreter

 

Examples *.bas programs

 

.\bas

test0.bas

test1.bas

test2.bas

test3.bas

test4.bas

test5.bas

test6.bas

test7.bas

test8.bas

test9.bas

test10.bas

test11.bas

test12.bas

test13.bas

test14.bas

test15.bas

test16.bas

test17.bas

test18.bas

test19.bas

test20.bas - files of examples which can execute by ob15_*.exe

 

Contents

 

Summary. 1

The Manufacturer 1

Feedback. 1

Guarantees. 2

Trademarks. 2

List of files. 2

1. The description of problem and purpose of the program.. 5

2. Conditions of application. 6

3. The input and output data. 6

3.1. How to use the interpreter. How to load and start *.bas program. 6

3.2. Review of technical decisions. 7

3.3. Description of methods and enumeration of class ob_obasic, which are used for loading and start *.bas programs 8

3.3.1. Constructor ob_obasic. 8

3.3.2. Enumeration typeload. 8

3.3.3. Method load. 9

3.3.4. Enumeration typeend. 9

3.3.5. Method run. 10

3.4. Methods and enumerations of class ob_obasic are used for the organization of debugging in interpreter 10

3.4.1. Enumerations step. 11

3.4.2. Method setstep. 11

3.4.3. Method getstep. 11

3.4.4. Function ob_loadbreakstr 11

3.4.5. Enumerations ob_operator::flbreak. 12

3.4.6. Method setoperatorbreak. 12

3.4.7. Method getcurrentoperatorname. 13

3.4.8. Methods setin and setout. 13

3.4.9. Enumerations ob_lex::typelex. 13

3.4.10. Methods gettypenextlex and restoreinputpointer. 13

3.5. Syntax of language Open Basic. 14

3.6. Types of the data, names and labels Open Basic. 14

3.7. User functions in Open Basic. 16

3.7.1. Type of returned value for user Functions. 16

3.7.2. Prototypes for the user function. 17

3.7.3. Choice of Basic name of user function. 18

3.7.4. Connection user function to execution system OB.. 18

3.8. Methods and enumerations of class ob_obasic for connection and disconnection user functions. 20

3.8.1. Enumerations ob_type_del 20

3.8.2. Methods setfun. 20

3.8.3. Methods delfun. 21

3.9. Purpose of parameters of user functions. 21

3.9.1. Introduction. 21

3.9.2. Parameters of the user functions. 21

3.10. Access from user function to *.bas program variables. 24

3.11. Methods and enumerations of class ob_obasic for access to Open Basic variables from user functions 24

3.11.1. Methods and enumerations of class ob_obasic for inquire types Open Basic variables and arrays 24

3.11.1.1. Enumeration ob_type_ident 24

3.11.1.2. Method typevar. 25

3.11.1.3. Method typearray. 25

3.11.2. Methods of class ob_obasic for inquire length string of Open Basic variables and elements of Basic string arrays. 26

3.11.3. Methods of class ob_obasic for inquire Open Basic arrays sizes. 27

3.11.4. Methods of class ob_obasic for recording Open Basic variables. 27

3.11.5. Methods of class ob_obasic for reading Open Basic variables. 28

3.11.6. Methods of class ob_obasic for creation and delete Open Basic variables and array. 29

3.11.6.1. Methods of class ob_obasic for creation Open Basic variables. 29

3.11.6.2. Methods of class ob_obasic for creation Open Basic arrays. 29

3.11.6.3. Methods of class ob_obasic for delete Open Basic variables and array. 30

3.12. The other methods of class ob_obasic. 30

3.13. Operators. 31

3.13.1. Operator PRINT. 31

3.13.2. Operator INPUT. 31

3.13.3. Operators FOR and NEXT. 32

3.13.4. Operator GOTO.. 33

3.13.5. Operators GOSUB and RETURN.. 33

3.13.6. Operator LET. 34

3.13.7. Operator DIM... 35

3.13.8. Operators STOP and END.. 36

3.13.9. Operator REM... 36

3.13.10. Operators OPEN and CLOSE. 37

3.13.11. Operator KILL. 38

3.13.12. Operators READ, DATA and RESTORE. 38

3.13.13. Operator RANDOMIZE. 39

3.13.14. Operator IF. 39

3.14. Built - in functions. 41

3.14.1. Function SGN%.. 41

3.14.2. Function ABS. 41

3.14.3. Function INT%.. 41

3.14.4. Functions SIN, COS, ATN, SQR, EXP, LOG and LOG10. 42

3.14.5. Function RND.. 42

3.14.6. Function LEN%.. 42

3.14.7. Functions DAT$ and CLK$. 43

3.14.8. Functions D2STR$, D2HEXSTR$, STR2FLOAT and STR2INT%.. 43

3.15. Error handling. 44

3.16. Table of diagnostic messages. 45

 

1. The description of problem and purpose of the program

 

Frequently in the user applications there is necessity use simple script language. Such problem arises, if the application operates some objects, which should be use in different sequences for different modes of operation.

 

For example:

 

- Searches to a database with different conditions of sample of the data

- Testing the hardware and/or the software

- The connection with the non-standard equipment on various channels

- Graphic interfaces and manipulations GUI objects

- Input language in programs - terminals for analysis of the command line

- Input language of the operator automated system control

- Input language of configuration files

- And many other things

 

Therefore frequently it is necessary to add the graphic interface to opportunities, which gives script language.

 

OB is developed for embed to user application as a script language.

Open Basic is delivered as library or source code.

 

User may attach user function to Open Basic execution system.

 

The user functions can be written on C/C++, assembler or others

languages.

The user functions can receive parameters from the Basic-program and return results to Basic-program.

 

Program interface of user functions allows determine type and order of parameters at run-time.

 

Also the user functions have access to all variable and arrays of

Basic programs. This access performs by names of variables and arrays.

 

2. Conditions of application

 

Open Basic is written completely on C++ and does not use system calls

any OS. Open Basic can be use with any graphic library.

 

3. The input and output data

 

3.1. How to use the interpreter. How to load and start *.bas program.

 

Interpreter Open Basic is realized as a class with name ob_obasic.

Work of the interpreter is execution program in language Basic.

In this document this program refers to as the *.bas-program. The program *.bas

is a text file or the buffer in the memory, open as stream istream.

 

Terms:

 

1. "Operator" is means operator of language Basic. For example PRINT, FOR etc.

2. " The user function " is means user function, attached to Open Basic execution system

3. "Function" is means function C++

4. "Method" is means a method of class ob_obasic.

5. ".bas-program" - the program in language Basic

 

To use the interpreter it is necessary:

 

1. To download from page http://www.mktmk.narod.ru the archive containing:

- Library of the interpreter for your compiler

- Header file ob.h

- Header files with realization of containers

(mstore.h, mvect.h, mlist.h, mstack.h, mhash.h)

 

2. Include in the project library of the interpreter

 

3. To specify way for connection of heading file of the interpreter ob.h

 

4. To specify way for connection of heading files of containers

(mstore.h, mvect.h, mlist.h, mstack.h, mhash.h)

 

5. Include in the user C++ files directive: #include <ob.h>

 

6. Create copy of class ob_obasic in the C++ program

 

7. Load *.bas the program by constructor ob_obasic or by method load

 

8. Start loaded program by method run

 

Example:

 

// Create interpreter and start of the program. *.bas program is stored

// in prog.bas file.

// Before load and run prog.bas file opens for reading

// as a stream inp

 

ifstream inp("prog.bas",ios::binary); // open input stream

ob_obasic basic_interpreter(&inp);// load *.bas programs by constructor

basic_interpreter.run();//start *.bas-program

 

ATTENTION! The input stream should be open in ios::binary mode.

 

Note:

 

In spite of the fact that *.bas-program is text file to open as

stream it should be in ios::binary mode. It is because symbols CR and LF do not access directly in ios::text mode.

 

Example:

 

// After end of program prog.bas load and run program

// prog1.bas

ifstream inp1("prog1.bas", ios::binary); // open input stream

basic_interpreter.load(&inp1); // load *.bas programs by method load

basic_interpreter.run(); // start *.bas-program

 

ATTENTION! The input stream should be open in ios::binary mode.

 

Example:

 

// After the end of program prog1.bas load and run program

// prog2.bas

ifstream inp2("prog2.bas", ios::binary); // open input stream basic_interpreter.load(&inp2, ob_obasic::OVERLAY); // load *.bas programs

// by method load in OVERLAY mode

basic_interpreter.run(); // start *.bas-program

 

ATTENTION! The input stream should be open in ios::binary mode.

 

3.2. Review of technical decisions

 

At designing the interpreter the following basic problems were solved:

 

1.    User can storage Basic-program in a file on disk or in the buffer of memory. For maintenance of this opportunity the interpreter accepts the input program as the index of input stream istream*. The concrete kind of a stream (a file or the buffer) defined by user. Similarly input stream of operator INPUT and output stream of operator PRINT can be buffers or files.

 

2.    For flexibility of functioning division of execution of program into two stages is applied. The first stage is program loading by method load. The second stage is execution of program by method run. During loading there is a creation of the table of labels and internal variables initializing. During execution reading text of program and execution is made (creation of variables, files, calculation and assignment of values by a variable, execution operators and functions etc.). The ending of method run occurs for the several reasons:

 

-          End input stream is found

-          Syntactic error in the program is found

-          Symbol of breakpoint is found

-          Symbol of the end of string at step-by-step mode of operation is found

 

 

At the ending the method run returns a code. Analyzing this code the user can find the reason of the ending. Division of execution of the program into two stages allows to continue a method run after the ending without program loading.

 

3.    One copy of the interpreter can execute one Basic-program at the same time. You can have some copies of the interpreter. The interpreter has no static members of the data (except for some read-only constants). Therefore some copies of the interpreter can work simultaneously in different threads of the C++ program.

 

4.    The user functions in Open Basic have the unified interface because language C++ does not allow transfer the information from compile-time stage to run-time stage. This interface allows analyse types and the order of following parameters in user function call at run-time. This approach demands from the programmer of accuracy, but does not limit an opportunity of creation of the user functions with different parameters.

 

3.3. Description of methods and enumeration of class ob_obasic, which are used for loading and start *.bas programs

 

3.3.1. Constructor ob_obasic

 

ob_obasic (istream* i=OB_NULL, ostream* o = &cout, istream* read = &cin);

 

Create copy of interpreter Open Basic.

 

Parameters of constructor:

 

1. Parameter i is pointer of input stream from which is read *.bas-program.

Current stream position of input stream should be in beginning of the stream. After end of method run current stream position of input stream is end of the stream. For restart the same program, it is necessary to remove current stream position of stream by method seekg and reload program by method load.

 

ATTENTION! The input stream should be open in ios::binary mode.

 

Note:

 

In spite of the fact that *.bas-program is text file to open as

stream it should be in ios::binary mode. It is because symbols CR and LF do not access directly in ios::text mode.

 

2. Parameter o is pointer of output stream. Operator PRINT printed its data to this stream.

 

ATTENTION! The output stream should be open in ios::text mode.

 

3. Parameter read is pointer of input stream from which data read by operator INPUT.

 

ATTENTION! This input stream should be open in ios::binary mode.

 

3.3.2. Enumeration typeload

 

Enumeration enum typeload {OVERLAY, NOOVERLAY}; - defines mode of loading

*.bas programs. It is used in method load.

 

Note:

 

During work the interpreter creates tables:

 

1. Table of variables

2. Table of arrays

3. Table of users functions

4. Table (stream) of the data of operator DATA

5. Table of labels

6. Table of operators FOR

7. Table of open files

8. Table (stack) of subroutines GOSUB

 

If typeload=OVERLAY metod load clear tables:

 

1. Tables of labels

2. Tables of operators FOR

3. Tables (stack) of subroutines GOSUB

 

Other tables:

 

1. Table of variables

2. Table of files

3. Table of users functions

4. Table (stream) of the data of operator DATA

5. Table of open files

 

Are not cleared and can be used by next program.

 

If typeload=NOOVERLAY metod load clear all tables except

user functions table.

 

User functions table is cleared only by call of method

void clrtablfun();

 

3.3.3. Method load

 

Method

 

void load (istream* i, typeload a=ob_obasic::NOOVERLAY);

 

Load *.bas-program.

 

Parameters of method:

 

1. Parameter i is pointer of input stream from which is read *.bas-program.

Current stream position of input stream should be in beginning of the stream. After end of method run current stream position of input stream is end of the stream. For restart the same program, it is necessary to remove current stream position of stream by method seekg and reload program by method load.

 

ATTENTION! The input stream should be open in ios::binary mode.

 

2. See previous topic

3.3.4. Enumeration typeend

Enumeration

enum typeend {

DUMMYEND, ENDFILEEND, ENDOPERATORDETECT, EOLEND, BREAKPOINTEND, NOLOADEND,

BREAKBEFOREOPERATOR, BREAKAFTEROPERATOR

};

 

Defines exit code of method run.

 

Exit codes:

 

1. typeend=DUMMYEND. At normal work never return by method

run. It is used for internal work.

 

2. typeend=ENDFILEEND. Method run has terminated because input stream has

expired. This is normal end of *.bas-program

 

3. typeend=ENDOPERATORDETECT. Method run has terminated because detect

operator END. This is normal end of *.bas-program

 

4. typeend=EOLEND. Method run has terminated after execution of the next

line, because flag step=STEP by a method setstep was established

 

5. typeend=BREAKPOINTEND. Method run has terminated after reading symbol '@'.

Symbol '@' is breakpoint symbol for Open Basic

 

6. typeend=NOLOADEND. Method run has terminated because method load was

not executed and input stream is not open

 

7. typeend=BREAKBEFOREOPERATOR. Method run has terminated before execution

operator OB

 

Note:

 

User can establish special mode of method run for each operator OB (PRINT, FOR etc.). In this mode method run ended before or after execution of any operator.

 

This mode is established by method:

 

bool setoperatorbreak(char* name,ob_operator::flbreak b,ob_operator::flbreak a);

 

Such opportunity is made for simplification of realization input and output operators PRINT and INPUT. If before operator execution is necessary execute

some actions (for example clear stream), is necessary establish mode

ended of method run before execute of operator PRINT.

More detail see description of method setoperatorbreak.

 

8. typeend=BREAKAFTEROPERATOR - the method run has terminated after execute

operator OB

 

Note:

 

If before operator execution is necessary execute some actions (for example send output string to window), is necessary establish mode ended of method run after execute of operator PRINT.

 

By default mode of end for all operators is disable.

 

3.3.5. Method run

 

Method typeend run (); start the loaded program. Or continues execution after end program.

 

3.4. Methods and enumerations of class ob_obasic are used for the organization of debugging in interpreter

 

In OB there are two modes of debugging: step-by-step execution of *.bas programs and breakpoints.

The opportunity of step-by-step execution of *.bas programs is realized by method setstep.

The symbol '@' in the text of *.bas program realizes a breakpoints.

User can have many breakpoints in one *.bas program. After entering breakpoint

to *.bas program needs reloaded it by method load.

After execute breakpoints, exit code of method run will be BREAKPOINTEND. For continue *.bas program need use method run again.

3.4.1. Enumerations step

 

Enumerations enum step {NOSTEP, STEP}; is defines mode of step-by-step execution of programs. It is used by methods setstep and getstep. By default step=NOSTEP.

If step=NOSTEP the program is run continuously.

If step=STEP the program is finished with code typeend=EOLEND after execute

each line of program.

 

3.4.2. Method setstep

 

Method

void setstep(step ts) - establishes or removes mode of step-by-step execute of

programs. This method can be used at any moment of work of the interpreter.

 

3.4.3. Method getstep

 

Method

 

step getstep () - returns the current mode of step-by-step execute of programs.

 

3.4.4. Function ob_loadbreakstr

 

Function

void ob_loadbreakstr (

istream* in,

ob_type_stringsize lengthbuffers,

ob_type_char* ptrbefore,

ob_type_char* ptrcurrent,

ob_type_char* ptrafter

);

 

Where:

 

istream* in - the current input *.bas-file

lengthbuffers - length of buffers

ptrbefore - the buffer for previous executed line

ptrcurrent - the buffer for the current executed line

ptrafter - the buffer for next executed line

 

Function ob_loadbreakstr loads into the appropriate buffer lines of program.

Function ob_loadbreakstr is not method of class ob_obasic.

 

Example:

 

// Create interpreter and start program in step-by-step mode.

// print current executed lines

 

ob_type_char strcurrent[ob_maxlengthstring]; // the buffer

 

ob_obasic basic_interpreter; // Create interpreter

 

// Load and start program

// prog2.bas

// In mode OVERLAY with step-by-step performance of the program

// And print current executed lines

 

ifstream inp2 ("prog2.bas", ios::binary); // open input stream

 

basic_interpreter.load(&inp2); // load *.bas-program

basic_interpreter.setstep(ob_obasic::STEP); // establishes step-by-step mode

 

while(1) {

 

// start *.bas-program

if(basic_interpreter.run()!=ob_obasic::EOLEND) break;

 

ob_loadbreakstr(&inp2, ob_maxlengthstring, OB_NULL, strcurrent, OB_NULL);

cout << endl << " String current: " << strcurrent;

 

}

 

Function ob_loadbreakstr is not method of class ob_obasic.

 

3.4.5. Enumerations ob_operator::flbreak

 

Enumerations enum flbreak {NOBREAK, BREAK};

 

It is used in method setoperatorbreak for installation and removal mode of ending before or after execution of specified operator.

 

3.4.6. Method setoperatorbreak

 

In OB for each operator (PRINT, FOR etc.) there is an opportunity to establish

mode of end of a method run before or after execution of this operator. A mode

end it is established by method:

 

bool setoperatorbreak(char* name,ob_operator::flbreak b,ob_operator::flbreak a);

 

Parameters:

 

1. name - a name of the operator

2. flbreak b - flag of end of method run before execution of this operator

3. flbreak a - flag of end of method run after execution of this operator

 

Returned value:

 

true - successful end

false name of operator error

 

Such opportunity is made for simplification of realization of operators of input and output PRINT and INPUT in concrete OS.

 

If before execution some operator is necessary execute some actions (for example clear stream), is necessary to establish mode of end of method run before execute this operator.

 

If after execution some operator is necessary execute some actions (for example send string to window), is necessary to establish mode of end of method run after execute this operator.

 

By default the mode of end before and after execute all operators is disable.

 

3.4.7. Method getcurrentoperatorname

 

The method allows inquire name of last execute operator.

 

ob_type_char* getcurrentoperatorname();

 

Method returns name of the operator.

 

3.4.8. Methods setin and setout

 

Methods allow to redefine input and output streams earlier determined

in constructor.

 

void setin (istream* i);

void setout (ostream* o);

 

ATTENTION! The input stream should be open in ios::binary a mode.

ATTENTION! The output stream should be open in ios::text a mode.

 

Method setin redefine stream read of constructor.

Method setout redefine stream o of constructor.

 

3.4.9. Enumerations ob_lex::typelex

 

Enumerations defines current lexeme.

 

enum typelex {

PLUS, MINUS, MUL, DIV, POWER, ASSIGN, LP, RP, STRING, SEMICOLON, COMMA, ENDPROGRAMM, EOL,

LESS, GREAT, SHARP, BREAKPOINT,

DECINTNUMBER, HEXINTNUMBER, FLOATNUMBER,

FUNC, OPERATOR,

OLDVARIABLE, OLDARRAY, NEWNAME,

BAD

};

 

3.4.10. Methods gettypenextlex and restoreinputpointer

 

Methods are intended for simplification of realization input and output operators.

 

- ob_lex::typelex gettypenextlex();

- void restoreinputpointer();

 

Method

ob_lex::typelex gettypenextlex();

 

Returns the following lexeme from input stream. Some operators (for example operator INPUT) have identical syntax for input from file and from the console.

The current direction of input is defined by the following lexeme #. Current direction of input can inquire by method gettypenextlex.

 

Method

void restoreinputpointer ();

 

Is intended for restore status of input stream after use method gettypenextlex.

 

3.5. Syntax of language Open Basic.

 

ATTENTION! All objects in the *.bas-program: variables, arrays, and

user functions should have different names.

 

Interpreter Open Basic supports subset of operators of language Basic.

These operators are described below. Open Basic support three types of the data:

 

1.    floating point

2.    signed integer

3.    string

 

Variables in Open Basic do not need to be described before first use.

The first occurrence of variable in the program should be to the left of the assignments operator.

Arrays of Open Basic need to be described before first by operator DIM.

Arrays can be multidimensional. Memory space for arrays and variables allocate

in free memory by operator new. Max size of arrays restrict by realization operator new in OS.

First index of arrays is 1.

As against standard language Basic, operator DIM in Open Basic is executed. It execute each time when execute.

The repeated description of array with the same name in operator DIM is supposed.

The new array can have other dimensions. The old data thus are lost.

This mechanism can be applied to clearing memory. After capture big

array by operator DIM it is possible to release memory, having described array with the same name and dimension in one element.

At the description of array file in operator DIM as dimensions can used the integer variables.

At creation numerical arrays are initialized by zero. String arrays

are initialized by empty line ("").

The range of data presentation with a floating point and integer depends on compiler. Usually integer is int, and floating is float.

The maximal length of string variables is defined by a constant ob_maxlengthstring in file ob.h. For version OB v1.50 ob_maxlengthstring=4096.

In *.bas program can be empty lines.

Interpreter Open Basic supports the following operations for numerical types:

 

+ - addition

- - subtraction

* - multiplication

/ - division

^ - power

- - unary minus

+ - unary plus

= - assignment

<,>, =, <>, <=, >= - condition expression "less", "equally", "not equally" etc. This expressions are used in operator IF.

 

3.6. Types of the data, names and labels Open Basic

 

As well as in standard language Basic type of a variable or array Open Basic

is defined by name.

 

Namely:

- If last symbol of name is symbol '%' it is integer variable or array

- If last symbol of name is symbol '$' it is string variable or array

- If last symbol of name is any other symbol, it is floating point variable or array

 

Many types Open Basic are described in ob.h by typedef.

The type ob_type_flo is type float.

The type ob_type_int is type int.

In the user functions is recommended use types ob_type_flo and ob_type_int.

 

Names of variables, arrays and the user functions can use any sequences of letters and digits. First symbol of name should be letters.

Letters in name can be upper or lower case. Names MASS, mass and Mass are different names. Symbols of underlining and symbols '$' and '%' are considered as letters.

The maximal length of name is defined by constant ob_maxlengthstring in file ob.h. For version OB v1.50 ob_maxlengthstring=4096.

 

Example:

 

Define of array and initialization of two variables integer and floating point. Last measurement of array is given by variable. Type of elements of array

mass is floating point. The variable counter% is integer type. Variable data is floating point.

 

counter%=7

DIM mass(2,3,10,counter%)

data=counter%+37.77

 

Example:

 

Define of array and use it. The repeated define array with the same name, but other dimension and use it.

 

DIM mass(10)

 

FOR i%=1 TO 10 STEP 1

mass(i%)=i%+37.77

NEXT i%

 

counter%=7

 

DIM mass(counter%,3)

 

FOR i%=1 TO counter% STEP 1

mass(i%,2)=i%+37.77

NEXT i%

 

For string data are supported only operations of addition of strings, comparisons and assignments.

If in expression are used the data of different types it is made types cast.

If in expression is used the integer data and the floating point data,

resulting type will be floating point data.

At assignment the type of the right expression cast to type of left expression.

If left expression is integer variable, and right expression floating point variable, the fractional part is rejected.

 

Interpreter Open Basic supports labels as numbers of lines. These numbers

not necessarily should go in succession. Not each line of the program should be

numbered. Jump by operators GOTO and GOSUB is possible only on numbered line. Is possible to mark and an empty line.

 

Example:

 

IF ii%=6 THEN GOTO 10

 

PRINT "ii%=";ii%;

10 PRINT "ii%!=6"

 

IF ik%=7 THEN GOSUB 11

 

PRINT "ik%=";ik%;

GOTO 12

11

PRINT "ik%!=7"

RETURN

12

STOP

END

3.7. User functions in Open Basic.

 

OB has an opportunity of expansion of system command by attach user functions to execution system Open Basic.

 

Parameters of the user functions allow define type and order of arguments during execution program.

 

The user functions are connected to execution system Open Basic under

some names ( Basic-names). Each user function is connected under different Basic name. After connection user functions can use in text of *.bas program.

Can use user functions with or without parameters.

User functions can be written on C/C ++, the assembler or others

languages.

 

All user functions have 2 names:

 

1. C++ name of function

2. Basic name of function

 

The user functions receive the first name at theircreation. The second name

user functions receive at a stage of connection to execution system Open Basic by method setfun.

 

For create user function and connect it to execution system Open Basic is necessary:

 

1. Choose type of returned value for user function

2. Choose C++ name of user function and write user function on one of three prototypes

3. Choose Basic name of user function

4. Connect user function to execution system OB by method setfun using Basic name and C++ name as parameters

 

After that is possible use Basic name of user function in *.bas program.

 

3.7.1. Type of returned value for user Functions

 

The user function can return values of three types:

 

- floating point ob_type_flo

- signed integer ob_type_int

- string ob_type_char*

 

 

3.7.2. Prototypes for the user function

 

The user function can have one of three prototypes:

 

1. The functions returning floating point value

 

ob_type_flo name_flo (

ob_obasic* ptr,

const ob_type_char* parstring,

const ob_type_parnum *descrf,

const ob_type_parnum *descri,

const ob_type_parnum *descrc,

const ob_type_flo* parf,

const ob_type_int* pari,

const ob_type_char* parc

);

 

2. The functions returning signed integer value

 

ob_type_int name_int (

ob_obasic* ptr,

const ob_type_char* parstring,

const ob_type_parnum *descrf,

const ob_type_parnum *descri,

const ob_type_parnum *descrc,

const ob_type_flo* parf,

const ob_type_int* pari,

const ob_type_char* parc

);

 

3. The functions returning string

 

ob_type_char* name_char (

ob_obasic* ptr,

const ob_type_char* parstring,

const ob_type_parnum *descrf,

const ob_type_parnum *descri,

const ob_type_parnum *descrc,

const ob_type_flo* parf,

const ob_type_int* pari,

const ob_type_char* parc

);

 

These prototypes differ only with type of returned value.

 

In a file ob.h contains macro OB_DECLFUNAPI (name, typeret) which can use for declare user functions. The parameter name is a name functions in C++, the parameter typeret is a type of returned value.

 

Example:

 

Declare of user function by OB_DECLFUNAPI.

C++ name of user function is "myfun1".

Type of returned value is ob_type_flo.

 

OB_DECLFUNAPI(myfun1, ob_type_flo);

 

Example:

 

Define of user function by OB_DECLFUNAPI.

C++ name of user function is "myfun2".

Type of returned value is ob_type_int.

 

OB_DECLFUNAPI(myfun2, ob_type_int) {

return 365;

}

 

Example:

 

Define of user function by OB_DECLFUNAPI.

C++ name of user function is "myfun3".

Type of returned value is ob_type_char*.

 

OB_DECLFUNAPI(myfun3, ob_type_char*) {

return "Hello world";

}

 

3.7.3. Choice of Basic name of user function

 

Basic name of user function should differ from names of variables,

Arrays and other user functions of *.bas program.

 

3.7.4. Connection user function to execution system OB

 

Connection user function to execution system OB is made by methods setfun.

 

bool setfun(ob_type_char* name, ob_type_flofun f);

bool setfun(ob_type_char* name, ob_type_intfun f);

bool setfun(ob_type_char* name, ob_type_charfun f, ob_type_del dt);

 

Parameters:

 

1. name - Basic-name of user function

2. f - pointer of user function

3. dt - type of allocation returned value (only for functions returning string)

 

Example:

 

// Function userfun1 is connected

// This function returns floating point value

// This function prints the message "hello world" and returns value 3.1416

// After connection it have Basic name "TEST_FUN1"

// That in *.bas-programs it can be call by name "TEST_FUN1"

 

OB_DECLFUNAPI(userfun1,ob_type_flo){

cout<<endl<<"hello world";

return 3.1416;

}

 

main() {

 

ob_obasic onebasic; // the copy of the interpreter is created

 

ifstream inonebasicf("EXAMPLE.BAS", ios::binary); // file EXAMPLE.BAS opens

 

onebasic.load(&inonebasicf); // file EXAMPLE.BAS is loaded into the interpreter

onebasic.setfun("TEST_FUN1", userfun1); // function TEST_FUN1 is connected

onebasic.run(); // start of *.bas program

}

 

For function returning string type is difference by way of connection.

Probably two variants of allocation returned value in memory:

 

- In heap by operator new[]

- In static memory

 

In the first case the user function is connected with parameter

dt=OB_DELETE.

After the ending of work of such function Open Basic will release memory by operator delete[].

 

Example:

 

In example the copy of the interpreter is created, the file with name EXAMPLE.BAS opens.

Also it is loaded into interpreter. After that four user functions TEST_FUN1-TEST_FUN4 are connected to execution system.

 

Function TEST_FUN1 prints the list of it parameters with a floating point and

returns floating point value, equal to the sum of all floating point parameters.

 

Function TEST_FUN2 prints the list of integer parameters and returns the integer value equal to the sum of all integer parameters.

Functions TEST_FUN3 and TEST_FUN4 print the first string parameter and return string "This is string".

Thus function TEST_FUN4 has returned value in static memories, and function TEST_FUN3 in free memory (in heap by operator new[]).

All functions supervise correctness of types of the parameters. In a case

absence of parameters of the necessary type functions print messages.

 

#include <ob.h>

 

char* s="This is string";

 

OB_DECLFUNAPI(userfun1,ob_type_flo){

ob_type_flo summ=0;

ob_type_parnum i;

if(descrf[0]==0) cout<<endl<<"Not float parameters";

for(i=0;i!=descrf[0];i++){

summ+=parf[i];

cout<<endl<<"parameters["<<i<<"]="<<parf[i];

}

return summ;

}

 

OB_DECLFUNAPI(userfun2,ob_type_int){

ob_type_int summ=0;

ob_type_parnum i;

if(descri[0]==0) cout<<endl<<"Not int parameters";

for(i=0;i!=descri[0];i++){

summ+=pari[i];

cout<<endl<<"parameters["<<i<<"]="<<pari[i];

}

return summ;

}

 

OB_DECLFUNAPI(userfun3,char*){

if(descrc[0]==0) cout<<endl<<"Not string parameters";

cout<<endl<<parc;

char* p=new char[strlen(s)+1];

strcpy(p,s);

return p;

}

 

OB_DECLFUNAPI(userfun4,char*){

if(descrc[0]==0) cout<<endl<<"Not string parameters";

cout<<endl<<parc;

return s;

}

 

main () {

ob_obasic onebasic; // the copy of the interpreter is created

 

ifstream inonebasicf("EXAMPLE.BAS", ios::binary); // file EXAMPLE.BAS opens

 

onebasic.load(&inonebasicf); // file EXAMPLE.BAS is loaded into the interpreter

 

onebasic.setfun("TEST_FUN1", userfun1); // function TEST_FUN1 is connected

onebasic.setfun("TEST_FUN2", userfun2); // function TEST_FUN2 is connected

onebasic.setfun("TEST_FUN3", userfun3, OB_DELETE); //it is connected TEST_FUN3

onebasic.setfun("TEST_FUN4", userfun4, OB_NODELETE); //it is connected TEST_FUN4

 

onebasic.run (); // start of the *.bas-program

}

 

At detection in the text of the *.bas-program name of the connected function execution system Open Basic makes the following actions:

 

1. Calculates all arguments in the current call of the *.bas-program

2. Fills arrays descr*

3. Fills arrays par*

4. Fills pointer ob_obasic* ptr by address of current Open Basic exemplar

5. Fills string parstring

6. Run user function

 

The user function should supervise types, amount and the order of parameters in the current call.

 

3.8. Methods and enumerations of class ob_obasic for connection and disconnection user functions

 

3.8.1. Enumerations ob_type_del

 

Enumerations enum ob_type_del {OB_DELETE, OB_NODELETE}; is defines type of allocated returned value by the user function.

It is used in a method setfun to connect only user functions, returning type ob_type_char*.

 

At dt=OB_DELETE returned value allocated in free memory by operator new. After ending of user function it will be removed by operator delete[].

At dt=OB_NODELETE returned value will not be removed by operator delete[].

 

3.8.2. Methods setfun

 

Methods

 

 

bool setfun(ob_type_char* name, ob_type_flofun f);

bool setfun(ob_type_char* name, ob_type_intfun f);

bool setfun(ob_type_char* name, ob_type_charfun f, ob_type_del dt);

 

Connect user function to execution system OB.

 

Parameters:

 

1. name Basic name of user function

2. f - pointer of user function

3. dt - type of allocation returned value (only for functions returning string)

 

Methods setfun returns value true if function is successfully connected and false

In case such function already exists.

 

Types ob_type_flofun, ob_type_intfun, ob_type_charfun it is indexes on function,

Described in ob.h. They differ type of returned value.

 

If user function do not connect to execution system OB, method setfun connect it and return false.

 

If user function already connects to execution system OB, method setfun replace it and return true.

3.8.3. Methods delfun

 

Method

 

bool delfun (ob_type_char* name);

 

Disconnects the user function from Open Basic.

 

Parameters:

 

1. name - Basic name of user function

 

The method delfun returns true if disconnects function is successfully and false in case such function does not exist.

3.9. Purpose of parameters of user functions

 

3.9.1. Introduction

 

The interface of user functions Open Basic is developed for provide an opportunity of the control of actual parameters in call at stage

of executions program.

For this purpose the set of parameters of the user functions contains two groups arrays.

The first group is three arrays of descriptions of parameters descrf, descri, descrc.

These arrays contain the information amount and the order of actual parameters in current call of user function.

The second group is three arrays of values of parameters parf, pari, parc.

These arrays contain values of actual parameters in current call user functions.

Purpose and structure of files descr* and par* is detail described in next topics.

3.9.2. Parameters of the user functions

 

There are three types of the user functions. All of them have identical

parameters and different type of returned value.

 

Let's consider parameters of user functions on an example of the function returning floating point value.

 

ob_type_flo name_flo (

ob_obasic* ptr,

const ob_type_char* parstring,

const ob_type_parnum *descrf,

const ob_type_parnum *descri,

const ob_type_parnum *descrc,

const ob_type_flo* parf,

const ob_type_int* pari,

const ob_type_char* parc

);

 

Parameters:

 

1. ob_obasic* ptr pointer of interpreter ob_obasic, to which function is connected. It is used for access to variable of the program by methods ob_obasic.

 

2. const char* parstring string image of all parameters.

 

Example:

 

If parameters of function USER_FUN1 in its call is specified

USER_FUN1(1.123,a_a%,1+2), in string parstring there will be following

string: "1.123", "a_a%","1+2".

These string will lay in succession, separate by zero byte.

 

3. arrays of description parameters descr*:

 

const ob_type_parnum *descrf - for floating point parameters

const ob_type_parnum *descri - for integer parameters

const ob_type_parnum *descrc - for string parameters

 

These arrays are describing amount, types and places of all parameters,

transferred to user function from *.bas-program. These arrays are

used for control of amount, type and order of parameters in call

of user function.

 

Structure of array descrf (the others it is similar):

 

descrf[0] - common number of floating point parameters in the current call

Other elements of array descrf (their amount is equal descrf[0])

these are position numbers of floating point parameters in current call.

Numbers are considered with 1.

 

Example:

If as parameters of function USER_FUN1 in it

call is specified USER_FUN1(1.123,a_a%,1+2),

In array descrf there will be following numbers:

1,1

In array descri there will be following numbers:

2,2,3

In array descrc there will be following numbers:

0

 

Example:

If as parameters of function USER_FUN1 in it

call is specified USER_FUN1("str1","srt2" + "str3",1.1,1.2,1.3,1.4),

In array descrf will be the following numbers:

4,3,4,5,6

In array descri there will be following numbers:

0

In array descrc there will be following numbers:

2,1,2

 

4. Arrays of values of parameters par*:

 

const ob_type_flo* parf - for floating point parameters

const ob_type_int* pari - for integer parameters

const ob_type_char* parc - for string parameters

 

These arrays are describing values of all parameters of appropriate types,

transferred to user function from *.bas-program in current call.

 

String parameters lay in succession, are separated zero byte.

 

Example:

 

([a_a%] is value of a_a% variable)

 

If as parameters of function USER_FUN1 in it

call is specified USER_FUN1(1.123,a_a%,1+2),

In array parf there will be following numbers:

1.123

In array pari there will be following numbers:

[a_a%],3

In array parc there will be no values

 

Example:

 

If as parameters of function USER_FUN1 in it

call is specified USER_FUN1("str1","srt2" + "str3",1.1,1.2,1.3,1.4),

In array parf will be following numbers:

1.1,1.2,1.3,1.4

In array pari there will be no values

 

In array parc there will be next lines:

"str1","srt2str3"

 

In a file ob.h contains macros OB_DECLFUNAPI(name,typeret) which it is possible

use for define and describe user functions. The parameter name is name

user functions in C++, the parameter typeret is type of returned value.

 

The maximal number of parameters is defined by constant ob_maxnumpar in file ob.h.

For version OB v1.50 ob_maxnumpar=64;.

 

Using arrays of description descr* and arrays values of parameters par* user can organize control of types and order of parameters in current call of user function.

The analysis of arrays descr* gives full information about types, amount and order of parameters in current call of user function.

 

Example:

 

To user function calculating a sine is transferred as parameter a string variable.

 

Thus arrays descrf, descri and descrc will contain values:

 

descrf[0]=0

descri[0]=0

descrc[0]=1

 

Analyzing this information, user can make necessary actions.

For example:

 

1. To generate the user exception

2. To substitute argument by default, for example 0.

3. To execute exit()

4. To try to transform a string to number by atof

 

For simplification of access to string parameters Open Basic provide function:

 

const ob_type_char*

ob_getstringparam (

const ob_type_parnum *descrc,

const ob_type_char* parc,

const ob_type_parnum i);

 

Parameters:

 

1. descrc array of description of string parameters

2. parc - array of values of string parameters

3. i - number of string, (zero-based)

 

It is possible to get access to any string from parc or parstring.

If i it is more, than descrc[0], function returns 0.

If descrc[0] is equal to zero, function returns 0.

 

Function ob_getstringparam is not method of class ob_obasic.

 

3.10. Access from user function to *.bas program variables.

 

Except access to parameters, user function has access to *.bas programs variable.

If *.bas program have variable or array, user function can read and write this variable and elements of array.

The user function has means of stock-taking of variables by its name. The user function can create variable in the table variable ob_obasic.

These opportunities are realized in Open Basic by methods described in the next topic.

 

3.11. Methods and enumerations of class ob_obasic for access to Open Basic variables from user functions

 

Methods of this topic are started usually in the user functions. Therefore

in examples they are started by ob_obasic* ptr.

Such name has first parameter of all user function, if user functions define by macros OB_DECLFUNAPI.

Generally methods of this topic can started in any place C++ programs in which interpreter is used. For example, after stop *.bas-programs by breakpoint, it is possible to print values of variables and arrays.

It is possible create and initialize some variables before start program by method run.

 

3.11.1. Methods and enumerations of class ob_obasic for inquire types Open Basic variables and arrays

 

3.11.1.1. Enumeration ob_type_ident

 

Enumeration

 

enum ob_type_ident {OB_IDENTFLO, OB_IDENTINT, OB_IDENTSTR, OB_NOIDENT};

 

Defines type of variable or array. It is used in methods typevar and typearray for define type of variable and array.

 

If ob_type_ident=OB_IDENTFLO the variable have floating point type.

If ob_type_ident=OB_IDENTINT the variable have integer type.

If ob_type_ident=OB_IDENTSTR the variable have string type.

If ob_type_ident=OB_NOIDENT the variable is not found.

 

3.11.1.2. Method typevar

 

Method

 

ob_type_ident typevar (ob_type_char* name); - returns type of variable.

 

Parameter:

 

1. name - name of Basic-variable

 

3.11.1.3. Method typearray

 

Method

 

ob_type_ident typearray (ob_type_char* name); - returns type of array.

 

Parameter:

 

1. name - name of Basic-array (without brackets and indexes)

 

Example: If there is *.bas program

 

DIM array1%(10,10), array2$(10,10), array3(10,10)

a%=10

b$="string example"

c=101.4

 

After execute this *.bas program user can inquire types of variable.

ob_type_ident ident;

 

ident=ptr->typevar ("a%"); // ident=OB_IDENTINT

ident=ptr->typevar ("b$"); // ident=OB_IDENTSTR

ident=ptr->typevar ("c"); // ident=OB_IDENTFLO

 

ident=ptr->typearray ("array1%"); // ident=OB_IDENTINT

ident=ptr->typearray ("array2$"); // ident=OB_IDENTSTR

ident=ptr->typearray ("array3"); // ident=OB_IDENTFLO

 

The ptr is first parameter user functions, the pointer of interpreter.

 

In example of this *.bas-program there is no variable with name VAR and array with name ARR.

Therefore application of these methods will yield the following results:

 

ident=ptr-> typevar ("VAR"); // ident matters OB_NOIDENT

ident=ptr-> typearray ("ARR"); // ident matters OB_NOIDENT

 

3.11.2. Methods of class ob_obasic for inquire length string of Open Basic variables and elements of Basic string arrays

 

Method

 

ob_type_ident

strlenvar (

ob_type_char* name,

ob_type_stringsize* len,

ob_type_arraysize* as=OB_NULL);

 

Defines type of variable and length of variable or an element of array.

 

Parameters:

 

1. name - name of Basic-variable or Basic-array

2. *len - for string variables contains length of string without finishing

zero. For floating point and integer variables contains

sizeof(ob_type_float) and sizeof(ob_type_int) accordingly.

3. *as - indexes of array in a case if name is name of array

 

The method strlenvar can be use for Basic-variable or elements Basic-array.

For Basic-array there are 2 ways of call of method strlenvar.

 

1. Indication of the current indexes in name (parameter as=OB_NULL)

2. Indication of the current indexes in parameter *as (parameter as!=OB_NULL)

 

The method returns type of variable.

If variable is not define, the method returns OB_NOIDENT.

 

Parameter *len for string variables contains length of string without finishing

zero. The parameter *len for floating point and integer variables contains

sizeof(ob_type_float) and sizeof(ob_type_int) accordingly.

 

Example: Using method strlenvar for element of array with indication current

indexes in a name:

 

There is *.bas program:

 

DIM array2$(10,10)

array2$(5,5)="array string example"

 

After execute this *.bas program user can inquire length of array element.

 

ob_type_stringsize len;

 

ob_type_ident ident;

ident=ptr->strlenvar("array2$(5,5)",&len);// ident==OB_IDENTSTR len==20

 

Example: Using method strlenvar for element of array with indication current

indexes in parameter *as:

 

 

There is *.bas program:

 

DIM array2$(10,10)

array2$(5,5)="array string example"

 

After execute this *.bas program user can inquire length of array element.

 

ob_type_stringsize len;

 

ob_type_ident ident;

ob_type_arraysize as[]={5,5};

ident=ptr->strlenvar("array2$",&len,as);// ident==OB_IDENTSTR len==20

 

Example: Using method strlenvar for variables

 

There is *.bas program:

 

DIM array1%(10,10), array3(10,10)

a%=10

b$="string example"

c=101.4

 

After execute this *.bas program user can inquire length of variable.

 

ob_type_ident ident;

ob_type_stringsize len;

 

ident=ptr->strlenvar("a%",&len);// ident==OB_IDENTINT len==4

ident=ptr->strlenvar("b$",&len);// ident==OB_IDENTSTR len==14

ident=ptr->strlenvar("c",&len); // ident==OB_IDENTFLO len==4

 

 

3.11.3. Methods of class ob_obasic for inquire Open Basic arrays sizes

 

Method

 

const ob_type_arraysize* getarraysize (

ob_type_char* name, ob_type_arraydimension* kr);

 

returns amount of dimension of array and size of each dimension.

 

Parameters:

 

1. name - a name of array.

2. *kr - amount of dimension of array. It is filled by method getarraysize.

Returned parameter pointer of internal buffer of sizes of each dimension. It is created during array creation by operator DIM. This parameter should be read only.

 

Example:

 

The array is create by operator DIM Array_1(10,11,12).

 

Using of method getarraysize.

 

const ob_type_arraysize *sr;

ob_type_arraydimension kr;

sr=ptr->getarraysize("Array_1",&kr);

 

After use kr=3, and pointer sr point to array {10,11,12}.

 

3.11.4. Methods of class ob_obasic for recording Open Basic variables

 

Methods

 

bool

writevar (ob_type_char* name, ob_type_flo val, ob_type_arraysize* as=OB_NULL);

 

bool

writevar (ob_type_char* name, ob_type_int val, ob_type_arraysize* as=OB_NULL);

 

bool

writevar (ob_type_char* name, ob_type_char* val, ob_type_arraysize* as=OB_NULL);

 

Parameters:

 

1. name - name of Basic-variable or Basic-array

2. val - value for assignment

3. *as - indexes of array, if name is a name of array

 

Methods writevar can use for Basic-variable or elements Basic-array.

For Basic-array there are 2 ways of call of methods writevar.

 

1. Indication of the current indexes in name (parameter as=OB_NULL)

2. Indication of the current indexes in parameter *as (parameter as!=OB_NULL)

 

Methods write a variable with name name in the table of variables and assignment value val to it.

If the variable does not exist, it is created.

If array does not exist, it is not created.

Check on type of a name is present, i.e. is created variable appropriate type.

 

The name name can be a name of an element of array. Then it should contain

indexes of concrete element by rules Basic.

Methods return false if error present, for example if array do not exist.

If not error present, methods return true.

 

If the type value does not correspond to type of a name (for example at

attempt to create integer variable with the second argument ob_type_char* val),

the method generates exception.

 

Example: Assignment to variable VAR value 10.4:

 

if(ptr->writevar("VAR",10.4)==false) cout<<endl<<"error in writevar";

 

Example: Assignment to third element of array array_string$ value "Hello

world":

 

if(ptr->writevar("array_string$(3)","Hello world")==false)

cout<<endl<<"error in writevar";

 

3.11.5. Methods of class ob_obasic for reading Open Basic variables

 

Methods

 

bool

readvar (ob_type_char* name, ob_type_flo* val, ob_type_arraysize* as=OB_NULL);

 

bool

readvar (ob_type_char* name, ob_type_int* val, ob_type_arraysize* as=OB_NULL);

 

bool

readvar (ob_type_char* name, ob_type_char* val, ob_type_arraysize* as=OB_NULL);

 

Parameters:

 

1. name - name of Basic-variable or Basic-array

2. *val - value for assignment

3. *as - indexes of array, if name is a name of array

 

Methods readvar can be use for Basic-variable or elements Basic-array.

For Basic-array there are 2 ways of call of methods writevar.

 

1. Indication of the current indexes in name (parameter as=OB_NULL)

2. Indication of the current indexes in parameter *as (parameter as!=OB_NULL)

 

Methods read a variable with a name name from the table of variables and assignment it value to *val.

If the variable does not exist, it is not created.

 

The name name can be a name of an element of array. Then it should contain

indexes of concrete element by rules Basic.

Methods return false if error present, for example if array do not exist.

If not error present, methods return true.

 

If the type value does not correspond to type of a name (for example at

attempt to read integer variable with the second argument ob_type_char* val),

the method generates exception.

 

Example: Read floating point variable VAR1

 

ob_type_flo val1;

if(ptr->readvar("VAR1",&val1)==false) cout<<endl<<"error name var in readvar";

 

Example: Read fourth element of array array_string$

 

ob_type_char buf[256];

ob_type_char* pchar=buf;

if(ptr->readvar("array_string$(4)",pchar)==false)

cout<<endl<<"error name var in readvar";

 

3.11.6. Methods of class ob_obasic for creation and delete Open Basic variables and array

 

3.11.6.1. Methods of class ob_obasic for creation Open Basic variables

 

Method

 

void createvar (ob_type_char* name);

 

Parameters:

 

1. name - name of Basic-variable or Basic-array

 

Creates a variable with name name in the table of variables.

The type of variable is defined by presence symbols '%' or '$' in a name.

3.11.6.2. Methods of class ob_obasic for creation Open Basic arrays

 

void createarray (

ob_type_char* name, ob_type_arraydimension kr, ob_type_arraysize* as);

 

Parameters:

 

1. name - name of Basic-variable or Basic-array

2. kr - amount of dimension of array

3. *as - buffer of the sizes of each dimension

 

Creates array with a name name in the table of array. If array already exists, it delete and created anew with specified sizes.

The type of elements of a created array is defined by presence symbols '%' or '$' in a name. The method is equivalent to operator DIM.

 

Parameters are similar to parameters of a method getarraysize.

 

Example: Create integer array ARRAY1%(5,10,20)

 

ob_type_arraysize as[]={5,10,20};

ptr->createarray("ARRAY1%",3,as);

 

3.11.6.3. Methods of class ob_obasic for delete Open Basic variables and array

 

Methods

 

void clrtabl (typeload a=NOOVERLAY);

void clrtablfun();

 

Clear tables of the interpreter.

The method clrtabl have parameter typeload, similar to parameter of method load.

The method clrtabl never clear the table of the user functions.

The method clrtablfun clear the table of the user functions.

 

3.12. The other methods of class ob_obasic

 

~ob_obasic(); - destructor.

 

The method static const ob_type_char* about() - returns string of the information about program. The string can contain symbols of a new string.

 

Example:

 

cout << ob_obasic::about (); // information about program

 

The method static const ob_type_serialnum serial_number() - returns serial umber of program.

 

The method static const ob_type_int version() - returns number of current version of programs. For version 1.50 method returns 150.

 

Methods:

 

time_t getstarttime();

time_t getstoptime();

 

Three functions from Open Basic, namely: constructor ob_obasic, method load and method run is kept to internal variables time of the beginning and time of the ending of these functions. Last started function fills these internal variables and erases the previous values.

 

Methods return time of the beginning and the ending of constructor ob_obasic and methods load and run.

 

 

3.13. Operators

 

Operators can place in one line and be separated from each other by space.

Some operators, for example DATA and PRINT should be unique operator in line. t Is necessary to limit the list of arguments of these operators.

At the description of operators symbols in square brackets mean optional fields.

 

Open Basic supports the following operators:

 

3.13.1. Operator PRINT

 

Print list of variables to a stream, specified at creation ob_obasic.

Format of the operator:

 

[N] PRINT [#EXP], [LIST]

 

Where

N - number of line (Basic-label)

LIST - the list of elements as constants, variable, string

or numerical expressions.

EXP - number of output channel opened by operator OPEN

 

Operator PRINT without list of elements print new line symbol.

If an element of list is expression, Open Basic calculates it and prints

result.

 

Example:

10 TT%=40

TTT=101.3

20 PRINT "TT%=";TT,"TTT=";TTT+0.3

 

Result:

 

TT%=40 TTT=101.6

 

Elements of the list are separated from each other by semicolon or a comma.

If elements of the list are separated by comma, tabulation symbol print between elements.

If at the end of the list of elements there is semicolon or a comma, new line symbol do not print.

 

3.13.2. Operator INPUT

 

Enters data from the input stream, specified at creation ob_obasic.

Format of the operator:

 

[N] INPUT [#EXP], VAR1, [VAR2, VAR3...]

 

Where

N - number of line (Basic-label)

VAR1, [VAR2, VAR3...] - the list of variables

EXP - number of input channel opened by operator OPEN

 

During execution operator INPUT Open Basic enters the data from stream and assignment it to variable from list of variables. String data in stream should be quoted.

 

Example:

10 TT%=40

TTT=101.3

20 INPUT TT%,TTT

 

3.13.3. Operators FOR and NEXT

 

Allow organize a cycle.

 

Format of operator FOR:

 

[N] FOR VAR=EXP1 TO EXP2 [STEP EXP3]

 

Where

N - number of a line (Basic-label)

VAR - counter of cycle

EXP1 - initial value of counter. Any numerical expression.

EXP2 - final value of counter. Any numerical expression.

EXP3 - an increment of counter. Any numerical expression.

Can be positive or negative. By default it is equal 1.

Counter of cycle can be an element of array.

 

Operators FOR and NEXT are used only in pair. Operator FOR defines the beginning of a cycle, operator NEXT - the end of a cycle.

 

Format of operator NEXT:

 

[N] NEXT VAR1

 

Where

N - number of line (Basic-label)

VAR1 - counter of cycle, used in operator FOR

 

If initial value of counter more than final value, a cycle is not performed.

Passing control inside of a cycle by operator GOTO is invalid.

It is recommended to use as variables of a cycle integer variables, for avoid rounding error.

Cycles can be put each other, the internal cycle should come to an end up to

external.

Because Open Basic is the interpreter, operator FOR has some features of execution. At an entrance in a cycle check of a condition is made.

If the condition of a cycle is not true, the cycle will not be executed never.

In this case Open Basic found operator NEXT and pass control

To this operator. But if operator GOTO present inside loop, error may occur.

 

Example:

 

GOTO 30

10

NEXT i%

GOTO 20

 

30 FOR i%=10 TO k% STEP 1

 

GOTO 10

 

 

20

STOP

END

 

This example will work, if k% it is more than 10. But if it not so,

will take place emergency abort.

 

Example:

 

FOR i%=1 TO 3

FOR ii%=4 TO 1 STEP -2

PRINT "Work FOR operator","ii%=";ii%,"i%=";i%

NEXT ii%

NEXT i%

 

Result:

 

Work FOR operator ii%=4 i%=1

Work FOR operator ii%=2 i%=1

Work FOR operator ii%=4 i%=2

Work FOR operator ii%=2 i%=2

Work FOR operator ii%=4 i%=3

Work FOR operator ii%=2 i%=3

 

Example:

 

FOR i%=1 TO 3

FOR ii%=4 TO 1 STEP -2

PRINT "Work FOR operator","ii%=";ii%,"i%=";i%

NEXT ii%

NEXT i%

 

Result:

 

Work FOR operator ii%=4 i%=1

Work FOR operator ii%=2 i%=1

Work FOR operator ii%=4 i%=2

Work FOR operator ii%=2 i%=2

Work FOR operator ii%=4 i%=3

Work FOR operator ii%=2 i%=3

 

3.13.4. Operator GOTO

 

Pass the control to the specified line.

 

Format of the operator:

 

[N] GOTO line_number

 

Where

N - number of line (Basic-label)

line_number - number of line (Basic-label)

 

Example:

 

20 GOTO 50

PRINT "This operator do not work in example"

50 PRINT "Work GOTO operator"

 

Result:

 

Work GOTO operator

 

3.13.5. Operators GOSUB and RETURN

 

Pass the control to the specified line and save return address to table (stack) gosub.

 

Format of the operator:

 

[N] GOSUB line_number

 

Where

N - number of line (Basic-label)

line_number - number of line (Basic-label)

 

During execution operator GOSUB, Open Basic pass control to a line,

given in operator GOSUB. The program continues since this line.

 

During execution operator RETURN, Open Basic retrieve return address from table (stack) gosub and pass control to this address.

 

Operators GOSUB and RETURN are used only in pair.

 

Format of operator RETURN:

 

[N] RETURN

 

Where

N - number of line (Basic-label)

 

Subroutines can be put each other.

 

Example:

 

GOSUB 10

GOTO 100

 

10

PRINT "Work GOSUB operator 1"

GOSUB 20

PRINT "Work GOSUB operator 2"

RETURN

20

PRINT "Work GOSUB operator 3"

PRINT "Work GOSUB operator 4"

RETURN

100

 

STOP

END

 

Result:

 

Work GOSUB operator 1

Work GOSUB operator 3

Work GOSUB operator 4

Work GOSUB operator 2

 

3.13.6. Operator LET

 

The operator assign value to variable.

 

Format of the operator:

 

[N] [LET] VAR=EXP

 

Where

N - number of line (Basic-label)

LET - optional name of operator

VAR - variable name

EXP - the expression determining new value

 

Example:

 

20 LET a=100.1

PRINT "Work LET operator","a=";a

 

Result:

 

Work LET operator a=100.1

 

3.13.7. Operator DIM

 

Operator create numerical or string array.

 

Format of the operator:

 

[N] DIM LIST

 

Where

N - number of line (Basic-label)

LIST - the list of names of the files, separated by comma

 

Arrays of Open Basic need to be described before first by operator DIM.

Arrays can be multidimensional. Memory space for arrays and variables allocate

in free memory by operator new. Max size of arrays restrict by realization operator new in OS.

 

For example MS DOS 'new' does not request more 64K byte. Therefore under MS DOS size of Open Basic array can not be more 64K byte. Size of one dimension thus also can not exceed 64K byte.

 

First index of arrays is 1.

 

As against standard language Basic, operator DIM in Open Basic is executed. It execute each time when execute.

The repeated description of array with the same name in operator DIM is supposed.

The new array can have other dimensions. The old data thus are lost.

This mechanism can be applied to clearing memory. After capture big

array by operator DIM it is possible to release memory, having described array with the same name and dimension in one element.

At the description of array file in operator DIM as dimensions can used the integer variables.

At creation numerical arrays are initialized by zero. String arrays

are initialized by empty line ("").

 

The type of array is defined by presence symbols '%' or '$' in a name.

 

Example:

DIM a%(2,2,3),b(3,2,4)

DIM a$(2,2,3,2)

 

a$="variable string"

a$(1,1,3,2)="array string"

a%(2,2,3)=10

b(1,1,1)=101.1

 

 

PRINT a$(1,1,3,2)

PRINT a$

PRINT "a%=";a%

PRINT "b=";b

 

Result:

 

array string

variable string

a%=10

b=101.1

 

 

3.13.8. Operators STOP and END

 

Operators are used for end of work of the program.

Operator STOP clear all tables Open Basic - variables, files etc.

Operator END also clear all tables Open Basic and in addition set internal flag endoperatordetect. Reset of this flag is made by method ob_obasic::load.

Operators do not clear table of user functions.

If Basic program has overlay structure and its subsequent parts are loaded by method load with parameter OVERLAY, operators STOP and END should place only at the end of last part of programs.

 

Format of operators:

 

[N] STOP

[N] END

 

Where

N - number of line (Basic-label)

 

Example:

PRINT "example STOP and REM operator"

10 STOP

20 END

 

3.13.9. Operator REM

 

Enters comments in the program.

 

Format of the operator:

 

[N] REM COMMENT

 

Where

N - number of line (Basic-label)

COMMENT - text of the comment

 

Operators REM and empty lines increase execution time of the program and take a place in memory.

 

Example:

 

10 REM this text is comment

 

3.13.10. Operators OPEN and CLOSE

 

Operator OPEN opens a file. Operator CLOSE closes a file.

 

Format of operator OPEN:

 

[N] OPEN filename FOR INPUT AS FILE #EXP

[N] OPEN filename FOR OUTPUT AS FILE #EXP

 

Where

N - number of line (Basic-label)

filename - a name of file

 

EXP - expression is calculated and resulted cast to integer type. Usually

use constants.

 

AS FILE - keywords

 

Operator OPEN FOR INPUT opens a file for read.

Operator OPEN FOR OUTPUT opens a file for write.

 

Format of operator CLOSE:

 

[N] CLOSE #EXP1,[#EXP1,#EXP2,...]

 

Where

 

N - number of line (Basic-label)

EXP - expression is calculated and resulted cast to integer type. Usually

use constants.

 

Example:

 

k%=10

 

OPEN "F000.TXT" FOR OUTPUT AS FILE #k%+1

OPEN "F001.TXT" FOR OUTPUT AS FILE #k%+2

 

FOR i%=1 TO KOL% STEP 1

PRINT "i%=",i%

PRINT #k%+1,i%

f=i%+0.1

PRINT #k%+2,f

NEXT i%

 

CLOSE #k%+1

CLOSE #k%+2

 

OPEN "F000.TXT" FOR INPUT AS FILE #k%+2

OPEN "F001.TXT" FOR INPUT AS FILE #k%+3

 

FOR i%=1 TO KOL% STEP 1

INPUT #k%+2,ii%

INPUT #k%+3,ff

PRINT "ii%=",ii%

f=i%+0.1

IF ii%<>i% THEN PRINT " Error test OPEN-CLOSE command" GOTO 10

IF ff<>f THEN PRINT " Error test OPEN-CLOSE command" GOTO 10

NEXT i%

 

CLOSE #k%+2

CLOSE #k%+3

 

10 STOP

END

 

3.13.11. Operator KILL

 

Delete file.

 

Format of the operator:

 

[N] KILL STR1[,STR2,STR3,...]

 

Where

 

N - number of line (Basic-label)

STR1,STR2,STR3 - names of files

 

Example:

 

10 KILL "F000.TXT","F001.TXT"

 

3.13.12. Operators READ, DATA and RESTORE

 

Operators READ and DATA are used for organization of the block of data, which is read by interpreter Open Basic in execution time of the program.

 

Format of operator READ:

 

[N] READ VAR1[,VAR2,VAR3,...]

 

Where

 

N - number of line (Basic-label)

VAR1, VAR2, VAR3 list of variables. This variables are assigned value from DATA list (block)

 

Format of operator DATA:

 

[N] DATA EXP1,[EXP1,EXP2,...]

 

Where

N - number of line (Basic-label)

EXP1, EXP2, EXP3, - expression is calculated placwd into DATA list (block). Can be numerical or string. Usually use constants.

 

Format of operator RESTORE:

 

[N] RESTORE

 

Where

N - number of line (Basic-label)

 

Before executing of program, Open Basic looks through all operators DATA in

the order of their occurrence and creates the list (block) of operators DATA.

 

During execution operator READ read next value from list (block) of operators DATA and assignment it to next variables from own list. After read internal position of list (block) of operators DATA is shifting.

 

Operator RESTORE set internal position of list (block) of operators DATA to first element.

 

Operator DATA should be the unique operator in a line.

 

Example:

 

DATA 1.1,2,3,4,"1 string for data"

DATA 5.1,6,7,4+4,"2 string for data"

 

DIM z%(3)

 

READ a2,z%(1),z%(2),z%(3),e2$

 

READ a,b%,c%,d%,e$

PRINT "a=";a;" b%=";b%;" c%=";c%;" d%=";d%;" e$=";e$

READ a1,b1%,c1%,d1%,e1$

PRINT "a1=";a1;" b1%=";b1%;" c1%=";c1%;" d1%=";d1%;" e1$=";e1$

RESTORE

READ a1,z%(1),z%(2),z%(3),e1$

PRINT "a1=";a1;" z%(1)=";z%(1);" z%(2)=";z%(2);" z%(3)=";z%(3);

PRINT " e1$=";e1$

 

Result:

 

a=1.1 b%=2 c%=3 d%=4 e$=1 string for data

a1=5.1 b1%=6 c1%=7 d1%=8 e1$=2 string for data

a1=1.1 z%(1)=2 z%(2)=3 z%(3)=4 e1$=1 string for data

 

3.13.13. Operator RANDOMIZE

 

Initializes random generator by new value. As new value current system time in seconds is used. Therefore repeatedly operator RANDOMIZE is necessary to use not earlier, than in 1 second after it previous use.

 

Format of the operator:

 

[N] RANDOMIZE

 

Where

N - number of line (Basic-label)

 

Operator RANDOMIZE is used before first use of random function RND.

 

Example:

 

10 RANDOMIZE

 

3.13.14. Operator IF.

 

Use for organization of conditional transitions. Have three formats: line, block and block short.

 

Line format of operator IF:

 

[N] IF REL-EXP THEN operators

 

Where

N - number of line (Basic-label)

THEN - keyword

REL-EXP - checked condition. Condition expression can be arithmetic or string.

operators - the operator or group of operators

 

If condition REL-EXP is true, operators are executed. If condition is false the operator in next line is executed.

 

Example:

TT%=40

20 IF TT%=40 THEN GOTO 50

PRINT "This operator do not work in example"

50 PRINT "Work IF operator","TT%=";TT%

 

Result:

 

Work IF operator TT%=40

 

Example:

 

TT%=40

IF TT%=40 THEN PRINT "Work IF operator","TT%=";TT% GOTO 10

PRINT "This operator do not work in example"

10 PRINT "Work IF operator","TT%=";TT%

 

Result:

 

Work IF operator TT%=40

Work IF operator TT%=40

 

Example:

 

TT%=40

IF TT%=40 THEN a=101.1 b=102.1 c=103.1 GOTO 10

a=1101.1 b=1102.1 c=1103.1

PRINT "This operator do not work in example"

10 PRINT "a=";a,"b=";b,"c=";c

 

Result:

 

a=101.1 b=102.1 c=103.1

 

Block format of operator IF:

 

[N] IF REL-EXP THEN

operators1

ELSE

operators2

ENDIF

 

Where

N - number of line (Basic-label)

THEN - keyword

REL-EXP - checked condition. Condition expression can be arithmetic or string.

operators - the operator or group of operators

 

If condition REL-EXP is true, operators in the block between keywords THEN and ELSE are executed.

If condition REL-EXP is false, operators in the block between keywords ELSE and ENDIF are executed.

 

The block short format of operator IF:

 

[N] IF REL-EXP THEN

operators1

ENDIF

 

Where

N - number of line (Basic-label)

THEN - keyword

REL-EXP - checked condition. Condition expression can be arithmetic or string.

operators - the operator or group of operators

 

If condition REL-EXP is true, operators in the block between keywords THEN and ELSE are executed.

If condition is false the operator in next line is executed.

 

3.14. Built - in functions

 

3.14.1. Function SGN%

 

Function SGN% - function of sign.

 

Format: SGN%(EXP)

 

Where EXP is integer or floating point expression.

 

Function returns +1 if EXP > 0,

Function returns -1 if EXP < 0,

Function returns 0 if EXP == 0,

 

If the argument is incorrectly (for example string type), error is generated.

 

Example:

 

PRINT "This is example SGN function"

PRINT "<0";SGN%(-1-2);" >0";SGN%(2*3);" =0";SGN%(9+1-10)

 

3.14.2. Function ABS

 

Function ABS - absolute value of argument.

 

Format: ABS(EXP)

 

Where EXP is integer or floating point expression.

 

Function returns result with a floating point for all argument types.

If the argument is incorrectly (for example string type), error is generated.

 

Example:

 

PRINT "This is example ABS function"

PRINT "abs(-20.5)=";ABS(-20.5);" abs(20.5)=";ABS(20.5)

 

3.14.3. Function INT%

 

Function INT% - integer part of argument.

 

Format: INT%(EXP)

 

Where EXP is integer or floating point expression.

 

Function returns integer result.

If the argument is incorrectly (for example string type), error is generated.

 

Example:

 

PRINT "This is example INT% function"

PRINT "int(-20.3)=";INT%(-20.3);" int(20.3)=";INT%(20.3)

 

3.14.4. Functions SIN, COS, ATN, SQR, EXP, LOG and LOG10

 

Functions calculate a sine, cosine, arctangent, a square root, exhibitor, logarithm, and the decimal logarithm accordingly.

 

Formats:

SIN(EXP),

COS(EXP),

ATN(EXP),

SQR(EXP),

EXP(EXP),

LOG(EXP),

LOG10(EXP)

 

Where EXP is integer or floating point expression.

 

Functions return floating point result.

If the argument is incorrectly (for example string type), error is generated.

 

Example:

 

PRINT "This is example trigonometric function"

a=SIN(3.14/2)

b=COS(0)

c=ATN(1)

d=SQR(4.0)

e=EXP(1)

f=LOG(EXP(1))

g=LOG10(10)

PRINT "a=";a;" b=";b;" c=";c;" d=";d;" e=";e;" f=";f;" g=";g

 

3.14.5. Function RND

 

Function RND - generates a random number in interval 0-1.

Format: RND().

 

Function returns floating point result.

Arguments are ignored.

 

Example:

 

PRINT "This is example RND function"

PRINT RND(),RND(),RND(),RND();

RANDOMIZE

PRINT RND(),RND(),RND(),RND();

 

3.14.6. Function LEN%

 

Function LEN% - length of string.

 

Format: LEN%(EXP)

 

Where EXP is string expression.

 

Function returns integer result.

If the argument is incorrectly (for example integer type), error is generated.

 

Example:

 

PRINT "This is example LEN function"

STRing_this$="aaa bbb ccc ddd"

PRINT "len=";LEN%(STRing_this$)

 

3.14.7. Functions DAT$ and CLK$

 

Functions return date and time accordingly.

 

Formats:

 

DAT$(),

CLK$()

 

Function are returned string result.

Arguments are ignored.

 

Format of date: day-month-year

Format of time: hour:min:sec

 

Example:

 

PRINT "This is example DAT$ & CLK$."

PRINT "data=";DAT$;" time=";CLK$

 

3.14.8. Functions D2STR$, D2HEXSTR$, STR2FLOAT and STR2INT%

 

Function D2STR$ - converts number to decimal string

 

Format: D2STR$(EXP)

 

Where EXP is integer or floating point expression

 

Function returns string result.

 

Function D2HEXSTR $ - converts integer number to hexadecimal string

 

Format: D2HEXSTR$(EXP)

 

Where EXP is integer expression

 

Function returns string result.

 

Function STR2FLOAT - converts string to floating point number

 

Format: STR2FLOAT(EXP)

 

Where EXP is string

 

Function returns floating point number. If the string can not be

converted to number, function returns zero.

 

Function STR2INT of % - converts string to integer

 

Format: STR2INT%(EXP)

 

Where EXP is string

 

Function returns integer number. If the string can not be

converted to number, function returns zero.

 

Example:

 

PRINT "converter from digit to string =";D2STR$(123)

PRINT "converter from string to float =";STR2FLOAT("1.234")

PRINT "converter from string to int =";STR2INT%("1234")

PRINT "converter from digit to hex string =";D2HEXSTR$(4660)

 

 

3.15. Error handling

 

During execution *.bas program Open Basic can generates exception.

Type of exception is class ob_err.

The user should intercept this exception and handling it.

For this purpose the class ob_err has special methods. The typical handling of exceptions ob_err:

 

int main(int argc, char * argv[]){

 

int ret=0;//return code main

 

ifstream fi;//input stream

 

try{

 

ob_obasic basic_interpreter(OB_NULL);//create interpreter

 

fi.open("test1.bas",ios::binary);//open input stream in ios::binary mode

 

basic_interpreter.load(&fi);//load *.bas program

 

ob_obasic::typeend te=basic_interpreter.run();//start *.bas program

 

cout<<endl<<"Stop by stop code";//print exit code

cout<<endl<<"Stop code=";

 

switch(te){

case ob_obasic::ENDOPERATORDETECT :cout<<"ENDOPERATORDETECT";break;

case ob_obasic::ENDFILEEND :cout<<"ENDFILEEND";break;

case ob_obasic::BREAKPOINTEND :cout<<"BREAKPOINTEND";break;

case ob_obasic::NOLOADEND :cout<<"NOLOADEND";break;

case ob_obasic::BREAKBEFOREOPERATOR:cout<<"BREAKBEFOREOPERATOR";break;

case ob_obasic::BREAKAFTEROPERATOR :cout<<"BREAKAFTEROPERATOR";break;

case ob_obasic::EOLEND :cout<<"EOLEND";break;

default:cout<<"Unknown stop code";break;

}//switch

 

}//try

 

catch(ob_err& e){

 

cout<<endl<<"Stop by OB exception catch";//error handling

ret=e.getcode(); //get error code

e.release(&cout,&ob_englmessage); //print diagnostic message to cout

 

}//OB catch

 

return ret;

}

 

For error handling class ob_err has methods getcode and release.

 

virtual ob_type_codeerror getcode ();

virtual void release(ostream* os, ob_message* currentmessage);

 

The method getcode has no arguments and returns an error code.

The method release has two arguments: stream pointer and table diagnostic messages.

The method release writes text message from tables diagnostic messages to specified stream.

Open Basic have table diagnostic messages in English ob_englmessage. User can create the own table diagnostic messages in the other language and use it as the second argument of method release.

For inquire line error, it is necessary use function ob_loadbreakstr.

 

More detail about exceptions handling see in file .\example\ob.cpp.

 

3.16. Table of diagnostic messages

The list of diagnostic messages is below given:

 

"End programm OK", // 0 - normal end of the program

 

"Divide by zero", // 1 - division by zero

 

"Incompatible operand for this operation", // 2 - incompatible operands

(for example string and numerical in arithmetic operation)

 

"Sintax error", // 3 - sintax error

 

"Missing ')'", // 4 - the right bracket do not found (may be too much

arguments in function or dimensions in array)

 

"Missing primary", // 5 - it is expected primary in this place of the program.

 

"Too long name or string", // 6 - too long string or name of variable

 

"Use variable before definition", // 7 - use variable in the right part of the operator of assignment before it use in the left part.

 

"Missing '='", // 8 - symbol of assignment is expected in this place of program.

 

"Error read input stream", // 9 read error from input stream.

 

"Duplicate label in program", // 10 - the label is described in program twice.

 

"System error. Please contact your dealer", // 11 - it is not used

 

"Label not present in GOTO or GOSUB", // 12 - label do not found in table of labels

 

"Missing compare operator in operator IF", // 13 - expression of the relation (< >, < =, etc.) is expected in operator IF

 

"Missing keyword THEN in operator IF", // 14 - keyword THEN is expected in operator IF

 

"System error. Please contact your dealer", // 15 - it is not used

 

"Missing label in GOTO or GOSUB operator (label must be decimal number)", // 16

- label is expected in operator GOTO.

 

"Not GOSUB operator for this RETURN operator", // 17 during execution operator RETURN the stack subroutines is empty

 

"Counter parameter of FOR operator must be variable or array element", // 18

- counter of cycle must be variable or element of array.

 

"Missing keyword TO in operator FOR", // 19 - keyword TO is expected in operator FOR

 

"System error. Please contact your dealer", // 20 - it is not used

"System error. Please contact your dealer", // 21 - it is not used

"System error. Please contact your dealer", // 22 - it is not used

 

"Error in parameters built-in function", // 23 error at analysis of parameters functions.

 

"Missing name array in DIM operator", // 24 - name of array is expected in operator DIM

 

"System error. Please contact your dealer", // 25 - it is not used

 

"Too many array dimension", // 26 - is too many dimension of array

 

"Missing ',' in DIM operator to separate value", // 27 - in operator

DIM use comma for separate names of array

 

"System error. Please contact your dealer", // 28 - it is not used

 

"Size of array is negative or zero", // 29 - zero or negative size of array

 

"System error. Please contact your dealer", // 30 - it is not used

 

"Size of array is zero", // 31 - the zero size of array

 

"Current index of array too big", // 32 - the additional control for error 59

 

"Missing keyword FOR in operator OPEN", // 33 - keyword FOR is expected in operator OPEN

 

"Missing mode opened file in operator OPEN", // 34 - keyword of a mode of opening is expected in operator OPEN

 

"Missing keyword ' AS' or ' FILE 'or' * ' in operator OPEN", // 35 - keyword AS FILE is expected in operator OPEN

 

"System error. Please contact your dealer", // 36 - it is not used

"System error. Please contact your dealer", // 37 - it is not used

 

"File not open", // 38 - the file is not open.

 

"System error. Please contact your dealer", // 39 - it is not used

"System error. Please contact your dealer", // 40 - it is not used

 

"Too many parameters in call function", // 41 - it is too many

parameters in a call of function.

 

"System error. Please contact your dealer", // 42 - it is not used

"System error. Please contact your dealer", // 43 - it is not used

"System error. Please contact your dealer", // 44 - it is not used

"System error. Please contact your dealer", // 45 - it is not used

"System error. Please contact your dealer", // 46 - it is not used

"System error. Please contact your dealer", // 47 - it is not used

"System error. Please contact your dealer", // 48 - it is not used

"System error. Please contact your dealer", // 49 - it is not used

 

"Unary minus can not use for string type", // 50 - attempt to apply operation

unary minus to string variable

 

"Compare with zero can not use for string type", // 51 - attempt to apply

operation of comparison with zero to string variable

 

"Arithmetic operator can not use for string type", // 52 - attempt to apply

arithmetic operation to string variable

 

"Can not compare string and digital type", // 53 - attempt to apply

operation of comparison with number and string variable

 

"Error format of float number (is two point in float number)", // 54 - error

format floating point constant

 

"Error format of hex number", // 55 error format hexadecimal constant

 

"Error format of number (is point and 'x' letter in hex number)", // 56

- error format hexadecimal constant

 

"String do not have right quote", // 57 do not found right quote in string

constant

 

"Current count dimension of array is not equal that DIM operator", // 58-

The amount of dimensions in the current reference of array is not equal amount

dimensions in operator DIM

 

"One or many current dimension of array is too big", // 59 - attempt will address to

To element of a file with number big, than it(he) is described in operator DIM.

For example, DIM a % (10,20) and the reference(manipulation) a % (5,21).

 

"System error. Please contact your dealer", // 60 - it is not used

"System error. Please contact your dealer", // 61 - it is not used

"System error. Please contact your dealer", // 62 - it is not used

"System error. Please contact your dealer", // 63 - it is not used

 

"Do not clear left in primary (debug error)", // 64 - debugging information.

Should not appear at normal work

 

"Do not clear left in run user function (debug error)", // 65 - debugging

information. Should not appear at normal work

 

"Do not found NEXT operator for FOR operator", // 66 - operator NEXT do not found for current operator FOR

 

"System error. Please contact your dealer", // 67 - it is not used

"System error. Please contact your dealer", // 68 - it is not used

 

"Parameter of NEXT operator must be variable or array element", // 69

- counter of cycle must be variable or element of array.

 

"Do not found ELSE or ENDIF operator for IF operator", // 70 do not found keywords ELSE or ENDIF for current operator IF

 

"Do not found FOR operator for this NEXT operator", // 71 - operator FOR is not found for current operator NEXT

 

"Need '(' in DIM operator or array use" // 72 - the left bracket is not found after array name in operator DIM

 

"Can not cast float to string" // 73 - attempt of cast number to string

 

"Can not cast int to string" // 74 - attempt of cast number to string

 

"Can not cast string to float" // 75 - attempt of cast string to number

 

"Can not cast string to int" // 76 - attempt of cast string to number

 

"Index of array must not be zero" // 77 - current index array is equal to zero

 

"Do not clear ptr in setptr for savewrapper (debug error)", // 78 - debugging

information. Should not appear at normal work

 

"Array dimension less than zero", // 79 - the current index array is less than zero

 

"Error file name format in OPEN operator", // 80 error of name of file

(it is possible an empty line)

 

"Error wrire to output stream", // 81 write error in operator PRINT

 

Сайт создан в системе uCoz