diff --git a/README.md b/README.md index 4becda6..cf40948 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/snippets/alvid.cent b/snippets/alvid.cent new file mode 100644 index 0000000..76cae13 --- /dev/null +++ b/snippets/alvid.cent @@ -0,0 +1,6 @@ +DESIGNA x VT VERITAS +SI x TVNC { + DICE(I) +} ALVID { + DICE(NVLLVS) +} diff --git a/snippets/alvid.png b/snippets/alvid.png new file mode 100644 index 0000000..649f9dd Binary files /dev/null and b/snippets/alvid.png differ diff --git a/snippets/alvid_si.cent b/snippets/alvid_si.cent new file mode 100644 index 0000000..500f856 --- /dev/null +++ b/snippets/alvid_si.cent @@ -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) +} diff --git a/snippets/alvid_si.png b/snippets/alvid_si.png new file mode 100644 index 0000000..ded4e95 Binary files /dev/null and b/snippets/alvid_si.png differ diff --git a/snippets/array_index.cent b/snippets/array_index.cent new file mode 100644 index 0000000..9b894b3 --- /dev/null +++ b/snippets/array_index.cent @@ -0,0 +1,2 @@ +DESIGNA x VT [I, II, III] +DICE(x[I]) diff --git a/snippets/array_index.png b/snippets/array_index.png new file mode 100644 index 0000000..4724f89 Binary files /dev/null and b/snippets/array_index.png differ diff --git a/snippets/array_literal.cent b/snippets/array_literal.cent new file mode 100644 index 0000000..2baa355 --- /dev/null +++ b/snippets/array_literal.cent @@ -0,0 +1 @@ +DESIGNA x VT [I, II, III] diff --git a/snippets/array_literal.png b/snippets/array_literal.png new file mode 100644 index 0000000..01e6827 Binary files /dev/null and b/snippets/array_literal.png differ diff --git a/snippets/array_vsqve.cent b/snippets/array_vsqve.cent new file mode 100644 index 0000000..aa5067c --- /dev/null +++ b/snippets/array_vsqve.cent @@ -0,0 +1 @@ +DESIGNA x VT [I VSQVE X] diff --git a/snippets/array_vsqve.png b/snippets/array_vsqve.png new file mode 100644 index 0000000..18b6b1a Binary files /dev/null and b/snippets/array_vsqve.png differ diff --git a/snippets/boolean_ops.cent b/snippets/boolean_ops.cent new file mode 100644 index 0000000..e275511 --- /dev/null +++ b/snippets/boolean_ops.cent @@ -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) +} diff --git a/snippets/boolean_ops.png b/snippets/boolean_ops.png new file mode 100644 index 0000000..60bc3d4 Binary files /dev/null and b/snippets/boolean_ops.png differ diff --git a/snippets/dice.cent b/snippets/dice.cent new file mode 100644 index 0000000..a3f3cc3 --- /dev/null +++ b/snippets/dice.cent @@ -0,0 +1,2 @@ +DICE("Hello, world!") +DICE(I, II, III) diff --git a/snippets/dice.png b/snippets/dice.png new file mode 100644 index 0000000..6fe5b8a Binary files /dev/null and b/snippets/dice.png differ diff --git a/snippets/donicvm.cent b/snippets/donicvm.cent new file mode 100644 index 0000000..7d27462 --- /dev/null +++ b/snippets/donicvm.cent @@ -0,0 +1,5 @@ +DESIGNA x VT NVLLVS +DONICVM y VT NVLLVS VSQVE X FACE { + DESIGNA x VT x + y +} +DICE(x) diff --git a/snippets/donicvm.png b/snippets/donicvm.png new file mode 100644 index 0000000..d3e0f8f Binary files /dev/null and b/snippets/donicvm.png differ diff --git a/snippets/dvm.cent b/snippets/dvm.cent new file mode 100644 index 0000000..1a0a7c6 --- /dev/null +++ b/snippets/dvm.cent @@ -0,0 +1,5 @@ +DESIGNA x VT NVLLVS +DVM x PLVS X FACE { + DESIGNA x VT x+I +} +DICE(x) diff --git a/snippets/dvm.png b/snippets/dvm.png new file mode 100644 index 0000000..09b4ccd Binary files /dev/null and b/snippets/dvm.png differ diff --git a/snippets/fibonacci.cent b/snippets/fibonacci.cent new file mode 100644 index 0000000..b8dd3a8 --- /dev/null +++ b/snippets/fibonacci.cent @@ -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)) + } +} diff --git a/snippets/fibonacci.png b/snippets/fibonacci.png new file mode 100644 index 0000000..7868f84 Binary files /dev/null and b/snippets/fibonacci.png differ diff --git a/snippets/fors.cent b/snippets/fors.cent new file mode 100644 index 0000000..064c444 --- /dev/null +++ b/snippets/fors.cent @@ -0,0 +1 @@ +CVM FORS diff --git a/snippets/fors.png b/snippets/fors.png new file mode 100644 index 0000000..e89a3c4 Binary files /dev/null and b/snippets/fors.png differ diff --git a/snippets/fractio.cent b/snippets/fractio.cent new file mode 100644 index 0000000..ce5b2f2 --- /dev/null +++ b/snippets/fractio.cent @@ -0,0 +1 @@ +CVM FRACTIO diff --git a/snippets/fractio.png b/snippets/fractio.png new file mode 100644 index 0000000..4c9c7fe Binary files /dev/null and b/snippets/fractio.png differ diff --git a/snippets/function.cent b/snippets/function.cent new file mode 100644 index 0000000..cca65c1 --- /dev/null +++ b/snippets/function.cent @@ -0,0 +1,5 @@ +DEFINI sqvare(x) VT { + REDI(x*x) +} + +DICE(INVOCA sqvare(XI)) diff --git a/snippets/function.png b/snippets/function.png new file mode 100644 index 0000000..574b8cb Binary files /dev/null and b/snippets/function.png differ diff --git a/snippets/guessing.cent b/snippets/guessing.cent new file mode 100644 index 0000000..d27a817 --- /dev/null +++ b/snippets/guessing.cent @@ -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!") diff --git a/snippets/guessing.png b/snippets/guessing.png new file mode 100644 index 0000000..1966c30 Binary files /dev/null and b/snippets/guessing.png differ diff --git a/snippets/hello_world.cent b/snippets/hello_world.cent new file mode 100644 index 0000000..4398b07 --- /dev/null +++ b/snippets/hello_world.cent @@ -0,0 +1,2 @@ +DESIGNA x VT "Hello World!" +DICE(x) diff --git a/snippets/hello_world.png b/snippets/hello_world.png new file mode 100644 index 0000000..9b62cc3 Binary files /dev/null and b/snippets/hello_world.png differ diff --git a/snippets/magnvm.cent b/snippets/magnvm.cent new file mode 100644 index 0000000..d9048b7 --- /dev/null +++ b/snippets/magnvm.cent @@ -0,0 +1 @@ +CVM MAGNVM diff --git a/snippets/magnvm.png b/snippets/magnvm.png new file mode 100644 index 0000000..c837444 Binary files /dev/null and b/snippets/magnvm.png differ diff --git a/snippets/module_decl.cent b/snippets/module_decl.cent new file mode 100644 index 0000000..e47bd22 --- /dev/null +++ b/snippets/module_decl.cent @@ -0,0 +1 @@ +CVM MODVLE_NOMEN diff --git a/snippets/module_decl.png b/snippets/module_decl.png new file mode 100644 index 0000000..6cb3bf1 Binary files /dev/null and b/snippets/module_decl.png differ diff --git a/snippets/per.cent b/snippets/per.cent new file mode 100644 index 0000000..7d30816 --- /dev/null +++ b/snippets/per.cent @@ -0,0 +1,4 @@ +DESIGNA x VT [I, II, III, IV, V] +PER y IN x FACE { + DICE(y) +} diff --git a/snippets/per.png b/snippets/per.png new file mode 100644 index 0000000..3503763 Binary files /dev/null and b/snippets/per.png differ diff --git a/snippets/si_tvnc.cent b/snippets/si_tvnc.cent new file mode 100644 index 0000000..10f34c2 --- /dev/null +++ b/snippets/si_tvnc.cent @@ -0,0 +1,7 @@ +DESIGNA x VT VERITAS +SI x TVNC { + DICE(I) + REDI(NVLLVS) +} + +DICE(NVLLVS) diff --git a/snippets/si_tvnc.png b/snippets/si_tvnc.png new file mode 100644 index 0000000..6363fee Binary files /dev/null and b/snippets/si_tvnc.png differ diff --git a/snippets/string_concat.cent b/snippets/string_concat.cent new file mode 100644 index 0000000..49e4289 --- /dev/null +++ b/snippets/string_concat.cent @@ -0,0 +1 @@ +DESIGNA greeting VT "Hello, " & "world!" diff --git a/snippets/string_concat.png b/snippets/string_concat.png new file mode 100644 index 0000000..56d9c47 Binary files /dev/null and b/snippets/string_concat.png differ diff --git a/snippets/string_literal.cent b/snippets/string_literal.cent new file mode 100644 index 0000000..65c7668 --- /dev/null +++ b/snippets/string_literal.cent @@ -0,0 +1 @@ +DESIGNA x VT "this is a string" diff --git a/snippets/string_literal.png b/snippets/string_literal.png new file mode 100644 index 0000000..9f1361d Binary files /dev/null and b/snippets/string_literal.png differ diff --git a/snippets/svbnvlla.cent b/snippets/svbnvlla.cent new file mode 100644 index 0000000..97387dc --- /dev/null +++ b/snippets/svbnvlla.cent @@ -0,0 +1 @@ +CVM SVBNVLLA diff --git a/snippets/svbnvlla.png b/snippets/svbnvlla.png new file mode 100644 index 0000000..a7e67ad Binary files /dev/null and b/snippets/svbnvlla.png differ diff --git a/snippets/syntax/centvrion.sublime-syntax b/snippets/syntax/centvrion.sublime-syntax new file mode 100644 index 0000000..700ccda --- /dev/null +++ b/snippets/syntax/centvrion.sublime-syntax @@ -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: '(?