Archive for September, 2005

September 27th 2005

Evening at Adler

I RSVP’d today, and am slated to go to DrunkenBlog’s Evening at Adler. Basically, it’s a bunch of developers sitting down and discussing a wide range of topics for several hours. It sounds like a perfect evening for a geek like myself. It’s in Chicago, at the Adler Planetarium & Astronomy Museum. If you’re in the area or think this sounds like fun, you should try to come. There’s limited seating though, but the good news is I think it sounds like a pretty good idea that might be done again in the future.

If you do happen to be attending, shoot me an email or leave a comment — I’d enjoy meeting up with fellow RB developers or readers of this site.

No Comments yet »

September 26th 2005

Not Amusing

It’s funny what one word can do. It yields the opposite results of what you’d expect. One word:

Not

Chooses run again after removing the not statement

No Comments yet »

September 24th 2005

Memory BinaryStreams

One cool feature in REALbasic 2005 is the ability to create a binary stream that points to a MemoryBlock. Aaron highlights it in this post on his blog. A quick rehash is that you can do something like this:

Dim bs As New BinaryStream( New MemoryBlock( 0 ) )

Which is a convenient way to construct a “file” in memory. However, what about reading? Well, since 5.5 (IIRC) REALbasic has allowed an automatic conversion from String to MemoryBlock. This can be used to our advantage in this situation. Let’s say I want to read a string as a BinaryStream?

Dim bs As New BinaryStream( myString )

This is extremely convenient. I’ve been using it all morning. This works because the BinaryStream constructor takes a MemoryBlock, and we also allow conversions from String to MemoryBlock.

Finally, you might ask yourself, what happens if I write to that stream? Well, it writes to it — however, it doesn’t write to the string itself. The key word above is “conversion” — the binary stream doesn’t point directly at the string, but to a MemoryBlock containing the data. So, this is 100% safe, and very very convenient.

No Comments yet »

September 21st 2005

Morphe Final Candidate 1

Well, I’ve updated Morphe again to fix an error introduced in the last build, and I’m now to the point in my other project that I started Morphe for that I can say that it’s parsing a complex grammar reliably and accurately. There are features I still want to add in the future for general parsing, but unless other people tell me they need a specific feature, I’m holding off on it for the time being.

I’d like to make an “IDE” for Morphe, to help construct grammars — but alas, with my current workload and the prospect of finishing the other project soon, it’s not the most important thing to do :)

If anyone is interesting in helping with either that aspect or any other aspect of Morphe, feel free to chime in. There’s a list of optimizations that I can make for more time-critical applications (such as a compiler that must run over and over and over), but for most projects the current speed probably isn’t that bad.

Anyways, the latest build can be downloaded on the Morphe site. I plan on spending an evening to write a simple interpreter for a language — any suggestions for a simple language to interpret? It’ll be used for an example of how to use Morphe on a little bit more of a complex grammar.

2 Comments »

September 15th 2005

Mophe Beta 5

Morphe has been updated again. The fixes include:

  • When an error occurs, the errors no longer grow more than they should. This was noticeable with a very complex grammar, but in the non-failure case, it would go unnoticed other than a large slowdown.
  • When the last branch of a multi-branch rule fails, it no longer leaves potentially more than one value on the stack. This ensures that when Parse returns, there will be exactly one result.
  • Now name the rules with a prefix, so as to avoid conflicts. I found that I often wanted a class with the same name as the rule which worked for the most part, except when trying to access the constants on said class.

All changes are internal changes that should not affect your existing applications in any way (except for making them better). The one feature I added that is useful for complex grammar is a way to specify the “main” rule — the rule that forms the basis for the entire grammar. You can specify it by using this option:

#option main RULENAME

As usual, you can download it on the Morphe site.

2 Comments »

September 13th 2005

RB-PHP Utils Update

The RB-PHP Utils have been updated. This update includes support for computed properties introduced in r2, the continue statement introduced in r3, and a few bug fixes with certain syntax, such as line continuation characters on an If statement. The computed properties support extends into the XML file parser as well.

More information about RBPHPUtils can be found here.

Property TestComputedProperty As Integer
Get
Return 42
End Get
Set
someValue = value
End Set
End Property

No Comments yet »

September 13th 2005

REALbasic 2005r3: Continue Statement

REALbasic 2005r3 was released a few minutes ago, and with it comes a Linux release, a lot of bug fixes, as well as a few new cool features. One thing I enjoyed implementing and immediately using was the Continue statement, as well as extended Exit statement syntax. Partially taken from Visual Basic, we now allow:

Exit // exit whatever loop we're in
Exit Do // exit the do loop we're inside, even if
// we're inside of another loop
Exit For // exit the for loop we're inside, even if
// we're inside of another loop
Exit While // exit the while loop we're inside, even if
// we're inside of another loop

Which is all fine and cool, but then we added an interesting twist tot he “exit for” statement:

Dim map(255,255) As Integer
Dim x, y As Integer

…

For y = 0 To 255
For x = 0 To 255
If map(x,y) = whatImLookingFor Then
Exit For y
End If
Next
Next

You can now identify which for loop you want to exit by specifying the loop variable. In this case, “y” identifies the outer for loop, and so this exit statement will exit that loop.

The Continue statement is another statement that can be used in a loop to immediately jump to the beginning of the loop, and continue executing. For example:

For i As Integer = 0 To 100
If i = 2 Or i = 31 Then
Continue
End If

// Do something with i
Next

This code will reach the “do something with i” portion in every case except for when i is 2 or i is 31. Often the uses for continue vary, but the prime reason for including it is to help decomplexify* code. For example:

Dim goodDate As New Date
Dim foundIdealDate As Boolean

While Not foundIdealDate
If goodDate.Hour > 20 Or _
(dateGettingPlanned IsA FriendlyDinner And goodDate.DayOfWeek = 6) Then
// We don't like planning things past 8 PM, and
// Fridays can't be for friendly dinners
goodDate.DayOfWeek = goodDate.DayOfWeek + 1
goodDate.Hour = 8
Continue
End If

For Each otherDate As Date In AlreadyPlannedDates
// For simplicity, all dates are exactly 1 hour
If otherDate.TotalSeconds < = goodDate.TotalSeconds And _
otherDate.TotalSeconds + 60*60*60 > goodDate.TotalSeconds Then
// In this case, we know we overlap with this date, so we might
// as well set the idealDate to the hour after this
goodDate.TotalSeconds = otherDate.TotalSeconds + 60*60*60
// We don't need to evaluate anymore, we conflicted &#8212; just continue
Continue While
End If
Next

// Check a few more things, and finally
foundIdealDate = True
Wend

In this example, we have several points where we hand-calculate the best “next” spot to check. Instead of having a lot of nexted if statements, a few temporary variables, or the dreaded GoTo statement**, we can simply use the new continue statement, and we’ll jump back to the top of the loop, and continue with execution again.

*While on the phone with Mars the other day, he used “my” word, complexify. I was pleased that it’s catching on, although I don’t actually know if he heard it first from me or not.
**GoTo can be used well in certain cases, but every time you’re about to use it, you should consider if there’s a better way :)

Have fun with r3. Time for me to get to work on r4!

No Comments yet »

September 12th 2005

Morphe Beta 3

Morphe Beta 3 is available. It has some parsing bug fixes, as well as the ability to use “-” in a rule name. It also removes the rather silly CreateErrorForPosition event, since there wasn’t really any good reason to have it there.

It can be downloaded via the Morphe site.

No Comments yet »

September 9th 2005

Random Speculations Time!

After Aaron’s post that contained no revealing facts about his super duper project, it’s my turn. However, I’m going to reveal at least one thing: it’s a feature :)

It’s a feature that another feature is going to rely on. In fact, on my way home from work after finishing it (mostly) this afternoon, I realized that it’s going to help out with yet another super-top-secret project of mine. Those who are unlucky enough to have my AIM name already have been teased about this forthcoming project. For some privileged folk, I’ve even given what has become my favorite clue to give, and it has yet to encourage the right answer (although once those people find out what the project is, they’ll most likely laugh at the clue).

Anyways, back to my cool feature for the day. It’s common enough that when I was programming tonight with the latest fc, I already ran into a case where I’d have used it. The feature, when thought about, will probably not be credited to me at first glance, although I cannot divulge to which engineer the credit would be given.

Like in Aaron’s post, you’re welcome to guess what this feature may be. As for me, I’m back to working on Morphe, and yet another related, yet slightly secret personal project. Have a great weekend everyone!

7 Comments »

September 6th 2005

Morphe, Beta 2

Morphe, a parser generator for REALbasic, has been substantially improved for beta 2. The generation algorithm has been mostly rewritten to help with flexibility. This beta includes error reporting, although it is likely to change by the next beta. However, what is there is functional, but I’d like to add more information to errors.

Morphe now generates commented code, but still isn’t quite human readable. The code generated is slightly more compact. Several more optimizations for speed are to come, but couldn’t be completed in time.

An infix grammar has been included, and a start of the advanced tutorial is now available on Morphe’s site.

Morphe Beta 2 is available for both Windows and Mac OS X, and can be downloaded here.

No Comments yet »

Next »