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