diff --git a/README.md b/README.md index a06475e..e801e71 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/compiler/.gitignore b/compiler/.gitignore new file mode 100644 index 0000000..2300c2f --- /dev/null +++ b/compiler/.gitignore @@ -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 diff --git a/compiler/dub.json b/compiler/dub.json new file mode 100644 index 0000000..8172f18 --- /dev/null +++ b/compiler/dub.json @@ -0,0 +1,9 @@ +{ + "authors": [ + "Andrew Lalis" + ], + "copyright": "Copyright © 2023, Andrew Lalis", + "description": "Compiler for the NIMP language.", + "license": "MIT", + "name": "compiler" +} \ No newline at end of file diff --git a/compiler/source/app.d b/compiler/source/app.d new file mode 100644 index 0000000..b02f56e --- /dev/null +++ b/compiler/source/app.d @@ -0,0 +1,5 @@ +import std.stdio; + +void main() { + writeln("Edit source/app.d to start your project."); +} diff --git a/examples/aggregates.nimp b/examples/aggregates.nimp new file mode 100644 index 0000000..f73c7f5 --- /dev/null +++ b/examples/aggregates.nimp @@ -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 []. + }. +}. diff --git a/examples/fibonacci.nimp b/examples/fibonacci.nimp new file mode 100644 index 0000000..7070a18 --- /dev/null +++ b/examples/fibonacci.nimp @@ -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. diff --git a/examples/functions.nimp b/examples/functions.nimp new file mode 100644 index 0000000..4207675 --- /dev/null +++ b/examples/functions.nimp @@ -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. +} diff --git a/examples/hello-world.nimp b/examples/hello-world.nimp new file mode 100644 index 0000000..a2b602b --- /dev/null +++ b/examples/hello-world.nimp @@ -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". +} diff --git a/examples/variables.nimp b/examples/variables.nimp new file mode 100644 index 0000000..3b62cf1 --- /dev/null +++ b/examples/variables.nimp @@ -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.".