Guest User

Local error operator

a guest
Jan 31st, 2011
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. %%{
  6. machine test;
  7. write data;
  8. }%%
  9.  
  10. void parse( char *str )
  11. {
  12. char *p = str, *pe = str + strlen( str );
  13. int cs;
  14. char* eof = 0;
  15.  
  16. %%{
  17. action parse_error { printf("parse error\n"); }
  18.  
  19. main = ('HELLO ' $^parse_error) 'WORLD' any*;
  20.  
  21. write init;
  22. write exec;
  23. }%%
  24.  
  25. printf("read: ");
  26. fwrite(str, 1, p - str, stdout);
  27. if (p <= str || *(p-1) != '\n') {
  28. putc('\n', stdout);
  29. }
  30. printf("len: %d, state: %d\n", p - str, cs);
  31. }
  32.  
  33.  
  34.  
  35. #define BUFSIZE 100024
  36.  
  37. int main()
  38. {
  39. char buf[BUFSIZE];
  40. while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
  41. parse( buf );
  42. }
  43. return 0;
  44. }
RAW Paste Data