Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define PUTS(desc) do { \
- printf(desc); \
- fwrite(ts, 1, te-ts, stdout); \
- printf("\n"); \
- } while(0)
- %%{
- machine Word;
- main := |*
- 'a' {PUTS("a: ");};
- [ab]+ . 'c' {PUTS("abc: ");};
- any;
- *|;
- }%%
- %% write data nofinal;
- void scan(char *buf, int len)
- {
- int cs, act;
- char *ts, *te = 0;
- %% write init;
- char *p = buf;
- char *pe = buf + len;
- char *eof = pe;
- %% write exec;
- if ( cs == Word_error ) {
- fprintf(stderr, "PARSE ERROR\n" );
- return;
- }
- if ( ts ) {
- // There is stuff left
- fprintf(stderr, "STUFF LEFT: '%s'\n", ts);
- }
- }
- int main(int argc, char **argv)
- {
- if (argc != 2) {
- printf("Usage: %s 'ba a'\n", argv[0]);
- exit(-1);
- }
- scan(argv[1], strlen(argv[1]));
- return 0;
- }
Add Comment
Please, Sign In to add comment