fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void decimal_to_hexadecimal(int decimal) {
  6. char hex[100];
  7. int index = 0;
  8.  
  9. if (decimal == 0) {
  10. printf("Hexadecimal: 0\n");
  11. return;
  12. }
  13.  
  14. printf("Decimal: %d\n", decimal);
  15.  
  16. // Perform the conversion by repeated division
  17. while (decimal > 0) {
  18. int remainder = decimal % 16;
  19. if (remainder < 10) {
  20. hex[index] = '0' + remainder;
  21. } else {
  22. hex[index] = 'A' + (remainder - 10);
  23. }
  24. printf("Step: Decimal = %d / 16, Remainder = %d, Quotient = %d\n", decimal, remainder, decimal / 16);
  25. decimal = decimal / 16;
  26. index++;
  27. }
  28.  
  29. // Hexadecimal digits are stored in reverse order
  30. printf("Hexadecimal: ");
  31. for (int i = index - 1; i >= 0; i--) {
  32. printf("%c", hex[i]);
  33. }
  34. printf("\n");
  35. }
  36. %}
  37.  
  38. %%
  39.  
  40. [0-9]+ {
  41. int decimal = atoi(yytext);
  42. decimal_to_hexadecimal(decimal);
  43. }
  44.  
  45. \n ;
  46.  
  47. . ; // Ignore all other characters
  48.  
  49. %%
  50.  
  51. int main() {
  52. yylex();
  53. return 0;
  54. }
  55.  
Success #stdin #stdout #stderr 0.02s 6952KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/zMqcOO/prog:2:1: Syntax error: Operator expected
ERROR: /home/zMqcOO/prog:54:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit