Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define PUTS(desc) do { \
  6. printf(desc); \
  7. fwrite(ts, 1, te-ts, stdout); \
  8. printf("\n"); \
  9. } while(0)
  10.  
  11. %%{
  12. machine Word;
  13.  
  14. main := |*
  15. 'a' {PUTS("a: ");};
  16. [ab]+ . 'c' {PUTS("abc: ");};
  17. any;
  18. *|;
  19. }%%
  20.  
  21. %% write data nofinal;
  22.  
  23. void scan(char *buf, int len)
  24. {
  25. int cs, act;
  26. char *ts, *te = 0;
  27.  
  28. %% write init;
  29.  
  30. char *p = buf;
  31. char *pe = buf + len;
  32. char *eof = pe;
  33.  
  34. %% write exec;
  35.  
  36. if ( cs == Word_error ) {
  37. fprintf(stderr, "PARSE ERROR\n" );
  38. return;
  39. }
  40.  
  41. if ( ts ) {
  42. // There is stuff left
  43. fprintf(stderr, "STUFF LEFT: '%s'\n", ts);
  44. }
  45. }
  46.  
  47. int main(int argc, char **argv)
  48. {
  49. if (argc != 2) {
  50. printf("Usage: %s 'ba a'\n", argv[0]);
  51. exit(-1);
  52. }
  53.  
  54. scan(argv[1], strlen(argv[1]));
  55. return 0;
  56. }
Add Comment
Please, Sign In to add comment