summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2026-03-14 20:45:12 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2026-03-14 20:45:12 -0400
commit68b9f87bc3b6bd6ccb3773641578b0d914e61104 (patch)
tree89d2851472d7331337e1a5e10bdc2e4634925b48 /src
parent0c81ee06d19d1d7f67dab3c2c9da268b0c55e3c0 (diff)
refactor!: Switched from x86_64 to RISC-V
Switched from x86_64 to RISC-V because RISC-V is a cleaner and simpler architecture and I'm more familiar with it since it's similar to MIPS. BREAKING CHANGE: Switched from x86_64 to RISC-V
Diffstat (limited to 'src')
-rw-r--r--src/lexer.l6
-rw-r--r--src/parser.y60
2 files changed, 40 insertions, 26 deletions
diff --git a/src/lexer.l b/src/lexer.l
index 46f6bc6..26be828 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -8,7 +8,7 @@ extern size_t line_number;
%option noyywrap
%%
^[a-zA-Z]+ { yylval.symbol = strdup(yytext); return T_INSTRUCTION; }
-%*[a-zA-Z\_\-]+[a-zA-Z0-9\_\-]* { yylval.symbol = strdup(yytext); return T_LABEL; }
+%*[a-zA-Z\_\-]+[a-zA-Z0-9\_\-]* { yylval.symbol = strdup(yytext); return T_SYMBOL; }
0x[0-9A-Fa-f]+ { yylval.i_val = atoi(yytext); return T_INTEGER; }
[0-9]+ { yylval.i_val = atoi(yytext); return T_INTEGER; }
-*[0-9]*\.*[0-9]* { yylval.i_val = atof(yytext); return T_FLOAT; }
@@ -21,7 +21,9 @@ extern size_t line_number;
return T_STRING;
}
, { return T_COMMA; }
-\$ { return T_IMMEDIATE; }
+\( { return T_OPENPAREN; }
+\) { return T_CLOSEPAREN; }
+#.* ;
[ \t] ;
\n { ++line_number; return T_ENDL; }
. ;
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) {