Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#include <stdio.h> #include <stdlib.h> %%{ machine test; action one { printf("%c\n", *(&fc-1)); } action two { printf("%c%c\n", *(&fc-2), *(&fc-1)); } action ans { exit(0); } TheUnknown = ( start: ( [4] -> StartsWithFour | (digit - [4]) -> OneDigit ), StartsWithFour: ( [2] @ans -> final | (digit - [2]) -> TwoDigits | '\n' @one -> start ), OneDigit: ( digit -> TwoDigits | '\n' @one -> start ), TwoDigits: ( '\n' @two -> start ) ); #ans = '42\n' @{ fbreak; exit(0); }; #one = digit '\n' @{ printf("%s\n", (p - 2)); }; #two = digit digit '\n' @{ printf("%s%s\n", (p - 2), (p - 1)); }; #main := (ans | one | two)*; main := TheUnknown; }%% #define BUFSIZE 100 %% write data; int main() { char buf[BUFSIZE]; char *p; int cs; while (fgets(buf, sizeof(buf), stdin) != 0) { p = buf; %%{ write init; write exec noend; }%% } return 0; }
This paste will be private.
From the Design Piracy series on my blog: