Advertisement
AnindyaBiswas

only.l

May 25th, 2023
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1.  
  2. %{
  3.  
  4. //ONLY LEX FILE
  5. //lex only.l
  6. //cc lex.yy.c -ll
  7.  
  8. #include<stdio.h>
  9. #include<stdlib.h>
  10.  
  11. void yyerror(char*);
  12.  
  13. %}
  14. %%
  15.  
  16.  
  17. [0-9]* { printf("\nInteger: %s", yytext); }
  18.  
  19. [ \t]* { printf("\nSpace"); }
  20.  
  21. [a-zA-Z]* { printf("\nAlphabet: %s", yytext); }
  22.  
  23. "(" { printf("\nOpen"); }
  24. ")" {printf("\nClosed"); }
  25.  
  26. . {printf("\n %s was not recognized!", yytext);}
  27.  
  28. ">end" { printf("\nBye"); exit(0);}
  29.  
  30.  
  31.  
  32. %%
  33.  
  34. int main() {
  35. printf("Enter something : \n");
  36. yylex();
  37. }
  38.  
  39. int yywrap(){
  40. return 1;
  41. }
  42.  
  43. void yyerror(char *S)
  44. {
  45. fprintf(stderr, "%s\n", S);
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement