fork download
  1. /* DESCRIPTION/DEFINITION SECTION */
  2. %{
  3. #include<stdio.h>
  4. int lc=0,sc=0,tc=0,ch=0,wc=0; // GLOBAL VARIABLES
  5. %}
  6.  
  7. // RULE SECTION
  8. %%
  9. [\n] { lc++; ch+=yyleng;}
  10. [ \t] { sc++; ch+=yyleng;}
  11. [^\t] { tc++; ch+=yyleng;}
  12. [^\t\n ]+ { wc++; ch+=yyleng;}
  13. %%
  14.  
  15. int yywrap(){ return 1; }
  16. /* After inputting press ctrl+d */
  17.  
  18. // MAIN FUNCTION
  19. int main(){
  20. printf("Enter the Sentence : ");
  21. yylex();
  22. printf("Number of lines : %d\n",lc);
  23. printf("Number of spaces : %d\n",sc);
  24. printf("Number of tabs, words, charc : %d , %d , %d\n",tc,wc,ch);
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout #stderr 0.02s 6916KB
stdin
hello world
this   is a lex program
stdout
Standard output is empty
stderr
ERROR: /home/nMwMDw/prog:27:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? Options:
+:                  spy        -:              no spy
/c|e|r|f|u|a goal:  find       .:              repeat find
a:                  abort      A:              alternatives
b:                  break      c (ret, space): creep
[depth] d:          depth      e:              exit
f:                  fail       [ndepth] g:     goals (backtrace)
h (?):              help       i:              ignore
l:                  leap       L:              listing
n:                  no debug   p:              print
r:                  retry      s:              skip
u:                  up         w:              write
m:                  exception details
C:                  toggle show context
   Exception: (3) program ? EOF: exit