STS Script AST¶
STS Script source code is parsed into an internal AST before validation and compilation.
The AST is not the public user-facing language, but it defines how the runtime understands script source.
Top-Level Program¶
{
type: "Program",
body: []
}
The body array contains statements.
Statement Types¶
| Type | Purpose |
|---|---|
Input |
Declares an input constant |
VarDecl |
Declares a local variable |
Assign |
Assigns a calculated series |
If |
Conditional branch |
For |
Bounded loop |
ExprStmt |
Function call statement |
Event |
Robot lifecycle event body |
Script Declaration¶
The first statement must be a script(...) expression statement.
script("MA Crossover", kind="robot")
{
type: "ExprStmt",
expr: {
type: "Call",
name: "script",
args: [
{ type: "Str", value: "MA Crossover" }
],
named: {
kind: { type: "Str", value: "robot" }
}
}
}
Input¶
input length = 20
{
type: "Input",
name: "length",
value: { type: "Num", value: 20 }
}
Series Assignment¶
ma = ta.sma(close, length)
{
type: "Assign",
name: "ma",
expr: {
type: "Call",
name: "ta.sma",
args: [
{ type: "Var", value: "close" },
{ type: "Var", value: "length" }
]
}
}
Event¶
onBar {
trade.buy(symbol="BTCUSD", volume=0.01)
}
{
type: "Event",
name: "onBar",
body: {
type: "Block",
body: []
}
}
Expressions¶
| Type | Purpose |
|---|---|
Num |
Numeric literal |
Str |
String literal |
Var |
Variable or series reference |
History |
Historical access, for example close[1] |
Bin |
Binary expression |
Unary |
Unary expression |
Cond |
Conditional expression |
Call |
Function call |
Validation¶
Validation checks that:
- unknown variables are rejected;
- indicator scripts cannot use robot-only functions;
- robot scripts can only use allowed trade bridge functions;
- inputs cannot be reassigned;
- series history access is used only on series values.