Created
December 18, 2009 22:01
-
-
Save zeen/259791 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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