From 1aff3b448668c5b61830368a9947b25fe4221f0f Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Wed, 8 Jun 2022 16:34:50 +0200 Subject: [PATCH] :sparkles: --- README.md | 14 +++++++------- centvrion/lexer.py | 2 +- centvrion/parser.py | 2 +- main.py | 8 ++++++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 13598cd..4ce8984 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ DEFINI fib x VT { ### Number guessing game ``` -VOCA FORS +CVM FORS DESIGNA correct VT FORTIS_NVMERVS I C DESIGNA gvess VT NVLLVS @@ -229,14 +229,14 @@ DICE (INVOCA square XI) ## Modules 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. 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 -```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]`. @@ -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)]```. ### FRACTIO -```VOCA FRACTIO``` +```CVM FRACTIO``` 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`". -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. ### 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, "`_`". @@ -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 `_`. ### SVBNVLLA -```VOCA SVBNVLLA``` +```CVM SVBNVLLA``` The `SVBNVLLA` module adds the ability to write negative numbers as `-II` instead of `NVLLVS-II`. diff --git a/centvrion/lexer.py b/centvrion/lexer.py index 6065481..0bdeb49 100644 --- a/centvrion/lexer.py +++ b/centvrion/lexer.py @@ -24,7 +24,7 @@ keyword_tokens = [("KEYWORD_"+i, i) for i in [ "VSQVE", "VT", "VERITAS", - "VOCA" + "CVM" ]] builtin_tokens = [("BUILTIN", i) for i in [ diff --git a/centvrion/parser.py b/centvrion/parser.py index 8767319..0d8333a 100644 --- a/centvrion/parser.py +++ b/centvrion/parser.py @@ -34,7 +34,7 @@ class Parser(): else: 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): return ast_nodes.ModuleCall(tokens[1].value) diff --git a/main.py b/main.py index 60e4844..ba6adcf 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,9 @@ from centvrion.lexer import Lexer from centvrion.parser import Parser +from centvrion.ast_nodes import Program text_input = """ -VOCA FORS +CVM FORS DESIGNA correct VT FORTIS_NVMERVS I C DESIGNA gvess VT NVLLVS @@ -30,4 +31,7 @@ tokens = lexer.lex(text_input) program = parser.parse(tokens) #print(x) -program.eval() +if isinstance(program, Program): + program.eval() +else: + raise Exception("Output not of type 'Program'", type(program))