Skip to content

Commit

Permalink
table: replaced type with code type enumeration
Browse files Browse the repository at this point in the history
named code type enumeration to 'code'
- changed old code enumerators to new enumerators throughout
moved code enumeration to table source file renamed as code index
- still used for the temporary alternates initializer list
replaced table entry type member with code member
- updated table entries with appropriate codes on select entries
added static code to entry map member
- add entries with a non-default code to map in add function
- added entry function taking code argument
- changed argument of entry function with data type to code
removed type access function, updated code and is code functions
changed token type function to code, removed is type function
modified switch statements on type to code in translator and tester
update parser expected results because identifier type names changed
  • Loading branch information
thunder422 committed Jan 19, 2015
1 parent eaa6e6d commit f19b061
Show file tree
Hide file tree
Showing 16 changed files with 577 additions and 533 deletions.
12 changes: 6 additions & 6 deletions basic/input.cpp
Expand Up @@ -38,7 +38,7 @@ void inputTranslate(Translator &translator)
{
token = std::make_shared<Token>(entry);
}
else // InputPrompt_Code
else // Input Prompt
{
try
{
Expand All @@ -54,11 +54,11 @@ void inputTranslate(Translator &translator)
}
translator.doneStackPop();
token = translator.moveToken(); // take next token
if (token->isCode(Comma_Code))
if (token->isCode(Code::Comma))
{
token->addSubCode(Option_SubCode);
}
else if (!token->isCode(SemiColon_Code))
else if (!token->isCode(Code::Semicolon))
{
throw TokenError {Status::ExpOpSemiOrComma, token};
}
Expand All @@ -79,12 +79,12 @@ void inputTranslate(Translator &translator)
// get and check next token
translator.getToken(Status::ExpCommaSemiOrEnd);

if (translator.token()->isCode(Comma_Code))
if (translator.token()->isCode(Code::Comma))
{
done = false;
token = translator.moveToken();
}
else if (translator.token()->isCode(SemiColon_Code))
else if (translator.token()->isCode(Code::Semicolon))
{
commandToken->addSubCode(Option_SubCode);
done = true;
Expand All @@ -100,7 +100,7 @@ void inputTranslate(Translator &translator)
translator.token()};
}
done = true;
token = std::make_shared<Token>(Table::entry(Code{}));
token = std::make_shared<Token>(Table::entry(Code::Null));
}

// change token to appropriate assign code and append to output
Expand Down
16 changes: 8 additions & 8 deletions basic/let.cpp
Expand Up @@ -36,7 +36,7 @@ void letTranslate(Translator &translator)

int column {translator.token()->column()};
bool hidden;
if (!translator.token()->isCode(Let_Code))
if (!translator.token()->isCode(Code::Let))
{
hidden = true;
}
Expand All @@ -63,8 +63,8 @@ void letTranslate(Translator &translator)
// next token determines error
translator.resetToken();
translator.getToken(Status{});
error = translator.token()->isCode(Comma_Code)
|| translator.token()->isCode(Eq_Code)
error = translator.token()->isCode(Code::Comma)
|| translator.token()->isCode(Code::Equal)
? Status::ExpAssignItem : Status::ExpCmdOrAssignItem;
}
catch (TokenError)
Expand All @@ -77,11 +77,11 @@ void letTranslate(Translator &translator)

// get and check next token for comma or equal
translator.getToken(Status::ExpEqualOrComma);
if (translator.token()->isCode(Comma_Code))
if (translator.token()->isCode(Code::Comma))
{
done = false;
}
else if (translator.token()->isCode(Eq_Code))
else if (translator.token()->isCode(Code::Equal))
{
done = true;
}
Expand All @@ -108,7 +108,7 @@ void letTranslate(Translator &translator)
{
token = translator.moveToken();
// change token to appropriate assign code
token->setTableEntry(Table::entry(Let_Code)->alternate(0));
token->setTableEntry(Table::entry(Code::Let)->alternate(0));
translator.processDoneStackTop(token);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ void assignRecreate(Recreator &recreator, RpnItemPtr &rpnItem)
std::stack<std::string> stack;

stack.emplace(recreator.popString()); // push value
std::string separator = ' ' + Table::entry(Eq_Code)->name() + ' ';
std::string separator = ' ' + Table::entry(Code::Equal)->name() + ' ';
while (!recreator.empty())
{
stack.emplace(recreator.popString() + separator);
Expand All @@ -218,7 +218,7 @@ void assignStrRecreate(Recreator &recreator, RpnItemPtr &rpnItem)
// check if this first assign code
if (!recreator.separatorIsSet())
{
string = ' ' + Table::entry(Eq_Code)->name() + ' ';
string = ' ' + Table::entry(Code::Equal)->name() + ' ';
recreator.setSeparator(',');
}
else // continuation of assignment list
Expand Down
4 changes: 2 additions & 2 deletions basic/print.cpp
Expand Up @@ -82,15 +82,15 @@ void printTranslate(Translator &translator)
lastSemiColon.reset(); // don't need last semicolon token
}

if (translator.token()->isCode(Comma_Code))
if (translator.token()->isCode(Code::Comma))
{
if (lastSemiColon)
{
throw TokenError {Status::ExpExprPfnOrEnd, translator.token()};
}
translator.outputAppend(translator.moveToken());
}
else if (translator.token()->isCode(SemiColon_Code))
else if (translator.token()->isCode(Code::Semicolon))
{
if (!separator)
{
Expand Down
212 changes: 26 additions & 186 deletions ibcp.h
Expand Up @@ -92,192 +92,6 @@ enum class Status
};


// code enumeration
enum Code
{
Let_Code = 1,
Print_Code, // REMOVE alternate[0] of SemiColon
Input_Code, // REMOVE will be removed
InputPrompt_Code, // REMOVE will be removed
Dim_Code, // REMOVE not currently used
Def_Code, // REMOVE not currently used
Rem_Code,
If_Code, // REMOVE not currently used
Then_Code, // REMOVE not currently used
Else_Code, // REMOVE not currently used
End_Code, // REMOVE not currently used
EndIf_Code, // REMOVE not currently used
For_Code, // REMOVE not currently used
To_Code, // REMOVE not currently used
Step_Code, // REMOVE not currently used
Next_Code, // REMOVE not currently used
Do_Code, // REMOVE not currently used
DoWhile_Code, // REMOVE not currently used
DoUntil_Code, // REMOVE not currently used
While_Code, // REMOVE not currently used
Until_Code, // REMOVE not currently used
Loop_Code, // REMOVE not currently used
LoopWhile_Code, // REMOVE not currently used
LoopUntil_Code, // REMOVE not currently used
Rnd_Code, // REMOVE primary function (will not be needed)
Mod_Code, // REMOVE primary operator (will not be needed)
And_Code, // REMOVE primary operator (will not be needed)
Or_Code, // REMOVE primary operator (will not be needed)
Not_Code, // REMOVE primary operator (will not be needed)
Eqv_Code, // REMOVE primary operator (will not be needed)
Imp_Code, // REMOVE primary operator (will not be needed)
Xor_Code, // REMOVE primary operator (will not be needed)
Abs_Code, // REMOVE primary function (will not be needed)
Fix_Code, // REMOVE primary function (will not be needed)
Frac_Code, // REMOVE primary function (will not be needed)
Int_Code, // REMOVE primary function (will not be needed)
RndArg_Code, // REMOVE primary function (will not be needed)
Sgn_Code, // REMOVE primary function (will not be needed)
Cint_Code, // REMOVE primary function (will not be needed)
Cdbl_Code, // REMOVE primary function (will not be needed)
Sqr_Code, // REMOVE primary function (will not be needed)
Atn_Code, // REMOVE primary function (will not be needed)
Cos_Code, // REMOVE primary function (will not be needed)
Sin_Code, // REMOVE primary function (will not be needed)
Tan_Code, // REMOVE primary function (will not be needed)
Exp_Code, // REMOVE primary function (will not be needed)
Log_Code, // REMOVE primary function (will not be needed)
Tab_Code, // REMOVE primary function (will not be needed)
Spc_Code, // REMOVE primary function (will not be needed)
Asc_Code, // REMOVE primary function (will not be needed)
Asc2_Code, // REMOVE alternate[1] of Asc
Chr_Code, // REMOVE primary function (will not be needed)
Instr2_Code, // REMOVE primary function (will not be needed)
Instr3_Code, // REMOVE alternate[2] of Instr2
Left_Code, // REMOVE primary function (will not be needed)
Len_Code, // REMOVE primary function (will not be needed)
Mid2_Code, // REMOVE primary function (will not be needed)
Mid3_Code, // REMOVE alternate[2] of Mid2
Repeat_Code, // REMOVE primary function (will not be needed)
Right_Code, // REMOVE primary function (will not be needed)
Space_Code, // REMOVE primary function (will not be needed)
Str_Code, // REMOVE primary function (will not be needed)
Val_Code, // REMOVE primary function (will not be needed)
Add_Code, // REMOVE primary operator (will not be needed)
Neg_Code, // REMOVE primary operator (will not be needed)
Mul_Code, // REMOVE primary operator (will not be needed)
Div_Code, // REMOVE primary operator (will not be needed)
IntDiv_Code, // REMOVE primary operator (will not be needed)
Power_Code, // REMOVE primary operator (will not be needed)
Eq_Code,
Gt_Code, // REMOVE primary operator (will not be needed)
GtEq_Code, // REMOVE primary operator (will not be needed)
Lt_Code, // REMOVE primary operator (will not be needed)
LtEq_Code, // REMOVE primary operator (will not be needed)
NotEq_Code, // REMOVE primary operator (will not be needed)
OpenParen_Code,
CloseParen_Code,
Comma_Code,
SemiColon_Code,
Colon_Code,
RemOp_Code,
Assign_Code, // REMOVE alternate to Let
AssignInt_Code, // REMOVE alternate[0] of Assign
AssignStr_Code, // REMOVE alternate[0] of Assign
AssignLeft_Code, // REMOVE alternate[1] of Left
AssignMid2_Code, // REMOVE alternate[1] of Mid2
AssignMid3_Code, // REMOVE alternate[1] of Mid3
AssignRight_Code, // REMOVE alternate[1] of Right
AssignList_Code, // REMOVE alternate[1] of Assign
AssignListInt_Code, // REMOVE alternate[1] of AssignInt
AssignListStr_Code, // REMOVE alternate[1] of AssignStr
AssignKeepStr_Code, // REMOVE alternate[0] of AssignStr
AssignKeepLeft_Code, // REMOVE alternate[0] of AssignLeft
AssignKeepMid2_Code, // REMOVE alternate[0] of AssignMid2
AssignKeepMid3_Code, // REMOVE alternate[0] of AssignMid3
AssignKeepRight_Code, // REMOVE alternate[0] of AssignRight
EOL_Code,
AddI1_Code, // REMOVE alternate[0] of Add
AddI2_Code, // REMOVE alternate[1] of Add
AddInt_Code, // REMOVE alternate[1] of AddI1
CatStr_Code, // REMOVE alternate[0] of Add
Sub_Code, // REMOVE alternate[1] of Neg
SubI1_Code, // REMOVE alternate[0] of Sub
SubI2_Code, // REMOVE alternate[1] of Sub
SubInt_Code, // REMOVE alternate[1] of SubI1
NegInt_Code, // REMOVE alternate[0] of Neg
MulI1_Code, // REMOVE alternate[0] of Mul
MulI2_Code, // REMOVE alternate[1] of Mul
MulInt_Code, // REMOVE alternate[1] of MulI1
DivI1_Code, // REMOVE alternate[0] of Div
DivI2_Code, // REMOVE alternate[1] of Div
DivInt_Code, // REMOVE alternate[1] of DivI1
ModI1_Code, // REMOVE alternate[0] of Mod
ModI2_Code, // REMOVE alternate[1] of Mod
ModInt_Code, // REMOVE alternate[1] of ModI1
PowerI1_Code, // REMOVE alternate[0] of Power
PowerMul_Code, // REMOVE alternate[1] of Power
PowerInt_Code, // REMOVE alternate[1] of PowerI1
EqI1_Code, // REMOVE alternate[0] of Eq
EqI2_Code, // REMOVE alternate[1] of Eq
EqInt_Code, // REMOVE alternate[1] of EqI1
EqStr_Code, // REMOVE alternate[0] of Eq
GtI1_Code, // REMOVE alternate[0] of Gt
GtI2_Code, // REMOVE alternate[1] of Gt
GtInt_Code, // REMOVE alternate[1] of GtI1
GtStr_Code, // REMOVE alternate[0] of Gt
GtEqI1_Code, // REMOVE alternate[0] of GtEq
GtEqI2_Code, // REMOVE alternate[1] of GtEq
GtEqInt_Code, // REMOVE alternate[1] of GtEqI1
GtEqStr_Code, // REMOVE alternate[0] of GtEq
LtI1_Code, // REMOVE alternate[0] of Lt
LtI2_Code, // REMOVE alternate[1] of Lt
LtInt_Code, // REMOVE alternate[1] of LtI1
LtStr_Code, // REMOVE alternate[0] of Lt
LtEqI1_Code, // REMOVE alternate[0] of LtEq
LtEqI2_Code, // REMOVE alternate[1] of LtEq
LtEqInt_Code, // REMOVE alternate[1] of LtEqI1
LtEqStr_Code, // REMOVE alternate[0] of LtEq
NotEqI1_Code, // REMOVE alternate[0] of NotEq
NotEqI2_Code, // REMOVE alternate[1] of NotEq
NotEqInt_Code, // REMOVE alternate[1] of NotEqI1
NotEqStr_Code, // REMOVE alternate[0] of NotEq
AbsInt_Code, // REMOVE alternate[0] of Abs
RndArgInt_Code, // REMOVE alternate[0] of RngArg
SgnInt_Code, // REMOVE alternate[0] of Sgn
CvtInt_Code,
CvtDbl_Code,
StrInt_Code, // REMOVE alternate[0] of Str
PrintDbl_Code, // REMOVE alternate[0] of Print
PrintInt_Code, // REMOVE alternate[0] of PrintDbl
PrintStr_Code, // REMOVE alternate[0] of PrintDbl
InputBegin_Code, // REMOVE alternate[0] of Input
InputBeginStr_Code, // REMOVE alternate[0] of InputPrompt
InputAssign_Code, // REMOVE alternate[1] of Input & InputPtompt
InputAssignInt_Code, // REMOVE alternate[0] of InputAssign
InputAssignStr_Code, // REMOVE alternate[0] of InputAssign
InputParse_Code, // REMOVE alternate[1] of InputAssign
InputParseInt_Code, // REMOVE alternate[1] of InputAssignInt
InputParseStr_Code, // REMOVE alternate[1] of InputAssignStr
Const_Code,
ConstInt_Code, // REMOVE alternate[0] of Const
ConstStr_Code, // REMOVE alternate[0] of Const
Var_Code,
VarInt_Code, // REMOVE alternate[0] of Var
VarStr_Code, // REMOVE alternate[0] of Var
VarRef_Code, // REMOVE alternate[1] or Var
VarRefInt_Code, // REMOVE alternate[0] of VarRef
VarRefStr_Code, // REMOVE alternate[0] of VarRef
Array_Code,
ArrayInt_Code, // REMOVE alternate[0] of Array
ArrayStr_Code, // REMOVE alternate[0] of Array
DefFuncN_Code,
DefFuncNInt_Code, // REMOVE alternate[0] of DefFuncN
DefFuncNStr_Code, // REMOVE alternate[0] of DefFuncN
DefFuncP_Code,
DefFuncPInt_Code, // REMOVE alternate[0] of DefFuncP
DefFuncPStr_Code, // REMOVE alternate[0] of DefFuncP
Function_Code,
FunctionInt_Code, // REMOVE alternate[0] of Function
FunctionStr_Code // REMOVE alternate[0] of Function
};


// miscellenous constant definitions
constexpr int HighestPrecedence {127}; // highest precedence value
// this value was selected as the highest value because it is the highest
Expand Down Expand Up @@ -306,6 +120,32 @@ enum class DataType
};


// code type enumeration
enum class Code
{
Null = 1,
OpenParen,
CloseParen,
Equal,
Comma,
Semicolon,
Colon,
EOL,
RemOp,
Rem,
Let,
CvtDbl,
CvtInt,
Constant,
Variable,
Array,
DefFunc,
DefFuncNoArgs, // TODO temporary until defined functions implemented
UserFunc,
Subroutine
};


// sub-code flags for use in Token and internal program
enum SubCode : uint16_t
{
Expand Down

0 comments on commit f19b061

Please sign in to comment.