Closed ogallagher closed 4 years ago
I’ve decided to do neither of the proposed solutions mentioned above. I’ll keep dictionary lookups, but have dictionary entry mapping references only refer to those where the token is a leader of that mapping. To handle mappings where an argument is the first token, the dictionary will have entries for each argument type. For example:
dict.txt:
@$ 1 4
@# 5
@w 2
@a 3
@+ 3 4
etc 6
When the instruction parser encounters a token without having any current language mappings pending resolution, it calls
Memory.dictionaryLookup(token)
. The idea here is that if the token is a keyword, then the hashmap language mappings data structure can do a quick lookup of mappings that include that keyword somewhere in its pattern. However, those lookups then have to be vetted to make sure that the current keyword is a leader token in the pattern; if not, they’re currently thrown away.If the instruction parser is currently resolving potential candidate language mappings, then the token is checked against those mappings’ possible follower tokens. In this case, the dictionary lookup is no longer used.
In either case, the parser does not handle instructions with typos that prefix the desired language mapping; once potential mappings are found, the parser tries to resolve those. This is a separate issue.
The issue at hand is that, going back to the assumption that the token is a leader, the lookup fails for mappings that have argument leader tokens. Since arguments are not keywords they cannot have dictionary entries, and cannot be found by looking up the leader token in the dictionary. This means that, regardless of whether the token could be a keyword leader, the parser still has to search to find all the mappings with argument leaders. I could either create an additional data structure that has all argument leader mappings, or skip the dictionary lookup and search all mappings in the case of the leader token.