Wednesday, September 26, 2012

Even More Betterer

As with any large project, there are a few things I would do differently if I could start over on Weapon M. The biggest change would be to develop JPlex further. Right now I'm using the same approach taken by the developers of Kokua, matching blocks of game data in the lexer and then hand-coding the parser. Writing the parser would be much easier if I'd extended JPlex to recognize productions composed of regular expression operators and token IDs, and associating these productions with methods that would receive them as collections of tokens. On the balance for a single project, that might have taken more time than just doing what I'm doing. But in the long run, it would have been preferable.

I may eventually get around to it. I'm thinking of an input syntax kind of like this:

TOKEN "sector" : "[1-9][0-9]+";
TOKEN "timeLeft" : "[0-9]{2}:[0-9]{2}:[0-9]{2}";

PRODUCTION "commandPrompt" : "\[35mCommand \[\[1;33mTL\[0;33m=\[1m" timeLeft "\[0;35m\]\[1;37m:\[0;35m\[\[1;36m" sector;

Productions could contain regular expression syntax for repetition, etc. The string literals in the production would generate anonymous tokens, and productions would produce methods in the parser interface that would receive the named tokens:

public void commandPrompt(String timeLeft, String sector);

By itself this is not much different from existing parser generators. But it would also have JPlex's unique characteristics of "loose" lexing and the ability to generate push parsers.

Yeah, someday...

No comments:

Post a Comment