From efb0a239c4aaee370d97caf216859a724d7f72bd Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Sun, 15 Mar 2026 20:03:26 -0400 Subject: feat: Parsing modifiers and directives Support added for parsing a limited set of directives and for all access modifiers. --- src/parser.y | 80 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 16 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index e63935a..5f7b4bb 100644 --- a/src/parser.y +++ b/src/parser.y @@ -14,20 +14,22 @@ void yyerror(const char *s); %union { int i_val; - float f_val; char *s_val; char *symbol; + char *modifier; + char *directive; } -%token T_INTEGER -%token T_FLOAT -%token T_STRING -%token T_SYMBOL -%token T_INSTRUCTION -%token T_ENDL -%token T_COMMA -%token T_OPENPAREN -%token T_CLOSEPAREN +%token T_INTEGER +%token T_STRING +%token T_SYMBOL +%token T_DIRECTIVE +%token T_LABEL +%token T_MODIFIER +%token T_ENDL +%token T_COMMA +%token T_OPENPAREN +%token T_CLOSEPAREN %% asm: statements @@ -39,48 +41,94 @@ statements: ; statement: - instructions + label + | directives + | instructions | T_ENDL ; +label: + T_LABEL T_ENDL + { + printf("Found Label: %s\n", $1); + }; + instructions: rb_type | i_type | s_type | u_type | j_type + | i_type_modifier + | s_type_modifier + | pseudo_type ; rb_type: - T_INSTRUCTION T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_SYMBOL T_ENDL + T_SYMBOL T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_SYMBOL T_ENDL { printf("Read instruction: %s(%s, %s, %s)\n", $1, $2, $4, $6); }; i_type: - T_INSTRUCTION T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_INTEGER T_ENDL + T_SYMBOL T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_INTEGER T_ENDL { printf("Read instruction: %s(%s, %s, %d)\n", $1, $2, $4, $6); }; +i_type_modifier: + T_SYMBOL T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_MODIFIER T_OPENPAREN T_SYMBOL T_CLOSEPAREN T_ENDL + { + printf("Read instruction: %s(%s, %s, %s of %s)\n", $1, $2, $4, $6, $8); + }; + s_type: - T_INSTRUCTION T_SYMBOL T_COMMA T_INTEGER T_OPENPAREN T_SYMBOL T_CLOSEPAREN T_ENDL + T_SYMBOL T_SYMBOL T_COMMA T_INTEGER T_OPENPAREN T_SYMBOL T_CLOSEPAREN T_ENDL { printf("Read instruction: %s(%s, %s + %d)\n", $1, $2, $6, $4); }; +s_type_modifier: + T_SYMBOL T_SYMBOL T_COMMA T_MODIFIER T_OPENPAREN T_SYMBOL T_CLOSEPAREN T_ENDL + { + printf("Read instruction: %s(%s, %s of %s)\n", $1, $2, $4, $6); + }; + u_type: - T_INSTRUCTION T_SYMBOL T_COMMA T_INTEGER T_ENDL + T_SYMBOL T_SYMBOL T_COMMA T_INTEGER T_ENDL { printf("Read instruction: %s(%s, %d)\n", $1, $2, $4); }; j_type: - T_INSTRUCTION T_SYMBOL T_COMMA T_SYMBOL T_ENDL + T_SYMBOL T_SYMBOL T_COMMA T_SYMBOL T_ENDL { printf("Read instruction: %s(%s, %s)\n", $1, $2, $4); }; +pseudo_type: + T_SYMBOL T_SYMBOL T_ENDL + { + printf("Read Pseudo Instruction: %s(%s)\n", $1, $2); + }; + +directives: + directive_int + | directive_string + ; + +directive_int: + T_DIRECTIVE T_INTEGER T_ENDL + { + printf("Read directive %s %d\n", $1, $2); + }; + +directive_string: + T_DIRECTIVE T_STRING T_ENDL + { + printf("Read directive %s %s\n", $1, $2); + }; + %% void yyerror(const char *s) { -- cgit v1.2.3