Wednesday, January 12, 2011

Parser – Token Length

In researching for the last post, some issues were found in the Parser with respect to the token length. The token class contained a length member, but it was contained in the union along with the double value and integer values members used for constants. The thinking was that length would never be used with number constants; the length would be obtained from the string of the constant (which is being kept so that the constant could be reproduced exactly as entered).

The test routine contained code for determining the length of string constants. This required adding two for the surrounding double quotes (which are not stored) and adding one for each double quote contained in the constant (which is entered with two double quotes). It turned out that the length of the original string constant, including the surrounding double quotes was already being stored in the length member of the token. The code in the test routine was redundant and unnecessary (and was removed).

Generally the length member was being used for the length of the token, but it wasn't being set for identifiers (variables, arrays, and user functions) and number constants where the length could be obtained from the string member.

It will be easier if the length member always contained the length of the token so it will not required to obtain the length from the string member for certain token types. The length member was moved out of the union so it can also be used for number constants, and in the Parser, the length member was set for identifiers and number constants so now all token types are covered.

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.)