Code Representation Using JSON Arrays
In Calcium, a program to output "Hello, World." looks like this:
[
[
1, // Block level. Same as the depth of indentation in Python.
[], // Arbitrary elements. Currently unused.
"expr", // Command name. Indicates what type of statement is being executed. This example is an "expression statement."
["call", ["var", "print"], ["Hello, World."]] // Command arguments. Explained later.
],
[1, [], "end"] // The program must end with the "end" command.
]
The equivalent Python code is:
print("Hello, World.")
Block Level
In the following Python code, the control statement increases the indentation by one level:
if answer is 42:
pass
In Calcium's JSON array, the leading integer represents this indentation level:
[1, [], "ifs"],
[2, [], "if", ["is", ["var", "answer"], ["num", "42"]]],
[3, [], "pass"],
[1, [], "end"]
Whitespace in JSON is meaningless, so indentation is represented by integers.
Commands
In Calcium, each statement is treated as a "command." Examples include if
, for
, and while
.
Basic Python statements are supported.
Expressions
Expressions in Calcium are slightly unique. They take the form of arrays, with the first element indicating the type.
For example, a variable is represented as ["var", "answer"]
.