-
Notifications
You must be signed in to change notification settings - Fork 0
Code structuring & Syntax
A Piège code is intended to be read from start to finish, through each and every character. It’s important for an interpreter to keep track of character indices.
At any main character index, if a structure, a function, or an operator (collectively called “function” for now) is detected from that index to the index a distance equal to the length of that function away, a temporary character index is created to read the content of the function.
Certain functions allow setting the main character index to a specific location in the code or moving the index a certain distance away from those functions.
The program should end when the main character index reaches the end of the code, or when an end function is called.
There are two fundamental sections of any Piège code: input-output instruction, and math operation.
The input-output instruction includes any functions that tell the interpreter from which source to import data and to which destination to export. Usually, an input source is not necessary if the input values are hardcoded into the program. An output source, however, is required and can go to the interpreter itself or an external file. The math operation includes all mathematical operations.
From version 2.0 of Piège, you no longer need to "call" these two "sections". These sections are purely theoretical, and you can use the functions categorised into one section inside the other section.
All functions are written in all caps and are separated from the actual data by a space. Every function call is separated by a line break, meaning one line does either one function or none at all, not multiple.
Semicolons denote the end a series of related data. Without it, the interpreter may continue to read values of other data series while not closing the previous one.
Commas denote a separation between mathematical entities in a multi-value math operation.
Parentheses groups mathematical entities inside a math operation.
Call for input of type type at directory. Not required if input values are hardcoded.
-
typeis required, can be:-
directoryto output to specified file
-
-
= directoryis optional, file name in double quotes, relative and absolute
INPUT directory = "constant.txt"Input files have to follow a specific syntax for each line:
variable=value
pi = 3.1415926
e = 2.7182818
Call for output of type type. Depending on this type, directory may or may not be called.
-
typeis required, can be:-
interpreterto output value to interpreter -
directoryto output to specified file
-
-
= directoryis optional, file name in double quotes, relative and absolute
OUTPUT interpreter
OUTPUT directory = "output.txt"Calculate the operation inside the brackets. This is used for basic calculation and assignment, and the output is a single value assigned to a new or preexisting variable.
-
operationis required. The following syntaxes can be used inside:- Data types:
-
float: number -
string: variable (doesn't include0123456789.-)
-
- Arithmetic operators:
-
sum(val1, val2, ...): sum -
dif(val1, val2): difference (non-negative) -
sub(val1, val2, ...): sum of val[1] and -val[>1] -
pro(val1, val2, ...): product -
rat(val1, val2): ratio -
quo(val1, val2, ...): product of val[1] and 1/val[>1] -
pow(val1, val2): power -
exp(val1): exponential -
mod(val1, val2): modulo -
fact(value): factorial -
abs(value): absolute value -
sign(value): sign of value (+/–/0) -
log(base, value): logarithm -
ln(value): natural logarithm -
sqrt(value): square root -
root(root, value): any nth root -
neg(value): negation
-
- Statistical operators:
-
squareSum(val1, val2, ...): sum of values squared -
cubeSum(val1, val2, ...): sum of values cubed -
max(val1, val2, ...): maximum value -
min(val1, val2, ...): minimum value -
aMean(val1, val2, ...): arithmetic mean -
gMean(val1, val2, ...): geometric mean -
agMean(val1, val2, ...): arithmetic-geometric mean -
median(val1, val2, ...): median -
mode(val1, val2, ...): mode -
quart1(val1, val2, ...): first quartile -
quart3(val1, val2, ...): third quartile -
iqr(val1, val2, ...): interquartile range -
meanAbsDev(val1, val2, ...): arithmetic mean absolute deviation -
medianAbsDev(val1, val2, ...): median absolute deviation -
modeAbsDev(val1, val2, ...): mode absolute deviation -
popVar(val1, val2, ...): population variance -
popStdDev(val1, val2, ...): population standard deviation -
samVar(val1, val2, ...): sample variance -
samStdDev(val1, val2, ...): sample standard deviation (unbiased)
-
- Rounding operators:
-
floor(value): floor/ round down -
ceil(value): ceiling/ round up -
round(value, decimal): round to the nth decimal place (can be negative) -
floorRat(val1, val2): floor division -
ceilRat(val1, val2): ceiling division
-
- Trigonometric operators (radian):
-
sin(value): sine -
cos(value): cosine -
tan(value): tangent -
cot(value): cotangent -
sec(value): secant -
csc(value): cosecant -
asin(value): arcsine/ inverse of sine -
acos(value): arccosine/ inverse of cosine -
atan(value): arctangent/ inverse of tangent -
acot(value): arccotangent/ inverse of cotangent -
asec(value): arcsecant/ inverse of secant -
acsc(value): arccosecant/ inverse of cosecant
-
- Hyperbolic operators (radian):
-
sinh(value): hyperbolic sine -
cosh(value): hyperbolic cosine -
tanh(value): hyperbolic tangent -
coth(value): hyperbolic cotangent -
sech(value): hyperbolic secant -
csch(value): hyperbolic cosecant -
asinh(value): inverse of hyperbolic sine -
acosh(value): inverse of hyperbolic cosine -
atanh(value): inverse of hyperbolic tangent -
acoth(value): inverse of hyperbolic cotangent -
asech(value): inverse of hyperbolic secant -
acsch(value): inverse of hyperbolic cosecant
-
- Matrix operators:
-
detMtrx(rows, cols, val1, val2, ...): determinant of matrixrowsxcols
-
- Vector operators (dimension = # of input values / # of intended vectors):
-
lenVect(val1, val2, ...): vector length -
dist(point1.val1, point1.val2, ..., point2.val1, point2.val2, ...): distance between two points -
dotVect(vect1.val1, vect1.val2, ..., vect2.val1, vect2.val2, ...): dot product of two vectors -
angle(vect1.val1, vect1.val2, ..., vect2.val1, vect2.val2, ...): angle of two vectors
-
- Randomiser operators (based on fractions of a second since the epoch):
-
rand(val1, val2): return a real number between two values -
randInt(val1, val2): return an integer between two values
-
- Data types:
-
outputis required. Enter a variable name to assign output to.
Input values for math operators don’t need to be strictly numerical values. They can be variables or math operators.
DO mod(pro(sum(9, 10), fact(2)), 4); a
# ((9 + 10) * 2!) % 4 -> aIf no math operator is used and only a single value or variable name takes place, the function is treated as an assign function.
DO 4; a # 4 -> a
DO m; n # m -> nReturn a numerical value or the value of an assigned variable to the selected output destination.
Return format on output: variable = value
-
variableis required. Enter an assigned variable name to return to output.
Print a string or the value of an assigned variable to the selected output.
-
obj1, obj2, ...are required. The following parameters can be used inside:- variable : reference without quotes
- strings : put in double quotes
Display quantities and values in various types of visualisation.
-
typeis required. The following parameters can be used inside:-
quantity/magnitude: display 1 quantity using custom characters -
matrix: display matrices using brackets / parentheses -
graph: display various quantities in a graph -
table: display various quantities in a table
-
-
obj1, obj2, ...are required. The following types can be used inside:- string : put in double quotes
- variable : use without quotes
- values : integer, float
-
option1, option2, ...are required. Number of options and parameters depend ontype. Order is important.-
quantity/magnitude- Option 1: Character to display. Type: string
- Option 2: Position of value (not required). Parameters:
after*,before
-
matrix- Option 1: Notation type. Parameters:
brackets,parentheses - Option 2: Row number. Type: integer (0 - inf)
- Option 1: Notation type. Parameters:
-
graph- Option 1: Graph type. Parameters:
bar,dot - Option 2: Scale type. Parameters:
scaled,literal - Option 3: Padding (not required). Parameters:
all*,noBetween,noOuter,none - Option 4: Scale factor % (not required). Type: float (0 - 100), * = 40
- Option 1: Graph type. Parameters:
-
table- Option 1: Main orientation. Parameters:
row,column - Option 2: Row / column number. Type: integer
- Option 1: Main orientation. Parameters:
-
Number of objects must be appropriate. For example, a 3-by-2 matrix should have 6 entries. If only 5 were found, a 2-by-2 matrix will be displayed, and the last entry is discarded.
(*) This asterisk indicates that options that don't need to be explicitly called have a specific parameter set as its default.
Delete variable along with its value.
-
variableis required. Enter an assigned variable name to remove from memory.
Set interpreter's cursor to a specific character index or line at index in the code if condition is True.
-
typeis required, can be:-
charfor individual characters -
linefor line of code
-
-
indexis required, is an integer -
conditionis required.SETCURexecutes whenconditionis True, can be:- Comparison operators:
-
less(val1, val2, ...): val1 < val2 < ... → True -
more(val1, val2, ...): val1 > val2 > ... → True -
equal(val1, val2, ...): val1 = val2 = ... → True -
notless(val1, val2, ...): val1 ≥ val2 ≥ ... → True -
notmore(val1, val2, ...): val1 ≤ val2 ≤ ... → True -
notequal(val1, val2, ...): val1 ≠ val2 ≠ ... → True
-
- Comparison operators:
SETCUR char = 100; less(i, 5) # set cursor at character index 100 if i < 5
SETCUR line = 8; notequal(i, j, 3) # set cursor at line 8 if i != j and j != 3
type = charis only for very niche cases and can break if done incorrectly. Usetype = lineinstead.
Move interpreter's cursor back or forth a number of character indices or lines in the code in relation to the start of the moveCursor[] function if condition is True.
-
typeis required, can be:-
charfor individual characters -
linefor line of code
-
-
amountis required, is an integer. Positive value to move forwards, negative value to move backwards -
conditionis required.MOVECURexecutes whenconditionis True. Can be one of 6 comparison operators
Ignore line line of the code.
-
lineis required, is an integer, must be in range 0 to total of lines
Abruptly stop the program at the current character index.
The wiki references version 2.1 (25 February, 2026) of the Piège programming language.
Due to a change in syntaxes, any version prior to 2.0 is completely incompatible with the latest version.