This server is intended for use for Academic Classwork related Git repositories only. Projects/repositories will generally be removed after 6 months following close of the semester. Inactive repositories from previous semester are now being archived when no activity for 365 days. They are renamed and marked as 'archived'. After 90 days in that state they will be removed from the system completely.

...
 
Commits (2)
......@@ -63,6 +63,10 @@ public:
else return(true);
}
SYMBOL_TABLE_ENTRY getEntry(string key){
return hashTable.find(key)->second;
}
};
#endif // SYMBOL_TABLE_H
......@@ -5,6 +5,7 @@
#include <iostream>
#include <string>
#include <stack>
#include <stdexcept>
#include "SymbolTable.h"
using namespace std;
......@@ -18,6 +19,7 @@ void cleanUp();
void prepareToTerminate();
void bail();
bool findEntryInAnyScope(const string theName);
SYMBOL_TABLE_ENTRY getEntryInAnyScope(const string key);
void printToken(const char* tokenType, char* lexeme);
......@@ -98,7 +100,7 @@ N_START : // epsilon
cout<<"STR_OR_BOOL"<<"\n";
break;
case 7:
cout<<"INT_STR_OR_BOOL"<<"\n";
cout<<"INT_OR_STR_OR_BOOL"<<"\n";
break;
}
}
......@@ -116,6 +118,8 @@ N_EXPR : N_CONST
yyerror("Undefined identifier");
//resulting type is the type of the identifier
//look up in the symbol table
SYMBOL_TABLE_ENTRY var = getEntryInAnyScope($1.text);
$$.type = var.getTypeCode();
}
| T_LPAREN N_PARENTHESIZED_EXPR T_RPAREN
......@@ -240,6 +244,7 @@ N_ARITHLOGIC_EXPR : N_UN_OP N_EXPR
}
| N_BIN_OP N_EXPR N_EXPR
{
//check if operation can be preformed
}
;
......@@ -297,15 +302,15 @@ N_ID_LIST : /* epsilon */
{
}
| N_ID_LIST T_IDENT
| N_ID_LIST T_IDENT
{
string lexeme = string($2.text);
printf("___Adding %s to symbol table\n", $2);
bool success = scopeStack.top().addEntry(SYMBOL_TABLE_ENTRY(lexeme,UNDEFINED));
if (! success)
yyerror("Multiply defined identifier");
$2.type=INT_OR_STR_OR_BOOL;
printf("___Adding %s to symbol table\n", $2);
bool success = scopeStack.top().addEntry(SYMBOL_TABLE_ENTRY(lexeme,UNDEFINED));
if (! success)
yyerror("Multiply defined identifier");
$2.type=INT_OR_STR_OR_BOOL;
}
;
N_PRINT_EXPR : T_PRINT N_EXPR
......@@ -329,7 +334,7 @@ N_EXPR_LIST : N_EXPR N_EXPR_LIST
$$.type=$1.type;
}
;
N_BIN_OP : N_ARITH_OP
N_BIN_OP : N_ARITH_OP
{
}
......@@ -342,10 +347,10 @@ N_BIN_OP : N_ARITH_OP
{
}
;
N_ARITH_OP : T_ADD
N_ARITH_OP : T_ADD
{
}
| T_SUB
| T_SUB
{
}
| T_MULT
......@@ -429,6 +434,18 @@ bool findEntryInAnyScope(const string theName)
}
}
SYMBOL_TABLE_ENTRY getEntryInAnyScope(const string key){
if(scopeStack.empty()){
// Shouldn't ever get here
yyerror("Undefined identifier");
} else if(scopeStack.top().findEntry(key)){
return scopeStack.top().getEntry(key);
} else {
return getEntryInAnyScope(key);
}
}
void cleanUp()
{
if (scopeStack.empty())
......