Skip to content

Commit

Permalink
table: replaced command type use with command flag
Browse files Browse the repository at this point in the history
changed to use command flag instead
added command flag to all command entries (formally command type)
- the type initializer was changed to the default type
added is command table entry and token pass-thru access functions
- also checks if not reference flag (assignment)
- and checks if not operator (comma, semicolon)
updated command type checks in tester and translator classes
  • Loading branch information
thunder422 committed Jan 18, 2015
1 parent 0c107e0 commit 098009d
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 192 deletions.
8 changes: 4 additions & 4 deletions programmodel.cpp
Expand Up @@ -45,9 +45,8 @@ std::ostream &operator<<(std::ostream &os, ProgramWord word)
if (word.instructionHasSubCode(ProgramMask_SubCode))
{
os << '\'';
bool command = entry->type() == Type::Command
|| entry->hasFlag(Command_Flag);
if (!command && word.instructionHasSubCode(Paren_SubCode))
if (!entry->hasFlag(Command_Flag)
&& word.instructionHasSubCode(Paren_SubCode))
{
os << ')';
}
Expand All @@ -56,7 +55,8 @@ std::ostream &operator<<(std::ostream &os, ProgramWord word)
std::string option {entry->optionName()};
os << (option.empty() ? "BUG" : option);
}
if (command && word.instructionHasSubCode(Colon_SubCode))
if (entry->hasFlag(Command_Flag)
&& word.instructionHasSubCode(Colon_SubCode))
{
os << ":";
}
Expand Down
8 changes: 4 additions & 4 deletions recreator.cpp
Expand Up @@ -51,13 +51,13 @@ std::string Recreator::operator()(const RpnList &rpnList, bool exprMode)
{
recreate(*this, rpnItem);
}
bool command = rpnItem->token()->isType(Type::Command)
|| rpnItem->token()->hasFlag(Command_Flag);
if (!command && rpnItem->token()->hasSubCode(Paren_SubCode))
if (!rpnItem->token()->hasFlag(Command_Flag)
&& rpnItem->token()->hasSubCode(Paren_SubCode))
{
parenRecreate(*this, rpnItem);
}
if (command && rpnItem->token()->hasSubCode(Colon_SubCode))
if (rpnItem->token()->hasFlag(Command_Flag)
&& rpnItem->token()->hasSubCode(Colon_SubCode))
{
// FLAG option: spaces before colons (default=no)
m_output += ':';
Expand Down
96 changes: 48 additions & 48 deletions table.cpp
Expand Up @@ -162,167 +162,167 @@ static TableEntry tableEntries[] =
// Commands
//--------------
{ // Let_Code
Type::Command,
Type{},
"LET", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
letTranslate, NULL, NULL, NULL, NULL
},
{ // Print_Code
Type::Command,
Type{},
"PRINT", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
printTranslate, NULL, NULL, NULL, printRecreate
},
{ // Input_Code
Type::Command,
Type{},
"INPUT", "", "Keep",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
inputTranslate, NULL, NULL, NULL, inputRecreate

},
{ // InputPrompt_Code
Type::Command,
Type{},
"INPUT", "PROMPT", "Keep",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
inputTranslate, NULL, NULL, NULL, inputRecreate

},
{ // Dim_Code
Type::Command,
Type{},
"DIM", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Def_Code
Type::Command,
Type{},
"DEF", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Rem_Code
Type::Command,
Type{},
"REM", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, remEncode, remOperandText, remRemove, remRecreate
},
{ // If_Code
Type::Command,
Type{},
"IF", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Then_Code
Type::Command,
Type{},
"THEN", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Else_Code
Type::Command,
Type{},
"ELSE", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // End_Code
Type::Command,
Type{},
"END", "", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // EndIf_Code
Type::Command,
Type{},
"END", "IF", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // For_Code
Type::Command,
Type{},
"FOR", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // To_Code
Type::Command,
Type{},
"TO", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Step_Code
Type::Command,
Type{},
"STEP", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Next_Code
Type::Command,
Type{},
"NEXT", "", "",
TableFlag{}, 4, &Null_ExprInfo,
Command_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Do_Code
Type::Command,
Type{},
"DO", "", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // DoWhile_Code
Type::Command,
Type{},
"DO", "WHILE", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // DoUntil_Code
Type::Command,
Type{},
"DO", "UNTIL", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // While_Code
Type::Command,
Type{},
"WHILE", "", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Until_Code
Type::Command,
Type{},
"UNTIL", "", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // Loop_Code
Type::Command,
Type{},
"LOOP", "", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // LoopWhile_Code
Type::Command,
Type{},
"LOOP", "WHILE", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
{ // LoopUntil_Code
Type::Command,
Type{},
"LOOP", "UNTIL", "",
Two_Flag, 4, &Null_ExprInfo,
Command_Flag | Two_Flag, 4, &Null_ExprInfo,
NULL, NULL, NULL, NULL, NULL

},
Expand Down
10 changes: 7 additions & 3 deletions table.h
Expand Up @@ -38,8 +38,7 @@ using TokenPtr = std::shared_ptr<Token>;
// TODO temporary until code type enumeration implemented
enum class Type
{
Command = 1,
Operator,
Operator = 1,
IntFunc,
Constant,
DefFunc,
Expand All @@ -61,7 +60,7 @@ enum TableFlag : unsigned
UseConstAsIs_Flag = 1u << 5, // use constant data type as is
Keep_Flag = 1u << 6, // sub-string keep assignment
Two_Flag = 1u << 7, // code can have two words or characters
Command_Flag = 1u << 8, // operator code is really a command
Command_Flag = 1u << 8, // code is a command
EndStmt_Flag = 1u << 31 // end statement
};

Expand Down Expand Up @@ -150,6 +149,11 @@ class TableEntry
{
return m_flags & flag ? true : false;
}
bool isCommand() const
{
return hasFlag(Command_Flag) && !hasFlag(Reference_Flag)
&& m_type != Type::Operator;
}
int precedence() const
{
return m_precedence;
Expand Down

0 comments on commit 098009d

Please sign in to comment.