diff --git a/basic/let.cpp b/basic/let.cpp index 5f672b0..cb562af 100644 --- a/basic/let.cpp +++ b/basic/let.cpp @@ -237,16 +237,9 @@ void assignStrRecreate(Recreator &recreator, RpnItemPtr &rpnItem) Code code {rpnItem->token()->code()}; if (recreator.table().hasFlag(code, SubStr_Flag)) { - // for sub-string assignments, get original sub-string function code - std::string name {recreator.table().name(code)}; - Code subStrCode = Table::find(name); - // check multiple flag to see if sub-string code is correct code - if (recreator.table().hasFlag(code, Multiple_Flag)) - { - subStrCode++; // move to next code - } - recreator.pushWithOperands(std::move(name), - recreator.table().operandCount(subStrCode)); + // for sub-string assignments, treat as function to recreate + recreator.pushWithOperands(std::string{recreator.table().name(code)}, + recreator.table().operandCount(code)); } // deterine if assignment is an sub-string assignment keep code diff --git a/ibcp.h b/ibcp.h index b70a4f9..9f8b3e2 100644 --- a/ibcp.h +++ b/ibcp.h @@ -271,22 +271,6 @@ enum Code Function_Code }; -// code operator in-line functions for additional, increment and decrement -inline Code operator +(Code code, int number) -{ - return (Code)((int)code + number); -} - -inline Code operator ++(Code &code) -{ - return code = code + 1; -} - -inline Code operator ++(Code &code, int) -{ - return code = code + 1; -} - // miscellenous constant definitions constexpr int HighestPrecedence {127}; // highest precedence value diff --git a/table.cpp b/table.cpp index c5b6b9c..c4436be 100644 --- a/table.cpp +++ b/table.cpp @@ -137,6 +137,7 @@ static Code Add_AssocCode[] = { AddInt_Code, CatStr_Code, AddI2_Code }; static Code AddInt_AssocCode[] = {AddI1_Code}; +static Code Asc_AssocCode[] = {Asc2_Code}; static Code Assign_AssocCode[] = { AssignInt_Code, AssignStr_Code, AssignList_Code }; @@ -168,6 +169,7 @@ static Code InputAssign_AssocCode[] = { }; static Code InputAssignInt_AssocCode[] = {InputParseInt_Code}; static Code InputAssignStr_AssocCode[] = {InputParseStr_Code}; +static Code Instr_AssocCode[] = {Instr3_Code}; static Code Left_AssocCode[] = {AssignLeft_Code}; static Code Lt_AssocCode[] = { LtInt_Code, LtStr_Code, LtI2_Code @@ -177,7 +179,7 @@ static Code LtEq_AssocCode[] = { LtEqInt_Code, LtEqStr_Code, LtEqI2_Code }; static Code LtEqInt_AssocCode[] = {LtEqI1_Code}; -static Code Mid2_AssocCode[] = {AssignMid2_Code}; +static Code Mid2_AssocCode[] = {AssignMid2_Code, Mid3_Code}; static Code Mid3_AssocCode[] = {AssignMid3_Code}; static Code Mod_AssocCode[] = {ModInt_Code, ModI2_Code}; static Code ModInt_AssocCode[] = {ModI1_Code}; @@ -583,7 +585,9 @@ static TableEntry tableEntries[] = { // Asc_Code Token::Type::IntFuncP, "ASC(", "", "", - Multiple_Flag, 2, &Int_Str_ExprInfo, DataType{}, + Multiple_Flag, 2, + new ExprInfo(DataType::Integer, Operands(Str), AssocCode(Asc)), + DataType{}, NULL, NULL, NULL, NULL, internalFunctionRecreate }, { // Asc2_Code @@ -601,7 +605,9 @@ static TableEntry tableEntries[] = { // Instr2_Code Token::Type::IntFuncP, "INSTR(", "2", "", - Multiple_Flag, 2, &Int_StrStr_ExprInfo, DataType{}, + Multiple_Flag, 2, + new ExprInfo(DataType::Integer, Operands(StrStr), AssocCode(Instr)), + DataType{}, NULL, NULL, NULL, NULL, internalFunctionRecreate }, { // Instr3_Code @@ -614,7 +620,7 @@ static TableEntry tableEntries[] = Token::Type::IntFuncP, "LEFT$(", "", "", SubStr_Flag, 2, - new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Left, -1)), + new ExprInfo(DataType::String, Operands(StrInt), AssocCode(Left)), DataType{}, NULL, NULL, NULL, NULL, internalFunctionRecreate }, @@ -628,7 +634,7 @@ static TableEntry tableEntries[] = Token::Type::IntFuncP, "MID$(", "2", "", Multiple_Flag | SubStr_Flag, 2, - new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Mid2, -1)), + new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Mid2, 1)), DataType{}, NULL, NULL, NULL, NULL, internalFunctionRecreate }, @@ -636,8 +642,8 @@ static TableEntry tableEntries[] = Token::Type::IntFuncP, "MID$(", "3", "", SubStr_Flag, 2, - new ExprInfo(DataType::String, Operands(StrIntInt), - AssocCode2(Mid3, -1)), DataType{}, + new ExprInfo(DataType::String, Operands(StrIntInt), AssocCode(Mid3)), + DataType{}, NULL, NULL, NULL, NULL, internalFunctionRecreate }, { // Repeat_Code @@ -650,7 +656,7 @@ static TableEntry tableEntries[] = Token::Type::IntFuncP, "RIGHT$(", "", "", SubStr_Flag, 2, - new ExprInfo(DataType::String, Operands(StrInt), AssocCode2(Right, -1)), + new ExprInfo(DataType::String, Operands(StrInt), AssocCode(Right)), DataType{}, NULL, NULL, NULL, NULL, internalFunctionRecreate }, @@ -816,7 +822,7 @@ static TableEntry tableEntries[] = Token::Type::Operator, "=", "Assign", "LET", Reference_Flag, 4, - new ExprInfo(DataType::Double, Operands(DblDbl), AssocCode2(Assign, 2)), + new ExprInfo(DataType::Double, Operands(Dbl), AssocCode2(Assign, 2)), DataType{}, NULL, NULL, NULL, NULL, assignRecreate }, @@ -824,14 +830,14 @@ static TableEntry tableEntries[] = Token::Type::Operator, "=", "Assign%", "LET", Reference_Flag, 4, - new ExprInfo(DataType::Integer, Operands(IntInt), AssocCode(AssignInt)), + new ExprInfo(DataType::Integer, Operands(Int), AssocCode(AssignInt)), DataType{}, NULL, NULL, NULL, NULL, assignRecreate }, { // AssignStr_Code Token::Type::Operator, "=", "Assign$", "LET", - Reference_Flag, 4, new ExprInfo(DataType::String, Operands(StrStr), + Reference_Flag, 4, new ExprInfo(DataType::String, Operands(Str), AssocCode2(AssignStr, 1)), DataType{}, NULL, NULL, NULL, NULL, assignStrRecreate }, @@ -839,7 +845,7 @@ static TableEntry tableEntries[] = Token::Type::Operator, "LEFT$(", "Assign", "LET", Reference_Flag | SubStr_Flag, 4, - new ExprInfo(DataType::String, Operands(StrStr), AssocCode(AssignLeft)), + new ExprInfo(DataType::String, Operands(StrInt), AssocCode(AssignLeft)), DataType{}, NULL, NULL, NULL, NULL, assignStrRecreate }, @@ -847,7 +853,7 @@ static TableEntry tableEntries[] = Token::Type::Operator, "MID$(", "Assign2", "LET", Reference_Flag | SubStr_Flag, 4, - new ExprInfo(DataType::String, Operands(StrStr), AssocCode(AssignMid2)), + new ExprInfo(DataType::String, Operands(StrInt), AssocCode(AssignMid2)), DataType{}, NULL, NULL, NULL, NULL, assignStrRecreate }, @@ -855,39 +861,42 @@ static TableEntry tableEntries[] = Token::Type::Operator, "MID$(", "Assign3", "LET", Reference_Flag | SubStr_Flag | Multiple_Flag, 4, - new ExprInfo(DataType::String, Operands(StrStr), AssocCode(AssignMid3)), + new ExprInfo(DataType::String, Operands(StrIntInt), + AssocCode(AssignMid3)), DataType{}, NULL, NULL, NULL, NULL, assignStrRecreate }, { // AssignRight_Code Token::Type::Operator, "RIGHT$(", "Assign", "LET", - Reference_Flag | SubStr_Flag, 4, new ExprInfo(DataType::String, - Operands(StrStr), AssocCode(AssignRight)), DataType{}, + Reference_Flag | SubStr_Flag, 4, + new ExprInfo(DataType::String, Operands(StrInt), + AssocCode(AssignRight)), + DataType{}, NULL, NULL, NULL, NULL, assignStrRecreate }, { // AssignList_Code Token::Type::Operator, "=", "AssignList", "LET", - Reference_Flag, 4, &Dbl_DblDbl_ExprInfo, DataType{}, + Reference_Flag, 4, &Dbl_Dbl_ExprInfo, DataType{}, NULL, NULL, NULL, NULL, assignRecreate }, { // AssignListInt_Code Token::Type::Operator, "=", "AssignList%", "LET", - Reference_Flag, 4, &Int_IntInt_ExprInfo, DataType{}, + Reference_Flag, 4, &Int_Int_ExprInfo, DataType{}, NULL, NULL, NULL, NULL, assignRecreate }, { // AssignListStr_Code Token::Type::Operator, "=", "AssignList$", "LET", - Reference_Flag, 4, &Str_StrStr_ExprInfo, DataType{}, + Reference_Flag, 4, &Str_Str_ExprInfo, DataType{}, NULL, NULL, NULL, NULL, assignRecreate }, { // AssignKeepStr_Code Token::Type::Operator, "", "AssignKeep$", "LET", - Reference_Flag | Keep_Flag, 4, &Str_StrStr_ExprInfo, DataType{}, + Reference_Flag | Keep_Flag, 4, &Str_Str_ExprInfo, DataType{}, NULL, NULL, NULL, NULL, assignStrRecreate }, { // AssignKeepLeft_Code @@ -1938,10 +1947,6 @@ bool Table::setTokenCode(TokenPtr token, Code code, DataType dataType, { // if not, see if data type of any associated code matches int i {secondAssociatedIndex(code)}; - if (i < 0) // if second index -1, then no associated codes to search - { - return false; - } // determine range of associated codes to search int end {associatedCodeCount(code)}; if (operandIndex == 0 && i != 0) // first operand? diff --git a/token.h b/token.h index 0b0249b..7e24106 100644 --- a/token.h +++ b/token.h @@ -169,10 +169,6 @@ class Token { m_code = code; } - Code nextCode(void) - { - return ++m_code; - } bool isCode(Code code) const { return code == m_code; diff --git a/translator.cpp b/translator.cpp index e1a81b8..276ac63 100644 --- a/translator.cpp +++ b/translator.cpp @@ -616,8 +616,9 @@ void Translator::processInternalFunction(Reference reference) // function doesn't have multiple entries throw TokenError {Status::ExpOpOrParen, m_token}; } - // move to next code; update code and last operand index - code = topToken->nextCode(); + // get second associated code; update code and last operand + code = m_table.secondAssociatedCode(topToken->code()); + topToken->setCode(code); lastOperand = m_table.operandCount(code) - 1; } m_token.reset(); // delete comma token, it's not needed