From 250b6ffd157b2001fb94ecefefc44e3fe2d98200 Mon Sep 17 00:00:00 2001 From: Thunder422 Date: Tue, 16 Jul 2013 10:31:08 -0400 Subject: [PATCH] corrected problem with print functions in expressions added a temporary check for if the command stack (which is not used with the new translator routines) is not empty in findCode() before checking for a print function added missing entries (specifically for the none data type) to the data type conversion table, which contain invalid codes, so that the table is not access beyond its bounds added additional statements with invalid print functions to translator test #3 (note: old translator does not correctly report errors for these so tests fail when using old translator) --- test/translator03.dat | 2 ++ test/translator03.txt | 6 ++++++ translator.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/test/translator03.dat b/test/translator03.dat index 3321403..f53a63f 100644 --- a/test/translator03.dat +++ b/test/translator03.dat @@ -33,3 +33,5 @@ A%,B$,C% = 1 A$,B$,C% = 1 A$,B$,C$ = 1 Z = A$ + B * C +A = TAB(4) +A = B + SPC(4) diff --git a/test/translator03.txt b/test/translator03.txt index deb4a87..0bc70fc 100644 --- a/test/translator03.txt +++ b/test/translator03.txt @@ -86,3 +86,9 @@ Input: A$,B$,C$ = 1 Input: Z = A$ + B * C ^^^^^-- expected string expression +Input: A = TAB(4) + ^^^^^^-- expected numeric expression + +Input: A = B + SPC(4) + ^^^^^^-- expected numeric expression + diff --git a/translator.cpp b/translator.cpp index 31516bf..634a1bf 100644 --- a/translator.cpp +++ b/translator.cpp @@ -39,7 +39,7 @@ enum { // array of conversion codes [have data type] [need data type] -static Code cvtCodeHaveNeed[numberof_DataType][numberof_DataType] = { +static Code cvtCodeHaveNeed[sizeof_DataType][numberof_DataType] = { { // have Double, need: Null_Code, // Double CvtInt_Code, // Integer @@ -58,11 +58,35 @@ static Code cvtCodeHaveNeed[numberof_DataType][numberof_DataType] = { Null_Code, // String Null_Code // SubStr }, - { // have SubStr, need: + { // have SubStr, need: (FIXME this data will be removed) Invalid_Code, // Double Invalid_Code, // Integer Null_Code, // String Null_Code // SubStr + }, + { // have numberof, need: (will not have any of this data type) + Invalid_Code, // Double + Invalid_Code, // Integer + Invalid_Code, // String + Invalid_Code // SubStr + }, + { // have None, need: (print functions have this data type) + Invalid_Code, // Double + Invalid_Code, // Integer + Invalid_Code, // String + Invalid_Code // SubStr + }, + { // have Number, need: (will not have any of this data type) + Invalid_Code, // Double + Invalid_Code, // Integer + Invalid_Code, // String + Invalid_Code // SubStr + }, + { // have Any, need: (will not have any of this data type) + Invalid_Code, // Double + Invalid_Code, // Integer + Invalid_Code, // String + Invalid_Code // SubStr } }; @@ -809,7 +833,9 @@ TokenStatus Translator::processFinalOperand(Token *&token, Token *token2, // process print-only internal functions // (check for function with no return value) - if (token->isDataType(None_DataType)) + // FIXME hack: check if command stack empty (for new translator) + // FIXME this section needs to be removed + if (token->isDataType(None_DataType) && !m_cmdStack.isEmpty()) { if (m_table.flags(token->code()) & Print_Flag) {