Skip to content

Code structuring & Syntax

RandomMaerks edited this page Feb 25, 2026 · 9 revisions

Reading Piège codes

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.

Basic structures & Syntax rules

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.

Syntax

a. Grammatical syntaxes

;

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.

b. Input-output instruction syntaxes

INPUT type = directory

Call for input of type type at directory. Not required if input values are hardcoded.

  • type is required, can be:
    • directory to output to specified file
  • = directory is 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

OUTPUT type (= directory)

Call for output of type type. Depending on this type, directory may or may not be called.

  • type is required, can be:
    • interpreter to output value to interpreter
    • directory to output to specified file
  • = directory is optional, file name in double quotes, relative and absolute
OUTPUT interpreter
OUTPUT directory = "output.txt"

c. Math operator syntaxes

DO operation; output

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.

  • operation is required. The following syntaxes can be used inside:
    • Data types:
      • float : number
      • string : variable (doesn't include 0123456789.-)
    • 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 matrix rows x cols
    • 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
  • output is 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 -> a

If 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 -> n

RETURN variable

Return a numerical value or the value of an assigned variable to the selected output destination.

Return format on output: variable = value

  • variable is required. Enter an assigned variable name to return to output.

PRINT obj1, obj2, ...

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

VISUAL type = option1, option2, ...; obj1, obj2, ...

Display quantities and values in various types of visualisation.

  • type is 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 on type. 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)
    • 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
    • table
      • Option 1: Main orientation. Parameters: row, column
      • Option 2: Row / column number. Type: integer

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

Delete variable along with its value.

  • variable is required. Enter an assigned variable name to remove from memory.

SETCUR type = index; condition

Set interpreter's cursor to a specific character index or line at index in the code if condition is True.

  • type is required, can be:
    • char for individual characters
    • line for line of code
  • index is required, is an integer
  • condition is required. SETCUR executes when condition is 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
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 = char is only for very niche cases and can break if done incorrectly. Use type = line instead.

MOVECUR type = amount; condition

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.

  • type is required, can be:
    • char for individual characters
    • line for line of code
  • amount is required, is an integer. Positive value to move forwards, negative value to move backwards
  • condition is required. MOVECUR executes when condition is True. Can be one of 6 comparison operators

IGNORE line

Ignore line line of the code.

  • line is required, is an integer, must be in range 0 to total of lines

END

Abruptly stop the program at the current character index.