fork download
  1.  
  2.  
  3. %{
  4. #include <stdio.h>
  5. #define LT 256
  6. #define LE 257
  7. #define EQ 258
  8. #define NE 259
  9. #define GT 260
  10. #define GE 261
  11. #define RELOP 262
  12. #define ID 263
  13. #define NUM 264
  14. #define IF 265
  15. #define THEN 266
  16. #define ELSE 267
  17. int attribute;
  18. %}
  19.  
  20. %delim [
  21. \t\n]
  22. %ws {delim}+
  23. %letter [A-Za-z]
  24. %digit [0-9]
  25. %id {letter}({letter}|{digit})*
  26. %num {digit}+(\.{digit}+)?(E[+\-]?{digit}+)?
  27.  
  28. %%
  29. {ws} {}
  30. if { return(IF); }
  31. then { return(THEN); }
  32. else { return(ELSE); }
  33. {id} { return(ID); }
  34. {num} { return(NUM); }
  35. "<" { attribute=LT;return(RELOP); }
  36. "<=" { attribute=LE;return(RELOP); }
  37. "<>" { attribute=NE;return(RELOP); }
  38. "=" { attribute=EQ;return(RELOP); }
  39. ">" { attribute=GT;return(RELOP); }
  40. ">=" { attribute=GE;return(RELOP); }
  41. %%
  42.  
  43. int yywrap() {
  44. return 1;
  45. }
  46.  
  47. int main() {
  48. int token;
  49. while((token = yylex())) {
  50. printf("<%d,", token);
  51. switch(token) {
  52. case ID:
  53. case NUM:
  54. printf("%s>\n", yytext);
  55. break;
  56. case RELOP:
  57. printf("%d>\n", attribute);
  58. break;
  59. default:
  60. printf(")\n");
  61. break;
  62. }
  63. }
  64. return 0;
  65. }
  66.  
Success #stdin #stdout #stderr 0.02s 6988KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/uXKLi1/prog:65:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit