On Mon, Nov 21, 2005 at 02:05:31PM -0500, Rob Kinyon wrote: : This is very close to a proposal I made to the ruby-dev mailing list : (which was Warnocked). I proposed a very basic engine that would work : with the parser/lexer to determine what action to take instead of : using the huge case statements that are the heart of both P5 and Ruby. : It would look something like: : : TOKEN: : while ( my $token = get_next_token(<params>) ) { : for my $length ( reverse length($token) .. 1 ) { : if ( my $actions = find_actions( substr( $token, 0, $length ) ) ) { : $action->[-1]->( < params, if necessary > ); : } : next TOKEN; : } : throw SyntaxError; : } : : The for-loop + substr() would be to handle longest-token-first rules. : So, "..." is correctly recognized instead of handled as ".." and ".". : The key would be that the $actions arrayref would get push'ed/pop'ed : as you enter/leave a given lexical scope. : : Obviously, this could be optimized to an extremely large degree, but : it -should- work.
Let's see, where did I put my stash of generic quotes? Ah, there is is. "Those who do not understand XXX are doomed to reinvent it, poorly." ~~ s/XXX/the Perl 6 grammar engine/; In particular, you've just reinvented the magic hash semantics mandated by P6 rules, except that P6 has some hope of optimizing the lookups to a cached trie or whatever. Larry