From 6869de047341e7640f964b5b8a6d1db597864ea1 Mon Sep 17 00:00:00 2001 From: Jonathan Evans Date: Wed, 8 Apr 2020 23:05:52 +0000 Subject: [PATCH] fixed operator! not working --- SymbolTableEntry.h | 7 ++++--- evanshogan.y | 11 +++++----- my_output/arithGood.txt.out | 3 +++ my_output/bigLet.txt.out | 17 ++------------- my_output/divGood.txt.out | 3 +++ my_output/ifGood1.txt.out | 3 +++ my_output/ifGood2.txt.out | 3 +++ my_output/ifGood3.txt.out | 3 +++ my_output/ifGood4.txt.out | 3 +++ my_output/intconst.txt.out | 3 +++ my_output/letPrint.txt.out | 12 +++-------- my_output/letPrintIf.txt.out | 14 ++++--------- my_output/logop_bool_int.txt.out | 5 ++++- my_output/logop_bool_str.txt.out | 5 ++++- my_output/logop_int_bool.txt.out | 5 ++++- my_output/logop_int_int.txt.out | 5 ++++- my_output/logop_int_str.txt.out | 5 ++++- my_output/logop_str_bool.txt.out | 5 ++++- my_output/logop_str_str.txt.out | 5 ++++- my_output/nestedLet.txt.out | 36 ++------------------------------ my_output/nil.txt.out | 5 ++++- my_output/not_int.txt.out | 7 +++++++ my_output/not_nil.txt.out | 7 +++++++ my_output/not_relexpr.txt.out | 7 +++++++ my_output/not_str.txt.out | 7 +++++++ my_output/not_t.txt.out | 7 +++++++ my_output/printProgn1.txt.out | 3 +++ my_output/printProgn2.txt.out | 7 +++++-- my_output/relop_int_int1.txt.out | 5 ++++- my_output/relop_int_int2.txt.out | 5 ++++- my_output/relop_str_str1.txt.out | 5 ++++- my_output/relop_str_str2.txt.out | 5 ++++- my_output/strconst.txt.out | 3 +++ my_output/t.txt.out | 5 ++++- 34 files changed, 140 insertions(+), 91 deletions(-) diff --git a/SymbolTableEntry.h b/SymbolTableEntry.h index 2fed779..5bff68b 100644 --- a/SymbolTableEntry.h +++ b/SymbolTableEntry.h @@ -57,7 +57,8 @@ struct TYPE_INFO int operatorType; int operatorInstance; - operator bool(){ + operator bool() + { if(type == BOOL){ return value.boolean; } @@ -65,7 +66,7 @@ struct TYPE_INFO } bool operator!(){ - return !(*this); + return !(bool(*this)); } // man I really wish I had c++20's operator<=>/operator semantics right now @@ -126,7 +127,7 @@ struct TYPE_INFO os << rhs.value.text; break; case BOOL: - os << rhs.value.boolean; + os << ((rhs.value.boolean)?"t":"nil"); break; default: throw std::invalid_argument("invalid type at print"); diff --git a/evanshogan.y b/evanshogan.y index 46ab219..c9c7aab 100644 --- a/evanshogan.y +++ b/evanshogan.y @@ -105,7 +105,7 @@ N_START : // epsilon break; } */ - cout << "---- Completed parsing ----\n" << endl; + cout << "\n---- Completed parsing ----\n" << endl; cout << "\nValue of the expression is: "; cout << $2 <<"\n"; } @@ -456,7 +456,7 @@ N_ID_EXPR_LIST : /* epsilon */ | N_ID_EXPR_LIST T_LPAREN T_IDENT N_EXPR T_RPAREN { string lexeme = string($3); - printf("___Adding %s to symbol table\n", $3); + // printf("___Adding %s to symbol table\n", $3); bool found = scopeStack.top().findEntry(lexeme); if (found){ yyerror("Multiply defined identifier"); @@ -611,13 +611,13 @@ void printToken(const char* tokenType, char* lexeme){ void beginScope() { scopeStack.push(SYMBOL_TABLE()); - printf("\n___Entering new scope...\n\n"); + // printf("\n___Entering new scope...\n\n"); } void endScope() { scopeStack.pop(); - printf("\n___Exiting scope...\n\n"); + // printf("\n___Exiting scope...\n\n"); } bool findEntryInAnyScope(const string theName) @@ -685,6 +685,7 @@ int main(int argc, char** argv) { yyparse(); } - while (!feof(yyin)); + while (!feof(yyin)); + bail(); return 0; } diff --git a/my_output/arithGood.txt.out b/my_output/arithGood.txt.out index a972454..03732e3 100644 --- a/my_output/arithGood.txt.out +++ b/my_output/arithGood.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: 60 + +Bye! diff --git a/my_output/bigLet.txt.out b/my_output/bigLet.txt.out index f9826e8..4a2a644 100644 --- a/my_output/bigLet.txt.out +++ b/my_output/bigLet.txt.out @@ -1,20 +1,7 @@ -___Entering new scope... - -___Adding bob to symbol table -___Adding fish to symbol table - -___Entering new scope... - -___Adding x to symbol table - -___Exiting scope... - -___Adding sandwich to symbol table - -___Exiting scope... - ---- Completed parsing ---- Value of the expression is: 0 + +Bye! diff --git a/my_output/divGood.txt.out b/my_output/divGood.txt.out index 818b23c..a0c247b 100644 --- a/my_output/divGood.txt.out +++ b/my_output/divGood.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: 20 + +Bye! diff --git a/my_output/ifGood1.txt.out b/my_output/ifGood1.txt.out index 3bdf606..83b16d6 100644 --- a/my_output/ifGood1.txt.out +++ b/my_output/ifGood1.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: 100 + +Bye! diff --git a/my_output/ifGood2.txt.out b/my_output/ifGood2.txt.out index 3bdf606..83b16d6 100644 --- a/my_output/ifGood2.txt.out +++ b/my_output/ifGood2.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: 100 + +Bye! diff --git a/my_output/ifGood3.txt.out b/my_output/ifGood3.txt.out index d187c49..6c02117 100644 --- a/my_output/ifGood3.txt.out +++ b/my_output/ifGood3.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: "false" + +Bye! diff --git a/my_output/ifGood4.txt.out b/my_output/ifGood4.txt.out index 3bdf606..83b16d6 100644 --- a/my_output/ifGood4.txt.out +++ b/my_output/ifGood4.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: 100 + +Bye! diff --git a/my_output/intconst.txt.out b/my_output/intconst.txt.out index 262426a..42f7527 100644 --- a/my_output/intconst.txt.out +++ b/my_output/intconst.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: -42 + +Bye! diff --git a/my_output/letPrint.txt.out b/my_output/letPrint.txt.out index 7c7b77d..12b8760 100644 --- a/my_output/letPrint.txt.out +++ b/my_output/letPrint.txt.out @@ -1,14 +1,8 @@ - -___Entering new scope... - -___Adding x to symbol table -___Adding y to symbol table -___Adding z to symbol table -34848944 - -___Exiting scope... +26185904 ---- Completed parsing ---- Value of the expression is: 0 + +Bye! diff --git a/my_output/letPrintIf.txt.out b/my_output/letPrintIf.txt.out index 8765af4..e99f6f7 100644 --- a/my_output/letPrintIf.txt.out +++ b/my_output/letPrintIf.txt.out @@ -1,15 +1,9 @@ - -___Entering new scope... - -___Adding x to symbol table -___Adding y to symbol table -___Adding z to symbol table -28856496 -28856496 - -___Exiting scope... +34783408 +34783408 ---- Completed parsing ---- Value of the expression is: 0 + +Bye! diff --git a/my_output/logop_bool_int.txt.out b/my_output/logop_bool_int.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_bool_int.txt.out +++ b/my_output/logop_bool_int.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/logop_bool_str.txt.out b/my_output/logop_bool_str.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_bool_str.txt.out +++ b/my_output/logop_bool_str.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/logop_int_bool.txt.out b/my_output/logop_int_bool.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_int_bool.txt.out +++ b/my_output/logop_int_bool.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/logop_int_int.txt.out b/my_output/logop_int_int.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_int_int.txt.out +++ b/my_output/logop_int_int.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/logop_int_str.txt.out b/my_output/logop_int_str.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_int_str.txt.out +++ b/my_output/logop_int_str.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/logop_str_bool.txt.out b/my_output/logop_str_bool.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_str_bool.txt.out +++ b/my_output/logop_str_bool.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/logop_str_str.txt.out b/my_output/logop_str_str.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/logop_str_str.txt.out +++ b/my_output/logop_str_str.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/nestedLet.txt.out b/my_output/nestedLet.txt.out index d9822c4..4a2a644 100644 --- a/my_output/nestedLet.txt.out +++ b/my_output/nestedLet.txt.out @@ -1,39 +1,7 @@ -___Entering new scope... - -___Adding x to symbol table - -___Entering new scope... - -___Adding y to symbol table - -___Entering new scope... - -___Adding z to symbol table - -___Entering new scope... - -___Adding w to symbol table - -___Entering new scope... - -___Adding p to symbol table - -___Exiting scope... - - -___Exiting scope... - - -___Exiting scope... - - -___Exiting scope... - - -___Exiting scope... - ---- Completed parsing ---- Value of the expression is: 0 + +Bye! diff --git a/my_output/nil.txt.out b/my_output/nil.txt.out index 7caf3ac..ac3fd84 100644 --- a/my_output/nil.txt.out +++ b/my_output/nil.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 0 +Value of the expression is: nil + +Bye! diff --git a/my_output/not_int.txt.out b/my_output/not_int.txt.out index e69de29..ac3fd84 100644 --- a/my_output/not_int.txt.out +++ b/my_output/not_int.txt.out @@ -0,0 +1,7 @@ + +---- Completed parsing ---- + + +Value of the expression is: nil + +Bye! diff --git a/my_output/not_nil.txt.out b/my_output/not_nil.txt.out index e69de29..93d6b69 100644 --- a/my_output/not_nil.txt.out +++ b/my_output/not_nil.txt.out @@ -0,0 +1,7 @@ + +---- Completed parsing ---- + + +Value of the expression is: t + +Bye! diff --git a/my_output/not_relexpr.txt.out b/my_output/not_relexpr.txt.out index e69de29..93d6b69 100644 --- a/my_output/not_relexpr.txt.out +++ b/my_output/not_relexpr.txt.out @@ -0,0 +1,7 @@ + +---- Completed parsing ---- + + +Value of the expression is: t + +Bye! diff --git a/my_output/not_str.txt.out b/my_output/not_str.txt.out index e69de29..ac3fd84 100644 --- a/my_output/not_str.txt.out +++ b/my_output/not_str.txt.out @@ -0,0 +1,7 @@ + +---- Completed parsing ---- + + +Value of the expression is: nil + +Bye! diff --git a/my_output/not_t.txt.out b/my_output/not_t.txt.out index e69de29..ac3fd84 100644 --- a/my_output/not_t.txt.out +++ b/my_output/not_t.txt.out @@ -0,0 +1,7 @@ + +---- Completed parsing ---- + + +Value of the expression is: nil + +Bye! diff --git a/my_output/printProgn1.txt.out b/my_output/printProgn1.txt.out index c379701..3f93ac0 100644 --- a/my_output/printProgn1.txt.out +++ b/my_output/printProgn1.txt.out @@ -1,5 +1,8 @@ "shake" + ---- Completed parsing ---- Value of the expression is: "shake" + +Bye! diff --git a/my_output/printProgn2.txt.out b/my_output/printProgn2.txt.out index 2e8ac83..a20f614 100644 --- a/my_output/printProgn2.txt.out +++ b/my_output/printProgn2.txt.out @@ -1,5 +1,8 @@ -0 +nil + ---- Completed parsing ---- -Value of the expression is: 0 +Value of the expression is: nil + +Bye! diff --git a/my_output/relop_int_int1.txt.out b/my_output/relop_int_int1.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/relop_int_int1.txt.out +++ b/my_output/relop_int_int1.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/relop_int_int2.txt.out b/my_output/relop_int_int2.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/relop_int_int2.txt.out +++ b/my_output/relop_int_int2.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/relop_str_str1.txt.out b/my_output/relop_str_str1.txt.out index 7caf3ac..ac3fd84 100644 --- a/my_output/relop_str_str1.txt.out +++ b/my_output/relop_str_str1.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 0 +Value of the expression is: nil + +Bye! diff --git a/my_output/relop_str_str2.txt.out b/my_output/relop_str_str2.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/relop_str_str2.txt.out +++ b/my_output/relop_str_str2.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! diff --git a/my_output/strconst.txt.out b/my_output/strconst.txt.out index dcee10d..6e220bd 100644 --- a/my_output/strconst.txt.out +++ b/my_output/strconst.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- Value of the expression is: "hello kitty!" + +Bye! diff --git a/my_output/t.txt.out b/my_output/t.txt.out index 5602a4d..93d6b69 100644 --- a/my_output/t.txt.out +++ b/my_output/t.txt.out @@ -1,4 +1,7 @@ + ---- Completed parsing ---- -Value of the expression is: 1 +Value of the expression is: t + +Bye! -- GitLab