tweaking statement options

This commit is contained in:
Partho
2025-05-06 02:45:17 -04:00
parent cab30dc2c5
commit e3081f35a4
3 changed files with 12 additions and 1 deletions

View File

@ -8,9 +8,11 @@
#include "../src/symbol_table.h" #include "../src/symbol_table.h"
extern FILE *asc_flag; extern FILE *asc_flag;
extern bool tc_flag; extern bool tc_flag;
extern bool entry_flag;
extern void insert_code_line(char *error_message, int line_number); extern void insert_code_line(char *error_message, int line_number);
extern bool contains_errors; extern bool contains_errors;
typedef enum { typedef enum {
ERROR_RUNTIME = 1, ERROR_RUNTIME = 1,
ERROR_SYNTAX = 2, ERROR_SYNTAX = 2,

View File

@ -170,6 +170,10 @@ definition:
} }
| ID { | ID {
if(strcmp($1, "entry") == 0){
//seen entry function
entry_flag = true;
}
emit_function_start(table_lookup(cur,$1)); emit_function_start(table_lookup(cur,$1));
//printf("ID: %s\n", $1); //printf("ID: %s\n", $1);
//printf("Type: %s\n", getType(table_lookup(getAncestor(cur), $1))); //printf("Type: %s\n", getType(table_lookup(getAncestor(cur), $1)));
@ -222,7 +226,7 @@ definition:
} }
if(type_of_param_type == TYPE_PRIMITIVE_TYPE){ if(type_of_param_type == TYPE_PRIMITIVE_TYPE){
CreateEntry(cur, TYPE_PRIMITIVE, parameter,NULL, getAdInfo(parameter))==undefined; CreateEntry(cur, TYPE_PRIMITIVE, parameter,NULL, getAdInfo(parameter));//==undefined;
// throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");} // throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");}
} }
@ -309,6 +313,7 @@ function_declaration:
if (CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL)) == undefined) { if (CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false,NULL)) == undefined) {
throw_error(ERROR_TYPE, "Duplicate defination of function in function declaration"); throw_error(ERROR_TYPE, "Duplicate defination of function in function declaration");
} }
} }
else{ else{
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2); throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2);
@ -722,9 +727,12 @@ simple_statement:
| RETURN expression { | RETURN expression {
$$ = getTypeEntry((TableNode*)$2); $$ = getTypeEntry((TableNode*)$2);
emit_return(tn_or_const(NODE,(TableNode*)$2));} emit_return(tn_or_const(NODE,(TableNode*)$2));}
// | assignable ASSIGN RESERVE assignable{ }
|simple_statement error {yyerrok; yyclearin; printdebug("error in simple statement");} |simple_statement error {yyerrok; yyclearin; printdebug("error in simple statement");}
; ;

View File

@ -56,6 +56,7 @@ FILE *ir_flag = NULL;
FILE *cg_flag = NULL; FILE *cg_flag = NULL;
bool tc_flag = false; bool tc_flag = false;
bool DEBUG = false; bool DEBUG = false;
bool entry_flag = false;
int no_flag = 0; int no_flag = 0;
int arg; int arg;
bool contains_errors = false; bool contains_errors = false;