Skip to content

Commit

Permalink
removal of old translator - sub-string data type
Browse files Browse the repository at this point in the history
the sub-string data type was only used in the old translator and is no
longer needed (the new translator uses the sub-string table entry flag);
the AssignSubStr and AssignListMix codes were also removed;
the maximum number of associated codes was reduced from 4 to 3;
the entries for the sub-string data type was removed from the convert
have need table and the expected error status table;
various checks for the sub-string data type was removed from the
translator support functions
  • Loading branch information
thunder422 committed Aug 24, 2013
1 parent f150fbe commit 71e97bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 70 deletions.
1 change: 0 additions & 1 deletion ibcp.h
Expand Up @@ -55,7 +55,6 @@ enum DataType
Double_DataType,
Integer_DataType,
String_DataType,
SubStr_DataType,
// end of the actual execution data types
// the following data types are used internally for other uses
None_DataType, // indicates none of the above data types
Expand Down
49 changes: 9 additions & 40 deletions table.cpp
Expand Up @@ -34,7 +34,7 @@ const int MaxOperands = 3;
// (arguments) for any operator or internal function (there are currently
// no internal function with more than 3 arguments)

const int MaxAssocCodes = 4;
const int MaxAssocCodes = 3;
// this value contains the maximum number of associated codes,
// codes in additional to the main code for different possible data types
// for the code (no code currently has more the 3 total codes)
Expand All @@ -46,7 +46,6 @@ static Code cvtCodeHaveNeed[sizeof_DataType][sizeof_DataType] = {
Null_Code, // Double
CvtInt_Code, // Integer
Invalid_Code, // String
Invalid_Code, // SubStr (FIXME this data will be removed)
Null_Code, // None
Null_Code, // Number
Null_Code // Any
Expand All @@ -55,7 +54,6 @@ static Code cvtCodeHaveNeed[sizeof_DataType][sizeof_DataType] = {
CvtDbl_Code, // Double
Null_Code, // Integer
Invalid_Code, // String
Invalid_Code, // SubStr (FIXME this data will be removed)
Null_Code, // None
Null_Code, // Number
Null_Code // Any
Expand All @@ -64,16 +62,6 @@ static Code cvtCodeHaveNeed[sizeof_DataType][sizeof_DataType] = {
Invalid_Code, // Double
Invalid_Code, // Integer
Null_Code, // String
Null_Code, // SubStr (FIXME this data will be removed)
Null_Code, // None
Invalid_Code, // Number
Null_Code // Any
},
{ // have SubStr, need: (FIXME this data will be removed)
Invalid_Code, // Double
Invalid_Code, // Integer
Null_Code, // String
Null_Code, // SubStr
Null_Code, // None
Invalid_Code, // Number
Null_Code // Any
Expand All @@ -82,7 +70,6 @@ static Code cvtCodeHaveNeed[sizeof_DataType][sizeof_DataType] = {
Invalid_Code, // Double
Invalid_Code, // Integer
Invalid_Code, // String
Invalid_Code, // SubStr (FIXME this data will be removed)
Null_Code, // None (print function allowed if needed None)
Invalid_Code, // Number
Invalid_Code // Any
Expand All @@ -91,7 +78,6 @@ static Code cvtCodeHaveNeed[sizeof_DataType][sizeof_DataType] = {
Invalid_Code, // Double
Invalid_Code, // Integer
Invalid_Code, // String
Invalid_Code, // SubStr (FIXME this data will be removed)
Invalid_Code, // None
Invalid_Code, // Number
Invalid_Code // Any
Expand All @@ -100,7 +86,6 @@ static Code cvtCodeHaveNeed[sizeof_DataType][sizeof_DataType] = {
Invalid_Code, // Double
Invalid_Code, // Integer
Invalid_Code, // String
Invalid_Code, // SubStr (FIXME this data will be removed)
Invalid_Code, // None
Invalid_Code, // Number
Invalid_Code // Any
Expand Down Expand Up @@ -201,12 +186,6 @@ static DataType StrStr_OperandArray[] = {
static DataType StrStrInt_OperandArray[] = {
String_DataType, String_DataType, Integer_DataType
};
static DataType Sub_OperandArray[] = {
SubStr_DataType
};
static DataType SubStr_OperandArray[] = {
SubStr_DataType, String_DataType
};


// associated code data type arrays
Expand All @@ -216,11 +195,11 @@ static Code Add_AssocCode[] = {
};
static Code AddI1_AssocCode[] = {AddInt_Code};
static Code Assign_AssocCode[] = {
AssignInt_Code, AssignStr_Code, AssignSubStr_Code, AssignList_Code
AssignInt_Code, AssignStr_Code, AssignList_Code
};
static Code AssignLeft_AssocCode[] = {AssignKeepLeft_Code};
static Code AssignList_AssocCode[] = {
AssignListInt_Code, AssignListStr_Code, AssignListMix_Code
AssignListInt_Code, AssignListStr_Code
};
static Code AssignInt_AssocCode[] = {AssignListInt_Code};
static Code AssignMid2_AssocCode[] = {AssignKeepMid2_Code};
Expand Down Expand Up @@ -566,7 +545,7 @@ static TableEntry tableEntries[] =
},
{ // Left_Code
IntFuncP_TokenType, OneWord_Multiple,
"LEFT$(", NULL, SubStr_Flag, 2, SubStr_DataType,
"LEFT$(", NULL, SubStr_Flag, 2, String_DataType,
new ExprInfo(Null_Code, Operands(StrInt), AssocCode2(Left, -1))
},
{ // Len_Code
Expand All @@ -576,12 +555,12 @@ static TableEntry tableEntries[] =
},
{ // Mid2_Code
IntFuncP_TokenType, OneWord_Multiple,
"MID$(", "MID2$(", Multiple_Flag | SubStr_Flag, 2, SubStr_DataType,
"MID$(", "MID2$(", Multiple_Flag | SubStr_Flag, 2, String_DataType,
new ExprInfo(Null_Code, Operands(StrInt), AssocCode2(Mid2, -1))
},
{ // Mid3_Code
IntFuncP_TokenType, OneWord_Multiple,
"MID$(", "MID3$(", SubStr_Flag, 2, SubStr_DataType,
"MID$(", "MID3$(", SubStr_Flag, 2, String_DataType,
new ExprInfo(Null_Code, Operands(StrIntInt), AssocCode2(Mid3, -1))
},
{ // Repeat_Code
Expand All @@ -591,7 +570,7 @@ static TableEntry tableEntries[] =
},
{ // Right_Code
IntFuncP_TokenType, OneWord_Multiple,
"RIGHT$(", NULL, SubStr_Flag, 2, SubStr_DataType,
"RIGHT$(", NULL, SubStr_Flag, 2, String_DataType,
new ExprInfo(Null_Code, Operands(StrInt), AssocCode2(Right, -1))
},
{ // Space_Code
Expand Down Expand Up @@ -737,7 +716,7 @@ static TableEntry tableEntries[] =
{ // Assign_Code
Operator_TokenType, OneWord_Multiple,
"=", "Assign", Reference_Flag, 4, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Assign, 3))
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Assign, 2))
},
{ // AssignInt_Code
Operator_TokenType, OneWord_Multiple,
Expand All @@ -749,11 +728,6 @@ static TableEntry tableEntries[] =
"=", "Assign$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(StrStr), AssocCode2(AssignStr, 1))
},
{ // AssignSubStr_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignSub$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(SubStr))
},
{ // AssignLeft_Code
Operator_TokenType, OneWord_Multiple,
"LEFT$(", "AssignLeft", Reference_Flag, 4, String_DataType,
Expand All @@ -777,7 +751,7 @@ static TableEntry tableEntries[] =
{ // AssignList_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignList", Reference_Flag, 4, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(AssignList, 3))
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(AssignList, 2))
},
{ // AssignListInt_Code
Operator_TokenType, OneWord_Multiple,
Expand All @@ -789,11 +763,6 @@ static TableEntry tableEntries[] =
"=", "AssignList$", Reference_Flag, 4, String_DataType,
&StrStr_ExprInfo
},
{ // AssignListMix_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignListMix$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(SubStr))
},
{ // AssignKeepStr_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignKeep$", Reference_Flag, 4, String_DataType, &StrStr_ExprInfo
Expand Down
2 changes: 1 addition & 1 deletion test/parser2.txt
Expand Up @@ -48,7 +48,7 @@ Input: LET PRINT end then xor Abs(CHR$(val( end if left$ left$(
32: IntFuncP () Double Val
37: Command Op EndIf
44: NoParen String |left$|
50: IntFuncP () SubStr Left
50: IntFuncP () String Left
56: Operator Op None EOL

Input: rem this should be a comment
Expand Down
2 changes: 1 addition & 1 deletion test/parser4.txt
Expand Up @@ -62,7 +62,7 @@ Input: A$ = """
Input: A$ = LEFT$("TEST", 1)
0: NoParen String |A$|
3: Operator Op Integer Eq
5: IntFuncP () SubStr Left
5: IntFuncP () String Left
11: Constant String |TEST|
17: Operator Op None Comma
19: Constant Integer 1 |1|
Expand Down
4 changes: 2 additions & 2 deletions test/parser5.txt
Expand Up @@ -2,7 +2,7 @@
Input: A$ = mid$("b",A+B*2,index)+LEFT$("TEST", 1)
0: NoParen String |A$|
3: Operator Op Integer Eq
5: IntFuncP () SubStr Mid2
5: IntFuncP () String Mid2
10: Constant String |b|
13: Operator Op None Comma
14: NoParen None |A|
Expand All @@ -14,7 +14,7 @@ Input: A$ = mid$("b",A+B*2,index)+LEFT$("TEST", 1)
20: NoParen None |index|
25: Operator Op None CloseParen
26: Operator Op Double Add
27: IntFuncP () SubStr Left
27: IntFuncP () String Left
33: Constant String |TEST|
39: Operator Op None Comma
41: Constant Integer 1 |1|
Expand Down
27 changes: 2 additions & 25 deletions translator.cpp
Expand Up @@ -154,12 +154,7 @@ TokenStatus Translator::processFinalOperand(Token *&token, Token *token2,
DoneItem::deleteCloseParen(last);
last = token2; // last operand is CloseParen token
}
// FIXME remove check when sub-string data type removed
if (token->isDataType(SubStr_DataType) && !token->reference())
{
// change non-reference sub-string function data type to string
token->setDataType(String_DataType);
}

if (token->reference())
{
doneAppend = false; // don't append sub-string assignment
Expand Down Expand Up @@ -317,10 +312,6 @@ TokenStatus Translator::processDoneStackTop(Token *&token, int operandIndex,
status = expectedErrStatus(dataType);
// sub-string no longer needed with first/last operands
}
else if (token->isDataType(SubStr_DataType))
{
status = ExpStrVar_TokenStatus;
}
else
{
status = variableErrStatus(dataType);
Expand Down Expand Up @@ -384,8 +375,7 @@ DataType Translator::equivalentDataType(DataType dataType)
static DataType equivalent[numberof_DataType] = {
Double_DataType, // Double
Integer_DataType, // Integer
String_DataType, // String
String_DataType // SubStr
String_DataType // String
};

return equivalent[dataType];
Expand Down Expand Up @@ -415,12 +405,6 @@ TokenStatus Translator::expectedErrStatus(DataType dataType,
ExpStrVar_TokenStatus, // VarDefFn
ExpStrItem_TokenStatus // All
},
{ // SubStr
ExpStrExpr_TokenStatus, // None
BUG_InvalidDataType, // Variable
BUG_InvalidDataType, // VarDefFn
BUG_InvalidDataType // All
},
{ // None
ExpExpr_TokenStatus, // None
ExpAssignItem_TokenStatus, // Variable
Expand Down Expand Up @@ -1089,13 +1073,6 @@ TokenStatus Translator::getInternalFunction(Token *&token)
break;
}

// FIXME this is temporary until old translator removed
// FIXME (SubStr_DataType will be removed)
if (topToken->isDataType(SubStr_DataType))
{
topToken->setDataType(String_DataType);
}

m_doneStack.drop(); // remove from done stack (remove paren tokens)

// add token to output list if not sub-string assignment
Expand Down

0 comments on commit 71e97bf

Please sign in to comment.