0 Members and 1 Guest are viewing this topic.
Welcome to SmallBASIC Sat, 12/22/2007 - 05:18 - chrisws SmallBASIC is a fast and easy to learn BASIC language interpreter ideal for everyday calculations, scripts and prototypes. SmallBASIC includes trigonometric, matrices and algebra functions, a built in IDE, a powerful string library, system, sound, and graphic commands along with structured programming syntax.Constants and Variables All user variables (include arrays) are ‘Variant’. That means the data-type is invisible to user.Arrays are always dynamic, even if you had declared their size, with dynamic size and type of elements. However, SmallBASIC uses, internally, 4 data-types Integer (32bit)Real (64bit)String (<32KB on 16bit / 2GB on 32bit)Array (~2970 elements on 16bit / ~50M elements on 32bit) Conversions between those types are performed internally. In any case there are functions for the user to do it manually.Variable namesVariable names can use any alphanumeric characters, extended characters (ASCII codes 128-255 for non-English languages) the symbol ‘_’, and the symbol ‘$’. The first character of the name cannot be a digit nor a ‘$’.About the dollar-symbolThe symbol ‘$’ is supported for compatibility. Since in SmallBASIC there are no data-types its use is meaningless.The dollar in function names will be ignored.The dollar in variable names will be count as part of the name (that means v and v$ are two different variables). It can be used only as the last character of the name, and only one allowed.The dollar in system variables names will be ignore it (that means COMMAND and COMMAND$ is the same)Example of variable names:abc, a_c, _bc, ab2c, abc$ -> valid names 1cd, a$b, $abc -> invalid names IntegersThis is the default data type. You can declare integers in decimal, hexadecimal, octal and binary form.x = 256 ' x = 0x100 ' Hexadecimal form 1 x = &h100 ' Hexadecimal form 2 x = 0o400 ' Octal form 1 x = &o400 ' Octal form 2 x = 0b111 ' Binary form 1 x = &b111 ' Binary form 2 RealsAny number which out-bounds the limits or an ‘integer’ or had decimal digits will be converted automatically to real.x = .25 x = 1.2 Reals can be also written by using scientific notation. 1E+2 or 1E-+2, 5E—2, 2.6E-0.25, etcStringsStrings may be appended to one another using the + operator.b = "Hello, " + "world!" ConstantsConstant variables can be declared by using the keyword CONST.CONST my_pi = 3.14 System VariablesSystem variables, are constant variables for the programmer. Those variables get values or modified at run-time by the SB’s subsystem. OSNAME Operating System nameOSVER Operating System Version (0xAABBCC (A=major, B=minor, C=patch))SBVER SmallBASIC Version (0xAABBCC)PI 3.14..XMAX Graphics display, maximum x (width-1)YMAX Graphics display, maximum y (height-1) valueBPP Graphics display: bits per pixel (color resolution)VIDADR Video RAM address (only on specific drivers)CWD Current Working DirectoryHOME User’s home directoryCOMMAND Command-line parametersTRUE The value 1FALSE The value 0 OperatorsSorted by priority ( ) Parenthesis+, – Unary~ bitwise NOTNOT or ! Logical NOT (NOT false = true)^ Exponentiation*, /, \ Multiplication, Division, Integer Division% or MOD Reminder (QB compatible: a=int(a), b=int(b), a-b*(a/b))MDL Modulus (a%b+b*(sgn(a)<>sgn(b)))+, – Addition/Concatenation, Subtraction= Equal<> or != Not Equal>, < Less Than, Greater Than=>, =< Less or Equal, Greater or Equal>=, <= Less or Equal, Greater or EqualIN belongs to … (see “The IN operatorâ€)LIKE Regular expression match (see “The LIKE operatorâ€)AND or && Logical ANDOR or Logical ORBAND or & bitwise ANDBOR or bitwise OREQV bitwise EQVIMP bitwise IMPXOR bitwise XORNAND bitwise NANDNOR bitwise NORXNOR bitwise XNOR Special Characters &h or 0x Prefix for hexadecimal constant (0×1F, &h3C)&o or 0o Prefix for octal constant (0o33, &o33)&b or 0b Prefix for binary constant (0b1010, &b1110)[,;] Array definition (function ARRAY) ($1)<< Appends to an array (command APPEND) ($1)++ Increase a value by 1 (x = x + 1) ($1)— Decrease a value by 1 (x = x – 1) ($1)p= Another LET macro (x = x p …). Where p any character of -+/\*^%&: Separates commands typed on the same line& Join code lines (if its the last character of the line). The result line its must not exceed the max. line size.# Meta-command (if its the first character of the line) or prefix for file handle@ The ‘at’ symbol can by used instead of BYREF ($1)‘ Remarks
abc, a_c, _bc, ab2c, abc$ -> valid names 1cd, a$b, $abc -> invalid names
x = 256 ' x = 0x100 ' Hexadecimal form 1 x = &h100 ' Hexadecimal form 2 x = 0o400 ' Octal form 1 x = &o400 ' Octal form 2 x = 0b111 ' Binary form 1 x = &b111 ' Binary form 2
x = .25 x = 1.2
b = "Hello, " + "world!"
CONST my_pi = 3.14