Monday, November 29, 2010

The reasons why things are the way they are

One of the best things about creating a programming language is that sudden realization on why people do the things they do.

One of the most common elements you see in a language is the "end of statement" the semi-colon ';'

In posl, there's no need for one, it's one line is one statement.

That sounds alright at first (if slightly restrictive, in the form of expression it's enlarged when you see that you can include a multi-line block of code within that single line.


if [<= 2 3] {
println "low!"
push () 4
} {
println "high!"
push () 8
}


In this contrived example, the parser sees a single line which equates to

command predicate multi-line multi-line

The problem comes when you typo



if [<= 2 3] {
println "low!"
push () 4
{
println "high!"
push () 8
}


This bad code, we forgot a right brace. However the parser isn't going to complain. It's going to assume that the brace will eventually come at some point. Currently I have an interactive parser (going to need to change that in some sort of switch mode) the interactive parser, when it runs out of code to parse, just assumes that it's going to show up at some point.

Now if we included a semi-colon


if [<= 2 3] {
println "low!"
push () 4
{
println "high!"
push () 8
};


The parser at this point damn well knows that there's something wrong and would throw a flag.

It's not enough to change my vision but it does provide insight into why it was done in the first place.

No comments: