-
Notifications
You must be signed in to change notification settings - Fork 0
Language Reference Manual
FBasic syntax represents the fundamental rules of a programming language. Without these rules, it is impossible to write a functioning code. FBasic is extendable and the developer can incorporate new functions and new statements. It is a free-form language, but as it is an interpreter, the error if that exists will be raised when the execution flow reaches the mistyped command.
In this manual you can find the following chapters
-
Flow Control Statements
-
Loops
-
Statements
-
Debugging
-
Comments
-
Datatypes
-
Functions
-
Operators
-
Libraries and Add-Ons
1. String functions
2. Mathematical functions
3. Date and Time functions
4. SQL Data provider (see Language Reference Collections)
5. Events triggering
6. Text (Placeholder) Replacer
7. Stack Library
8. Artificial intelligence (AI) Chat Library
9. Events Library
10. Json Library
11. Streams Library
12. Decision Tables -
Handlers
- IF … THEN … ELSE … ENDIF
- GOTO
- GOSUB … RETURN
- CALL
- CHAIN
- HALT or END
- RESULT
The command HALT or END ends the processing of the current program and lets the interpreter return to the caller. Using the statement RESULT, the program can return a value to the caller. This value is available as value to the variable RESULTVALUE as well as a property to the execution result. The program can have several RESULT statements and the active value is the value specified by the last RESULT statement. The RESULTVALUE is a variable and can be used as any variable.
Example:
RESULT 0 If a > 10 Then RESULT 3 Else RESULT 456 EndIf print RESULTVALUE
See more information about RESULT at Chapter Identifiers - Special Purpose Variables - Variable RESULTVALUE
- FOR … TO … NEXT
- FOREACH ( for further info check collections paragraf )
FOR is used to create a loop within a program with the given parameters. In each loop, the variable value is increased by 1. When the variable value is above the TO value, the loop stops. The increase of the variable value happened on the NEXT statement.
Note: the word STEP known from other BASICs is not supported.
Example:
For i = 1 To 10 let a = a + 1 print a Next i assert a = 10
- LET
- INPUT
- RINPUT
Used to assign the value of an expression to a variable. Syntax is: Let varname = expression
LET D=12 LET E=12^2 LET F=12^4 LET SUM=D+E+F
Both statements are used for input and output. They have only one argument, which is variable or literal. The input and the output handler should be installed.
| Statement Reference | Notes |
|---|---|
| See examples here and in statements manual page | |
| INPUT | See examples for input usage |
example:
print "Enter value for a1:"; input a1 print a1
Used to perform an input request to the RequestObjectHandler. Has 3 arguments separated by comma.
Usage: RINPUT group, name, identifier
Where Group and Name are identifiers that are passed to the RequestObjectHandler to organize the request. The Context is always "IN"
The last argument, which is variable name that will store the return of the request.
The RequestObjectHandler, handler should be installed.
example:
let s="empty!" print s rinput TEST, NAME, s print s End
- ASSERT
- DUMP
- LOGINFO
- REM
- inline comment character: ' [single quote]
example:
REM test code let a=10 ' set the value 10 to variable a
FBASIC, as programming language, typically offers two primary data types: String and Real.
- A String is a sequence of characters, such as letters, numbers, or symbols, enclosed in double quotes. It's used for handling text.
- A Real (also known as a floating-point number) represents a number with a fractional component. It's used for all numerical calculations, from simple arithmetic to complex equations.
In FBASIC interpreter, other data types like Integer, Boolean, Date, and Time are not natively supported. The FBASIC simulate these by using the existing Real and String types and applying specific conventions or libraries to manage them. For instance, integers are stored as Real numbers, and logical values (true/false) can be represented by numeric value. This simplifies the language while still allowing for a wide range of programming tasks.
Especially for Date and Time datatypes check this manual at libraries chapter (Date & Time libraries).
About the Boolean values there a need to explain further the concept. In most of the BASIC implementations, 0 is false and -1 is true.
Why this? In most modern programming languages, the integer 0 represents false, and any non-zero integer represents true.
However, in early versions of BASIC, a different convention was adopted. This was due to the way logical operations were implemented at the machine-code level.
The bitwise operations for AND, OR, and NOT were often optimized to work with all the bits of a value.
A bitwise NOT of 00000000 (which is 0 in a byte) results in 11111111, which is -1 in two's complement representation.
This made it convenient to use -1 for true, as it was the direct result of a NOT operation on the false value (0).
In conclusion, FBASIC will consider the zero (0) numeric value as False, and any non-zero as True. If the value of True will requested the interpreter will return -1.
| Function | Description |
|---|---|
| str(n) | converts the numeric value n to a string value |
| num(s) | converts the string value s to a numeric value |
| abs(n) | the absolute value of the numeric value n
|
| ubound("entity") | Function returns the total number of elements (upper bound) for the entity array, collection or other entities. |
| min(n,n) | the minimum number between the two numbers in the arguments |
| max(n,n) | the maximum number between the two numbers in the arguments |
| not(n) | If the underlying number is not equal to the value for true (1) return True, otherwise returns False (-1) |
Functions for string manipulation, available if library FBasicStringFunctions is enabled.
- len(string): Returns the length (number of characters) of a string.
- left(string, n): Extracts the first n characters from a string.
- right(string, n): Extracts the last n characters from a string.
- mid(string, start, length): Extracts a substring of a specific length from a string, starting at a given position.
- ucase(string): Converts a string to uppercase.
- lcase(string): Converts a string to lowercase.
- instr(start, string1, string2): Returns the position of the first occurrence of string2 within string1, starting the search at the specified position.
FBASIC, includes a variety of built-in mathematical functions to perform common calculations. There are available if library FBasicMathFunctions is enabled.
Trigonometric Functions
- sin(X): Returns the sine of X. The value of X must be in radians.
- cos(X): Returns the cosine of X. The value of X must be in radians.
- tan(X): Returns the tangent of X. The value of X must be in radians.
- atn(X): Returns the arctangent of X. The result is in radians.
Logarithmic and Exponential, Powers Functions
- log(X): Returns the natural logarithm (base e) of X.
- exp(X): Returns the value of e raised to the power of X. This is the inverse of the LOG function.
- sqr(X): Square Root. Returns the square root of X. The value of X must be non-negative.
Value Functions
- abs(X): Returns the absolute value of X. This function is useful for ensuring a number is non-negative. Note that abs() functions is available without the math library.
- sgn(X): Returns the sign of X. It returns 1 if X>0, -1 if X<0, and 0 if X=0.
- rnd(): This function is used to generate a random number. Its behavior can vary between different versions of BASIC. Often, RND without an argument generates a random number between 0 and 1.
- mod(X, Y): Returns the remainder of X divided by Y. This is useful for various calculations, including determining even or odd numbers.
Integer and Rounding Functions
- int(X): Returns the largest integer less than or equal to X. For positive numbers, this is equivalent to truncating the decimal part.
- fix(X): Returns the integer part of X by truncating the decimal part. For negative numbers, it behaves differently from INT. For example, fix(-3.7) returns -3, while int(-3.7) returns -4.
- round(X,D): Rounds X to D decimal places.
Constants
as the FBASIC does not support constants, a constant is a variable with a value. Its up to the programmer to avoid to modify that value.
- PI: The PI value, approximately equal to 3.14159.
Date and Time functions in the BASIC programming language are used to handle and manipulate dates and times. These functions allow programs to retrieve the current date and time, perform calculations with dates, and format dates for display or any other usage. The native date format is the DD-MM-YYYY. As the FBASIC does not support date as datatype, the functions will consider any valid value having this format as a date.
Date and Time functions listed here are available if library FBasicDateFunctions is enabled.
| Function | Syntax | Description |
|---|---|---|
| date() | date() | This function returns a string representing the current system date. The format typically includes the day, month, and year. |
| isdate() | isdate(d) | Check if the input string is a valid date. |
| day() | day(d) | Extract the day as an numeric value (integer) from a date variable. For example, day("26-10-2025") would return 26. |
| month() | monrh(d) | Extract the month as an numeric value (integer) from a date variable. For example, month("26-10-2025") would return 10. |
| year() | year(d) | Extract the year as an numeric value (integer) from a date variable. For example, year("26-10-2025") would return 2025. |
| jtod() | jtod(d) | Converts the japan style of date (YYYY-MM-DD) to International (DD-MM-YYYY). For example, JTOD("2025-10-26") would return “26-10-2025” |
| dtoj() | dtoj(d) | Converts the International (DD-MM-YYYY) date to japan style of date (YYYY-MM-DD). |
| datediff() | datediff(unit, d1, d2) | Calculates the differect bettween d2 and d1 and return the requestd unit. Units are: YEAR,MONTH,DAY. |
| dateadd() | dateadd(unit,num,d) | Add the number of units to the input date d, and returns the new date. |
The native time format is the HH:MM:SS.FFF. As the FBASIC does not support date or time as datatype, the functions will consider any valid value having this format as a time. Also the functions will consider valid a time of the formats: HH:MM:SS, HH:MM, and the HH:MM:SS.FFF, HH:MM:SS.FF and HH:MM:SS.F
| Function | Syntax | Description |
|---|---|---|
| time() | time() | This function returns a string representing the current system time. The format is usually HH:MM:SS. |
| hour() | hour(d) | extracts the hours as an integer from a time variable. |
| minute() | minute(d) | extracts the minutes as an integer from a time variable. |
| second() | second(d) | extracts the seconds as an integer from a time variable. |
FBASIC supports the following operators:
| Comparisons | < | > | <> | >= | <= |
Example:
|
| Arithmetic Operations | + | - | * | / | ^ | |
| Equality and Assignment | = | |||||
| Other | ( | ) | ||||
| Logical | And | Or | Not | |||
Libraries are add-ons to the main FBASIC Interpreter that provide functions, statements, and variables (or constants). You can only enable a library during the interpreter's initialization, before you run the FBASIC program. Implementing a library is incredibly easy; refer to the how-to manual for more information.
| Library | Description |
|---|---|
| Buildins | contains the very basic functions are available to the FBASIC programing language, without the need to enable it. There is switch that the developer can disable that code. |
| Buildins Collections | contains the very basic functions and statements for collections manipulation. It is enabled by default but the developer can disable that code. |
| Strings | The name of this library is: FBasicStringFunctions and for further information see the Functions section of this document. |
| Mathematical | The name of this library is: FBasicMathFunctions and for further information see the Functions section of this document. |
| Date & Time | The name of this library is: FBasicDateFunctions and for further information see the Functions section of this document. |
| Events Triggering | The name this library is: FBasicEvents (see below for further information) |
| 2D Arrays | Library FBasic2DArrays used to implement the basic functions of the 2D named arrays. |
| Decision Tables | Library FBasicDecisionTables used to implement decision tables and decision support functionallity |
| Json | Library FBasicJsonLibrary implements the Json functionallity for the FBasic interpreter |
| SQLDataAdapter | Library FBasicSQLDataAdapter used to access SQL databases via a ADO connection |
| Stack | For enchance the FBasic program with stack functions use the FBasicStack library |
| Streams | The powerfull streams are enpowering the FBasic by using the library FBasicStreams
|
| Text Replacer | Library FBasicTextReplacer offering the basic functions for text templating and replaceing |
| Word Templating | Used for advnaced Word templating. To use it install the nuget package FAST.FBasicTemplatingLibrary and then add the library FBasicTemplatingLibrary
|
Event triggering is the act of generating a signal that notifies other parts of a program or system that a specific,
significant action or condition has occurred. Essentially, it's the mechanism that initiates
the event-driven sequence.
It is provided by the Library FBasicEvents and for further details see the document: Events
Placeholder Replacer implements the low level functionality is necessary to substitute placeholders in a string with value of identifiers (variables or collections).
It is provided by the Library FBasicTextReplacer
For further technical details and syntax about placeholder, format specifiers and text templating managment statements and functions see chapter "Language Reference Text Replacer Library"
Stack functionality is provided and the stack can hold values by pushing a variable or a value to the stack.
It is provided by the Library FBasicStack
For further technical details and sytax about stack managment statements and functions see chapter "Language Reference Stack Library"
The AI Chat Library enables seamless integration with AI providers for conversational and generative tasks. It supports session management, dynamic provider switching, and prompt-response workflows. It is provided by the Library FBasicAIChat
For further technical details and syntax about placeholder, format specifiers and text templating managment statements and functions see chapter "Language Reference AI Chat Library"
- PRINT handler
- INPUT handler
- Program load handler
- Request for Objecthandler
The FBASIC system raises a comprehensive set of messages to help developers debug their code and address operational issues. These messages are primarily divided into Errors and Exceptions, more categories can listed for error message have their source in Statement and Functions Libraries.
See the error message in this Language Reference Manual - Error Messages
Notes:
The editor of this file is: https://onlinemarkdowneditor.dev/