%{
#include <stdio.h>
#include <stdlib.h>

void decimal_to_hexadecimal(int decimal) {
    char hex[100];
    int index = 0;
    
    if (decimal == 0) {
        printf("Hexadecimal: 0\n");
        return;
    }

    printf("Decimal: %d\n", decimal);
    
    // Perform the conversion by repeated division
    while (decimal > 0) {
        int remainder = decimal % 16;
        if (remainder < 10) {
            hex[index] = '0' + remainder;
        } else {
            hex[index] = 'A' + (remainder - 10);
        }
        printf("Step: Decimal = %d / 16, Remainder = %d, Quotient = %d\n", decimal, remainder, decimal / 16);
        decimal = decimal / 16;
        index++;
    }
    
    // Hexadecimal digits are stored in reverse order
    printf("Hexadecimal: ");
    for (int i = index - 1; i >= 0; i--) {
        printf("%c", hex[i]);
    }
    printf("\n");
}
%}

%%

[0-9]+ {
    int decimal = atoi(yytext); 
    decimal_to_hexadecimal(decimal);
}

\n  ;

.    ; // Ignore all other characters

%%

int main() {
    yylex();
    return 0;
}
