-
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 | variableName = value |
TotalSales = 1500.25 |
| Read Value | expression |
LET Margin = TotalSales * 0.1 |
| Print Value | PRINT variableName |
PRINT TotalSales |
Got it. I will remove the section on Collections (Stack) from the previous reference and incorporate the new "Square Bracket Reference" rules for arrays and collections based on your notes. I'll also clarify the default index access.
Here is the revised reference page, focusing only on Variables and Array/Collection referencing:
Once an entity (Variable, Array, or Collection) is declared or created in FAST.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 assisgn operations, including standard (parentheses) and specialized (square bracket) access.
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] entityReference = valueOrExpression| Element | Description |
|---|---|
[LET] |
The optional assignment keyword. |
entityReference |
The identifier of the Variable, Array element, or Collection member being set (e.g., A, Price(1), [col.column]). |
= |
The assignment operator. |
valueOrExpression |
A literal value, another entity's name, or the result of a mathematical or string expression. |
To retrieve a value, the entity's reference is used as part of an expression:
PRINT entityReference
LET anotherVar = entityReferenceA simple variable holds a single value (numeric or string) and is referenced solely by its unique identifier.
| Operation | Syntax | Example |
|---|---|---|
| Set Value | variableName = value |
TotalSales = 1500.25 |
| Read Value | expression |
LET Margin = TotalSales * 0.1 |
| Print Value | PRINT variableName |
PRINT TotalSales |
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.
| Operation | Syntax | Description | Example |
|---|---|---|---|
| Set Value | arrayName(index) = value |
Assigns value to the element at index. |
Price(2) = 19.99 |
| Read Value | arrayName(index) |
Retrieves the value at index. |
LET Sum = Price(1) + Price(2) |
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 (SDIM) |
References the value of the current item in the static collection. |
[col.column] |
Collections / Arrays | References the value of a column in the collection or array. column can be a column name or a numeric index. |
[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. |
REM Example 1: Variables and Standard Array Access
LET A = 10
DIM Price(10)
Price(1) = 9.99
LET Sum = Price(1) + A
PRINT "Total="; Sum
' Output: Total=19.99
REM Example 2: Square Bracket Collection/Column Access
REM Assume a Collection 'ClientData' with a column 'FirstName'
LET Name = [ClientData.FirstName]
PRINT Name
REM Example 3: Square Bracket Array Column Access
REM Assume an Array 'Trades' with a column 'Quantity'
Trades(5) = 100
' Standard array write (index 5) - assuming 'Quantity' is the default column
LET Qty = [Trades.Quantity(5)]
PRINT "Quantity at index 5: "; Qty
' Output: Quantity at index 5: 100