fork download
  1. %{
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #define MAX_IDENTIFIER_LENGTH 50
  6. %}
  7. %option noyywrap
  8. %option yylineo
  9. void addto symboltable(const char*)
  10. %%
  11. [\t]
  12. /n/
  13. \n*([^*]|\*+[^*/])*
  14. [0-9]+{printf("constant:%s\n*,yytext");}
  15. ={printf("%s is an assignment operator\n",yytext);}
  16. \*/
  17. \+/
  18. \-{printf("%s is a operator\n",yytext);}
  19. [a-ZA-Z][a-ZA-Z0-9]*{printf("identifier:%s\n",yytext);addsymboltable(yytext);}
  20. {printf("Invalid token:%s\n",yytext);}
  21. %%
  22. typedef struct
  23. {
  24. charname[MAX_IDENTIFIER_LENGTH];
  25. }symbol;
  26. symbol symbol_table[100];
  27. int symbol_count=0;
  28. void addtosymboltable(const char*identifier){
  29. if(symbol_count<100)
  30. {
  31. strncpy(symbol_table(symbol_count].name,identifier,MAX_IDENTIFIER_LENGTH-1);
  32. symbol_table[symbol_count].name[MAX_IDENTIFIER_LENGTH-1]='\0';
  33. symbol_count++;
  34. printf("Identifier %s is entered in the symbol table",idnetifier);
  35. }
  36. else
  37. {
  38. printf("symbol table is full.cannot add more identifier.\n");
  39. exit(0);
  40. }
  41. }
  42. int main()
  43. {
  44. yylex();
  45. return 1;
  46.  
Success #stdin #stdout #stderr 0.03s 6980KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/0YbrVB/prog:46:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit