🐐 Update code snippets

This commit is contained in:
2026-04-10 12:56:44 +02:00
parent 6aafab47a2
commit e2688b49ea
49 changed files with 298 additions and 117 deletions

170
README.md
View File

@@ -5,53 +5,20 @@
## Example code
### Hello World
```
DESIGNA x VT "Hello World!"
DICE(x)
```
![Hello World](snippets/hello_world.png)
### Recursive Fibonacci number function
```
DEFINI fib(x) VT {
SI x EST NVLLVS TVNC {
REDI(NVLLVS)
} ALVID SI x EST I TVNC {
REDI(I)
} ALVID {
REDI(INVOCA fib(x-II) + INVOCA fib(x-I))
}
}
```
![Fibonacci](snippets/fibonacci.png)
### Number guessing game
```
CVM FORS
DESIGNA correct VT FORTIS_NVMERVS(I,C)
DESIGNA gvess VT NVLLVS
DVM FALSITAS FACE {
DESIGNA gvess VT AVDI_NVMERVS()
SI gvess MINVS correct TVNC {
DICE("Too low!")
} ALVID SI gvess PLVS correct TVNC {
DICE("Too high!")
} ALVID {
ERVMPE
}
}
DICE("You guessed correctly!")
```
![Number guessing game](snippets/guessing.png)
## Variables
Variables are set with the `DESIGNA` and `VT` keywords. Type is inferred.
```
DESIGNA x VT XXVI
```
![Variable assignment](snippets/variable.png)
Variable can consist of lower-case letters, numbers, as well as `_`.
@@ -63,15 +30,11 @@ Variable can consist of lower-case letters, numbers, as well as `_`.
Strings are written as text in quotes (`'` or `"`).
```
DESIGNA x VT "this is a string"
```
![String literal](snippets/string_literal.png)
Strings are concatenated with `&`:
```
DESIGNA greeting VT "Hello, " & "world!"
```
![String concatenation](snippets/string_concat.png)
`NVLLVS` coerces to an empty string when used with `&`. Note: `+` is for arithmetic only — using it on strings raises an error.
@@ -106,22 +69,17 @@ Booleans are denoted with the keywords `VERITAS` for true and `FALSITAS` for fal
### Arrays
Arrays are defined using square brackets (`[]`) and commas (`,`):
```
DESIGNA x VT [I, II, III]
```
![Array literal](snippets/array_literal.png)
An array of integers can also be initialized with the `VSQVE` keyword:
```
DESIGNA x VT [I VSQVE X]
```
![Array with VSQVE](snippets/array_vsqve.png)
Individual elements can be accessed by index using square brackets. Indexing is 1-based, so `I` refers to the first element:
```
DESIGNA x VT [I, II, III]
DICE(x[I])
![Array indexing](snippets/array_index.png)
```
> I
```
@@ -129,17 +87,7 @@ DICE(x[I])
### SI/TVNC
If-then statements are denoted with the keywords `SI` (if) and `TVNC` (then). Thus, the code
```
DESIGNA x VT VERITAS
SI x TVNC {
DICE(I)
REDI(NVLLVS)
}
DICE(NVLLVS)
> I
```
![SI/TVNC](snippets/si_tvnc.png)
Will return `I` (1), as the conditional evaluates `x` to be true.
@@ -150,29 +98,17 @@ In conditionals, `EST` functions as an equality evaluation, and `MINVS` (<) and
When using `SI`/`TVNC` statements, you can also use `ALVID` as an "else".
```
DESIGNA x VT VERITAS
SI x TVNC {
DICE(I)
} ALVID {
DICE(NVLLVS)
}
![ALVID](snippets/alvid.png)
```
> I
```
`SI` statements may follow immediately after `ALVID`.
```
DESIGNA x VT II
SI x EST I TVNC {
DICE(I)
} ALVID SI x EST II TVNC {
DICE(II)
} ALVID {
DICE(III)
}
![ALVID SI](snippets/alvid_si.png)
```
> II
```
@@ -180,51 +116,34 @@ SI x EST I TVNC {
The keyword `ET` can be used as a boolean "and". The keyword `AVT` can be used as a boolean "or".
```
DESIGNA x VT VERITAS
DESIGNA y VT FALSITAS
SI x ET y TVNC {
DICE(I)
} ALVID SI x AVT y TVNC {
DICE(II)
} ALVID {
DICE(III)
}
![Boolean operators](snippets/boolean_ops.png)
```
> II
```
## Loops
### DONICVM loops
```
DESIGNA x VT NVLLVS
DONICVM y VT NVLLVS VSQVE X FACE {
DESIGNA x VT x + y
}
DICE(x)
![DONICVM loop](snippets/donicvm.png)
```
> XLV
```
### DVM loops
```
DESIGNA x VT NVLLVS
DVM x PLVS X FACE {
DESIGNA x VT x+I
}
DICE(x)
![DVM loop](snippets/dvm.png)
```
> XI
```
### PER loops
```
DESIGNA x VT [I, II, III, IV, V]
PER y IN x FACE {
DICE(y)
}
![PER loop](snippets/per.png)
```
> I
> II
> III
@@ -237,34 +156,51 @@ Functions are defined with the `DEFINI` and `VT` keywords. The `REDI` keyword is
Calling a function is done with the `INVOCA` keyword.
![Function definition](snippets/function.png)
```
DEFINI square(x) VT {
REDI(x*x)
}
DICE(INVOCA square(XI))
> CXXI
```
## Built-ins
### DICE
`DICE value ...`
Prints one or more values to stdout, space-separated, with integers rendered as Roman numerals. Returns the printed string.
![DICE](snippets/dice.png)
### AVDI
`AVDI()`
Reads one line from stdin and returns it as a string.
### AVDI_NVMERVS
`AVDI_NVMERVS()`
Reads one line from stdin, parses it as a Roman numeral, and returns it as an integer. Raises an error if the input is not a valid numeral.
### ERVMPE
`ERVMPE`
Breaks out of the current loop (`DVM` or `PER`). Has no meaningful return value.
### LONGITVDO
`LONGITVDO array`
Returns the length of `array` as an integer.
## Modules
Modules are additions to the base `CENTVRION` syntax. They add or change certain features. Modules are included in your code by having
```CVM %MODVLE NAME%```
![Module declaration](snippets/module_decl.png)
In the beginning of your source file.
Vnlike many other programming languages with modules, the modules in `CENTVRION` are not libraries that can be "imported" from other scripts written in the language. They are features of the compiler, disabled by default.
### FORS
```CVM FORS```
![CVM FORS](snippets/fors.png)
The `FORS` module allows you to add randomness to your `CENTVRION` program. It adds 2 new built-in functions: `FORTIS_NVMERVS int int` and `FORTIS_ELECTIONIS ['a]`.
@@ -273,7 +209,7 @@ The `FORS` module allows you to add randomness to your `CENTVRION` program. It a
`FORTIS_ELECTIONIS ['a]` picks a random element from the given array. `FORTIS_ELECTIONIS array` is identical to ```array[FORTIS_NVMERVS NVLLVS ((LONGITVDO array)-I)]```.
### FRACTIO
```CVM FRACTIO```
![CVM FRACTIO](snippets/fractio.png)
The `FRACTIO` module adds floats, in the form of base 12 fractions.
@@ -286,7 +222,7 @@ The symbol `|` can be used to denote that the following fraction symbols are 1 "
A single "set" of fraction symbols can only represent up to 11/12, as 12/12 can be written as 1.
### MAGNVM
```CVM MAGNVM```
![CVM MAGNVM](snippets/magnvm.png)
`MAGNVM` adds the ability to write integers larger than `MMMCMXCIX` (3.999) in your code, by adding the thousands operator, "`_`".
@@ -295,6 +231,6 @@ When `_` is added _after_ a numeric symbol, the symbol becomes 1.000 times large
All integer symbols except `I` may be given a `_`.
### SVBNVLLA
```CVM SVBNVLLA```
![CVM SVBNVLLA](snippets/svbnvlla.png)
The `SVBNVLLA` module adds the ability to write negative numbers as `-II` instead of `NVLLVS-II`.

6
snippets/alvid.cent Normal file
View File

@@ -0,0 +1,6 @@
DESIGNA x VT VERITAS
SI x TVNC {
DICE(I)
} ALVID {
DICE(NVLLVS)
}

BIN
snippets/alvid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

8
snippets/alvid_si.cent Normal file
View File

@@ -0,0 +1,8 @@
DESIGNA x VT II
SI x EST I TVNC {
DICE(I)
} ALVID SI x EST II TVNC {
DICE(II)
} ALVID {
DICE(III)
}

BIN
snippets/alvid_si.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -0,0 +1,2 @@
DESIGNA x VT [I, II, III]
DICE(x[I])

BIN
snippets/array_index.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@@ -0,0 +1 @@
DESIGNA x VT [I, II, III]

BIN
snippets/array_literal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@@ -0,0 +1 @@
DESIGNA x VT [I VSQVE X]

BIN
snippets/array_vsqve.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -0,0 +1,9 @@
DESIGNA x VT VERITAS
DESIGNA y VT FALSITAS
SI x ET y TVNC {
DICE(I)
} ALVID SI x AVT y TVNC {
DICE(II)
} ALVID {
DICE(III)
}

BIN
snippets/boolean_ops.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

2
snippets/dice.cent Normal file
View File

@@ -0,0 +1,2 @@
DICE("Hello, world!")
DICE(I, II, III)

BIN
snippets/dice.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

5
snippets/donicvm.cent Normal file
View File

@@ -0,0 +1,5 @@
DESIGNA x VT NVLLVS
DONICVM y VT NVLLVS VSQVE X FACE {
DESIGNA x VT x + y
}
DICE(x)

BIN
snippets/donicvm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

5
snippets/dvm.cent Normal file
View File

@@ -0,0 +1,5 @@
DESIGNA x VT NVLLVS
DVM x PLVS X FACE {
DESIGNA x VT x+I
}
DICE(x)

BIN
snippets/dvm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

9
snippets/fibonacci.cent Normal file
View File

@@ -0,0 +1,9 @@
DEFINI fib(x) VT {
SI x EST NVLLVS TVNC {
REDI(NVLLVS)
} ALVID SI x EST I TVNC {
REDI(I)
} ALVID {
REDI(INVOCA fib(x-II) + INVOCA fib(x-I))
}
}

BIN
snippets/fibonacci.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

1
snippets/fors.cent Normal file
View File

@@ -0,0 +1 @@
CVM FORS

BIN
snippets/fors.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

1
snippets/fractio.cent Normal file
View File

@@ -0,0 +1 @@
CVM FRACTIO

BIN
snippets/fractio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

5
snippets/function.cent Normal file
View File

@@ -0,0 +1,5 @@
DEFINI sqvare(x) VT {
REDI(x*x)
}
DICE(INVOCA sqvare(XI))

BIN
snippets/function.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

17
snippets/guessing.cent Normal file
View File

@@ -0,0 +1,17 @@
CVM FORS
DESIGNA correct VT FORTIS_NVMERVS(I,C)
DESIGNA gvess VT NVLLVS
DVM FALSITAS FACE {
DESIGNA gvess VT AVDI_NVMERVS()
SI gvess MINVS correct TVNC {
DICE("Too low!")
} ALVID SI gvess PLVS correct TVNC {
DICE("Too high!")
} ALVID {
ERVMPE
}
}
DICE("You guessed correctly!")

BIN
snippets/guessing.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

View File

@@ -0,0 +1,2 @@
DESIGNA x VT "Hello World!"
DICE(x)

BIN
snippets/hello_world.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

1
snippets/magnvm.cent Normal file
View File

@@ -0,0 +1 @@
CVM MAGNVM

BIN
snippets/magnvm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -0,0 +1 @@
CVM MODVLE_NOMEN

BIN
snippets/module_decl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

4
snippets/per.cent Normal file
View File

@@ -0,0 +1,4 @@
DESIGNA x VT [I, II, III, IV, V]
PER y IN x FACE {
DICE(y)
}

BIN
snippets/per.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

7
snippets/si_tvnc.cent Normal file
View File

@@ -0,0 +1,7 @@
DESIGNA x VT VERITAS
SI x TVNC {
DICE(I)
REDI(NVLLVS)
}
DICE(NVLLVS)

BIN
snippets/si_tvnc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -0,0 +1 @@
DESIGNA greeting VT "Hello, " & "world!"

BIN
snippets/string_concat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1 @@
DESIGNA x VT "this is a string"

BIN
snippets/string_literal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

1
snippets/svbnvlla.cent Normal file
View File

@@ -0,0 +1 @@
CVM SVBNVLLA

BIN
snippets/svbnvlla.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@@ -0,0 +1,77 @@
%YAML 1.2
---
name: Centvrion
file_extensions:
- cent
scope: source.centvrion
contexts:
main:
- include: comments
- include: strings
- include: fractions
- include: numerals
- include: constants
- include: builtins
- include: modules
- include: keywords
- include: operators
- include: identifiers
comments:
- match: '//[^\n]*'
scope: comment.line.centvrion
- match: '/\*'
scope: comment.block.centvrion
push:
- meta_scope: comment.block.centvrion
- match: '\*/'
pop: true
strings:
- match: '"'
scope: string.quoted.double.centvrion
push:
- meta_scope: string.quoted.double.centvrion
- match: '"'
pop: true
- match: "'"
scope: string.quoted.single.centvrion
push:
- meta_scope: string.quoted.single.centvrion
- match: "'"
pop: true
fractions:
- match: '\b[IVXLCDM][IVXLCDM_]*(?:S[S:.|]*|:[S:.|]+|\.[S:.|]*)'
scope: constant.numeric.fraction.centvrion
- match: '(?<![IVXLCDM_])(?:S[S:.|]+|:[S:.|]+)'
scope: constant.numeric.fraction.centvrion
numerals:
- match: '\b[IVXLCDM][IVXLCDM_]*\b'
scope: constant.numeric.centvrion
constants:
- match: '\b(VERITAS|FALSITAS|NVLLVS)\b'
scope: constant.language.centvrion
builtins:
- match: '\b(AVDI_NVMERVS|AVDI|DICE|FORTIS_NVMERVS|FORTIS_ELECTIONIS|LONGITVDO)\b'
scope: support.function.builtin.centvrion
modules:
- match: '\b(FORS|FRACTIO|MAGNVM|SVBNVLLA)\b'
scope: support.class.module.centvrion
keywords:
- match: '\b(ALVID|AVT|DEFINI|DESIGNA|DONICVM|DVM|ERVMPE|EST|ET|FACE|INVOCA|IN|MINVS|NON|PER|PLVS|REDI|SI|TVNC|VSQVE|VT|CVM)\b'
scope: keyword.control.centvrion
operators:
- match: '[+\-*/&]'
scope: keyword.operator.centvrion
identifiers:
- match: '[abcdefghiklmnopqrstvxyz_]+'
scope: variable.other.centvrion

View File

@@ -0,0 +1,77 @@
%YAML 1.2
---
name: Centvrion
file_extensions:
- cent
scope: source.centvrion
contexts:
main:
- include: comments
- include: strings
- include: fractions
- include: numerals
- include: constants
- include: builtins
- include: modules
- include: keywords
- include: operators
- include: identifiers
comments:
- match: '//[^\n]*'
scope: comment.line.centvrion
- match: '/\*'
scope: comment.block.centvrion
push:
- meta_scope: comment.block.centvrion
- match: '\*/'
pop: true
strings:
- match: '"'
scope: string.quoted.double.centvrion
push:
- meta_scope: string.quoted.double.centvrion
- match: '"'
pop: true
- match: "'"
scope: string.quoted.single.centvrion
push:
- meta_scope: string.quoted.single.centvrion
- match: "'"
pop: true
fractions:
- match: '\b[IVXLCDM][IVXLCDM_]*(?:S[S:.|]*|:[S:.|]+|\.[S:.|]*)'
scope: constant.numeric.fraction.centvrion
- match: '(?<![IVXLCDM_])(?:S[S:.|]+|:[S:.|]+)'
scope: constant.numeric.fraction.centvrion
numerals:
- match: '\b[IVXLCDM][IVXLCDM_]*\b'
scope: constant.numeric.centvrion
constants:
- match: '\b(VERITAS|FALSITAS|NVLLVS)\b'
scope: constant.language.centvrion
builtins:
- match: '\b(AVDI_NVMERVS|AVDI|DICE|FORTIS_NVMERVS|FORTIS_ELECTIONIS|LONGITVDO)\b'
scope: support.function.builtin.centvrion
modules:
- match: '\b(FORS|FRACTIO|MAGNVM|SVBNVLLA)\b'
scope: support.class.module.centvrion
keywords:
- match: '\b(ALVID|AVT|DEFINI|DESIGNA|DONICVM|DVM|ERVMPE|EST|ET|FACE|INVOCA|IN|MINVS|NON|PER|PLVS|REDI|SI|TVNC|VSQVE|VT|CVM)\b'
scope: keyword.control.centvrion
operators:
- match: '[+\-*/&]'
scope: keyword.operator.centvrion
identifiers:
- match: '[abcdefghiklmnopqrstvxyz_]+'
scope: variable.other.centvrion

1
snippets/variable.cent Normal file
View File

@@ -0,0 +1 @@
DESIGNA x VT XXVI

BIN
snippets/variable.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB