kolorScript
A modern variant of Charles H. Moore's colorForth that uses ASCII for encoding and text files as storage to allow code sharing using modern repositories.
Just in case, here is a good reference for Forth programming: Starting Forth
Features
- 80 built-in Forth words
- Color blind mode
- Your script will run on all three major OS (Mac/Win/Linux) with 100% NO modifications needed! Even path separators and EOL will be kept as it is
Installation
- Download and install Visual Studio Code on your preferred OS
- Open Visual Studio Code and go to
Extensions
- Type
kolorScript
in the search box, then click Install
Quick start
Create new file and name it test.ks
Copy and paste the code below (including whitespaces)
"Hello world!" .
Or type:
<space><space>"Hello world!"<space><space>.
Save and press F2 to load your code
Result:
Again, copy and paste the code below (including whitespaces)
my-name (--) This function prints my name
"My name is George!" . ; my-name
Or type:
my-name<space><space><space>(--)<space><space><space><space>This function prints my name<enter><space>"My name is George!"<space>.<space>;<space><space>my-name
Save and press F2 to load your code
Result:
IMPORTANT: Explicitly showing <space>
when typing the code is due to prefix whitespaces are CRITICAL, for it defines the color of the word. Please make sure there are NO unused prefix whitespace anywhere in the file.
Usage
Running your code
Press F2
OR press F1
then type kolor
and scroll to select kolorScript: Load file
Please make sure the editor window with intended code has the focus.
Execute some words
Press F4
OR press F1
then type kolor
and scroll to select kolorScript: Execute words
Please make sure the words you plan to execute has already been loaded. This mechanism is like executing Forth words in a command line.
Showing all the words
Press F6
OR press F1
then type kolor
and scroll to select kolorScript: Show words
This is a replacement and improvement for WORDS
from Forth. It shows the stack-effect and brief description for BOTH built-in and user defined (after loading) words in the Output panel.
Color blind theme
Press F8
OR press F1
then type kolor
and scroll to select kolorScript: Toggle Color Blind theme
Where:
GREEN words are kept as Normal text
YELLOW words are set to Bold text
GRAY words are set to Italic text
BLUE words are set to Underlined text
MAGENTA words are set to Underlined text
RED words are set to Underlined text
Light theme
Press F9
OR press F1
then type kolor
and scroll to select kolorScript: Toggle Light theme
TIP: Use the function keys for faster and convenient access.
Settings
Enable verbose loading
- Go to
Extensions
, find kolorScript
on the Installed list
- Click setting icon of
kolorScript
extension and select Extension Settings
- Check the
Show more details when loading
checkbox
- Close
Settings
tab, click the editor window and press F2
Coding guidelines
- There only three types: Number, String, or a Word
- Numbers are written as signed integer, hexadecimal, or float
- Strings must be enclosed with single or double quote
- Words are built-in functions or user-defined functions/variables/constants
- Executing a Number will push the that Number to Data stack
- Executing a String will push that String to Data stack
- Executing a Word (function) will call the function
- Executing a Word (variable) will push an index to Data stack to be used by
@
and !
- Executing a Word (constant) will push the value to Data stack
GREEN means "COMPILE this word"
Syntax: <space>
word
Description:
- Are executed at run-time
- Used for initializing constants or defining functions
YELLOW means "INTERPRET this word"
Syntax: <space><space>
word
Description:
- Are executed at compile-time
- Used for initializing variables or as macros
Syntax 1: <space><space><space>
word
Syntax 2: <space><space><space>
(word1 word2 word3)
Syntax 3: <space><space><space><space>
word1 word2 ... wordN
Description:
- Syntax 1 is for commenting a single word
- Syntax 2 is for commenting a set of words
- Syntax 3 is for commenting all the words to the right
BLUE means "define a CONSTANT with this word as its name"
Syntax: word <space>
value
Description:
- Are global in scope
- Only GREEN Number or String is acceptable to initialize constants
Note:
- Should be one liner and focusing only for initializing the value
- After value , comments (gray words) or macros (yellow words) can follow
MAGENTA means "define a VARIABLE with this word as its name"
Syntax: word <space><space>
value and/or word(s)
Description:
- Are global in scope
- Only YELLOW Number, String or Word(s) that leaves a value in the Data stack is acceptable to initialize variables
Note:
- Should be one liner and focusing only for initializing the value
- The top of Data stack before leaving the line is popped and becomes the value of the variable
RED means "define a FUNCTION with this word as its name"
Syntax 1: word <space><space><space>
stack-effect <space>
value(s) and/or word(s) ;
Syntax 2: word <space><space><space>
(stack - effects) <space>
value(s) and/or word(s) ;
Syntax 3: word <space><space><space><space>
brief description <enter>
<space>
value(s) and/or word(s) ;
Syntax 4: word <space><space><space>
(stack - effects) <space><space><space><space>
brief description <enter>
<space>
value(s) and/or word(s) ;
Description:
- GREEN Number, String or Word(s) is used to define the function
- YELLOW Word is fully recommended when utilizing constants and variables within function definition, this is for readability and performance
- GREEN semi-colon ( ; ) is used for closing function definition
Note:
- Transition of YELLOW to GREEN word within function definition will have the top of Data stack popped and compiled as literal, this mechanism is useful for handling constants and variables within function definition
- Comments inline with the function name is used when
Showing all the words
by pressing F6
, so Syntax 4 is fully recommended
WHITE (for dark theme) or BLACK (for light theme) means "this word has INVALID format"
Syntax: Applicable to all patterns
Description:
- If a Number or a String is used as name for defining a new word
- If a Word has a combination of characters not recognized by internal regex (Please inform me for this case)
Reference
(Link to be followed)
Examples
(Link to be followed)
Release Notes
Please refer to CHANGELOG.md