Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
%%{
machine p;
action error
{
puts("error");
fnext beg;
}
action packet
{
puts("packet");
}
action addr
{
printf("%c\n", fc);
}
token = 'T';
beg = token 'a';
mid = token 'b';
end = token 'c';
normal = (^token | token token);
packet = (beg (normal @ addr){4} mid normal* end) @ packet @!error;
main := (packet)*;
}%%
%% write data;
static int cs; /* The current parser state */
void init( void )
{
%% write init;
}
int parse(const char* p, int len)
{
const char* pe = p + len;
const char* eof = (char*)0;
%% write exec;
}
int main()
{
char b[] = "Ta123TTTbTTTTTcfgTa4567TbTTTTTc TacbdtTbTch";
init();
parse(b, strlen(b));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment