adroit
Joined: 21 Feb 2010
Posts: 252
|
I've been thinking of designing a command (script) language for my OS and a markup language for applications.
(NOTE: I posted my idea here, so I wouldn't forget about it. These are my concepts/abstractions of both languages. Please comment.)
Script Language
The script language will be used in CLI and GUI environment of the OS. It is different than the command language.
Concept (Goals)
The overall concept (goals) for the script language are:
•Easily understood syntax (or something like that);
•Mathematically based (e.i, can perform mathematical operations -- simple and complex);
•Data manipulation;
•Console (CLI) and GUI script based (e.i, can be ran to perform CLI environment tasks: deleting a file and GUI environment tasks: like making a message box);
•Support macro recording (e.i, set macro commands);
•Support function definition (e.i, set functions);
•Support transput (e.i, input and output);
•Support english-like commands (e.g: move file (to) destination);
•Proficiency for both general and programmer users;
•Support variables and variable interpolation;
•Application program execution;
•Support different datatypes: string, integer (sizes: 8,16,32), character, boolean, floating point (real values), array, pointer (address), constants;
•Support control flow statements: if, while, for, loop, repeat, is; (please add more statements, if possible);
•Provide functions for the user: length, maxlength, void, join, upcase, lowcase, find, equal, inequal, reverse, list, trim, chop, free, tmap, lookup, fetch, random
Variables
incomplete
When a user declares a variable, a variety of information about the variable are saved. Information such a length, data type, scope, etc. These information are known as metadata. They give the properties of a allocated variable. The following are stored:
•Identifier the name or label of the variable.
•Data the value of the variable.
•Datatype the datatype of the variable.
•Length the length of the data stored. (Number of bytes). This is represented by an integer.
•Maximum length allowed the maximum length allowed for data storage. The maxumun length is represented as an integer
•Access right the privilage the user has to access the data and alter it. User access and system access are recognized by a 'U' or 'S', repectively.
•scope whether data is Global or Local. These are denoted by a 'G' or 'L', respectively.
•definition Whether the data was initialized or uninitialized. These are denoted by an 'I' or 'U', repectively.
•status functionality unknown
It is still known as to how variables are stored in memory.
Command Syntaxes
1. Syntax for command. (Each command has it's own syntax).
Name -Parameter1 -Parameter2 Argument1, Argument2, Argument3,...
2. Sytanx for control-flow statements
Name (Condition): { Commands )
3. Syntax for functions
;Function statement
Name(Argument1, Argument2,...)
;Defining a function
Func(Parameter1,Parameter2,...)
{
commands
}
Commands
incomplete
Functions
Every function returns the result of the function into the system variable %RETURN%, if the return command isn't in a function.
Here are some possible functions which are to be provided to the users:
1. Length returns the length of a string in to the return variable.
Example:
set length = length("Hello World")
print "Length of string %length%"
Output:
2. MaxLength specifies the number of bytes a variable can store.
MaxLength(variable,maximum_length)
Example:
set hello = "Hello World"
maxlength(%hello%,5)
print %hello%
Output:
3. Void this function does not return any value to %RETURN%. Void() is used with other functions if no value is required to be returned. Even if a return command is used in it, there this is no return value.
Example:
set hello = "hello world"
void(upcase(%hello%))
print "%hello%. %return%"
Output:
The return variable is null, of the Void().
4. Join concatenates two or more strings into one. It returns the result into %RETURN%.
Join(string1,string2,...)
Example:
set part2 = "world"
join("Hello ",%part2%)
print %return%
Output:
5. Upcase converts lowercased characters into uppercased characters. If a string is presented, then the result returns to %RETURN%. But if a variable is given, then it is converted directly, and the result is also placed in %RETURN%.
Example:
upcase("hello world")
print %return%
Output:
6. Lowcase converts uppercased characters into lowercased characters. if a string is presented, then the result returns to %RETURN%. But if a variable is given, then it is converted directly, and the result is also placed in %RETURN%.
Example:
lowcase("HeLLo WorlD")
print %return%
Output:
7. Find searches for a character, or sequence of characters in a string. It can be have a delimiter, as to where it where it can go, in the sequence. A token is specified; giving the number of characters that are the same, which their positions can be return. See, example [insert example number here]. When found, it returns the position(s) of the character(s) found. If it is a string, then it returns the range of the string, found in the array. If there are more than one positions found, then each position number is separated by ';' in %RETURN%. When no character is found, a '!' exclaimation mark is return, signifying that nothing was found.
Find(character,string,token,delimiter)
Example:
find("a","Armed with a a knife; we won!",*,";")
print %return%
Output:
The numbers show where each 'a' is located in the string. It doesn't identify the capital 'A' this function is case sensitive. A token specifies how many positions of the character are to be collected. The delimiter limits how far the function should scan for the character. A delimiter can either be a character or a an interger.
8. Equal checks to see if the two strings are equal. If the two strings are equal, then it returns (interger) 1 else, it returns 0. (Redundant).
Example:
equal("meshnix" == "meshnix")
if %result%:
{
print "Strings are equal"
else:
print "Strings are not equal"
}
Output:
9. Inequal checks to see if the two strings are negates, if so then it returns 1, else 0. (Redundant).
Inequal(string != string)
Example:
equal("meshnix" != "some other guy")
if %result%:
{
print "Strings are equal"
else:
print "Strings are not equal"
}
Output:
10. Reverse reorders or overturns the sequence of a string.
Example:
reverse("Radar")
print %return%
Output:
11. List [functionality unknown]
Example:
set fruits = "mango;orange;apple;grape;kiwi;cherry"
list(%fruits%)
print %return%
Output:
•mango
•orange
•apple
•grape
•kiwi
•cherry
12. Trim is used to remove whitespaces from the beginning an end of a string.
Example:
trim(" spacious ")
print %return%
Output:
13. Chop removes the last character from a string but, it leaves a whitespace in its place.
14. Free deallocates a variable that was allocated. It's status is set to 'I'(nactive) instead of 'A'(ctive). The metadata of the object are nullified. The object can be defined as a different datatype and new values can be set, with a different name (indentifier). Free() allows for the reuse of variables, since there is a limitation of 256 allocation areas for each datatype.
Example:
set score = 125
print %score%
free(%score%)
print %score%
Output:
Nothing is printed a null, because the score variable was deallocated, so it doesn't exist anymore.
15. Tmap is a table structure that stores data. The data can be stored in a 8*2 (col*rows) table. Each table cell stores 16 bytes. Each name is unique to data. Tables are basically variables whose array is 16 bytes. There can only be 8 variables.
TMap(table_name,name,data)
Example:
tmap("score","level1",100)
tmap("score","level2",99)
print "%score[Level1]%"
Output:
16. Fetch grabs an element from the table.
Example:
fetch(score,level1)
print %return%
Output:
17. Lookup looks up a byte in a linear array (directly from memory), and places it in %RETURN%.
Lookup(base_address, index)
Example:
set hello = "Hello World"
point hello_addr = %hello%
lookup(hello_addr,7)
print %return%
Output:
18. Random generates a random number and places it in the given variable. It also returns to %RETURN%.
Arrays
If we want to select an element from the array 'greeting', it can be done two ways:
1. Using interpolation and array splicing
start:
string greeting = "HELLOWORLD" # set an array called greeting
print %greeting[5]% # print the element
2. Finding the element using the address of the array
start:
string greeting = "HELLOWORLD" # set an array called greeting
int index = 5 # set the column (index) position we want
point base = %greeting # set greeting memory location
set element = %base + %index # find element on array
print %element% # print the element
Markup Language
The markup language would be used change the form of text on an application (only in GUI). It is codenamed: MetaMarkup
Concept (Goals)
The overall concept (goal) for the markup language are:
•Colored text;
•Text shadows;
•Different text formats: bold, italic, underline, superscript, subscript,block, delete, glow /outline (not animated);
•Text animation;
•HyperLinks (e.i, text can be used to launch a dialog instead of buttons);
•Text alignments: left, center, right (maybe justified);
Tags and Syntax
The application would have these scripts and reference from the string and format during initialization. Each string can be used by the application. A string is identified by using its ID number.
Here are some of the possible tags for MetaMarkup:
Header
<?mml version=mml version?> MML magic number (and version identifier).
<doctype name=document name id=doc ID number type=document type(usually MML) description=doc description> document information and it's type.
Body
<body>markup tags</body> defines the area which contains the application strings and formats.
<window name type=msgbox/window/dialog/control id=gadget id> defines the window which the text is located.
<string id=string id>string</string> specifies the string which is to be formatted.
Text Formats
<font face=font name color=font color>text</font> speficies font to be used.
<size>element</size> resizes text.
<align>text</align> align text within a specified area.
<b>text</b> bolds text.
<i>text</i> italizes text.
<u>text</u> underlines text.
<sup>text</sup> superscrips text.
<sub>text</sub> subscripts text.
<block>text</block> highlights or creates a box aroung text.
<delete>text</delete> stikes text, by placing a line through it.
<outline color=outline color>text</outline> outlines text with a colour.
<glow>text</glow> creates a glow effect around text. It can be animated.
HyperLinks
<a href=file path>link label</a> creates a link in the window to a file.
<xa href=window idlink label</xa> creates a link in the window to another window of that thread.
Example
Example markup script:
I just decided to post the ideas that I had about the languages. It will help me to have my ideas critiqued, so I can improved them. These just the concept of the language, not really the final draft. I am trying to get out the details of the syntax an semantics, and allowing them to work together (I would be 100%, but I think I can ge something close to that).
(Incomplete notes)
_________________ meshnix
Last edited by adroit on 20 Jun 2010, 06:53; edited 5 times in total
|