Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.48 KB | None | 0 0
  1. %{
  2. #undef yywrap
  3. #define yywrap() 1
  4. #include <math.h>
  5. #include <unistd.h>
  6. %}
  7.  
  8. CONSTANT ["][a-zA-Z0-9 :\*><+!=>><<::\.]*["]
  9. IDENTIFIER ^[a-zA-Z][a-zA-Z0-9]{0,7}
  10. DIGIT ^[0-9]
  11. FLOAT ^[1-9][0-9]*\.*[0-9]*
  12.  
  13. %%
  14. "{"  printf("%s with code : %d\n",yytext,2);return 3;
  15. "}"  printf("%s with code : %d\n",yytext,3);return 3;
  16. "if"  printf("%s with code : %d\n",yytext,51);return 3;
  17. "else"  printf("%s with code : %d\n",yytext,52);return 3;
  18. "("  printf("%s with code : %d\n",yytext,71);return 3;
  19. ")"  printf("%s with code : %d\n",yytext,72);return 3;
  20. "<"  printf("%s with code : %d\n",yytext,73);return 3;
  21. ">"  printf("%s with code : %d\n",yytext,74);return 3;
  22. "="  printf("%s with code : %d\n",yytext,75);return 3;
  23. ";"  printf("%s with code : %d\n",yytext,76);return 3;
  24. "*"  printf("%s with code : %d\n",yytext,77);return 3;
  25. "+"  printf("%s with code : %d\n",yytext,78);return 3;
  26. "-"  printf("%s with code : %d\n",yytext,79);return 3;
  27. "#include"  printf("%s with code : %d\n",yytext,80);return 3;
  28. "using namespace"  printf("%s with code : %d\n",yytext,81);return 3;
  29. "int main"  printf("%s with code : %d\n",yytext,82);return 3;
  30. "int"  printf("%s with code : %d\n",yytext,83);return 3;
  31. "double"  printf("%s with code : %d\n",yytext,84);return 3;
  32. "const"  printf("%s with code : %d\n",yytext,85);return 3;
  33. "while"  printf("%s with code : %d\n",yytext,86);return 3;
  34. "cout"  printf("%s with code : %d\n",yytext,87);return 3;
  35. "endl"  printf("%s with code : %d\n",yytext,88);return 3;
  36. "return"  printf("%s with code : %d\n",yytext,89);return 3;
  37. "!="  printf("%s with code : %d\n",yytext,90);return 3;
  38. "<<"  printf("%s with code : %d\n",yytext,91);return 3;
  39. ">>"  printf("%s with code : %d\n",yytext,92);return 3;
  40. "::"  printf("%s with code : %d\n",yytext,93);return 3;
  41. ","  printf("%s with code : %d\n",yytext,94);return 3;
  42. {CONSTANT} printf("CONSTANT %s \n",yytext);return 0;
  43. {DIGIT} printf("CONSTANT %s \n",yytext);return 0;
  44. {FLOAT} printf("CONSTANT %s \n",yytext);return 0;
  45. {IDENTIFIER} printf("IDENTIFIER %s\n",yytext);return 1;
  46. [ \t\n]+        /* eat up whitespace */
  47. . printf("Eroare\n");return -1;
  48. %%
  49.  
  50. //";" printf("%s with code : %d",yytext,95);
  51.  
  52. main( argc, argv )
  53. int argc;
  54. char **argv;
  55. {
  56.     ++argv, --argc; /* skip over program name */
  57.     if ( argc > 0 )
  58.     yyin = fopen( argv[0], "r" );
  59.     else
  60.      yyin = stdin;
  61.     int token = -1;
  62.     while (token !=0) {
  63.         token = yylex();
  64.         printf("TOKEN IS %d\n",token);
  65.         token = yylex();
  66.     }
  67. //    yylex();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement