Declaring a variable
The declaration syntax is:Types
OCat has three value types:number
number
Stores an integer or floating-point number. The literal pattern is one or more digits, optionally followed by a decimal point and more digits.
| Detail | Value |
|---|---|
| Keyword | number |
| Literal pattern | \d+(\.\d+)? |
| Example literals | 0, 42, 3.14 |
string
string
Stores a sequence of characters enclosed in double quotes. Escape sequences using a backslash are supported within the string literal.String values also support interpolation using
${varName} syntax:| Detail | Value |
|---|---|
| Keyword | string |
| Literal pattern | "..." (double-quoted) |
| Interpolation | ${identifier} inside the string |
bool
bool
Stores a boolean value. The only valid literals are
true and false.| Detail | Value |
|---|---|
| Keyword | bool |
| Valid literals | true, false |
Mutating a variable with set
The set keyword is part of the OCat syntax for updating a variable’s value. The full declaration syntax (type, name, and value) is repeated with set as a prefix:
Constants with const
The const keyword is defined in the lexer and accepted by the parser. The syntax is:
Printing variables
Pass the variable name (without quotes) toprint to output its current value:
Scope
Variables are stored in theCoreContext that is active when the declaration runs. Variables declared at the top level of a file are available throughout that file. Variables declared inside a function body are stored in that function’s own isolated scope and do not affect the outer context.
Types
Detailed reference for each value type and its literal syntax.
Functions
How function scope relates to variable visibility.