added more helper functions
This commit is contained in:
@ -145,7 +145,8 @@ idlist:
|
|||||||
|
|
||||||
sblock:
|
sblock:
|
||||||
L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
|
L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
|
||||||
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock {printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE
|
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);}
|
||||||
|
dblock {printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE
|
||||||
;
|
;
|
||||||
|
|
||||||
dblock:
|
dblock:
|
||||||
@ -157,10 +158,7 @@ declaration_list:
|
|||||||
;
|
;
|
||||||
|
|
||||||
declaration:
|
declaration:
|
||||||
id_or_types COLON ID {
|
id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL);}
|
||||||
TableNode* type = table_lookup(getAncestor(cur), $<words>1);
|
|
||||||
AdInfo* info = NULL;
|
|
||||||
id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
id_or_types:
|
id_or_types:
|
||||||
@ -202,46 +200,49 @@ expression:
|
|||||||
$$=strdup("undefined");}else{$$=$2;}}
|
$$=strdup("undefined");}else{$$=$2;}}
|
||||||
| NOT expression {printf("not expression\n"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined");
|
| NOT expression {printf("not expression\n"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined");
|
||||||
printf("mismatch at line %d and column %d\n",@1.first_line,@1.first_column);}}
|
printf("mismatch at line %d and column %d\n",@1.first_line,@1.first_column);}}
|
||||||
| expression ADD expression {printf("add expression\n");}
|
| expression ADD expression
|
||||||
{printf("less than expression\n");
|
{printf("add expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression SUB_OR_NEG expression {printf("subtract expression\n");}
|
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");
|
| expression SUB_OR_NEG expression
|
||||||
|
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression MUL expression {printf("multiply expression\n");}
|
| expression MUL expression
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");
|
{printf("multiply expression\n");
|
||||||
|
printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression DIV expression {printf("division expression\n");}
|
| expression DIV expression
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression REM expression {printf("remainder expression\n");}
|
| expression REM expression
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
|
|
||||||
| expression AND expression {printf("and expression\n");}
|
| expression AND expression
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
|
|
||||||
| expression OR expression {printf("or expression\n");}
|
| expression OR expression
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 &&
|
{printf("less than expression\n");if(strcmp($1,$3)==0 &&
|
||||||
strcmp($1,"integer")==0){$$=strdup("Boolean");
|
strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
|
|
||||||
| expression LESS_THAN expression
|
| expression LESS_THAN expression
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 &&
|
{printf("less than expression\n");if(strcmp($1,$3)==0 &&
|
||||||
strcmp($1,"integer")==0){$$=strdup("Boolean");
|
strcmp($1,"integer")==0){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
|
|
||||||
| expression EQUAL_TO expression {printf("equals check expression\n");
|
| expression EQUAL_TO expression {printf("equals check expression\n");
|
||||||
if(strcmp($1,$3)==0){$$=strdup("Boolean");}else if((strcmp($1,"array")==0||strcmp($1,"record")==0||
|
if(strcmp($1,$3)==0){$$=strdup("Boolean");}
|
||||||
|
else if((strcmp($1,"array")==0||strcmp($1,"record")==0||
|
||||||
strcmp($1,"function type primitive")==0) && (strcmp($3,"address")==0)){$$=strdup("Boolean");}
|
strcmp($1,"function type primitive")==0) && (strcmp($3,"address")==0)){$$=strdup("Boolean");}
|
||||||
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);$$=strdup("undefined");}}
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);$$=strdup("undefined");}}
|
||||||
| assignable {printf("assignable expression\n");$$=$1;}
|
| assignable {printf("assignable expression\n");$$=$1;}
|
||||||
|
@ -72,7 +72,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|||||||
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}}
|
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}}
|
||||||
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}}
|
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}}
|
||||||
|
|
||||||
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);yylval.integ = atoi(yytex)/*words = strdup("integer")*/;return C_INTEGER;}}
|
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);yylval.integ = atoi(yytext)/*words = strdup("integer")*/;return C_INTEGER;}}
|
||||||
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);yylval.words = strdup("character");return C_CHARACTER;}}
|
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);yylval.words = strdup("character");return C_CHARACTER;}}
|
||||||
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);yylval.words = strdup("string");return C_STRING;}}
|
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);yylval.words = strdup("string");return C_STRING;}}
|
||||||
{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}}
|
{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}}
|
||||||
|
@ -145,7 +145,6 @@ int getNumArrDim(TableNode *definition) {
|
|||||||
printf("passed an NULL entry to getNumArrDim function. Invalid.\n");
|
printf("passed an NULL entry to getNumArrDim function. Invalid.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(
|
|
||||||
if (strcmp(getType(definition), "array") != 0) {
|
if (strcmp(getType(definition), "array") != 0) {
|
||||||
printf("not checking the dim of an array -- invalid op\n");
|
printf("not checking the dim of an array -- invalid op\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -236,6 +235,15 @@ int getStartLine(TableNode *definition) {
|
|||||||
}
|
}
|
||||||
return definition->additionalinfo->FunDecAdInfo->startlinenumber;
|
return definition->additionalinfo->FunDecAdInfo->startlinenumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TableNode* setStartLine(TableNode* tn, int start){
|
||||||
|
if(tn == NULL){
|
||||||
|
printf("passing in a NULL entry to setStartLine. invalid\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
tn->additionalinfo->FunDecAdInfo->startlinenumber = start;
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
// checks if "as" keyword was used for function definition. Either 0 or 1 for
|
// checks if "as" keyword was used for function definition. Either 0 or 1 for
|
||||||
// not used or used.
|
// not used or used.
|
||||||
bool getAsKeyword(TableNode *definition) {
|
bool getAsKeyword(TableNode *definition) {
|
||||||
@ -246,6 +254,16 @@ bool getAsKeyword(TableNode *definition) {
|
|||||||
}
|
}
|
||||||
return definition->additionalinfo->FunDecAdInfo->regularoras;
|
return definition->additionalinfo->FunDecAdInfo->regularoras;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TableNode* setAsKeyword(TableNode* tn, bool as){
|
||||||
|
if(tn == NULL){
|
||||||
|
printf("passing in a NULL entry to setAsKeyword. invalid\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
tn->additionalinfo->FunDecAdInfo->regularoras = as;
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
|
|
||||||
// stores the type of a function (parameter type and return type)
|
// stores the type of a function (parameter type and return type)
|
||||||
AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
|
AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
|
||||||
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
||||||
|
Reference in New Issue
Block a user