Added compiler stub, more examples.

git status
This commit is contained in:
Andrew Lalis 2023-06-01 13:35:12 +02:00
parent 3f0ce063e7
commit d9d1b539cd
9 changed files with 131 additions and 1 deletions

View File

@ -1,2 +1,18 @@
# nimp
A simple programming language that anyone can read, and where nothing is implied.
A simple programming language that anyone can read, and where nothing is
implied.
nimp is designed to be intentionally verbose to the point of pain, because it
is meant to be read by **anyone**, including non-programmers, without
sacrificing functionality.
Here's how you'd write a _Hello world_ program in nimp:
```nimp
import module io from standard-library.
call io.print with contents as "Hello world!".
```
Everything in nimp is defined as a sentence that can be read in plain English.

16
compiler/.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
.dub
docs.json
__dummy.html
docs/
/compiler
compiler.so
compiler.dylib
compiler.dll
compiler.a
compiler.lib
compiler-test-*
*.exe
*.pdb
*.o
*.obj
*.lst

9
compiler/dub.json Normal file
View File

@ -0,0 +1,9 @@
{
"authors": [
"Andrew Lalis"
],
"copyright": "Copyright © 2023, Andrew Lalis",
"description": "Compiler for the NIMP language.",
"license": "MIT",
"name": "compiler"
}

5
compiler/source/app.d Normal file
View File

@ -0,0 +1,5 @@
import std.stdio;
void main() {
writeln("Edit source/app.d to start your project.");
}

24
examples/aggregates.nimp Normal file
View File

@ -0,0 +1,24 @@
# Arrays
define a1 as array of integer with value [1, 2, 3].
define a2 as array of boolean with value [true, false].
define a3 as array of float with size 64.
# Structs
define S1 as struct with body {
define a as integer.
define b as float.
define sum as function returning integer with body {
return sum of a from this and b from this.
}.
}.
# Interfaces
define Gettable as interface with body {
define get as function returning integer.
define getAll as function returning array of integer.
define getNone as function returning array of integer with body {
return array of integer with value [].
}.
}.

14
examples/fibonacci.nimp Normal file
View File

@ -0,0 +1,14 @@
define fibonacci as function
taking n as integer
and returning integer
with body {
if n is less than or equal to 1 then return n.
return sum of
call fibonacci with n as difference of n and 1, and
call fibonacci with n as difference of n and 2.
}.
define x as integer with value of call fibonacci with n as 42.
import module io from standard-library.
call io:print with contents as string of x.

22
examples/functions.nimp Normal file
View File

@ -0,0 +1,22 @@
define foo as function with body {
import module io from standard-library.
call io:print with contents as "Hello world".
}
define sumInts as function
taking a as integer,
b as integer,
and returning integer,
with body {
return sum of a and b.
}
define malloc as external function taking size as integer, and returning pointer to void.
define free as external function taking ptr as pointer to void.
define main as function returning integer with body {
call foo.
define x as integer with value of call sumInts with a as 3 and b as 5.
define ptr as pointer to void with value of call malloc with size as 42.
call free with ptr as ptr.
}

View File

@ -0,0 +1,5 @@
import module io from standard-library.
define main as function taking args as array of character with body {
call io.print with contents as "Hello world".
}

19
examples/variables.nimp Normal file
View File

@ -0,0 +1,19 @@
# Syntax: define _SYMBOL_ as _TYPE_ with value of _EXPRESSION[_TYPE_]_.
# Or shortcut: define _SYMBOL_ as _EXPRESSION[_TYPE_]_.
define x as integer with value of 42.
define b as boolean.
assign true to b.
define bString as string of b.
define constant PI as float with value of 3.14.
define quarterCircle as float with value of PI divided by 2.
define s1 as string with value of "Hello world!".
# Shortcut expressions where type is implied:
define a as sum of 3 and 2.
define c as true or false.
define s2 as "Hello world, again.".