Saturday, September 21, 2013

Table – Finding and Setting Token Codes

At the moment, the token codes are assigned to the constant and identifiers with no parentheses token types after the translation is complete.  This was initially the first step of encoding, but was moved into the translator.  Before moving this code assignment earlier in the translation,  a simplified routine was needed where it is given a token with a data type and for a base code, find a code for that data type (which will be either the base code or one of its associated codes).

The table find code routine was being called to perform this action, but this routine does a lot more including converting a constant to the expected data type (so no hidden conversion code needs to be added), finding a conversion code if there was no associated code with the desired data type, and returning the expected data type when data type cannot be converted (an error).

The find code routine contained the part for finding an associated code, so this part was moved into the new set token code routine.  This new routine just looks up an associated code if the expected data type of base case does not match a specified data type for a given operand of the code.  If the base code or an associated code matches, then the token is set to the code and its type and data type is set to that of the code.  Otherwise it returns false.

A secondary simplified set token code routine was added for setting the code of a token for a base code for the data type already in the token.  The base codes that are used for this routine have only one operand, which currently only includes the Const, Var and VarRef codes.  This secondary routine just calls the main set token code with the data type of the token and for the first (and only) operand of the base code.

[commit 32eec6f3c0]

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