fork download
  1. %{
  2. #include <stdio.h>
  3. #include <math.h>
  4. %}
  5.  
  6. DIGIT [0-9]
  7. %%
  8. {DIGIT}+ {
  9. int num = atoi(yytext);
  10. int original = num;
  11. int n = strlen(yytext);
  12. int sum = 0;
  13.  
  14. while (num > 0) {
  15. int digit = num % 10;
  16. sum += pow(digit, n);
  17. num /= 10;
  18. }
  19.  
  20. if (sum == original) {
  21. printf("%s is an Armstrong number\n", yytext);
  22. } else {
  23. printf("%s is not an Armstrong number\n", yytext);
  24. }
  25. }
  26. .|\n ; // Ignore other characters
  27. %%
  28.  
  29. int main() {
  30. yylex();
  31. return 0;
  32. }
  33.  
Success #stdin #stdout #stderr 0.02s 6804KB
stdin
123
stdout
Standard output is empty
stderr
ERROR: /home/fo8DTY/prog:32:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit