Showing posts with label syntax. Show all posts
Showing posts with label syntax. Show all posts

12/29/2011

An esoteric language

As I have posted earlier, I was planning to create a new programming language. Since then, I have written a simple interpreter. The idea is not to create a functional language, but just an esoteric language. A language to prove a point, not to solve a problem.
The following is an example of a program written in this language:

Create a variable named name. Display "Enter your name: " and a newline.
Vary the value of name by call the function "ask". Make another variable called age.
Display "Enter your age: " and a newline.
Set the value of age to call function "to number" with call another function "ask".
Display "The name is " and the name. Show "." plus a newline. Show "The age is ".
Display the age. Show "." and another newline.
If the name equals "World" then:
Display "Hello World!" and a newline.
Display another newline.
That's all. Else, then:
Display "Now this is no longer a 'Hello, world!' program..." and a newline. That's all.
If the age is larger than 100 or the age equals 100 then:
Display "You are very old." and a newline.
Display another newline. That's all.
Otherwise, then:
Display "You are less than 100 years old." and a newline. That's it. Show "Bye!" and a newline.
Stop the program.
As you can see, some statements(statements are sentences) or expressions may seem a little weird and not exactly like you would say or write it yourself. This is because it is simply too hard (for me at least) to write a parser that can understand the complete English language.
Vary the value of name by call the function "ask".
The above probably seems very weird. But in fact, "by" is declared as a synonym for "to"(which is required for changing the values of variables) and "call the function "ask"" is considered a part of an expression.
The following...
Set the value of age to call function "to number" with call another function "ask".
...is probably the weirdest statement of all. This is because it uses no temporary variables. It could be rewritten as following:
Declare a new variable named temp. Set the value of temp call function "get input". Change the value of age to execute procedure "to number" on temp.
I think the above is a more "natural", but it is also longer.
Also note that the last statement("Stop the program.") is actually only executed until "Stop" and no dot is actually required after it. "the program." will be tokenized by the parser to(displayed on a stack of tokens here):
-token::Article("the")
-token::VarName("program")
-token::Dot('.')
But these tokens will never reach the interpreter, and thus cannot cause errors(most likely "unexpected token" errors). This all means that we could also write:

Stop the current program and do something else.
So, what have I done so far and what are the parameters of the language?
I have added expressions, variables, "if" and "else" statements, an output language construct and function calls(no user defined functions, only system functions). I have also added a "newline" variable and 2 system functions("to number" and "ask"/"get input"). I am not yet sure when and if I will add features such as user-defined functions, but I will most likely add at least one type of loop(probably while).
Some specific things for this programming language are the huge amount of synonyms available for every word, the fact that if statements have no separate scope and the ability to "formulate" sentences in a different way(made possible by "optional" words such as "the value"). Because of these things, I hope it seems clear that this language has no intention of being functional in any way.

This interpreter will be available soon, although I cannot and will therefor not give you a date yet.

11/25/2011

Booleans and boolean expressions

It is highly likely that you have noticed that boolean expressions are horribly supported in TBS alpha-2.9 and older. Luckily, alpha-3 may come to the rescue!
The following(pointless but interesting) program and its explanation, should provide you with an idea of how alpha-3 will handle boolean expressions.
using(Stdio);
#func() {
    ?blnTest =: 1 == 1 && 1 <> 2 && :<>false;
    _if(:false || 1>0 && :?blnTest) {
        !out(~"New, working expressions! Finally!\n");
    }
    : : :true;
};
!func();
_die();
The first thing you should know is that the boolean operator was changed from '|' to ':', I know, neither are "logical", but it's really hard to find a more logical character that a normal keyboard has.

Besides that, you must also know that the previous "=/" operator has been changed to "<>", the "=<" operator to "<=", the "=>" operator to ">=" and the previous "/" to "<>". The "&" operator is now "&&", just like the "|" was changed to "||". Notice however that "|" still exists, as the exclusive or(XOR).
I truly believe this is a good change as this notation is more widely used.

The return statement(": : :true;") might seem a little weird, but it is only logical: the first ':' represents the return command, the second one indicates that we will be returning a boolean expression, and the last one that we read a boolean value in that expression. For example, if we wanted to return a string we would write ":~?string;", or if we wanted to return a boolean as the result of a string comparison we would write  ": : ~"string" == ?string;".

10/28/2011

Variable access changes


To improve is to change; to be perfect is to change often.
Winston Churchill

Alpha-2.9 was supposed to be released this weak, however I have decided to change a little thing about the way you can access variables. Instead of only using '?' for declarations, the question mark will now be used in front of all variables, similar to the PHP syntax.
For example, the following:
?greeting =~ "Hello!";
!out(~greeting, ~"\n");

Will now be written as:
?greeting =~ "Hello!";
!out(~?greeting, ~"\n");
I am aware of the fact that this is a big change that will affect almost all TBS code, although there should be no problem with this as alpha versions do not guarantee backwards compatibility.