← Back to Pull requests

feat: implement lexer functionality and file reading #1

Merged
Ma7moudEGY merged 8 files (430 lines) on Oct 30, 2026 23:08 UTC
View on GitHub
Ma7moudEGY Ma7moudEGY commented on Oct 24, 2026 22:05 UTC
Author

No description provided by author.

Diff: 430 lines (+426 / -4) across 8 files Reviewer: hulxv Review duration: 8702m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.56) × (1 − Review Confidence (0.70)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.56 · 430 lines diff across 8 files
0.56
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.50 · 5 substantive comment(s)
0.50
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
70%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.363
Empty Description empty_description
0.060
Real PR Conversation Timeline
16 items
copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 24, 2026 22:05 UTC
Reviewer

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

hulxv hulxv commented on code on Oct 27, 2026 15:47 UTC
Code Review
mips-asm/src/lexer.c:1
@@ -1,3 +1,307 @@
 #include "lexer.h"
+#include "stdio.h"
+#include <string.h>
+#include <ctype.h>
 
-// todo: implement the lexer here
+int lines_counter = 1;
+bool inc_lines_counter = false;
+
+int isbinary(int c) {
+    return c == '1' || c == '0';
+}
+
+TokenState* init_token_state(int start, int end, int line) {
+    TokenState* state = calloc(1 , sizeof(TokenState));
+    state->start_index = start;
+    state->end_index = end  ;
+    state->line_index = line;
+
+    return state;
+}
+
+Token* init_token(char* value, int type, TokenState* state) {
+    Token* token = calloc(1, sizeof(Token));
+    token->value = value;
+    token->type = type;
+
+    if (state != NULL) 
+        token->state = state;
+
+    return token;
+}
+
+static const char* token_type_to_str(int type) {
+    switch (type) {
+        case TOKEN_IDENTIFIER: return "TOKEN_ID";
+        case TOKEN_LABEL_DEF: return "TOKEN_LABLE";
+        case TOKEN_REGISTER: return "TOKEN_REGISTER";
+        case TOKEN_IMMEDIATE: return "TOKEN_IMMEDIATE";
+        case TOKEN_STRING: return "TOKEN_STRING";
+        case TOKEN_DIRECTIVE: return "TOKEN_DIRECTIVE";
+        case TOKEN_COMMA: return "TOKEN_COMMA";
+        case TOKEN_LPAREN: return "TOKEN_LPAREN";
+        case TOKEN_RPAREN: return "TOKEN_RPAREN";
+        case TOKEN_EOF: return "TOKEN_EOF";
+        case TOKEN_NEW_LINE: return "TOKEN_NEW_LINE";
+    }
+
+    return "not_stringable";
+}
+
+char* token_to_str(Token* token) {
+    const char* type_str = token_type_to_str(token->type);
+    const char* template = "<type=`%s`, int_type=`%d`, value=`%s`, start=`%d', end=`%d`, line=`%d`>\n";

    const char* template = "<type=`%s`, int_type=`%d`, value=`%s`, start=`%d', end=`%d`, line=`%d`>";

hulxv hulxv commented on code on Oct 27, 2026 15:52 UTC
Code Review
mips-asm/src/lexer.c:1
@@ -1,3 +1,307 @@
 #include "lexer.h"
+#include "stdio.h"
+#include <string.h>
+#include <ctype.h>
 
-// todo: implement the lexer here
+int lines_counter = 1;
+bool inc_lines_counter = false;
+
+int isbinary(int c) {
+    return c == '1' || c == '0';
+}
+
+TokenState* init_token_state(int start, int end, int line) {
+    TokenState* state = calloc(1 , sizeof(TokenState));
+    state->start_index = start;
+    state->end_index = end  ;
+    state->line_index = line;
+
+    return state;
+}
+
+Token* init_token(char* value, int type, TokenState* state) {
+    Token* token = calloc(1, sizeof(Token));
+    token->value = value;
+    token->type = type;
+
+    if (state != NULL) 
+        token->state = state;
+
+    return token;
+}
+
+static const char* token_type_to_str(int type) {
+    switch (type) {
+        case TOKEN_IDENTIFIER: return "TOKEN_ID";
+        case TOKEN_LABEL_DEF: return "TOKEN_LABLE";
+        case TOKEN_REGISTER: return "TOKEN_REGISTER";
+        case TOKEN_IMMEDIATE: return "TOKEN_IMMEDIATE";
+        case TOKEN_STRING: return "TOKEN_STRING";
+        case TOKEN_DIRECTIVE: return "TOKEN_DIRECTIVE";
+        case TOKEN_COMMA: return "TOKEN_COMMA";
+        case TOKEN_LPAREN: return "TOKEN_LPAREN";
+        case TOKEN_RPAREN: return "TOKEN_RPAREN";
+        case TOKEN_EOF: return "TOKEN_EOF";
+        case TOKEN_NEW_LINE: return "TOKEN_NEW_LINE";
+    }
+
+    return "not_stringable";
+}
+
+char* token_to_str(Token* token) {
+    const char* type_str = token_type_to_str(token->type);
+    const char* template = "<type=`%s`, int_type=`%d`, value=`%s`, start=`%d', end=`%d`, line=`%d`>\n";
+
+    char* str = calloc(strlen(type_str) + strlen(template) + 24, sizeof(char));

why plus 24? there's a way to calculate the required size. i think your way may cause issues

something like that:

    size_t len = snprintf (NULL, len, template, type_str, token->type, token->value, token->state->start_index, token->state->end_index, token->state->line_index);

source: https://stackoverflow.com/a/29763828

hulxv hulxv commented on code on Oct 27, 2026 16:01 UTC
Code Review
mips-asm/src/lexer.c:1
@@ -1,3 +1,307 @@
 #include "lexer.h"
+#include "stdio.h"
+#include <string.h>
+#include <ctype.h>
 
-// todo: implement the lexer here
+int lines_counter = 1;
+bool inc_lines_counter = false;
+
+int isbinary(int c) {
+    return c == '1' || c == '0';
+}
+
+TokenState* init_token_state(int start, int end, int line) {
+    TokenState* state = calloc(1 , sizeof(TokenState));
+    state->start_index = start;
+    state->end_index = end  ;
+    state->line_index = line;
+
+    return state;
+}
+
+Token* init_token(char* value, int type, TokenState* state) {
+    Token* token = calloc(1, sizeof(Token));
+    token->value = value;
+    token->type = type;
+
+    if (state != NULL) 
+        token->state = state;
+
+    return token;
+}
+
+static const char* token_type_to_str(int type) {
+    switch (type) {
+        case TOKEN_IDENTIFIER: return "TOKEN_ID";
+        case TOKEN_LABEL_DEF: return "TOKEN_LABLE";
+        case TOKEN_REGISTER: return "TOKEN_REGISTER";
+        case TOKEN_IMMEDIATE: return "TOKEN_IMMEDIATE";
+        case TOKEN_STRING: return "TOKEN_STRING";
+        case TOKEN_DIRECTIVE: return "TOKEN_DIRECTIVE";
+        case TOKEN_COMMA: return "TOKEN_COMMA";
+        case TOKEN_LPAREN: return "TOKEN_LPAREN";
+        case TOKEN_RPAREN: return "TOKEN_RPAREN";
+        case TOKEN_EOF: return "TOKEN_EOF";
+        case TOKEN_NEW_LINE: return "TOKEN_NEW_LINE";
+    }
+
+    return "not_stringable";
+}
+
+char* token_to_str(Token* token) {
+    const char* type_str = token_type_to_str(token->type);
+    const char* template = "<type=`%s`, int_type=`%d`, value=`%s`, start=`%d', end=`%d`, line=`%d`>\n";
+
+    char* str = calloc(strlen(type_str) + strlen(template) + 24, sizeof(char));
+    sprintf(str, template, type_str, token->type, token->value, token->state->start_index, token->state->end_index, token->state->line_index);
+
+    return str;
+}
+
+Lexer* init_lexer(const char* src) {
+    Lexer* lexer = calloc(1, sizeof(Lexer));
+    lexer->src = src;
+    lexer->src_size = strlen(src);
+    lexer->i = 0;
+    lexer->c = src[lexer->i];
+
+    return lexer;
+}
+
+void lexer_next(Lexer* lexer) {
+    if (lexer->i < lexer->src_size && lexer->c != '\0') {
+        lexer->i += 1;
+        lexer->c = lexer->src[lexer->i];
+    }
+}
+
+char lexer_peek(Lexer* lexer, int offset) {
+    return lexer->src[lexer->i + offset];
+}
+
+void lexer_skip_whitespace(Lexer* lexer) {
+    while (lexer->c == ' ' || lexer->c == '\t' || lexer->c == '\r') {
+        lexer_next(lexer);
+    }
+}
+
+Token* lexer_parse_id(Lexer* lexer) {
+    char* value = calloc(1, sizeof(char));
+    int start = lexer->i;
+
+    while (isalpha(lexer->c)) {
+        size_t len = strlen(value);
+        value = realloc(value, len + 2);
+
+        value[len] = lexer->c;
+        value[len + 1] = '\0';
+
+        lexer_next(lexer);
+    }
+
+    if (lexer->c == ':') {
+        size_t len = strlen(value);
+        value = realloc(value, len + 2);
+
+        value[len] = lexer->c;
+        value[len + 1] = '\0';
+        
+        lexer_next(lexer);
+
+        int end = lexer->i-1;
+        TokenState* state = init_token_state(start, end, lines_counter);
+
+        return init_token(value, TOKEN_LABEL_DEF, state);
+    } 
+        
+    int end = lexer->i-1;
+    TokenState* state = init_token_state(start, end, lines_counter);
+
+    return init_token(value, TOKEN_IDENTIFIER, state);
+}
+
+Token* lexer_parse_number(Lexer* lexer) {
+    char* value = calloc(1, sizeof(char));

instead of repeating using value and realloc it, we can use the index in the lexer directly. wtdy? i am not sure if it's necessary, but it also adds more complexity

hulxv hulxv commented on code on Oct 27, 2026 16:02 UTC
Code Review
mips-asm/src/lexer.c:1
@@ -1,3 +1,307 @@
 #include "lexer.h"
+#include "stdio.h"
+#include <string.h>
+#include <ctype.h>
 
-// todo: implement the lexer here
+int lines_counter = 1;
+bool inc_lines_counter = false;
+
+int isbinary(int c) {
+    return c == '1' || c == '0';
+}
+
+TokenState* init_token_state(int start, int end, int line) {
+    TokenState* state = calloc(1 , sizeof(TokenState));
+    state->start_index = start;
+    state->end_index = end  ;
+    state->line_index = line;
+
+    return state;
+}
+
+Token* init_token(char* value, int type, TokenState* state) {
+    Token* token = calloc(1, sizeof(Token));
+    token->value = value;
+    token->type = type;
+
+    if (state != NULL) 
+        token->state = state;
+
+    return token;
+}
+
+static const char* token_type_to_str(int type) {
+    switch (type) {
+        case TOKEN_IDENTIFIER: return "TOKEN_ID";
+        case TOKEN_LABEL_DEF: return "TOKEN_LABLE";
+        case TOKEN_REGISTER: return "TOKEN_REGISTER";
+        case TOKEN_IMMEDIATE: return "TOKEN_IMMEDIATE";
+        case TOKEN_STRING: return "TOKEN_STRING";
+        case TOKEN_DIRECTIVE: return "TOKEN_DIRECTIVE";
+        case TOKEN_COMMA: return "TOKEN_COMMA";
+        case TOKEN_LPAREN: return "TOKEN_LPAREN";
+        case TOKEN_RPAREN: return "TOKEN_RPAREN";
+        case TOKEN_EOF: return "TOKEN_EOF";
+        case TOKEN_NEW_LINE: return "TOKEN_NEW_LINE";
+    }
+
+    return "not_stringable";
+}
+
+char* token_to_str(Token* token) {
+    const char* type_str = token_type_to_str(token->type);
+    const char* template = "<type=`%s`, int_type=`%d`, value=`%s`, start=`%d', end=`%d`, line=`%d`>\n";
+
+    char* str = calloc(strlen(type_str) + strlen(template) + 24, sizeof(char));
+    sprintf(str, template, type_str, token->type, token->value, token->state->start_index, token->state->end_index, token->state->line_index);
+
+    return str;
+}
+
+Lexer* init_lexer(const char* src) {
+    Lexer* lexer = calloc(1, sizeof(Lexer));
+    lexer->src = src;
+    lexer->src_size = strlen(src);
+    lexer->i = 0;
+    lexer->c = src[lexer->i];
+
+    return lexer;
+}
+
+void lexer_next(Lexer* lexer) {
+    if (lexer->i < lexer->src_size && lexer->c != '\0') {
+        lexer->i += 1;
+        lexer->c = lexer->src[lexer->i];
+    }
+}
+
+char lexer_peek(Lexer* lexer, int offset) {
+    return lexer->src[lexer->i + offset];
+}
+
+void lexer_skip_whitespace(Lexer* lexer) {
+    while (lexer->c == ' ' || lexer->c == '\t' || lexer->c == '\r') {
+        lexer_next(lexer);
+    }
+}
+
+Token* lexer_parse_id(Lexer* lexer) {
+    char* value = calloc(1, sizeof(char));
+    int start = lexer->i;
+
+    while (isalpha(lexer->c)) {
+        size_t len = strlen(value);
+        value = realloc(value, len + 2);
+
+        value[len] = lexer->c;
+        value[len + 1] = '\0';
+
+        lexer_next(lexer);
+    }
+
+    if (lexer->c == ':') {
+        size_t len = strlen(value);
+        value = realloc(value, len + 2);
+
+        value[len] = lexer->c;
+        value[len + 1] = '\0';
+        
+        lexer_next(lexer);
+
+        int end = lexer->i-1;
+        TokenState* state = init_token_state(start, end, lines_counter);
+
+        return init_token(value, TOKEN_LABEL_DEF, state);
+    } 
+        
+    int end = lexer->i-1;
+    TokenState* state = init_token_state(start, end, lines_counter);
+
+    return init_token(value, TOKEN_IDENTIFIER, state);
+}
+
+Token* lexer_parse_number(Lexer* lexer) {
+    char* value = calloc(1, sizeof(char));
+    int start = lexer->i;
+    int (*func)(int) = isdigit;
+
+    if (lexer->c == '0') {
+        value[0] = lexer->c;
+        lexer_next(lexer);
+
+        if (lexer->c == 'x') {
+            size_t len = strlen(value);
+            value = realloc(value, len + 2);
+        
+            value[len] = lexer->c;
+            value[len + 1] = '\0';
+
+            func = isxdigit;
+
+            lexer_next(lexer);
+        } else if (lexer->c == 'b') {
+            size_t len = strlen(value);
+            value = realloc(value, len + 2);
+        
+            value[len] = lexer->c;
+            value[len + 1] = '\0';
+
+            func = isbinary;
+
+            lexer_next(lexer);
+        }
+    } else if (lexer->c == '-') {
+        value[0] = lexer->c;
+        lexer_next(lexer);
+
+        func = isdigit;
+    }
+
+
+    while (func(lexer->c)) {
+        size_t len = strlen(value);
+        value = realloc(value, len + 2);
+        
+        value[len] = lexer->c;
+        value[len + 1] = '\0';
+
+        lexer_next(lexer);
+    }
+
+    int end = lexer->i-1;
+    TokenState* state = init_token_state(start, end, lines_counter);
+
+    return init_token(value, TOKEN_IMMEDIATE, state);
+}
+
+Token* lexer_char_token(Lexer* lexer, int type) {
+    char* value = calloc(2, sizeof(char));
+    int start = lexer->i;
+    int end = lexer->i;
+
+    value[0] = lexer->c;
+    value[1] = '\0';
+
+    TokenState* state = init_token_state(start, end, lines_counter);
+
+    Token* token = init_token(value, type, state);
+    lexer_next(lexer);
+
+    return token;
+}
+
+Token* lexer_directive_token(Lexer* lexer, int type) {
+    char* value = calloc(1, sizeof(char));

same above with all values in the lexer functions

hulxv hulxv requested changes on Oct 27, 2026 16:02 UTC
Changes Requested Reviewer

Requested changes.

hulxv hulxv commented on code on Oct 27, 2026 16:04 UTC
Code Review
mips-asm/src/lexer.h:1
@@ -1,7 +1,82 @@
+#include <stdlib.h>
+
 #ifndef _LEXER_H
 
 #define _LEXER_H
+typedef enum {
+    TOKEN_EOF = 0,
+    TOKEN_ERROR,
+    
+    // Identifiers & Labels
+    TOKEN_IDENTIFIER,  // Generic symbol or user label reference
+    TOKEN_LABEL_DEF,   // Identifier followed by a colon (e.g., "main:")
+    
+    // Registers (MIPS explicitly prefixes these with '$')
+    TOKEN_REGISTER,    // e.g., $t0, $v0, $at, $ra, $0
+    
+    // Literals
+    TOKEN_IMMEDIATE,   // Hex (0x10), Decimal (42), Negative integers (-4)
+    TOKEN_STRING,      // Used in .asciiz directives (e.g., "Hello\n")
+    
+    // Directives
+    TOKEN_DIRECTIVE,   // e.g., .text, .data, .word, .asciiz
+    
+    // Delimiters & Operators
+    TOKEN_COMMA,       // ,
+    TOKEN_LPAREN,      // (  used in memory addressing like 4($sp)
+    TOKEN_RPAREN,       // )
+    TOKEN_NEW_LINE     // Identifies a new line 
+} TokenType;
+
+typedef struct {
+    int start_index;
+    int end_index;
+    int line_index;
+} TokenState;
+
+typedef struct {
+    TokenType type;
+    TokenState* state;

we can add current_index. would be helpful in the value thing

hulxv hulxv requested changes on Oct 27, 2026 16:04 UTC
Changes Requested Reviewer

Requested changes.

hulxv hulxv commented on code on Oct 27, 2026 16:05 UTC
Code Review
mips-asm/src/lexer.h:1
@@ -1,7 +1,82 @@
+#include <stdlib.h>
+
 #ifndef _LEXER_H
 
 #define _LEXER_H
+typedef enum {
+    TOKEN_EOF = 0,
+    TOKEN_ERROR,
+    
+    // Identifiers & Labels
+    TOKEN_IDENTIFIER,  // Generic symbol or user label reference
+    TOKEN_LABEL_DEF,   // Identifier followed by a colon (e.g., "main:")
+    
+    // Registers (MIPS explicitly prefixes these with '$')
+    TOKEN_REGISTER,    // e.g., $t0, $v0, $at, $ra, $0
+    
+    // Literals
+    TOKEN_IMMEDIATE,   // Hex (0x10), Decimal (42), Negative integers (-4)
+    TOKEN_STRING,      // Used in .asciiz directives (e.g., "Hello\n")
+    
+    // Directives
+    TOKEN_DIRECTIVE,   // e.g., .text, .data, .word, .asciiz
+    
+    // Delimiters & Operators
+    TOKEN_COMMA,       // ,
+    TOKEN_LPAREN,      // (  used in memory addressing like 4($sp)
+    TOKEN_RPAREN,       // )
+    TOKEN_NEW_LINE     // Identifies a new line 
+} TokenType;
+
+typedef struct {
+    int start_index;
+    int end_index;
+    int line_index;
+} TokenState;
+
+typedef struct {
+    TokenType type;
+    TokenState* state;

ignore this, i didn't notice it inside Lexer struct

hulxv hulxv commented on code on Oct 27, 2026 16:23 UTC
Code Review
mips-asm/src/lexer.h:1
@@ -1,7 +1,82 @@
+#include <stdlib.h>
+
 #ifndef _LEXER_H
 
 #define _LEXER_H
+typedef enum {
+    TOKEN_EOF = 0,
+    TOKEN_ERROR,
+    
+    // Identifiers & Labels
+    TOKEN_IDENTIFIER,  // Generic symbol or user label reference
+    TOKEN_LABEL_DEF,   // Identifier followed by a colon (e.g., "main:")
+    
+    // Registers (MIPS explicitly prefixes these with '$')
+    TOKEN_REGISTER,    // e.g., $t0, $v0, $at, $ra, $0
+    
+    // Literals
+    TOKEN_IMMEDIATE,   // Hex (0x10), Decimal (42), Negative integers (-4)
+    TOKEN_STRING,      // Used in .asciiz directives (e.g., "Hello\n")
+    
+    // Directives
+    TOKEN_DIRECTIVE,   // e.g., .text, .data, .word, .asciiz
+    
+    // Delimiters & Operators
+    TOKEN_COMMA,       // ,
+    TOKEN_LPAREN,      // (  used in memory addressing like 4($sp)
+    TOKEN_RPAREN,       // )
+    TOKEN_NEW_LINE     // Identifies a new line 
+} TokenType;
+
+typedef struct {
+    int start_index;
+    int end_index;
+    int line_index;
+} TokenState;
+
+typedef struct {
+    TokenType type;
+    TokenState* state;
+    char* value;
+} Token;
+
+Token* init_token(char* value, int type, TokenState* state);
+
+static const char* token_type_to_str(int type);
+
+char* token_to_str(Token* token);
+
+typedef struct {
+    const char* src;
+    size_t src_size;
+    char c; // current character
+    unsigned int i; 

    char current_char;
    unsigned int current_index; 

better naming:)

hulxv hulxv requested changes on Oct 27, 2026 16:23 UTC
Changes Requested Reviewer

Requested changes.

hulxv hulxv commented on code on Oct 28, 2026 11:15 UTC
Code Review
mips-asm/src/lexer.c:1
@@ -1,3 +1,227 @@
 #include "lexer.h"
+#include "token.h"
+#include "helper.h"
+#include "stdio.h"
+#include <string.h>
+#include <ctype.h>
 
-// todo: implement the lexer here
+int lines_counter = 1;
+bool inc_lines_counter = false;
+
+Lexer* init_lexer(const char* src) {
+    Lexer* lexer = calloc(1, sizeof(Lexer));
+    lexer->src = src;
+    lexer->src_size = strlen(src);
+    lexer->current_index = 0;
+    lexer->current_char = src[lexer->current_index];
+
+    return lexer;
+}
+
+void lexer_next(Lexer* lexer) {
+    if (lexer->current_index < lexer->src_size && lexer->current_char != '\0') {
+        lexer->current_index += 1;
+        lexer->current_char = lexer->src[lexer->current_index];
+    }
+}
+
+char lexer_peek(Lexer* lexer, int offset) {
+    return lexer->src[lexer->current_index + offset];
+}
+
+char* lexer_get_substring(Lexer* lexer, int start, int end) {
+    size_t size = (end - start) + 1;
+    char* value = calloc(size + 1, sizeof(char));
+
+    memcpy(value, lexer->src + start, size);
+
+    value[size] = '\0';
+
+    return value;
+}
+
+void lexer_skip_whitespace(Lexer* lexer) {
+    while (lexer->current_char == ' ' || lexer->current_char == '\t' || lexer->current_char == '\r') {
+        lexer_next(lexer);
+    }
+}
+
+Token* lexer_parse_id(Lexer* lexer) {
+    int start = lexer->current_index;
+    lexer_next(lexer);
+
+    while (isalpha(lexer->current_char)) {
+        lexer_next(lexer);
+    }
+
+    if (lexer->current_char == ':') {
+        lexer_next(lexer);
+
+        int end = lexer->current_index - 1;
+
+        char* value = lexer_get_substring(lexer, start, end);
+
+        TokenState* state = init_token_state(start, end, lines_counter);
+
+        return init_token(value, TOKEN_LABEL_DEF, state);
+    }
+        
+    int end = lexer->current_index - 1;
+
+    char* value = lexer_get_substring(lexer, start, end);
+
+    TokenState* state = init_token_state(start, end, lines_counter);
+
+    return init_token(value, TOKEN_IDENTIFIER, state);
+}
+
+Token* lexer_parse_number(Lexer* lexer) {
+    int start = lexer->current_index;
+    lexer_next(lexer);
+
+    int (*func)(int) = isdigit;
+
+    if (lexer->current_char == '0') {
+        lexer_next(lexer);
+
+        if (lexer->current_char == 'x') {
+            func = isxdigit;
+
+            lexer_next(lexer);
+        } else if (lexer->current_char == 'b') {
+            lexer_next(lexer);

shouldn't assign func to isbinary?

hulxv hulxv requested changes on Oct 28, 2026 11:16 UTC
Changes Requested Reviewer

looks good. one missed thing

Ma7moudEGY Ma7moudEGY commented on code on Oct 28, 2026 12:12 UTC
Code Review
mips-asm/src/lexer.c:1
@@ -1,3 +1,227 @@
 #include "lexer.h"
+#include "token.h"
+#include "helper.h"
+#include "stdio.h"
+#include <string.h>
+#include <ctype.h>
 
-// todo: implement the lexer here
+int lines_counter = 1;
+bool inc_lines_counter = false;
+
+Lexer* init_lexer(const char* src) {
+    Lexer* lexer = calloc(1, sizeof(Lexer));
+    lexer->src = src;
+    lexer->src_size = strlen(src);
+    lexer->current_index = 0;
+    lexer->current_char = src[lexer->current_index];
+
+    return lexer;
+}
+
+void lexer_next(Lexer* lexer) {
+    if (lexer->current_index < lexer->src_size && lexer->current_char != '\0') {
+        lexer->current_index += 1;
+        lexer->current_char = lexer->src[lexer->current_index];
+    }
+}
+
+char lexer_peek(Lexer* lexer, int offset) {
+    return lexer->src[lexer->current_index + offset];
+}
+
+char* lexer_get_substring(Lexer* lexer, int start, int end) {
+    size_t size = (end - start) + 1;
+    char* value = calloc(size + 1, sizeof(char));
+
+    memcpy(value, lexer->src + start, size);
+
+    value[size] = '\0';
+
+    return value;
+}
+
+void lexer_skip_whitespace(Lexer* lexer) {
+    while (lexer->current_char == ' ' || lexer->current_char == '\t' || lexer->current_char == '\r') {
+        lexer_next(lexer);
+    }
+}
+
+Token* lexer_parse_id(Lexer* lexer) {
+    int start = lexer->current_index;
+    lexer_next(lexer);
+
+    while (isalpha(lexer->current_char)) {
+        lexer_next(lexer);
+    }
+
+    if (lexer->current_char == ':') {
+        lexer_next(lexer);
+
+        int end = lexer->current_index - 1;
+
+        char* value = lexer_get_substring(lexer, start, end);
+
+        TokenState* state = init_token_state(start, end, lines_counter);
+
+        return init_token(value, TOKEN_LABEL_DEF, state);
+    }
+        
+    int end = lexer->current_index - 1;
+
+    char* value = lexer_get_substring(lexer, start, end);
+
+    TokenState* state = init_token_state(start, end, lines_counter);
+
+    return init_token(value, TOKEN_IDENTIFIER, state);
+}
+
+Token* lexer_parse_number(Lexer* lexer) {
+    int start = lexer->current_index;
+    lexer_next(lexer);
+
+    int (*func)(int) = isdigit;
+
+    if (lexer->current_char == '0') {
+        lexer_next(lexer);
+
+        if (lexer->current_char == 'x') {
+            func = isxdigit;
+
+            lexer_next(lexer);
+        } else if (lexer->current_char == 'b') {
+            lexer_next(lexer);

you're completely right

hulxv hulxv approved these changes on Oct 30, 2026 23:07 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
Ma7moudEGY Ma7moudEGY
Labels
risk: low confidence: 70.4% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 55.5% (MEDIUM) · Higher = larger blast radius
55.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 70.4% · Lower = rushed or shallow review
70.4%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.4% · Safe to merge
16.4%
Repository