fork download
  1. %{
  2.  
  3.  
  4.  
  5. #include <math.h>
  6.  
  7.  
  8.  
  9. %}
  10.  
  11.  
  12.  
  13. DIGIT [0-9]
  14.  
  15.  
  16.  
  17. ID [a-z][a-z0-9]*
  18.  
  19.  
  20.  
  21.  
  22.  
  23. %%
  24.  
  25.  
  26.  
  27. {DIGIT}+ {
  28.  
  29. printf {"An integer: %s (%d)\n", yytext, atoi( yytext ) );
  30.  
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37. {DIGIT}+" ." {DIGIT}*
  38.  
  39. printf( "A float : %s (%g)\n", yytext), atof( yytext ) );
  40.  
  41.  
  42.  
  43. }
  44.  
  45. if|then|begin|end|procedure|function {
  46.  
  47.  
  48.  
  49. printf( "A keyword: %s\n", yytext );
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57. {ID} printf (" An identifier : %s\n" , yytext );
  58.  
  59.  
  60.  
  61. "+"|"-"||"*"|"/" printf ( "An operator: %s\n" , yytext );
  62.  
  63.  
  64.  
  65. "{"{^}\n}*"}"
  66.  
  67.  
  68.  
  69. { \t\n}+
  70.  
  71.  
  72.  
  73. printf( "Unrecongnized character: %s\n", yytext);
  74.  
  75.  
  76.  
  77. %%
  78.  
  79.  
  80.  
  81. int yywrap() {} int main () { FILE *fp;
  82.  
  83. char filename[50];
  84.  
  85.  
  86.  
  87. printf("Enter the filename : \n");
  88.  
  89.  
  90.  
  91. scanf("%s",filename);
  92.  
  93.  
  94.  
  95. fp = fopen(filename ,"r");
  96.  
  97.  
  98.  
  99. yyin = fp;
  100.  
  101.  
  102.  
  103. yylex ();
  104.  
  105.  
  106.  
  107. }
  108.  
  109.  
  110.  
  111. int yywrap() {
  112.  
  113.  
  114.  
  115. return 1; // Indicate end of input (EOF)
  116.  
  117.  
  118.  
  119. }
Success #stdin #stdout #stderr 0.02s 6740KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/B7FgKk/prog:119:1: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit