This commit is contained in:
NikolajDanger
2022-06-08 16:34:50 +02:00
parent 05072e5a0a
commit 1aff3b4486
4 changed files with 15 additions and 11 deletions

View File

@@ -27,7 +27,7 @@ DEFINI fib x VT {
### Number guessing game ### Number guessing game
``` ```
VOCA FORS CVM FORS
DESIGNA correct VT FORTIS_NVMERVS I C DESIGNA correct VT FORTIS_NVMERVS I C
DESIGNA gvess VT NVLLVS DESIGNA gvess VT NVLLVS
@@ -229,14 +229,14 @@ DICE (INVOCA square XI)
## Modules ## Modules
Modules are additions to the base `CENTVRION` syntax. They add or change certain features. Modules are included in your code by having Modules are additions to the base `CENTVRION` syntax. They add or change certain features. Modules are included in your code by having
```VOCA %MODVLE NAME%``` ```CVM %MODVLE NAME%```
In the beginning of your source file. 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. 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 ### FORS
```VOCA FORS``` ```CVM FORS```
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]`. 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]`.
@@ -245,7 +245,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)]```. `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 ### FRACTIO
```VOCA FRACTIO``` ```CVM FRACTIO```
The `FRACTIO` module adds floats, in the form of base 12 fractions. The `FRACTIO` module adds floats, in the form of base 12 fractions.
@@ -253,12 +253,12 @@ In the `FRACTIO` module, `.` represents 1/12, `:` represents 1/6 and `S` represe
Fractions can be written as an extension of integers. So 3.5 would be "`IIIS`". Fractions can be written as an extension of integers. So 3.5 would be "`IIIS`".
The symbol `|` can be used to denote that the following fraction symbols are 1 "level down" is base 12. So after the first `|`, the fraction symbols denote 144ths instead of 12ths. So 7 and 100/144 would be "`VIIS:|::`", as "7 + 100/144" is also "7+9/12+4/144". The symbol `|` can be used to denote that the following fraction symbols are 1 "level down" in base 12. So after the first `|`, the fraction symbols denote 144ths instead of 12ths. So 7 and 100/144 would be "`VIIS:|::`", as "7 + 100/144" is also "7+9/12+4/144".
A single "set" of fraction symbols can only represent up to 11/12, as 12/12 can be written as 1. A single "set" of fraction symbols can only represent up to 11/12, as 12/12 can be written as 1.
### MAGNVM ### MAGNVM
```VOCA MAGNVM``` ```CVM MAGNVM```
`MAGNVM` adds the ability to write integers larger than `MMMCMXCIX` (3.999) in your code, by adding the thousands operator, "`_`". `MAGNVM` adds the ability to write integers larger than `MMMCMXCIX` (3.999) in your code, by adding the thousands operator, "`_`".
@@ -267,6 +267,6 @@ When `_` is added _after_ a numeric symbol, the symbol becomes 1.000 times large
All integer symbols except `I` may be given a `_`. All integer symbols except `I` may be given a `_`.
### SVBNVLLA ### SVBNVLLA
```VOCA SVBNVLLA``` ```CVM SVBNVLLA```
The `SVBNVLLA` module adds the ability to write negative numbers as `-II` instead of `NVLLVS-II`. The `SVBNVLLA` module adds the ability to write negative numbers as `-II` instead of `NVLLVS-II`.

View File

@@ -24,7 +24,7 @@ keyword_tokens = [("KEYWORD_"+i, i) for i in [
"VSQVE", "VSQVE",
"VT", "VT",
"VERITAS", "VERITAS",
"VOCA" "CVM"
]] ]]
builtin_tokens = [("BUILTIN", i) for i in [ builtin_tokens = [("BUILTIN", i) for i in [

View File

@@ -34,7 +34,7 @@ class Parser():
else: else:
return [calls[0]] + calls[2] return [calls[0]] + calls[2]
@self.pg.production('module_call : KEYWORD_VOCA MODULE') @self.pg.production('module_call : KEYWORD_CVM MODULE')
def module_call(tokens): def module_call(tokens):
return ast_nodes.ModuleCall(tokens[1].value) return ast_nodes.ModuleCall(tokens[1].value)

View File

@@ -1,8 +1,9 @@
from centvrion.lexer import Lexer from centvrion.lexer import Lexer
from centvrion.parser import Parser from centvrion.parser import Parser
from centvrion.ast_nodes import Program
text_input = """ text_input = """
VOCA FORS CVM FORS
DESIGNA correct VT FORTIS_NVMERVS I C DESIGNA correct VT FORTIS_NVMERVS I C
DESIGNA gvess VT NVLLVS DESIGNA gvess VT NVLLVS
@@ -30,4 +31,7 @@ tokens = lexer.lex(text_input)
program = parser.parse(tokens) program = parser.parse(tokens)
#print(x) #print(x)
if isinstance(program, Program):
program.eval() program.eval()
else:
raise Exception("Output not of type 'Program'", type(program))