fork download
  1. %{
  2. #include <stdio.h>
  3. void hexToDecimal(char*);
  4. %}
  5.  
  6. %%
  7. [0-9A-Fa-f]+ {hexToDecimal(yytext);}
  8. %%
  9.  
  10. void hexToDecimal(char *yytext){
  11. int value = 0;
  12. int i = 0;
  13.  
  14. while (yytext[i] != '\0') {
  15. value = value * 16;
  16. if (yytext[i] >= '0' && yytext[i] <= '9') {
  17. value = value + (yytext[i] - '0');
  18. } else if (yytext[i] >= 'A' && yytext[i] <= 'F') {
  19. value = value + (yytext[i] - 'A' + 10);
  20. } else if (yytext[i] >= 'a' && yytext[i] <= 'f') {
  21. value = value + (yytext[i] - 'a' + 10);
  22. }
  23. i++;
  24. }
  25. printf("%d\n", value);
  26. }
  27.  
  28. int yywrap() {
  29. return 1;
  30. }
  31.  
  32. int main() {
  33. yylex();
  34. return 0;
  35. }
Success #stdin #stdout #stderr 0.02s 6840KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/xzpAJ6/prog:35:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit