Skip navigation

Documentation

Learn about the syntax of Phyrex and all the language features it contains.

Fundamentals

Statement

Phyrex code consists of a series of statements. All statements start with a |, which is the sentence starting character within the Phyrexian writing system. One statement ends where the next statement starts.

Token

Statements are composed of a series of tokens. Tokens are separated by a ,, which is the word separator character within the Phyrexian writing system.

As in the Phyrexian writing system, white space is completely ignored. This means individual statements, and even individual tokens, can be spread across multiple lines.

Expression

Expressions can be part of a statement. Expressions can contain other expressions, called subexpressions. Expressions evaluate to a value.

Expressions follow the following order of operations:

  1. Multiplication and Division
  2. Addition and Subtraction
  3. Equals and Greater Than and Less Than

There are no brackets to change the effective order of operations of subexpressions.

Block

DEEstiYDC Pcne%m (beginning, end)

Blocks starts with the keyword DEEstiYDC followed by a sequence of statements followed by the keyword DEEstiYDC. When a block is ran, the statements in the sequence are executed in order.

Data Types

String

A string is a string of unicode characters. Strings start with a ~ and end with a /, which are respectively the open and close quotation mark characters from the Phyrexian writing system.

 ~Detn,huZFGK/

Strings cannot be escaped, so using ~ or / as characters within a string is not supported.

Number

A number is a positive integer number. Floats are not supported. Numbers are represented in octal (base 8) format.

 14

Null

FEsEvv (void)

A null value. This is returned by some inbuilt functions and is the default value when a variable is not assigned a value. In code, nulls are represented by the keyword FEsEvv.

 FEsEvv

Variables

Declaration

neBm (create)

Variables are scoped to the block in which they are declared. Variable declaration is a statement. It starts with the keyword neBm (create) followed by a name for the variable.

 |neBm,gYCn

An initial value for the variable may also be assigned by following the variable name with the keyword Q (to) followed by an expression

 |neBm,wYSW%,Q,1

If an initial value is not assigned for a variable, then it will default to FEsEvv (void).

Assignment

Q (to)

Variable assignment is a statement. It consists of the name of the variable followed by the keyword Q (to) and an expression.

 |wYSW%,Q,1

Attempting to assign a value to a nonexistent variable will raise an error.

Reference

Variables are referenced using their name. Variables declared in a narrower scope shadow those of the same name in looser scopes.

Arithmetic

Addition

sF (addition)

Addition is an expression. It consists of one subexpressions followed by the keyword sF followed by another subexpression.

If both subexpressions evaluate to numbers, then the addition expression evaluates to those numbers added together.

 1,sF,2

If both subexpressions evaluate to strings, then the addition expression evaluates to those strings joined together.

 ~Detn,/,sF,~huZFGK/

Subtraction

FssF (unaddition)

Subtraction is an expression. It consists of one subexpressions followed by the keyword FssF followed by another subexpression.

If both subexpressions evaluate to numbers, then the subtraction expression evaluates to the first number minus the second number.

 3,FssF,2

Multiplication

tOvp (multiplication)

Multiplication is an expression. It consists of one subexpressions followed by the keyword tOvp followed by another subexpression.

If both subexpressions evaluate to numbers, then the multiplication expression evaluates to those numbers multiplied together.

 2,tOvp,3

Division

FstOvp (unmultiplication)

Division is an expression. It consists of one subexpressions followed by the keyword FstOvp followed by another subexpression.

If both subexpressions evaluate to numbers, then the division expression evaluates to the first number divided by the second number. This is performed as integer division, so the remainder if any is discarded.

 6,FstOvp,3

Comparators

Equals

aDynpp (equal)

Equals is an expression. It consists of one subexpressions followed by the keyword aDynpp followed by another subexpression.

If both subexpressions evaluate to the same value, then the equals expression evaluates to the number 1. Otherwise, it evaluates to the number 0.

 2,aDynpp,2

Greater Than

horskr (more)

Greater Than is an expression. It consists of one subexpressions followed by the keyword horskr followed by another subexpression.

If both subexpressions evaluate to numbers and the first number is greater than the second number, then the greater than expression evaluates to the number 1. Otherwise, if the first number is not greater than the second number, then the greater than expression evaluates to the number 0.

 3,horskr,2

Less Than

krmUzk (less)

Less Than is an expression. It consists of one subexpressions followed by the keyword krmUzk followed by another subexpression.

If both subexpressions evaluate to numbers and the first number is less than the second number, then the less than expression evaluates to the number 1. Otherwise, if the first number is not less than the second number, then the less than expression evaluates to the number 0.

 2,krmUzk,3

Conditional

If, Else If, Else

beCEcs Lecc,beCEcs Lecc (if, other if, other)

If, Else If, Else is a statement. It consists of a number of branches.

The first branch consists of the keyword beCEcs followed by an expression followed by a block. If the expression evaluates to a number greater than zero, the block is executed.

 |beCEcs,wYSW%,aDynpp,3,DEEstiYDC,
  |DYsuC,-pEQg,~%E/,co,
Pcne%m

The statement may have additional branches, each consisting of the keyword Lecc followed by the keyword beCEcs followed by an expression followed by a block. If the expression of a branch evaluates to a number greater than zero, the branch's block is executed.

 |beCEcs,wYSW%,aDynpp,3,DEEstiYDC,
  |DYsuC,-pEQg,~%E/,co,
Pcne%m,Lecc,beCEcs,wYSW%,aDynpp,2,DEEstiYDC,
  |DYsuC,-pEQg,~%Y/,co,
Pcne%m,Lecc,beCEcs,wYSW%,horskr,3,DEEstiYDC,
  |DYsuC,-pEQg,~more,%E/,co,
Pcne%m

Once a branch's block has finished executing, control is passed to after the final branch. That is to say, later branches are not checked if an earlier one's condition has been met.

The final branch may consist of the keyword Lecc followed by a block. If that is the case and no other branch's block has been executed, then the final branch's block will be executed.

 |beCEcs,wYSW%,aDynpp,3,DEEstiYDC,
  |DYsuC,-pEQg,~%E/,co,
Pcne%m,Lecc,beCEcs,wYSW%,aDynpp,2,DEEstiYDC,
  |DYsuC,-pEQg,~%Y/,co,
Pcne%m,Lecc,beCEcs,wYSW%,horskr,3,DEEstiYDC,
  |DYsuC,-pEQg,~horskr,%E/,co,
Pcne%m,Lecc,DEEstiYDC,
  |DYsuC,-pEQg,~krmUzk,%Y/,co,
Pcne%m

Loops

While

besYf (whenever)

While is an expression. It consists of the keyword besYf followed by an expression followed by a block. If the expression evaluates to a number greater than zero, the block is executed. Once the block has finished executing, the expression is reevaluated. If it again evaluates to a number greater than zero, the block is executed again. This loop continues until the expression evaluates to zero.

 |whenever,wYSW%,less,3,beginning
  |wYSW%,to,wYSW%,addition,1
  |DYsuC,-pEQg,~Detn/,co,
end

For

JhE (for)

For is a statement. It consists of the keyword JhE followed by three parts followed by a block.

The first part is a variable declaration. When the for statement is ran, this variable will be declared and scoped to the statement.

The second part is the keyword besYf followed by a expression. The block will loop while this expression evaluates to a number greater than one.

The third part is the keyword IytPt followed by a variable assignment. After each execution of the block but before the expression to loop is reevaluated, the assignment will run.

 |JhE,neBm,wYSW%,Q,0,besYf,wYSW%,krmUzk,5,IytPt,wYSW%,Q,wYSW%,sF,1,DEEstiYDC
  |DYsuC,-pEQg,~Detn/,co,
Pcne%m

Functions

Definition

ZtetcmEDc (commandment)

Function Definition is a statement. It consists of the keyword ZtetcmEDc followed by an identifier, which is the name of the function being declared, followed by a block.

 |ZtetcmEDc,hrupk,DEEstiYDC,
  |DYsuC,-pEQg,~Detn,huZFGK/,co,
Pcne%m

The function definition may have one or more parameters. If so, they are placed after the name but before the block. Parameters are identifiers.

 |ZtetcmEDc,hrupk,DEE,DEEstiYDC,
  |DYsuC,-pEQg,DEE,co,
Pcne%m

If there is more than one parameter, they must be seperated by the keyword CFr.

 |ZtetcmEDc,hrupk,DEE,CFr,%Y,CFr,%E,DEEstiYDC,
  |DYsuC,-pEQg,DEE,sF,%Y,sF,%E,co,
Pcne%m

Function declarations are scoped to the block they are defined within. They cannot be invoked outside that block or by statements earlier in the block before the function is defined.

Invocation

DYsuC (command)

Function Invocation is an expression. It consists of the keyword DYsuC followed by an identifier, which is the name of the function to be invoked, followed by the keyword co.

 |DYsuC,hrupk,co

The function invocation may have one or more arguments. If so, they are placed after the name but before co. Arguments are expressions.

 |DYsuC,hrupk,~Detn/,co

If there is more than one argument, they must be seperated by the keyword CFr.

 |DYsuC,hrupk,~Detn,/,CFr,~goprept,/,CFr,~huZFGK/,co

When a function is invoked, the function definition with the same name as the invocation is used. Function definitions in tigher scopes shadow those of the same name in looser scopes, with inbuilt functions considered the loosest.

The parameters, if any, are declared as variables and each are assigned as the values that their respective argument evaluates to. The block of the function definition is then ran. Once it has finished, it is removed from the callstack and the function invocation expression evaluates to the return value or a null value if there is no return value.

Inbuilt Functions

Print

-pEQg (-speak)

A function with the name -pEQg. It takes one argument. The argument must be a string. It prints that string to the output console on a new line.

 |DYsuC,-pEQg,~|Detn,huZFGK/,co

Input

-DFtLsn (-ask)

A function with the name -DFtLsn. It one argument. The argument must be a string. It prints that string to the output console as a prompt then waits for the user to type and submit a string. The function then returns the user submitted string.

 |DYsuC,-DFtLsn,~|iudSLtLCycm,/,co

Number

-eLFrZ (-number)

A function with the name -eLFrZ. It takes one argument. The argument must be a string, number or null.

If the argument is a string that contains a valid number, it returns that number as a number.

If the argument is a number, it returns that number.

If the argument is null, it returns the number zero.

 |DYsuC,-eLFrZ,~|123/,co

String

-FseLFrZ (-unnumber)

A function with the name -FseLFrZ. It takes one argument. The argument must be a number, string or null.

If the argument is a number, it returns that number as a string.

If the argument is a string, it returns that string.

If the argument is null, it returns an empty string.

 |DYsuC,-FseLFrZ,123,co

Modulo

-ApenDk (-splinter)

A function with the name -ApenDk. It takes two arguments. The first argument must be a number and the second argument must be a non-zero number. It returns the result of the first argument moduloed by the second argument.

 |DYsuC,-ApenDk,5,CFr,2,co

Character

-tepC (-get)

A function with the name -tepC. It takes two arguments. The first argument must be a string and the second argument must be a number. It returns as a string the character at the index specified by the second argument, starting at zero, of the first argument.

 |DYsuC,-tepC,~Detn/,CFr,1,co

Length

-Lemh (-long)

A function with the name -Lemh. It takes one arguments. The argument must be a string. It returns the number of characters, that is to say the length, of the string provided as the argument.

 |DYsuC,-Lemh,~Detn/,co

Random

-DumCrYhm (-prediction)

A function with the name -DumCrYhm. It takes two arguments. The first argument must be a number and the second number must be a number. It returns a random number between the first argument (inclusive) and the second argument (inclusive).

 |DYsuC,-DumCrYhm,1,CFr,5,co