-
Notifications
You must be signed in to change notification settings - Fork 0
Language Reference ‐ Identifiers
Identifiers are names used within FBasic to uniquely denote program elements such as statements, variables, arrays, collections, and defined functions. This section outlines the specific rules governing the construction and interpretation of these names by the interpreter.
All identifiers in FBasic must adhere to the following basic rules:
- They must begin with a letter (A-Z or a-z).
- They must be composed exclusively of alphabetic characters (letters) and digits (0-9).
-
No other characters are permitted, including spaces, underscores (
_), hyphens (-), or special symbols.
Statement names refer to the keywords that define an action or control flow (e.g., PRINT, PUSH, GOTO).
| Rule | Specification |
|---|---|
| Allowed Characters | Letters and Digits. Must start with a letter. |
| Word Structure | Must be a single, contiguous word (no spaces). |
| Case Sensitivity |
Case-Insensitive. The interpreter treats PRINT, print, and Print as the same statement. |
These names are used for storing and referencing data. They represent user-defined entities.
| Rule | Specification |
|---|---|
| Allowed Characters | Letters and Digits. Must start with a letter. |
| Word Structure | Must be a single word. |
| Case Sensitivity |
Case-Sensitive. The names MyVar and myvar are treated as two distinct, separate identifiers. |
Function names follow the same naming conventions and case sensitivity rules as variables, arrays, and collections.
| Rule | Specification |
|---|---|
| Allowed Characters | Letters and Digits. Must start with a letter. |
| Word Structure | Must be a single word. |
| Case Sensitivity |
Case-Sensitive. For example, stackcnt() and StackCnt() would refer to different functions if both were defined. |
The table below illustrates valid and invalid identifiers based on the rules for case-sensitive elements (Variables/Functions).
| Identifier | Valid? | Reason / Status |
|---|---|---|
Total1 |
Valid | Starts with a letter, contains only letters and digits. |
CustName |
Valid | Contains only letters. |
1stVar |
Invalid | Cannot start with a digit. |
Array_X |
Invalid | Contains an illegal character (underscore _). |
POPTEMP |
Valid | Valid format, but if it clashes with a statement name, a conflict may arise depending on context. |
PopTemp |
Valid | If poptemp is a variable, PopTemp is a different variable due to case-sensitivity. |
Final Price |
Invalid | Contains a space (must be one word). |
Once an entity (Variable, Collection, or Array) is declared or created in FBasic, it can be referenced to either read its current value or set/update its value. This section details the syntax used for these read and write (assign) operations.
The fundamental syntax for manipulating the value of a non-statement entity is through the assignment statement, usually involving the LET keyword (or implicit assignment).
The syntax to store a new value into an entity is:
[LET] entityName = valueOrExpression| Element | Description |
|---|---|
[LET] |
The optional assignment keyword. |
entityName |
The identifier of the Variable, Collection, or Array element being set. |
= |
The assignment operator. |
valueOrExpression |
A literal value, another entity's name, or the result of a mathematical or string expression. |
Note: The implicit assignment is supported but its a nice practice to avoid it and specify the LET statement
To retrieve a value, the entity's identifier is used as part of an expression:
PRINT entityName
LET anotherVar = entityNameA simple variable holds a single value (numeric or string) and is referenced solely by its unique identifier.
| Operation | Syntax | Example |
|---|---|---|
| Set Value | LET variableName = value |
TotalSales = 1500.25 |
| Set Expression | expression |
LET Margin = TotalSales * 0.1 |
| Get Value | PRINT variableName |
PRINT TotalSales |
In FBASIC, supports data consumption from static or dynamic collections that must be bound to the interpreter environment prior to program execution. The language facilitates this collection mechanism through a set of built-in statements, functions, and optional add-on libraries. **Collections **are fundamental data structures used to manage lists of values and result sets from data sources. While traditional single variables hold one value, collections allow a program to store and iterate over multiple related items efficiently. The two primary collection types referenced in the language are Static (or SDATA) and Dynamic (Fetchable). Static collections is a type of signle dimension array but not only.
For further details, syntax of the statements, functions and examples see the Chapter: Language Reference - Collections
Based on your notes, here is the consolidated and enriched text detailing the foundation and referencing of arrays in FAST.FBasic:
Arrays are a core, 1-based feature of the FAST.FBasic interpreter, where the first element is always at index one (1). Though built-in, they are inert until an external Library (like FBasic2DArrays) initializes and defines their behavior. Internally, the interpreter models arrays as 2D Jagged Arrays (an array of arrays), where the first index acts as the Row (Y-Axis) and the second as the Column (X-Axis). While the primary index is strictly numeric, the secondary (column) index can be accessed either numerically or by a ColumnName (a mnemonic name specified by the array's creator, which might be a Library or a C# host program). Referencing elements is achieved through the standard Parentheses () notation (e.g., array(index)) or the specialized Square Bracket [] notation (e.g., [arr.column(index)]), with the built-in function UBOUND(arrayName) providing the total Row count (length).
The Square Bracket Reference provides a specialized syntax for accessing complex data structures, specifically columns within collections (tables) and arrays. Brackets may be present or omitted, depending on the context.
| Syntax | Applies to | Description |
|---|---|---|
[col.Item] |
Static Collections (also known as SDIM) |
References the value of the current item in the static collection. The keyword Item can be in any case |
[col.column] |
Collections | References the value of a column in the collection. column can be a column name. |
[arr.column(index)] |
Arrays | References the value of a specific column of an array at the specified index. This combines column naming with array indexing. The column can be a Column Name or a Number. The index can be a variable or a number
|
Attention: the 2D array, has an unusal notation where the second index is before the first index. A memonic way to remeber it as
table->column->rowreference, wheretableis thecollection,columnis thesecond index(or name) and therowis thefirst index
Arrays hold multiple values of the same type, accessed using a numeric index enclosed in parentheses (). Array indexes typically start at 1 (one). This is the standard BASIC array access method.
| Entity | Operation | Syntax | Description | Example |
|---|---|---|---|---|
| Collections | Assign | N/A | To assign value in a collection it is not applicable directly. The to collection's item | |
| Get | [collection.entity] | Read the value for entity or column entity from collection collection
|
print [C1.name] | |
| Static Collection | Assign | SSET collection index value | A static collection is a form of general collections, but using the build-in library for collections, the SSET statment is performing the assignment. Attention to the syntax, does not use comma as argument separator. | SSET C1 1 "XXX" |
| Get | [collection.Item] | Read the value from static collection collection
|
print [months.Item] | |
| Array | Assign | [array,index2(index1)] | Assign a value to 2D array having index1 (number or name) and index as second dimension index (number or variable. Attension to the sequence of the indexes first the 2nd the in parenthesis the 1st. |
LET [A1,1(2)]=1234.34 or LET [A1,Col3(index)]="XX" |
| Get | [array,index2(index1)] | Same syntax of Assign | print [arr2,Name(selectedRow)] |
In FBasic, Constants represent a unique classification of variables distinguished by how their values are sourced. Unlike standard variables set directly within the FBasic program, a Constant's value is derived externally, typically from the caller C# program that hosts the interpreter, or implicitly by an internal library, function, or statement that affects its variable state. This mechanism provides the FBasic environment access to fixed or dynamically determined environmental values.
As Constants are essentially common variables, the programmer should avoid modifying their value using any assignment statement, treating them as read-only identifiers to maintain the integrity of the external or library-defined value.
Illustrative examples include the mathematical constant PI exposed by the FBasicMathFunctions library, and the flag FOUND whose status is managed by the FBasicDecisionTables library after a lookup operation.
FBasic utilizes special purpose variables that serve dedicated functions within the program's execution flow. A primary example is RESULTVALUE, which acts as a versatile container for conveying a return value. Its value is set by the RESULT statement and can be retrieved from any point in the program. Importantly, RESULTVALUE facilitates the transfer of a result from a called subprogram (initiated by CALL or CHAIN statements) back to the calling program. Furthermore, its final value is automatically exposed within the ExecutionResult structure provided to the ultimate caller, the embedding C# host application.
RESULT 555
print RESULTVALUE
Output will be: 555