Programming

This site is designed for people with programming experience to understand mscript's programming system so they can teach others how to write meaningful programs
Check out this Code Project article describing the technical details of the implementation of mscript.

You can download the mscript app from the Microsoft Store

Once you understand the programming language, check out all the Functions available, and Database Programming.  Finally, check out Colors, an extended sample program that puts all the pieces together.
With mscript I wanted to create a programming system for folks new to programming.  mscript was born out of my appreciation for VBScript and C, with no aspirations for the sophistication of C++ or Java or .NET, and with no plans for making it production grade.  mscript has the bare minimum of features, yet you can create database-driven web pages with it. 
mscript has a quirky programming language.  It's sort of like C, and it's sort of like VBScript. And those are very different!
There are only five types of data in mscript:

1. number: a floating point number; internally a 64-bit floating point number, a double
2. string: text; internally a Unicode string
3. boolean: true or false; internally a bool
4. list: a collection of items; internally a List<object>
5. index: a collection of pairs of items, mapping keys to values, internally my ListDictionary<object, object>, an ordered Dictionary<object, object> of sorts
NOTE: You can add to lists and indexes once created, but you cannot alter the contents once in there. This leads to easier to understand programs what with fewer side effects.
To add comments to the program, you can use C-style block comments, or VBScript-style line comments.
To create a single line comment, you put an exclamation point at the beginning of the line, like…
! this a line comment
To make a multi-line comment, do like so…
/*
all
these
lines
are a comment
*/
Program output is done with the print >> or > statements:
To print a verbatim line of text, use >>.  Anything after >> on the line is printed.
>> 4 + 5
...will output "4 + 5" without the quotes.  

If you want to evaluate the line, you use >.
> 4 + 5
...would output "9" without the quotes
> "A nice number: " + 42
...would output "A nice number: 42" without the quotes.
You can output blocks of text verbatim using the block literal print statement:
{>>
Anything written here 
will be output directly
just like you had used >> for each line
>>}
Block printing is for <script> and <style> blobs.
Variables must be declared and initialized before they are used.  This is done with the $ statement:
$ x = 10
You can change the value of a variable with the & statement:
& x = 11
Basic loops are programmed using the O statement, ending with a }:
$ counter = 0
O
	> "Inside the loop...forever...at least until 3!"
	& counter = counter + 1
	> counter
	? counter >= 3
		v
	}
}
This program would output…
Inside the loop…until 3!
1
Inside the loop…until 3!
2
Inside the loop…until 3!
3

The v line is a break statement.
An isolated place for declaring and working with variables can be created using the { / } statement:
{
    $ something_good = "anything goes"
}
{
    $ something_good = "no problem at all"
}
Basic HTML tags can be created using the < statement:
<h1 index("inner", "a great heading")
This tag statement would result in output of…
<h1>a great heading</h1>
HTML tags that contain other tags can be created using the block tag <{ statement:
<{head
<title index("inner", "great title!")
}
That would generate the following HTML:
<head>     
    <title>great title!</title> 
</head> 
A link to Yahoo might look like:
<a href="https://yahoo.com">Yahoo!</a>
In mscript, that would be:
 < a index("href", "https://yahoo.com", "inner", "Yahoo!") 
The index is used to set the attributes of the tag. "inner" is a special attribute used to specify the inner HTML for a simple tag.
A simple form’s HTML might look like: 
<form> 
    Enter your email address: 
    <input type="email" name="email"/> 
    <input type="submit" value="Submit"/> 
</form> 
The mscript for that would be:
<{ form 
    >> Enter your email address: 
    < input index("type", "email", "name", "email") 
    < input index("type", "submit", "value", "Submit") 
} 
You see how mscript code tags mirror web page tags. 
To test for different conditions and execute commands accordingly use the ? / <> statement:
? x = 10
    > "not quite"
? x > 10
    > "yep, there it is"
<>
    > "nowhere close"
}
To iterate over a list of values use the @ / every statement:
@ val : list(1, 2, 3)
    > val
}
This would output...
1
2
3
To process numbers in a range use the # / count statement:
# val : 10 -> 7
    > val
}
This would output…
10
9
8
7
You can define your own functions using the f / function statement, with <- to exit the function:
f iseven(val)
    <- (val % 2) = 0
}
Inside a loop, you can use continue ^ to go back to the beginning of the loop (continue), or leave v to exit the loop (break):
# cur : low -> high
    ? cur < 3
        ^
    ? cur > 5
        v
    }
    > cur
}
That would make functionality that really wanted to print 3, 4, 5, or 5, 4, 3 if low was > high.
Finally, to run code that does not need to process a result use the * statement:
$ my_list = list(1, 2)
* my_list.add(3)
That's it, those are all the statements in mscript's programming language.
Here is a small example program for working with the Fibonacci sequence of numbers:
f fib (n)
    ? n <= 1 
        <- 1
    <>
        <- fib(n - 2) + fib(n - 1)
    }
}

# n : 1 -> 10
    > fib(n)
}
Now check out all the Functions available, and Database Programming. 
Once you have read the references, check out Colors, an extended sample program for a web page that can change its background color, and even add new colors to pick from.

All of the mscript software is Open Source

First, there's the database engine, metastrings

There's the core mscript language implementation, mscript-core

And then there's the mscript web server, mscript-server

Finally, there's the mscript app, mscript-ide

%d bloggers like this: