X syntax is easy to understand. A single statement in X starts with the command you wish to execute followed by arguments seperated by space characters.
myCommand arg0 arg1 arg2 arg3
Arguments may be seperated by any space character, including newline charaters and tabs.
myCommand
arg0
arg1 arg2
arg3
Multiple statements can be executed at once by seperating them with semicolons. If multiple statement terminator characters are in a row without statements between them, the extras are ignored. Technically, null termination characters are treated like semicolons, so the last statement doesn't need a semicolon following it.
commandFoo foo0 foo1 foo2;;
commandBar bar0 bar1 bar2
Commands can return values, like functions in other programming languages. The return of a command can be passed as an argument into another command by surrounding it with square brackets []
.
commandFoo foo0 [commandBar bar0 bar1] foo2
Strings may be passed as arguments by surrounding text with double quote marks.
commandFoo "This string is arg0" "This string is arg1"
Numbers can be passed as arguments as well. When a number argument starts with a minus sign, it is interpreted as a negative number. Numbers that include a decimal point are interpreted as floating point numbers.
myCommand 5 -533 3.14159
Commands can be user defined within the application code. X comes with a set of "standard" commands and variables that do common tasks, but they don't have to be enabled by the application and custom user defined commands can be accepted instead. The standard command echo
concatinates a stringified version of all arguments and prints them to the console. All C character escape sequences work as expected.
echo "Hello, World!"
The standard command echos
concatinates stringified arguments with automatically concatinated between them.
echos "Hello," "World!"
The standard variable n
always contains a string with only a new line character. Likewise, s
contains a space and t
contains a tab. These can help with writing echo
and echos
statements. If an n is added to the end of an echos
statement, no space is added before the newline.
echos "\tline 1" n;
echos t "line" 2 n;
echo t "line" s 3 n;
The standard commands +
, -
, *
, /
, and %
can be used to do mathematical operations with numbers.
echo "seven plus five is " [+ 7 5] n;
echo "three minus two is " [- 3 2] n;
echo "five times eight is " [* 5 8] n;
echo "seven divided by three is " [/ 7 3] n;
echo "the remainder of nine divided by two is " [% 9 2] n;
X keeps track of variables, which are remembered even between command executions. Values can be stored in variables using the standard command =
. Variable names can contain upper and lowercase letters, numbers, and underscores. They can not start with a number. When you assign a value to a variable, all future assignments must be of the same type.
= myVar 7;
= my_other_var "foo";
= my_3rd_var 3.333;
The values of variables can be modified with mathematical operations using the standard commands +=
, -=
, *=
, /=
, and %=
.
Likewise, simillar standard commands exist to modify a variable but return the initial value of the variable, including ++
, --
, **
, //
and %%
.
Scopes can be created by surrounding statments with curly braces {}
. Curly braces also act like semicolons in that they terminate any proceeding statments. Variables declared within a scope are automatically undeclared when the scope ends.
{
= myVar "this is scoped"
}
echo "myVar is undeclared"
Boolean values can be created with the standard variables true
and false
.
= myTrueVar true;
= myFalseVar false;
The standard command ==
can be used to determine if the arguments are equal. Other standard comparison commands include >
, <
, >=
, <=
, and !=
.
echo "All of the following assigned variables are true.";
= valsEqual [== 5 5];
= valGreaterThan [> 6 4];
= valLessThan [< 4 6];
= valGreaterOrEqual [>= 6 6];
= valLessOrEqual [<= 6 6];
= valNotEqual [!= 4 5];
The standard if
command will enter the following scope only if the first argument is true
or a nonzero number. If the scope is followed by an elif
command, it will do the same as the if
only if all previous conditions didn't yet pass. If an else
is found, the following scope is entered just like elif
but without any arguments to be compared.
if [== myVar 7]
{
echo "myVar is 7"
}
elif [> myVar 7]
{
echo "myVar is greater than 7"
}
else
{
echo "myVar is less than 7"
}
Statements or groups of statements can be passed as arguments by passing them surrounded with parenthesis ()
, creating a macro. Macros can be run by calling their variable like a command.
= myVar 7;
= myMacro (if[== myVar 7]{echo "Hello, world!"}else{echo "The sky is falling!"});
myMacro;
The hardcoded return
command can be used to break out of a macro. If an argument is passed, this value is returned when the statements are called.
= myMacro (return [+ 4 5]);
echo [myMacro];
If a macro return nothing, they return a special type called "void", which can only have the value null
.
= myMacro (echo "I return nothing" n);
if [== [myMacro] null]
{
echo "myMacro doesn't return anything." n;
}
Macro variables are reassigned to the top level scope if a new value is assigned to them later.
= myMacro (echo "I return nothing" n);
{
= myMacro (echo "I also return nothing" n);
}
echo "myMacro is undeclared";
Variables declared within macros are declared in the scope outside of the macro, so they still exist after the macro has finished executing.
= myMacro (= myVar 7);
myMacro;
echo myVar;
Commands can be declared with the standard cm
command. The first argument is the command name. The following arguments are the argument variables of the command. The final argument is the macro that the command executes. Commands are undeclared when their scope ends, and they are resassigned to the top level scope when a new value is assigned to them, just like macros. Commands are executed with their own scope, meaning that all variables created within them are undeclared when the command ends.
cm add arg0 arg1 (return [+ arg0 arg1]);
echo [add 4 2];
The standard commands for
and while
work just like they do in C, accepting their conditions with macros.
for (= i 0) (i < 5) (++ i 1)
{
echo i n;
}
= i 0;
while (i < 5)
{
++ i 1;
echo i n;
}