diff options
Diffstat (limited to 'src/parser.y')
| -rw-r--r-- | src/parser.y | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/src/parser.y b/src/parser.y index 719643d..e63935a 100644 --- a/src/parser.y +++ b/src/parser.y @@ -22,11 +22,12 @@ void yyerror(const char *s); %token <i_val> T_INTEGER %token <f_val> T_FLOAT %token <s_val> T_STRING -%token <symbol> T_LABEL +%token <symbol> T_SYMBOL %token <symbol> T_INSTRUCTION %token T_ENDL %token T_COMMA -%token T_IMMEDIATE +%token T_OPENPAREN +%token T_CLOSEPAREN %% asm: statements @@ -38,37 +39,48 @@ statements: ; statement: - instruction_one_param_symbol T_ENDL - | instruction_one_param_immediate T_ENDL - | instruction_two_param_symbols T_ENDL - | instruction_symbol_immediate T_ENDL - | instruction_immediate_symbol T_ENDL + instructions | T_ENDL ; -instruction_one_param_symbol: - T_INSTRUCTION T_LABEL { - printf("Found instruction %s(%s)\n", $1, $2); +instructions: + rb_type + | i_type + | s_type + | u_type + | j_type + ; + +rb_type: + T_INSTRUCTION T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_SYMBOL T_ENDL + { + printf("Read instruction: %s(%s, %s, %s)\n", $1, $2, $4, $6); }; -instruction_one_param_immediate: - T_INSTRUCTION T_IMMEDIATE T_INTEGER { - printf("Found instruction %s(%d)\n", $1, $3); +i_type: + T_INSTRUCTION T_SYMBOL T_COMMA T_SYMBOL T_COMMA T_INTEGER T_ENDL + { + printf("Read instruction: %s(%s, %s, %d)\n", $1, $2, $4, $6); }; -instruction_two_param_symbols: - T_INSTRUCTION T_LABEL T_COMMA T_LABEL { - printf("Found instruction %s(%s, %s)\n", $1, $2, $4); + +s_type: + T_INSTRUCTION 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); }; -instruction_symbol_immediate: - T_INSTRUCTION T_LABEL T_COMMA T_IMMEDIATE T_INTEGER { - printf("Found instruction %s(%s, %d)\n", $1, $2, $5); - } +u_type: + T_INSTRUCTION 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 + { + printf("Read instruction: %s(%s, %s)\n", $1, $2, $4); + }; -instruction_immediate_symbol: - T_INSTRUCTION T_IMMEDIATE T_INTEGER T_COMMA T_LABEL { - printf("Found instruction %s(%d, %s)\n", $1, $3, $5); - } %% void yyerror(const char *s) { |
