I've mentioned to a few people here and there that I'm working on a standalone actionscript compiler. This is, in fact, still true. The first phase is more or less complete, and I'm currently in the process of creating the ActionScript grammatical rules for the second phase.
A compiler, in a nutshell, is just a text parser with some transformations applied (how's that for an over-simplification?). A typical compiler consists of 4 or more phases, with each phase building off of the previous.
The first phase is the lexical analysis phase. The purpose of this phase is to determine what tokens are in the input stream (file, console, etc), and strip out any comments. For example, the statement "if (a > b)" might be tokenized as the following series of tokens: Token.IF, Token.L_PAREN, Token.IDENTIFIER "a", Token.GT, Token.IDENTIFIER "b", Token.R_PAREN.
Anyhow, in order to perform lexical analysis correctly all of the reserved words of the language must be known. Each reservered word gets its own special token to make it easier to parse the input file (variables are all lumped into the "identifier" token). Below a list of all of the reserved words (keywords), and what version of the Flash Player supports them.
| Flash Reserved Word Listing | |
| Flash Player 2 | on |
| Flash Player 3 | ifFrameLoaded |
| Flash Player 4 | add, and, break, case, continue, default, do, else, eq, ge, gt, if, le, lt, ne, not, or, switch, tellTarget, while |
| Flash Player 5 | delete, for, function, in, new, onClipEvent, return, this, typeof, var, void, with |
| Flash Player 6 | instanceof |
| Flash Player 7 | catch, finally, throw, try |
| ActionScript 2.0 - Flash Player 6 | class, dynamic, extends, get, implements, import, interface, intrinsic, private, public, set, static |
| "Special" Functions and Constants | call, duplicateMovieClip, eval, fscommand, getProperty, getTimer, getURL, getVersion, gotoAndPlay, gotoAndStop, int, length, loadMovie, loadMovieNum, loadVariables, loadVariablesNum, mbchr, mblength, mbord, mbsubstring, NaN, nextFrame, nextScene, Number, ord, play, prevFrame, prevScene, print, printNum, random, removeMovieClip, set, setProperty, startDrag, stop, stopAllSounds, stopDrag, substring, targetPath, toggleHighQuality, trace, unloadMovie, unloadMovieNum |
| Reserved for future use | abstract, boolean, byte, char, const, debugger, double, enum, export, final, float, goto, int, long, native, package, protected, short, synchronized, throws, transient, volatile |
Special functions are ones that are not reserved words, but have compile-time parameter checking. For an example, trace is not reserved yet "trace()" will give an error saying it requires exactly 1 parameter. Also, "NaN()" will report "A function call on a non-function was attempted."
Note that the keywords listed are grouped by which Flash Player supports them, and not by which Flash version they were introduced. Flash Player 4 supports the bytecodes generated by switch..case..default statements, yet those keywords were introduced in Flash MX. I separated the keywords like this because my compiler will support a targetted Flash Player version, and will generate errors if you attempt to use a feature not included in the target player. For instance, you can't use try..catch..finally if you're compiling for Flash Player 5.
An easy way to determine if a word is reserved is simply to try and use it as a function.
function dynamic() { }; // reports an error
I don't believe that I've missed anything, but I wanted to post this and see if anyone can catch any mistakes I may have made. Also, I'm thinking that the "special" functions like trace should actually be reserved words. Sure you can write a function trace(), but what's the point of allowing that since you can't override it anyway?
However, a problem arises with words like duplicateMovieClip though. Used as a standalone function Flash will check parameters.. but used as a function on a MovieClip it won't. That may get a bit tricky, and I haven't given it much thought yet...
Anyway, expect to hear more about this in the future... I'm still in the somewhat early/planning stages, but once I complete the parser I'll release it open-source and hopefully gather some support. By the way, I'm coding the compiler in Java.

6 Comments
The lists of reserved words seems to be quite comprehensive.
I'll wait for the compiler. It's just what I need to move to Eclipse.
Posted by: Cesar Tardaguila | April 13, 2004 2:50 AM
I consider it a bug that Flash checks parameters for things like duplicateMovieClip as if they were the deprecated global functions. If they appear in a class, which inherits from MovieClip, you should assume they refer to the method.
Posted by: Peter Hall | April 13, 2004 4:59 AM
Hey
I guess that list is quiet enough.
just wanted 2 post 2 tell U 2 keep it up cause a flash compiler in Java would run in linux :D
& that's a thingie I've waited 4 so long
KEEP IT UP LAD ;)
Posted by: bassouma86 | April 16, 2004 3:05 PM
recently I found that "throw" seems reserved.
Posted by: olivier besson | May 10, 2004 2:45 AM
Correct - throw is a reserved word that Flash Player 7 supports. So is try, catch, and finally. Throws will probably be implemented in a future version.
Posted by: darron | May 10, 2004 6:50 AM
Any chance I could reprint this excellent chart in a book about Flash I have under contract? You would get full credit, of course, and any kind of URL you wanted to be included.
Posted by: Mindy McAdams | July 3, 2004 4:02 PM