From 42716b24c986d0f99de76c5100e5804bf8aba581 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 15 Aug 2022 12:29:27 +0100 Subject: [PATCH] Updated README.md --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 35e0ff8..940c557 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,39 @@ Special thanks to http://craftinginterpreters.com/ for their fantastic book that Simply run make in the root directory. +## Syntax + +``` +import "standard"; //for a bunch of utility functions + + +print "Hello world"; //"print" is a keyword + +var msg = "foobar"; //declare a variable like this + +assert true, "This message won't be seen"; //assert is another keyword + +//------------------------- + +fn makeCounter() { //declare a function like this + var total: int = 0; //declare a variable with a type like this + + fn counter(): int { //declare a return type like this + return ++total; + } + + return counter; //closures are explicitly supported +} + +var counter = makeCounter(); + +print counter(); //1 +print counter(); //2 +print counter(); //3 + +export makeCounter; //export this variable to the host program +``` + # License Copyright (c) 2020-2022 Kayne Ruse, KR Game Studios