User Tools


reference:language_specifications

Language Specifications

Character Codes

Handles UTF-8 for external I/O and UTF-16 for internal. Only Basic Multilingual Plane are supported, and extended planes from the Plane 1 are not supported.

Surrogate pairs are ignored.

Types of Words in a Program

Words used in a program are roughly divided into two types: identifiers and literals.

Identifiers are used as commands, variables, constants, labels, and reserved words in a program.

Literals are used to represent numeric data and text data in a program.

Identifiers

The identifier is a sequence of alphanumeric characters or underscores of any length that begin with a letter or underscore. (Regular expressions are [_A-Z] [_A-Z0-9]+) It's case-insensitive.

One of symbol characters, %, # and $, may be added at the end of the identifier. This symbol is called a type suffix.

Reserved Words

The following identifiers are said to be reserved words, and cannot be used for variable names or command/function names because they are used for linguistic structure.

IF THEN ELSE ELSEIF ENDIF CASE WHEN OTHERWISE ENDCASE GOTO GOSUB RETURN ON LOOP ENDLOOP FOR NEXT WHILE WEND REPEAT UNTIL BREAK CONTINUE
DEF END DEFOUT VAR DIM AND OR XOR NOT DATA READ RESTORE PRINT TPRINT INPUT LINPUT CALL SWAP OUT COMMON EXEC

Labels

Identifiers beginning with '@' are called a label, and are used to display a position in the program.

When a label appears in a normal string expression, it is treated as a string value containing the label itself.

Constants

Identifiers beginning with '#' are called a constant, and the corresponding numerical value or string is determined for each constant. When a constant appears in an expression, it is replaced with the corresponding value.

Literals

There are roughly two types of the basic data handled by SmileBASIC: numeric type and string type. Words that represent basic data are called literals.

Numeric literals are divided into Int literals and Real literals.

Integer literal is a decimal number from 0 to ‭2147483647, a hexadecimal value with &H at the beginning, or a binary value with &B at the beginning.

Floating point number literals are numbers that include a decimal point or exponential notation.

String literals are text enclosed in double quotation marks ".

Values

The basic unit of data handled by SmileBASIC is called a value.

There are numerical types (Int type, Real type), String type, Array type, and Empty type.

Int Type

Signed 32-bit integer number. Values ​​from -2147483648 to 2147483647 can be expressed.

Real Type

64bit. IEEE754 double-precision floating point number.

String Type

A sequence of characters of any length. Maximum length is 2^31 characters (depending on available memory).

The character unit consists of UTF-16.

Array Type

Multiple Int, Real, and string types can be stored.

Maximum number of elements is 2^31 (depends on available memory)

The maximum number of dimension is 4 dimensions.

Arrays of two or more dimensions are all subsets of 1D arrays and can be referred to as 1D arrays.

Empty Type

This is the default type, and displays "no value".

Attempting to use an empty type within an operation will result in an error.

Value Type Conversion

All values ​​exchanged between Int and Real types are implicitly converted.

In addition, when performing a mixed operation of an Int type and a Real type, the handling varies depending on whether the operator performs an Int calculation.

For operators that perform Int calculations, Real type is implicitly converted to an Int type, and the result will be also an Int type.

For operators that perform Real calculations, Int type implicitly converted to Real type, and the result will be also Real type.

In the case of operators other than those described above, a binary operator has a Real type when either of the left side and the right side is a Real type, or when a calculation result exceeds Int type value range with a double-sided Int type.

See the explanation of operators below for whether operators perform Int calculations or Real calculations.

About Reference Types

・Values ​​have a type with the characteristic of a reference type.

・The string type and all array types are reference types.

・When a numeric type is substituted from one variable A to another variable B, the value A to B is copied, and treated as a completely different value, and even if the contents of the original variable are changed, the substituted value does not change.

・The reference type value is divided into two parts, the data entity and the reference information. Only the reference information stores variables, not the data entity.

・If a variable A containing a reference type value is substituted to another variable B, the value A to B is copied in the same way as the numeric type, but only the reference information is copied, not the data entity.

・ As a result, different variables A and B referencing the same data entity are created.

・In this state, if you use commands to manipulate the string of A, it will appear that the contents of B have changed.

・To avoid this situation, copy the data entity using the COPY command. However, if you understand the above characteristics, you will find that there are not many situations where you need to use the COPY command.

Reference Type Examples

A$="ABC"     'Reserve initial ABC memory
B$=A$        'Variables are different, but they refer the same data entity
?A$,B$       'ABC and ABC are displayed
A$[1]="Z"    'Rewrite the data entity
?A$,B$       'AZC and AZC are displayed

B$=B$+"X"    'String+String creates another string
?A$,B$       'AZC and AZCX are displayed
C$=B$        'Variables are different, but the reference is the same memory
?A$,B$,C$    'AZC and AZCX and AZCX are displayed
PUSH C$,"W"  'W is added to the referent C$ data entity
?A$,B$,C$    'AZC and AZCXW and AZCXW are displayed

A$="ABC" 
B$=COPY(A$)  'Use COPY function to create a different string
A$[1]="Z" 
?A$,B$       'Unlike the first example, AZC and ABC are displayed

Variables

Variable is equivalent to a box for storing any values.

The initial value of a variable is determined by the type suffix attached to the variable name.

None Default Type Value
$ Empty String (Zero-Length String)
% Zero (Int)
# Zero (Real)

The default type value is normally a Real zero, and when OPTION DEFINT is specified, it is an Int zero.

The variable itself has no type, and it can store any type of values regardless of the immediately preceding value type.

Variable Scope

There are two types of variable scope: Global and Local.

Global variables are variables defined outside of user-defined commands and functions, and they can be referenced from anywhere in the program.

Local variables are variables defined inside of user-defined commands and functions, and they can be referenced only within the defined user-defined commands and functions.

Name Space

Variables, constants, commands/functions, and labels are divided into different name spaces, and using the same names does not cause an error.

This rule also applies to built-in commands and functions.

Runtime References for Language Elements

Among the language elements of SmileBASIC, labels, variables, commands and functions can be searched and used from strings at runtime.

Runtime References for Labels

You can specify strings as the destination of GOTO / GOSUB and the argument of RESTORE.
If a string is specified, it will search for the destination at runtime and jump to it.
If the destination is not found, an undefined label error will occur.
If a string starts with the prefix "Number:", the label of the specified program slot is searched.

Runtime References for Variables

By specifying VAR ("VariableName"), it is possible to search for and use a variable at runtime.
For example, VAR ("FOO") = 3 has the same meaning as FOO = 3.
If the variable is not found, an undefined variable error will occur.
If a string starts with the prefix "Number:", the variable of the specified program slot is searched.

Runtime References for Commands and Functions

The CALL keyword can be used to find and call commands and functions at runtime.

  • CALL ("FOO",A,B,C) is equivalent to FOO A,B,C
  • A = CALL ("FOO",A,B,C) is equivalent to A = FOO (A,B,C)
  • CALL ("FOO",A) ,B,C is equivalent to FOO (A), B,C

When the command or function is not found, an undefined function error will occur.
Commands and functions can be referenced regardless of whether they are built-in or user-defined, but PRINT and INPUT cannot be referenced because they are built in as language elements.
If a string starts with the prefix "Number:", the command/function of the specified program slot is searched.

reference/language_specifications.txt · Last modified: 2020/08/24 12:17 (external edit)

Page Tools