From e3081f35a4032949e2ca3b599edf50efc2e719d5 Mon Sep 17 00:00:00 2001 From: Partho Date: Tue, 6 May 2025 02:45:17 -0400 Subject: [PATCH] tweaking statement options --- src/grammar.h | 2 ++ src/grammar.y | 10 +++++++++- src/runner.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/grammar.h b/src/grammar.h index ec850a2..a4a9300 100644 --- a/src/grammar.h +++ b/src/grammar.h @@ -8,9 +8,11 @@ #include "../src/symbol_table.h" extern FILE *asc_flag; extern bool tc_flag; +extern bool entry_flag; extern void insert_code_line(char *error_message, int line_number); extern bool contains_errors; + typedef enum { ERROR_RUNTIME = 1, ERROR_SYNTAX = 2, diff --git a/src/grammar.y b/src/grammar.y index 3d7db57..4129d38 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -170,6 +170,10 @@ definition: } | ID { + if(strcmp($1, "entry") == 0){ + //seen entry function + entry_flag = true; + } emit_function_start(table_lookup(cur,$1)); //printf("ID: %s\n", $1); //printf("Type: %s\n", getType(table_lookup(getAncestor(cur), $1))); @@ -222,7 +226,7 @@ definition: } 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.");} } @@ -309,6 +313,7 @@ function_declaration: 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"); } + } else{ throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2); @@ -722,9 +727,12 @@ simple_statement: | RETURN expression { $$ = getTypeEntry((TableNode*)$2); emit_return(tn_or_const(NODE,(TableNode*)$2));} + + // | assignable ASSIGN RESERVE assignable{ } |simple_statement error {yyerrok; yyclearin; printdebug("error in simple statement");} + ; diff --git a/src/runner.h b/src/runner.h index 37c7bad..5736311 100644 --- a/src/runner.h +++ b/src/runner.h @@ -56,6 +56,7 @@ FILE *ir_flag = NULL; FILE *cg_flag = NULL; bool tc_flag = false; bool DEBUG = false; +bool entry_flag = false; int no_flag = 0; int arg; bool contains_errors = false;