|
Looks good, but... That's not what I had in mind - but you're on the right track!
What your code does it stops at every char and tries to match ALL other terminals - making a full TryMatch call. This is very inefficient.
What you should do instead is: get a full list of all Firsts symbols from all other terminals (using Terminal.GetFirsts() method);
then in Match method run through this list and make a search for the first occurrence of any of these First prefixes.
(There might be some extra optimizations, like you group terminals by first char and first for this first char first, then try to match all prefixes in the group at this position P.)
When finally you match the prefix at position Px, you call otherTerminal.TryMatch to try full match and create a token; if a non-null token OToken is returned, you don't throw it away;
you first create a Background token Btoken with all text before position Px, and then return multitoken with (BToken, OToken) inside.
|