Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- %%{
- machine test;
- write data;
- }%%
- void parse( char *str )
- {
- char *p = str, *pe = str + strlen( str );
- int cs;
- char* eof = 0;
- %%{
- action parse_error { printf("parse error\n"); }
- main = ('HELLO ' $^parse_error) 'WORLD' any*;
- write init;
- write exec;
- }%%
- printf("read: ");
- fwrite(str, 1, p - str, stdout);
- if (p <= str || *(p-1) != '\n') {
- putc('\n', stdout);
- }
- printf("len: %d, state: %d\n", p - str, cs);
- }
- #define BUFSIZE 100024
- int main()
- {
- char buf[BUFSIZE];
- while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
- parse( buf );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement