Scripting Flash apps: scanning the input file

Here we go. I know that probably I should have started this new topic talking about the grammar of the language we are going to implement, but as long as I see grammar strictly related to parsing, I’ve preferred to talk about scanning first.

We will go back to the grammar the next time, when talking about how to parse an input file.

I wrote about scanning (or lexing if you prefer) a while ago, when blogging about expression evalution in ActionScript. Scanning an input file is quite always the same (although some languages might require unusual features), and what I wrote about expressions works also for a general language.

The goal of the scanning process is to group some characters together, skipping the ones that have no meaning for the language like spaces. Each group of characters is usually called token. So a Scanner converts a textual input into a stream of tokens, each one rappresenting a possible valid word for our language. While scanning you don’t take care about the meaning of what you are grouping or about the fact that a sequence of tokens is meaningful. This is a task for the Parser as we will see.

When talking about expressions, I showed a manual implementation for a Lexer. Now I want to take a different approach and show you a possible implementation for a simple dynamic scanner. This scanner will be based on regular expressions: each regular expression will rappresent a given token, and we will be able to assign callbacks to the scanner that will be executed each time a given token is extracted from the input.
Writing a general and reusable scanner is usually a good practice. A common approach is to use some scanner generators, that are usually regular expression based too but are able to generate the code for a scanner at compile time. Our approach is different (and generates slower scanners) because regular expressions are evaluated at runtime; but it is fine for a test project.

You can download the source code for the regular expression based lexer (RegexLexer) here, as long as a simple usage example. Let’s see this example together so we can briefly discuss it (PBLexer.as):

Continue reading

PHP6?

Have you already play with PHP6?
Today I discovered the PHP6 CVS snapshots and I decided to take a look at it (still not tested).

I read some unhappy comment to the fact php want to put the Unicode settings into the php.ini, but if this change will make PHP faster  I would prefer in this way, expecially if unicode will be always set to on.
Is there a reason to put unicode support off in this world? (for example I haven’t still understood why wxPython continues to releases both ansi and unicode builds…)
Finally register globals‘ PHP3 BC to go!
Namespaces. Maybe they will add namespace.. I really hope so! This is indeed one of the most awaited features for me! (read about a discussion on namespaces)
Support for delegates.

My big hope is also to see a “real” strict type language, but this is only my though.
Backward Compatibility. Well this could cause a flame for many developers but if they really want to make a solid new product from scratch probably they dont have to take care about BC.

Read more about the PHP6 Novermber meeting and all the proposals.
Download the PHP6 snapshot

Flex2 and namespaces extending components

I took 2 hours to find a solution for that and I decided to blog it..
I was creating my new Flex2 component extending the UIComponent class and I need to define new custom styles for my own component…
Ok, i opened the “create and extend components” PDF guide and found that I need to put this code to accomplish it:
private static function classConstruct():Boolean
{
if (!StyleManager.getStyleDeclaration("ResizeManager"))
{
var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration();
newStyleDeclaration.setStyle("boxSize", 4);
StyleManager.setStyleDeclaration("ResizeManager", newStyleDeclaration, true);
}
return true;
}

That’s all, but at this time the compiler die with that error message “1000: Riferimento ambiguo a setStyle”, which in english should be: “1000: Ambiguous reference to setStyle“.
I google for some time but without finding a solution, then I discovered the problem. I was using in my component the mx_internal namespace, that was the problem. Once changed namespace everything was ok.