TABLES
This document captures the current v0.5 concept for tabular data syntax in ASCEND. It is a language design draft, not a complete implementation specification.
Goals
- Keep ASCEND’s explicit, type-aware style.
- Minimize repetitive boilerplate for indexed data.
- Support both compact in-model data and external datasets.
- Preserve dimensional/unit checking as a first-class feature.
New Declarations
TABLE Syntax (Implemented)
TABLE <target_name> [POSITIONAL] [DEFAULT <expr>]; ... END TABLE;
Where <target_name> is an indexed array reference such as:
cost[r,c]
or
cost[r][c]
Notes:
POSITIONALandDEFAULTmay both be written.- Body rows are newline-based.
- Tokens accepted in TABLE body include identifiers, quoted symbols, integers, reals,
{...}, and punctuation:=,+-;.
TABLE Compilation Behavior
1) POSITIONAL TABLE
TABLE cost[r,c] POSITIONAL; 11 12 13 21 22 23 END TABLE;
Implemented behavior:
- Supports 1-D and 2-D targets.
- Values must be numeric.
- Signs
+/-are supported. - Comma can be used as a value separator.
- A sequence containing at least one semicolon and/or newline ends the current row.
- Enforces row/column/value counts against index cardinality.
- Sparse punctuation (
:,=) is rejected in POSITIONAL mode.
2) Dense non-POSITIONAL TABLE
TABLE cost[r,c]; 3 1 2 2 23 21 22 1 13 11 12 END TABLE;
Implemented behavior:
- Dense non-POSITIONAL mode currently requires exactly 2 indices.
- First non-empty row is the column-label header.
- Header may optionally start with
:. - Each data row begins with a row label;
:after row label is optional. - Cell values are numeric only.
- Row/column labels can be integer or symbol-valued.
- Duplicate row labels and duplicate column labels are rejected.
- Label membership is checked against index sets when those sets are already defined.
- Row/column counts must match first/second index set cardinality.
- Comma-separated rows (CSV-like) are accepted.
- A sequence containing at least one semicolon and/or newline ends the current row.
Label Rules
Examples:
TABLE cost[r,c]; x y north 11 12 south 21 22 END TABLE;
TABLE cost[r,c]; c3,c1,c2; alan,23,21,22; bernhard,13,11,12; END TABLE;
Current label handling:
- Integer labels: parsed as integers and matched to integer sets.
- Symbol labels: unquoted identifiers or quoted symbols (e.g.
'New York') are matched to symbol sets.
Implicit Set Inference (Implemented for Dense TABLE)
If an index set expression cannot yet be evaluated and it is a simple named set, dense TABLE can infer and assign that set from labels.
Example:
r IS_A set OF integer_constant; c IS_A set OF symbol_constant; cost[r][c] IS_A integer_constant; TABLE cost[r,c]; a b 2: 21 22 1: 11 12 END TABLE;
Behavior:
- If all labels are unquoted integers, infer integer set.
- Otherwise infer symbol set.
- Duplicate inferred labels are rejected.
Current Limitations
- Sparse non-POSITIONAL TABLE assignment (e.g.
row: col=value ...) is not implemented. DEFAULT <expr>is parsed and stored but not yet used in TABLE lowering.- Non-numeric TABLE cell values are not yet supported.
- TABLE index ranges written directly in index expressions are not currently supported by dense lowering.
VALUESandDATASETare parse-only at this stage.
2) VALUES
Intended for vectors and sparse ND assignments.
VALUES <array_name>[<index_set>, ...] [DEFAULT <expr>]; <k1>[,<k2>...] = <value>; ... END VALUES;
Example:
VALUES demand[customer] DEFAULT 0; 1 = 45; 2 = 30; 3 = 40; 4 = 35; END VALUES;
3) DATASET
Intended for external files, especially large time-series and operational data.
DATASET <dataset_name> FROM "file.csv"; INDEX <set_name> FROM COLUMN <col_name> IS_A <type_name>; <array_name>[<index_set>] FROM COLUMN <col_name> [{<units>}] [IS_A <type_name>]; ... END DATASET;
Example:
DATASET ops FROM "ops.csv"; INDEX t FROM COLUMN timestamp IS_A time; load[t] FROM COLUMN load_MW {MW}; END DATASET;
Notes:
DATASETmap targets must be indexed (name[...]).- If
IS_Ais omitted on a map line, a default type (planned:real_constant, dimensionless) can be assumed during compile/lowering.
Labels and Quoting
- Identifier-like labels can be unquoted.
- Labels with spaces/punctuation require symbol-constant quoting: 'New York'
Units Concept
- Unit metadata may come from file metadata/rows (future data-handler behavior).
- Inline units in
DATASETmappings are allowed and should be checked for compatibility against declared type dimensions.