Skip to content

Commit

Permalink
corrected problem with print functions in expressions
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
thunder422 committed Jul 16, 2013
1 parent 8c872f6 commit 250b6ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/translator03.dat
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions test/translator03.txt
Expand Up @@ -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

32 changes: 29 additions & 3 deletions translator.cpp
Expand Up @@ -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
Expand All @@ -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
}
};

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 250b6ff

Please sign in to comment.