fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. /* Definitions */
  6. DIGIT [0-9]
  7. ID [a-zA-Z][a-zA-Z0-9]*
  8.  
  9. %%
  10. /* Rules Section */
  11.  
  12. /* Keywords */
  13. int|float|char|if|else|while|for|return
  14. { printf("Keyword : %s\n", yytext); }
  15.  
  16. /* Identifiers */
  17. {ID} { printf("Identifier : %s\n", yytext); }
  18.  
  19. /* Floating Numbers */
  20. {DIGIT}+\.{DIGIT}+
  21. { printf("Float Number : %s\n", yytext); }
  22.  
  23. /* Integers */
  24. {DIGIT}+ { printf("Integer : %s\n", yytext); }
  25.  
  26. /* Increment & Decrement */
  27. "++" { printf("Increment Op : ++\n"); }
  28. "--" { printf("Decrement Op : --\n"); }
  29.  
  30. /* Operators */
  31. "+"|"-"|"*"|"/"|"="|"%"
  32. { printf("Operator : %s\n", yytext); }
  33.  
  34. /* Special Symbols */
  35. "(" | ")" | "{" | "}" | ";" | ","
  36. { printf("Special Symbol : %s\n", yytext); }
  37. /* Ignore spaces and tabs */
  38. [ \t\n]+
  39. ;
  40. /* Any other character */
  41. .
  42. { printf("Unknown :%s\n",yytext);}
  43. %%
  44. int main() {
  45. printf("Enter input:\n");
  46. yylex();
  47. return 0;
  48. }
  49. int yywrap() {
  50. return 1;
  51. }
Success #stdin #stdout #stderr 0.02s 6952KB
stdin
int a;
a++;
for(int i=0;i<n;i++){
a=a%i;
}
stdout
Standard output is empty
stderr
ERROR: /home/sLh5fy/prog:2:1: Syntax error: Operator expected
ERROR: /home/sLh5fy/prog:51:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? % Execution Aborted
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit