diff --git a/src/grammar.y b/src/grammar.y index cbb9ec1..33599a3 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -47,15 +47,16 @@ %union { int integ; - char * words; + TableNode *tn; + char *words; } %type idlist -%type assignable -%type expression -%type constant -%type id_or_types -%type types +%type assignable +%type expression +%type constant +%type id_or_types +%type types %token ID 101 %token T_INTEGER 201 %token T_ADDRESS 202 @@ -141,36 +142,36 @@ prototype: definition: TYPE ID COLON { - printdebug("Currently see a record definition for %s", $2); + printdebug("Currently see a record definition for %s", $2); tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0))); - if (table_lookup(getAncestor(cur), $2) == undefined) { + if (look_up(cur, $2) == undefined) { printdebug("rec not found "); } } dblock { - setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur)); + setRecSize(look_up(cur, $2), getRecSize(cur)); cur = getParent(cur); } | TYPE ID COLON C_INTEGER ARROW id_or_types { - printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, $6, $4); - CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6))); - printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, $6); + printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName($6), $4); + CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, $6)); + printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName($6)); } | function_declaration | TYPE ID COLON id_or_types ARROW id_or_types { - printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", $2, $4, $6); - CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6))); + printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", getName($2), getName($4), getName($6)); + CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo($4 ,$6)); } | ID { - TableNode *node = table_lookup(getAncestor(cur), $1); + TableNode *node = table_lookup(getAncestor(cur), $1); if (node == undefined) { printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column); } else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { @@ -184,11 +185,11 @@ definition: L_PAREN ID { printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s", $1,$4); - CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))), $4, NULL); + CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))), $4, NULL); } R_PAREN ASSIGN sblock - | ID + | ID //EVERYTHING UP UNTIL THIS POINT HAS BEEN CHECKED FOR $TN TYPES { TableNode *node = table_lookup(getAncestor(cur), $1); if (node == undefined) { @@ -236,7 +237,7 @@ definition: } } } idlist {printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d", - $1,$6);} R_PAREN ASSIGN sblock + $1,$6);} R_PAREN ASSIGN sblock //check sblock type ; @@ -343,7 +344,8 @@ declaration: id_or_types: ID { - printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); $$ = $1; + printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); + $$ = look_up(cur, $1); } | types @@ -415,7 +417,6 @@ ablock: argument_list: -<<<<<<< HEAD expression COMMA argument_list { CreateEntry(cur, look_up(cur, $1), $1, NULL); @@ -587,8 +588,7 @@ expression: assignable: ID { - //$$ = $1; - $$ = getType(look_up(cur,$1)); + $$ = look_up(cur,$1); printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1); } @@ -685,37 +685,37 @@ memOp: constant: C_STRING { - $$ = $1; + $$ = $1; printdebug("string of C_STRING in constant is %s",$1); } | C_INTEGER { - $$ = "integer"; + $$ = integ; printdebug("string of C_INTEGER in constant is integer"); } | C_NULL { - $$ = $1; + $$ = $1; printdebug("string of C_NULL in constant is %s",$1); } | C_CHARACTER { - $$ = $1; + $$ = $1; printdebug("string of C_CHARACTER in constant is %s",$1); } | C_TRUE { - $$ = $1; + $$ = $1; printdebug("string of C_TRUE in constant is %s",$1); } | C_FALSE { - $$ = $1; + $$ = $1; printdebug("string of C_FALSE in constant is %s",$1); }