The old translator routines had a somewhat complex method to detect and report data type errors. The new translator will have a simpler method. The new translator will have a routine for getting an expression from the input line and will have an argument for the desired data type. At the end of the expression, if the data type does not match this, then the appropriate hidden conversion code (CvtDbl or CvtInt) will be added or an "expected XX expression" error will be reported.
For example, an IF command will call get expression for an integer expression, the INPUT PROMPT command will call for a string expression and the PRINT command will call for any type of expression. The same method will apply to the arguments of internal functions and operands of operators. Two new data types were implemented to support this, the Number and Any data types.
Since the initial new translator implementation will only handle unary and binary operators, the get expression routine needs to know the expected data type that will follow a unary operator. For the minus (negate) operator, this is a numeric expression (either double or integer). For the NOT operator, this is an integer expression.
For binary operators, the first operand has already been processed and the appropriate associated code of the operator will already have been found. The get expression routine will need to know the expected data type of the second operand for the selected associated code.
Therefore, a new expected data type member was added to the expression information structure stored in the table. Code was added to the table setup and check routine to automatically generate the values for this new member by looking at the table entry for of the code and its associated codes, specifically at the operand data types of the last operand. If multiple data types are found, then the expected data type is set to the Number or Any data type appropriately.
[commit aa7d7bec92]
Sunday, June 30, 2013
Subscribe to:
Post Comments (Atom)
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.)