started changing to pass up table nodes
This commit is contained in:
@ -47,15 +47,16 @@
|
|||||||
|
|
||||||
%union {
|
%union {
|
||||||
int integ;
|
int integ;
|
||||||
|
TableNode *tn;
|
||||||
char *words;
|
char *words;
|
||||||
}
|
}
|
||||||
|
|
||||||
%type <integ> idlist
|
%type <integ> idlist
|
||||||
%type <words> assignable
|
%type <tn> assignable
|
||||||
%type <words> expression
|
%type <tn> expression
|
||||||
%type <words> constant
|
%type <t > constant
|
||||||
%type <words> id_or_types
|
%type <tn> id_or_types
|
||||||
%type <words> types
|
%type <tn> types
|
||||||
%token <words> ID 101
|
%token <words> ID 101
|
||||||
%token <words> T_INTEGER 201
|
%token <words> T_INTEGER 201
|
||||||
%token <words> T_ADDRESS 202
|
%token <words> T_ADDRESS 202
|
||||||
@ -141,36 +142,36 @@ prototype:
|
|||||||
definition:
|
definition:
|
||||||
TYPE ID COLON
|
TYPE ID COLON
|
||||||
{
|
{
|
||||||
printdebug("Currently see a record definition for %s", $<words>2);
|
printdebug("Currently see a record definition for %s", $2);
|
||||||
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
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 ");
|
printdebug("rec not found ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dblock
|
dblock
|
||||||
{
|
{
|
||||||
setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur));
|
setRecSize(look_up(cur, $2), getRecSize(cur));
|
||||||
cur = getParent(cur);
|
cur = getParent(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
| TYPE ID COLON C_INTEGER ARROW id_or_types
|
| 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);
|
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, look_up(cur, $6)));
|
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, $6));
|
||||||
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, $6);
|
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName($6));
|
||||||
}
|
}
|
||||||
|
|
||||||
| function_declaration
|
| function_declaration
|
||||||
|
|
||||||
| TYPE ID COLON id_or_types ARROW id_or_types
|
| 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);
|
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(table_lookup(cur,$4),table_lookup(cur,$6)));
|
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo($4 ,$6));
|
||||||
}
|
}
|
||||||
|
|
||||||
| ID
|
| ID
|
||||||
{
|
{
|
||||||
TableNode *node = table_lookup(getAncestor(cur), $<words>1);
|
TableNode *node = table_lookup(getAncestor(cur), $1);
|
||||||
if (node == undefined) {
|
if (node == undefined) {
|
||||||
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
||||||
} else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
|
} else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
|
||||||
@ -184,11 +185,11 @@ definition:
|
|||||||
L_PAREN ID
|
L_PAREN ID
|
||||||
{
|
{
|
||||||
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s", $1,$4);
|
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), $<words>1)))), $<words>4, NULL);
|
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $4, NULL);
|
||||||
}
|
}
|
||||||
R_PAREN ASSIGN sblock
|
R_PAREN ASSIGN sblock
|
||||||
|
|
||||||
| ID
|
| ID //EVERYTHING UP UNTIL THIS POINT HAS BEEN CHECKED FOR $TN TYPES
|
||||||
{
|
{
|
||||||
TableNode *node = table_lookup(getAncestor(cur), $<words>1);
|
TableNode *node = table_lookup(getAncestor(cur), $<words>1);
|
||||||
if (node == undefined) {
|
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",
|
} 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_or_types:
|
||||||
ID
|
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
|
| types
|
||||||
@ -415,7 +417,6 @@ ablock:
|
|||||||
|
|
||||||
|
|
||||||
argument_list:
|
argument_list:
|
||||||
<<<<<<< HEAD
|
|
||||||
expression COMMA argument_list
|
expression COMMA argument_list
|
||||||
{
|
{
|
||||||
CreateEntry(cur, look_up(cur, $1), $1, NULL);
|
CreateEntry(cur, look_up(cur, $1), $1, NULL);
|
||||||
@ -587,8 +588,7 @@ expression:
|
|||||||
assignable:
|
assignable:
|
||||||
ID
|
ID
|
||||||
{
|
{
|
||||||
//$$ = $1;
|
$$ = look_up(cur,$1);
|
||||||
$$ = getType(look_up(cur,$1));
|
|
||||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);
|
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,37 +685,37 @@ memOp:
|
|||||||
constant:
|
constant:
|
||||||
C_STRING
|
C_STRING
|
||||||
{
|
{
|
||||||
$$ = $<words>1;
|
$$ = $1;
|
||||||
printdebug("string of C_STRING in constant is %s",$<words>1);
|
printdebug("string of C_STRING in constant is %s",$<words>1);
|
||||||
}
|
}
|
||||||
|
|
||||||
| C_INTEGER
|
| C_INTEGER
|
||||||
{
|
{
|
||||||
$$ = "integer";
|
$$ = integ;
|
||||||
printdebug("string of C_INTEGER in constant is integer");
|
printdebug("string of C_INTEGER in constant is integer");
|
||||||
}
|
}
|
||||||
|
|
||||||
| C_NULL
|
| C_NULL
|
||||||
{
|
{
|
||||||
$$ = $<words>1;
|
$$ = $1;
|
||||||
printdebug("string of C_NULL in constant is %s",$<words>1);
|
printdebug("string of C_NULL in constant is %s",$<words>1);
|
||||||
}
|
}
|
||||||
|
|
||||||
| C_CHARACTER
|
| C_CHARACTER
|
||||||
{
|
{
|
||||||
$$ = $<words>1;
|
$$ = $1;
|
||||||
printdebug("string of C_CHARACTER in constant is %s",$<words>1);
|
printdebug("string of C_CHARACTER in constant is %s",$<words>1);
|
||||||
}
|
}
|
||||||
|
|
||||||
| C_TRUE
|
| C_TRUE
|
||||||
{
|
{
|
||||||
$$ = $<words>1;
|
$$ = $1;
|
||||||
printdebug("string of C_TRUE in constant is %s",$<words>1);
|
printdebug("string of C_TRUE in constant is %s",$<words>1);
|
||||||
}
|
}
|
||||||
|
|
||||||
| C_FALSE
|
| C_FALSE
|
||||||
{
|
{
|
||||||
$$ = $<words>1;
|
$$ = $1;
|
||||||
printdebug("string of C_FALSE in constant is %s",$<words>1);
|
printdebug("string of C_FALSE in constant is %s",$<words>1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user