Skip to content

Instantly share code, notes, and snippets.

@zeen
Created December 18, 2009 22:01
Show Gist options
  • Save zeen/259791 to your computer and use it in GitHub Desktop.
Save zeen/259791 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
%%{
machine foo;
alphtype unsigned char;
action char { printf("> %c\n", *p); } Char = any* @char;
S = (0x20 | 0x9 | 0xD | 0xA)+;
NameStart = [a-zA-Z:];
NameChar = [a-zA-Z0-1:];
action colon { colons++; printf("colon!\n"); }
action reset { colons = 0; }
action print { printf("name %d\n", colons); }
action newline { printf("newline\n"); }
ColonMachine = ((':' @colon) | (any - ':'))*;
Name = ('<' @reset (NameStart NameChar*) '>' @print) & ColonMachine & Char;
NewlineMachine = ((any - '\n') | ('\n' %newline))*;
main := (Name S Name) & NewlineMachine;
write data;
}%%
int main() {
int cs, act;
char str[] = "<hel:lo> <wo:r:lds>";
//char str[] = "<x/>123";
int len = sizeof(str) - 1;//strlen(str);
char *p = str, *pe = str+len;
char *ts, *te, *eof = 0;
int colons = 0;
%% write init;
%% write exec;
if (p != pe) printf("Error: EOF\n");
printf("%d - %d - %d\n", str-str, p-str, pe-str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment