Sunday, October 27, 2013

Dictionaries – Key Case Sensitivity

The BASIC language is traditionally not case sensitive.  The keyword lookup of the BASIC commands and operators are already case insensitive.  However, the dictionary lookup was not, so variables entered as VAR, Var, and var would be three different variables.  This is incorrect.  However, only one form can be stored in the dictionary.  The first instance of the variable name seen, will be the one stored.  Later there will be a facility for renaming variables.

The key map in the dictionary was changed from the QMap class to the QHash class.  These two classes are very similar for use in the dictionary class with a few differences.  The QMap class stores the key values in order and the QHash class stores them in an arbitrarily order, and QHash provides faster lookups.  Since the keys do not need to be sorted (they can always be sorted from the key list in the dictionary), the faster lookup feature is desirable.

To make the lookup of the key value case insensitive, the key string is first converted to all upper case and this all upper case string is use to lookup an index for a key and is the string stored as the hash key.  Upon the initial add of the key string to the key list, the original string entered is stored and is the string returned for all instances.

However, the remark and string constants dictionaries must be case sensitive.  Therefore a case sensitivity option argument was added to the dictionary class add routine with a default value for a case insensitive lookup.  The remark and string constant encode routines use the case sensitive option.

New encoder test #3 was added to test various forms of variables, remarks, string constants and exponential numeric constants.  Exponential numeric constants can have either an upper or lower case 'E' for the exponent.  Again, the first instance of the constant seen will be stored, so the user can decide which form is desirable.

[commit da56095d1a]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)