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.

Commit 05d08b00 authored by Hogan's avatar Hogan

Added value to symbol table but not done correctly(need help with that)

parent 541d123b
......@@ -7,12 +7,14 @@ using namespace std;
#define UNDEFINED -1
typedef struct
{
{
//value can be int, bool or str not sure how to do this correctly
int value; //place holder
// one of the above type codes
int type;
// numParams and returnType only applicable if type == FUNCTION
int numParams;
int numParams;
int returnType;
// operatorType is only applicable if production is an operator
......
......@@ -102,19 +102,23 @@ N_START : // epsilon
break;
}
*/
cout << "\nValue of the expression is: \n";
cout << "\nValue of the expression is: ";
cout << $2.value<<"\n";
cout << "---- Completed parsing ----\n" << endl;
}
;
N_EXPR : N_CONST
{
//resulting type is the type of N_CONST
//value is the value of N_CONST
$$.type=$1.type;
$$.numParams=NOT_APPLICABLE;
$$.returnType=NOT_APPLICABLE;
$$.value=$1.value;
}
| T_IDENT
{
//look up T_IDENT in symbol table
string lexeme = string($1);
if(!findEntryInAnyScope(lexeme)){
yyerror("Undefined identifier");
......@@ -125,6 +129,7 @@ N_EXPR : N_CONST
}
| T_LPAREN N_PARENTHESIZED_EXPR T_RPAREN
{
//resulting value is the value of the N_PARENTHESIZED_EXPR
//resulting type is the resulting type of the parenthesized expr
$$.type=$2.type;
$$.numParams=$2.numParams;
......@@ -133,6 +138,7 @@ N_EXPR : N_CONST
;
N_CONST : T_INTCONST
{
//value is the value of the T_INTCONST
//type is int
$$.type=INT;
$$.numParams=NOT_APPLICABLE;
......@@ -140,6 +146,7 @@ N_CONST : T_INTCONST
}
| T_STRCONST
{
//value is the value of the T_STRCONST
//type is string
$$.type=STR;
$$.numParams=NOT_APPLICABLE;
......@@ -147,6 +154,7 @@ N_CONST : T_INTCONST
}
| T_T
{
//Be careful with choosing the const value for these
//type is bool
$$.type=BOOL;
$$.numParams=NOT_APPLICABLE;
......@@ -154,6 +162,7 @@ N_CONST : T_INTCONST
}
| T_NIL
{
//Be careful with choosing the const value for these
//type is bool
$$.type=BOOL;
$$.numParams=NOT_APPLICABLE;
......@@ -161,8 +170,10 @@ N_CONST : T_INTCONST
}
;
N_PARENTHESIZED_EXPR : N_ARITHLOGIC_EXPR
{
//check for divison by 0
//resulting type of whatever rule is applied
{
$$.type=$1.type;
$$.numParams=$1.numParams;
$$.returnType=$1.returnType;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment