New identifier definitions

Today I effectively scrapped the entire AnalyseSyntax()-function in the compiler and wrote it all over again from the scratch. Then I realised that the rewrite wasn’t much better then the original so I scrapped that too. And I did it again. I ended up with version 4 of that procedure. The reason? Gathering the identifiers can be done in many ways. There are good ways and not so good ways. The essential difference of these algorithms derives from only one fact: which ever ends up being the most dynamical one, tends to make future updates easier.

So what is the key that all new identifiers have in common in BASIC languages? It’s the keyword “As”. My original system scanned the modifiers and flag values within statements with no strict relations between them. This resulted in lots of extra conditions and made my code a bit tangly. The next version tried to build statements keyword by keyword eventually forming the statement with all attributes included. Since keywords have dependencies on each other and strictly pre-defined legal order in which they can appear, it was made impossible to make them “conditional” especially when they appear before the actual keyword that identifies the statement.

Then there was an option to use regexp templates on structural representation of the statement. However, this can lead to problems with non-constant syntaxes like function or operator declarations, or array definitions; typically everything that can have comma-separated parameters.

Finally, the best solution (so far) was to scan the entire statement token by token, just like I did in the first place, but this time by defining rules how keywords can be linked. Basically, each modifier and flag value has list of those keywords that can lead to them – including line start. This will ensure that no keyword can be out of place nor out of context. In addition, it should be easy to add new keywords in the future.

So what is now done? It’s still the constants. But I hope I’ve created a base on which I can start building new things soon. Oh, and I did something else, too: You can now define new instances just like in Visual Basic, “Dim i As New k” is equivalent to “Dim i As k = New k

Analysing the syntax

The compiler is currently at a stage where syntax of program basic structures need to be validated. This pass involves parsing and data gathering, from which the first refers to syntax cheking of classes/functions/constants etc, and the latter is basically forming the Token Table for the program. There are 9 data structures to do: constants, enumerations, program flow, jumps, structures, variable definition, functions, operators and classes.

There is no “properties” in this list. While this is something that would be exciting to implement, I’ve decided not to – just yet. Properties are part of classes that involve usually two functions: getters and setters for certain attributes. Traditionally programmers used to have these two separate functions, but it’s more elegant to have normal assignments and values in spite of they actually perform more code under the hood. You could use something like this:

myClassVariable.SetMyPropertyValue(myValue)
variable = myClassVariable.GetMyPropertyValue()

However, the following way is cleaner:

myClassVariable.myProperty = value
variable = myClassVariable.myProperty

Both of these would still perform a function within the class. I’ll keep this item on my TODO-list, but let’s try to establish the core first 🙂

Back to the analysing process. So those 9 keyword statements need to be parsed in order for CoolBasic to be able to compile a list of all token names. Naturally, each token must have additional data assigned to them such as access modifiers, inheritance modifiers, overriding modifiers and certain flag values. I don’t want to attach all these fields to every token data because not all of them is never needed at the same time and this would only munch unneeded memory for large programs. So it’s quite challenging task to create any “optimal” way to store this kind of data that could bend to all needs at once.

The programming tool I’m using to create CoolBasic V3 compiler doesn’t really support classes and inheritance properly (woot! why can’t you just use Visual Studio?! – It’s not fast enough ^^). I’m using allocated memory blocks to store only the most relevant data. This will make my code somewhat uglier than I had hoped, but at least it’s memory efficient. Note to self: Just remember to maintain the clean-up functions accordingly, mmkay…

And finally, some good news. The consants are already done 🙂

Skewing forum votes must end!

This news has nothing to do with the development of Coolbasic V3, but I decided to share it anyways since the issue appears to be rather interesting. I’d like to start by telling I always enjoy seeing the community living vivid on the forums. It creates this feeling you’ve affected people’s lives by offering them means to showcase their creativity through game making. And that the community has grown and roaming. That said, I’m also very happy that the community features game making competitions in a regular basis and having fun with it.

However, while competitions tend to be healthy for any community (as long as it goes along the rules), there is always somebody who likes to manipulate the results given it’s possible in some way. It has come to the attention of the moderators and administrators (and me) that there exists some evidence of mischief within the results of voting. It appears to be that some users have created fake accounts which they use to cast extra votes for an entry of their choise. This, of course, distorts the votes and may result in declaration of false winner.

CoolBasic forums do require a unique email address for activation of new forum accounts. The main purpose of this is to discourage multiple users from the same person to be created. Even if someone wanted to activate more than one forum account for some purpose, he/she would need several working email addresses to get them running. That’s a nuisance I couldn’t be arsed to do, at least. But then again, I wouldn’t want to skew the votes either :/

What we’re seeing here, is someone motivated enough to carry over the pain and doing an annoying deed just so that he/she could cast some extra votes. The results must be very important to that user 🙂 Maybe we’re looking right into the face of the guilty when we’re declaring the winner. I don’t have the details of these cases (I haven’t consulted the moderation team in such detail), but I agreed that something has to be done to prevent this abuse.

We had a conversation on IRC what would be the best solution to solve this issue, and the common concept seemed to be that we’d simply move majority of the users into a different group and then allowing polls only for that group. The major factor was agreed upon to be the post count because, let’s face it, would someone really go through all this and, in addition, bother to increase all of those fake accounts’ post count above the treshold? A 3rd party MOD was suggested to be installed on the board. It was to be a new tool for administrators to mass-move users from a group to another based on some customisable conditions such as post count.

I did consider it, but I wasn’t quite happy with what would have been the outcome of that. Firstly, the administrators would regularly need to make this “pass”, say, in every week, where queried users would be moved to the poll-enabled user group. Secondly, it’d have been be just another user group with extra management and set-up every now and then.

Another option would have been to write a simple PHP-script that would perform this task automatically on page load (of which only certain people have access to). Umm.. naaah!

So what did I do? Without a word with the moderating team, one morning at work, I took the forum source, poked it a little bit, and uploaded a “tweak”. Just like that without any approval or discussion. I hope I don’t get blamed for this, and I hope the “fix” works and doesn’t cause any bugs or problems for the forums. I added a treshold value that a user must have exceeded in terms of post count in order to be allowed for voting. It’s a change in one certain place and easily modifiable should we come across the need to increase or decrease this treshold.

No error message is shown when a user with less than TEN posts tries to cast a vote. The forum simply reloads the page after pressing the “Submit vote”-button. It doesn’t completely eliminate the problem, but atleast it discourages more strongly the deceit. I look forward to see how this phenomenom evolves.

Managed inheritance

One of the coolest new features of CoolBasic V3 will be classes and their inheritance. In this blog entry, I’m not going into details nor will I summary exactly what aspects belong to it in CoolBasic’s case (I’ll leave that for later), but I’d like to share some conclusions on how to perserve data integrity through inheritance.

CoolBasic will support perfect hierchical inheritance of multiple classes. As in Visual Basic .NET, there will be “Me” and “MyBase” keywords which point to the current class and the parent class the current class was derived from. By default, overloaded functions between the derived and parent classes reference primarily to “local scope”. In order to specifically call the parent class’ functions “MyBase” keyword must be used in conjunction with the member access operator, for example “MyBase.MyFunction()”.

ChaosBasic (read more at CoolBasic forums) introduced a syntax which allowed multiple inheritances when a new class is created. Parent classes were separated by commas such as: “Class OpacityCow Inherits Cow, OpacityObject”. Now the question is… where does MyBase point to? How do you access the parents’ constructors? There’s obviously a design flaw with this concept, so I decided not to implement multiple inheritances in this way. Instead, much more coherent way to approach this problem, would be to only allow one inheritance per class. If the programmer wished to link multiple classes via inheritance it’d needed to be done like a->b, b->c.

In VB.NET, C#, and Java access is resticted to the direct base class to prevent inconsistencies in an object’s state. That’s why MyBase.MyBase does not exist. Some languages, however, do give access to traversing underlying classes… i.e. “::”. I haven’t decided yet whether or not I should allow this. For those who are interested in knowing more about the pros and cons of grand parent reference, I recommend visiting http://bytes.com/forum/thread372516.html.

This “safety net” applies to class constructors as well; CoolBasic V3 will force you to call the parent’s constructor in the derived class’ constructor. This ensures that all constructors are called when a new instance is created which in turn will result in complete and “well-formed” class instance.

Comment parsing

A few things about source code comments worth mentioning. First of all, both singleline comments and multiline comments will still exist in V3. Comments will be written pretty much the same way they’re written in C (and the related) languages. That is, singleline comments beginning with double slashes “//”, and multiline comments introduced as block that starts with “/*” and ends with “*/”. No more remstart/remend.

For now, multiline comments are stripped already in the file reading pass, and not in the lexical phase (singleline comments are handled here, though). I thought it’d be more efficient in terms of compilation time if lines that wouldn’t be processed anyway, were ignored completely instead of going through the normal tokenization. Due to this, comment ending and starting can’t occurr within a logical line. Obviously this would be easily fixed, but it’s extra work and some code recycling – which is rarely a good thing. This means that the “/*” and “*/” must be on their respective lines alone in a similar manner to how remstart and remend currently work. It may require some time to get used to this, but as it stands now, my decision is justifiable.

Images and the blind

This is old news (about a month), but due to the extraordinary nature of this issue, I decided to share it anyway. I received an interesting email from someone who’s completely blind. He told me that he couldn’t read the ASCII-table of the manual because it’s there as an image. Now that you think about it, there’s really no reason why the same table couldn’t be illustrated in text as well, and therefore be available to those few who are actually using special equipment to read information on “screen”. In today’s Windows world ASCII-tables are quite irrelevant apart from console applications, so the last 128 characters of the table weren’t even presented in their original DOS-symbols.

Funnily enough, most of the ASCII-tables you’ll find when you browse, for example, results of a Google search, are indeed images. Is it because it’s easier to generate the codes of each individual characters in a form of a table on some “canvas” and then simply screencapture it? Or is it just so much more work to write the HTML-table generation within the loop that iterates the character codes? Maybe we’re just lazy. Either way, I’ll make sure that the next ANSI-table within CoolBasic V3 manual is in pure text format.

The Dragon Book

I finally got my hands on the Bible of all compilers, The Dragon Book. Yep, it’s over 1,000 pages of pure knowledge and covers basically all one would ever want to know about how to make a high-end compiler for modern programming languages. The real name of this epic tome is “Compilers – principles, techniques, and tools”, but the reason why it’s called “The Dragon Book” derives from its cover illustration: There’s a dragon and a knight fighting each other. Inside, however, wall of 8pt text crits you for over 9,000! The books was originally written back in the 80’s, but the fresh second edition was published in 2006. This newer, updated version is the one I currently have.

Greedily I started munching the text, and to my surprise, I noticed that the described techniques are exactly how I’ve been writing the V3 compiler. Good. I probably won’t build the V3 compiler all by the guidelines of this book because there’s way too much information for me to handle at this point. But hey, I can always improve the compiler as I learn more and advance through this book. Mark Sibly (head programmer of Blitz 3D) once said, “When I was making my first compiler I couldn’t understand half the material (books) I had.” I can’t remember what the exact quote was, but you get the idea. I have a feeling that this book will serve me well in the future 😉

Assembly Summer 2008

The annual summer party for coders, gamers, composers and artists took place again in Hartwall Arena, Helsinki Finland. 5,000 people was there! Although this time I decided not to purchase a computer ticket (a seat and a network spot reserved just for you) it was nice to be there again, after 3 years of break. The biggest reason to actually go visit the arena and not just sit home and watch all that from the Assembly-TV network stream, was that there were quite a few CoolBasic users with their desktops and laptops. I felt it’d be cool to go there and say hello face to face. So I did. Thanks to an “organized” topic on the CoolBasic forums, some real meets actually took place where members of community could talk and share thoughts in more “quiet” place. I myself missed all the meetings, but I heard afterwards that they were a success. I did, however, drop to say hello at the seats that were announced on the Assembly topic.

I probably said things I shouldn’t have, but the feeling and atmosphere was so amazing I guess I just accidentally slipped out some surprises about CoolBasic V3 I’d prefer not to ruin at this point just yet. However, now that I think of it, I hope I gave some hope to those who listened to me, that a new version is indeed in development and it’s going to bring a lot more to the table than the current CoolBasic version 2 (which is still at Beta, lol).

As I walked around the arena in darkness it wasn’t hard to spot these guys 🙂 I saw CoolBasic forums and editors open on their screens. I was flattered. It’s rewarding to see people actually using something that you’ve created. They even arranged a little competition of which I saw 4 CoolBasic entries (or they did it just because they knew I was coming to a visit, hehe). In addition, I saw a splendid graphical “demo” made in CoolBasic, covering some nice effects I’ve no idea how they’re carried out code-wise. This whole thing drove some new energy into me, and I feel encouraged to continue. I hear people thanking me for making tem what they are – without CoolBasic some people would never had started coding, and some of them are already growing out of the current CoolBasic due to its limitations. Those limitations I wish to lift in V3.

Again, Thank You!

AeroGlass Candy

I can’t help but keep liking Windows Vista AeroGlass UI. It’s simply amazing. Not an overkill, but impressive enough to get me thinking of it all the time I use Windows. That being said, I recently came across with this article in the MSDN magazine, where this effect was introduced in-depth. I found out that enabling this effect in Windows Forms was not so difficult a task after all. With a simple API, a programmer can enable the blur behind the window, extend the glassy client area, or change the color theme for a single window. All this got me pretty excited, so I thought why not give it a try and play with this little eye candy a bit.

Since it’s practically only about calling the Desktop Window Manager DLL (that ships with Windows Vista), achiving the effect would be easy and independant from the programming language used. I wrote a simple test application in VB.NET, and was pretty satisfied with the results. However, as the current plan stands, only the code editor in CoolBasic project would be written in .NET. All important tools, the engine and the libraries would be written in other languages such as VC++ 6.0 and PureBasic in order to establish as low software requirements for CoolBasic games and using CoolBasic development environment in general. So I tried to achieve the AeroGlass effect in PureBasic too (since it’s used to create some tools), and succeeded at it!

At that moment, I was on fire. Then I tried to apply this effect to one of my tools (Work In Progress, huss). That particular tool had some controls on its main Form. The glassy look worked fine on it, but as soon as you have labels, buttons or other controls, things get messy. The controls had opaque background color whereas their front color was transparent. Meaning that label texts, for instance, weren’t black but appeared in a carved manner. All control texts were difficult to read. Now the control background color isn’t really too much a problem as it’s easy to apply a transparent brush on them. However, fixing the foreground color proofed to be a lot trickier task.

It’s obviously a GDI-related problem: It ignores alpha data whereas DWM takes advantage of ARGB-encoded brushes. It’s possible to set the Form color manually with alpha value being zero, but that way the window transparency would be gone and that’d be completely against the purpose of the entire implementation of AeroGlass. The only solution to this would be to manually draw label texts with standard bitmap blitter – which supports alpha data. All this involve creating bitmaps using DC, in addition to some tricky code for event custom handling. You’d get a text effect similar to Windows Media Player (the Vista version), including the glow behind the text. But buttons and other controls would still render incorrectly. I’ve yet to figure out a fix for this.

AeroGlass could perhaps be applied to the new Editor, but not on the tools such as Auto Updater. I decided not to implement the effect for now.

Designing the new Website

Due to the incident with coolbasic.com webhotel I decided to change hosts and move the domain and the entire website to a new provider. After being absent for almost 3 years, I also feel that the current CoolBasic website is simply put, quite awful; Its look is outdated beyond all hope, and in fact its inner stucture collects dust in all essence – something that is completely left out of the current trends and CSS-based styling standards.

Also, CoolBasic V3 has its very own theme now (of which I will not elaborate just yet), so I decided to create a new website that is a little more appealing to a certain degree. The new website framework is already complete and looking good, but until CoolBasic V3 launch I don’t want to release the site since it would ruin the surprise (by its theme). Although the visio I’m having right now is just brilliant (*cough*) I really think that CoolBasic V3 should be released not until its Beta stage, and as a whole. Meaning that the Beta, website, manual and all other related things will just pop up during one night, and the users would wake to a beautiful morning 🙂

That being said, a placeholder website is needed. The current one really sucks (what have I been thinking while doing that?!), so I also took the effort and conjured up a little website for the current CoolBasic (2.x -generation). It’ll remain in effect until the massive Beta-launch takes place and the actual website will be introduced. Both websites, the placeholder and the final site, will be bilingual i.e. available in both english and finnish.

So far, the final website passes the strict HTML 4.01 validation.

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress