diff --git a/Makefile b/Makefile index c10fbda..6a46e57 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) +CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) -Isrc OFLAGS = -O3 -DNDEBUG #OFLAGS = -pg @@ -17,47 +17,69 @@ leg : leg.o $(OBJS) ROOT = PREFIX = /usr/local BINDIR = $(ROOT)$(PREFIX)/bin +MANDIR = $(ROOT)$(PREFIX)/man/man1 -install : $(BINDIR)/peg $(BINDIR)/leg +install : $(BINDIR) $(BINDIR)/peg $(BINDIR)/leg $(MANDIR) $(MANDIR)/peg.1 + +$(BINDIR) : + mkdir -p $(BINDIR) $(BINDIR)/% : % cp -p $< $@ strip $@ +$(MANDIR) : + mkdir -p $(MANDIR) + +$(MANDIR)/% : src/% + cp -p $< $@ + uninstall : .FORCE rm -f $(BINDIR)/peg rm -f $(BINDIR)/leg + rm -f $(MANDIR)/peg.1 -peg.o : peg.c peg.peg-c +%.o : src/%.c + $(CC) $(CFLAGS) -c -o $@ $< -%.peg-c : %.peg compile.c - ./peg -o $@ $< +peg.o : src/peg.c src/peg.peg-c + +leg.o : src/leg.c -leg.o : leg.c +check : check-peg check-leg + +check-peg : peg.peg-c .FORCE + diff src/peg.peg-c peg.peg-c + +check-leg : leg.c .FORCE + diff src/leg.c leg.c -leg.c : leg.leg compile.c +peg.peg-c : src/peg.peg peg + ./peg -o $@ $< + +leg.c : src/leg.leg leg ./leg -o $@ $< -check : check-peg check-leg +new : newpeg newleg -check-peg : peg .FORCE - ./peg < peg.peg > peg.out - diff peg.peg-c peg.out - rm peg.out +newpeg : peg.peg-c + mv src/peg.peg-c src/peg.peg-c- + mv peg.peg-c src/. -check-leg : leg .FORCE - ./leg < leg.leg > leg.out - diff leg.c leg.out - rm leg.out +newleg : leg.c + mv src/leg.c src/leg.c- + mv leg.c src/. -test examples : .FORCE +test examples : peg leg .FORCE $(SHELL) -ec '(cd examples; $(MAKE))' clean : .FORCE - rm -f *~ *.o *.peg.[cd] *.leg.[cd] + rm -f src/*~ *~ *.o *.peg.[cd] *.leg.[cd] peg.peg-c leg.c $(SHELL) -ec '(cd examples; $(MAKE) $@)' spotless : clean .FORCE + rm -f src/*- + rm -rf build rm -f peg rm -f leg $(SHELL) -ec '(cd examples; $(MAKE) $@)' diff --git a/README.md b/README.md index fc1a4d6..9a5b136 100644 --- a/README.md +++ b/README.md @@ -26,28 +26,36 @@ distribute them any way you like. ## Version history -* **0.1.9** ([zip](peg/zipball/0.1.9), [tar.gz](peg/tarball/0.1.9)) — 2012-04-29 +* **0.1.11** ([zip](../../archive/0.1.11.zip), [tar.gz](../../archive/0.1.11.tar.gz)) — 2013-06-03 +Add error actions via `"~"` operator. +Support declaration of local variables at the top level of semantic actions. +Dynamically grow data structures to remove artificial limits on rule recursion (thanks to Alex Klinkhamer). +Many small changes to better support C++. +Add build files for Win32 and MacOS (thanks to Fyodor Sheremetyev). +Update manual page to describe new features. +* **0.1.10** — missing in upstream +* **0.1.9** ([zip](../../archive/0.1.9.zip), [tar.gz](../../archive/0.1.9.tar.gz)) — 2012-04-29 Move global state into a structure to facilitate reentrant and thread-safe parsers (thanks to Dmitry Lipovoi). -* **0.1.8** ([zip](peg/zipball/0.1.8), [tar.gz](peg/tarball/0.1.8)) — 2012-03-29 +* **0.1.8** ([zip](../../archive/0.1.8.zip), [tar.gz](../../archive/0.1.8.tar.gz)) — 2012-03-29 Allow nested, matched braces within actions. -* **0.1.7** ([zip](peg/zipball/0.1.7), [tar.gz](peg/tarball/0.1.7)) — 2011-11-25 +* **0.1.7** ([zip](../../archive/0.1.7.zip), [tar.gz](../../archive/0.1.7.tar.gz)) — 2011-11-25 Fix matching of 8-bit chars to allow utf-8 sequences in matching expressions (thanks to Grégory Pakosz). -* **0.1.6** ([zip](peg/zipball/0.1.6), [tar.gz](peg/tarball/0.1.6)) — 2011-11-24 +* **0.1.6** ([zip](../../archive/0.1.6.zip), [tar.gz](../../archive/0.1.6.tar.gz)) — 2011-11-24 Allow octal escapes in character classes. -* **0.1.5** ([zip](peg/zipball/0.1.5), [tar.gz](peg/tarball/0.1.5)) — 2011-11-24 +* **0.1.5** ([zip](../../archive/0.1.5.zip), [tar.gz](../../archive/0.1.5.tar.gz)) — 2011-11-24 Remove dwarf sym dirs when cleaning. Fix size calculation when resizing text buffers. Backslash can be escaped. -* **0.1.4** ([zip](peg/zipball/0.1.4), [tar.gz](peg/tarball/0.1.4)) — 2009-08-26 +* **0.1.4** ([zip](../../archive/0.1.4.zip), [tar.gz](../../archive/0.1.4.tar.gz)) — 2009-08-26 Fix match of a single single quote character. Rename `getline` -> `nextline` to avoid C namespace conflict. -* **0.1.3** ([zip](peg/zipball/0.1.3), [tar.gz](peg/tarball/0.1.3)) — 2007-09-13 +* **0.1.3** ([zip](../../archive/0.1.3.zip), [tar.gz](../../archive/0.1.3.tar.gz)) — 2007-09-13 Allow matched braces inside `leg` actions. Handle empty rules. Handle empty grammars. -* **0.1.2** ([zip](peg/zipball/0.1.2), [tar.gz](peg/tarball/0.1.2)) — 2007-08-31 +* **0.1.2** ([zip](../../archive/0.1.2.zip), [tar.gz](../../archive/0.1.2.tar.gz)) — 2007-08-31 Grow buffers while (not if) they are too small. Remove dependencies on grammar files. Add more basic examples. -* **0.1.1** ([zip](peg/zipball/0.1.1), [tar.gz](peg/tarball/0.1.1)) — 2007-05-15 +* **0.1.1** ([zip](../../archive/0.1.1.zip), [tar.gz](../../archive/0.1.1.tar.gz)) — 2007-05-15 First public release. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..1b011d0 --- /dev/null +++ b/README.txt @@ -0,0 +1,42 @@ +Building on a Unix-like system +------------------------------ + +Type 'make' or 'make test'. + +The latter builds all the examples and runs them, comparing their +output with the expected output. + +Type 'make install' to install the binaries and manual page under +/usr/local. (Type 'make uninstall' to remove them.) You may have to +do this using 'sudo' or while logged in as root. + +Edit 'Makefile' to change the way things are built and/or the places +where things are installed. + + +Building on MacOS X +------------------- + +Run the 'build-mac.sh' script from a terminal or by double-clicking on +it in the Finder. + +You will need Xcode. The provided project is known to work with Xcode +versions 3.2.6 and 4.3.2. + +Modify build-mac.sh and/or peg.xcodeproj to change the way things are +built. + + +Building on Windows +------------------- + +Run the 'build-win.cmd' script. + +You will need Visual Studio 2010 Express. + +Modify build-win.cmd, leg.vcxproj, leg.vcxproj.filters, peg.gyp, +peg.sln, peg.vcxproj and/or peg.vcxproj.filters to change the way +things are built. + +Local implementations of getopt() and basename() are provided in the +'win' directory. diff --git a/build-mac.sh b/build-mac.sh new file mode 100755 index 0000000..b8180a4 --- /dev/null +++ b/build-mac.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +xcodebuild -project peg.xcodeproj -configuration Release + +cp build/Release/peg ./ +cp build/Release/leg ./ diff --git a/build-win.cmd b/build-win.cmd new file mode 100644 index 0000000..5c3893d --- /dev/null +++ b/build-win.cmd @@ -0,0 +1,5 @@ +@echo off +call "%VS100COMNTOOLS%vsvars32.bat" +msbuild peg.sln /p:Configuration=Release + +xcopy /Y /D Release\*.exe .\ diff --git a/examples/Makefile b/examples/Makefile index 30d3cc8..f943a4d 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,4 +1,4 @@ -EXAMPLES = test rule accept wc dc dcv calc basic localctx +EXAMPLES = test rule accept wc dc dcv calc basic localpeg localleg erract CFLAGS = -g -O3 @@ -71,14 +71,30 @@ basic : .FORCE rm -f $@.out @echo -localctx : .FORCE +localpeg : .FORCE ../peg -o test.peg.c test.peg - $(CC) $(CFLAGS) -o localctx localctx.c + $(CC) $(CFLAGS) -o localpeg localpeg.c echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | ./$@ | $(TEE) $@.out $(DIFF) $@.ref $@.out rm -f $@.out @echo +localleg : .FORCE + ../leg -o localleg.leg.c localleg.leg + $(CC) $(CFLAGS) -o localleg localleg.leg.c + ./$@ < localleg.leg | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +erract : .FORCE + ../leg -o erract.leg.c erract.leg + $(CC) $(CFLAGS) -o erract erract.leg.c + echo '6*9' | ./$@ | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + clean : .FORCE rm -f *~ *.o *.[pl]eg.[cd] $(EXAMPLES) rm -rf *.dSYM diff --git a/examples/erract.leg b/examples/erract.leg new file mode 100644 index 0000000..5575730 --- /dev/null +++ b/examples/erract.leg @@ -0,0 +1,27 @@ +%{ +#include +%} + +Expr = a:NUMBER PLUS ~{ printf("fail at PLUS\n") } b:NUMBER { printf("got addition\n"); } + | ( a:NUMBER MINUS b:NUMBER { printf("got subtraction\n"); } ) ~{ printf("fail at subtraction\n") } + | a:NUMBER TIMES b:NUMBER { printf("got multiplication\n"); } + | a:NUMBER DIVIDE b:NUMBER { printf("got division\n"); } + +NUMBER = < [0-9]+ > - { $$= atoi(yytext); } +PLUS = '+' - +MINUS = '-' - +TIMES = '*' - +DIVIDE = '/' - + +- = (SPACE | EOL)* +SPACE = [ \t] +EOL = '\n' | '\r\n' | '\r' | ';' + +%% + +int main() +{ + while (yyparse()); + + return 0; +} diff --git a/examples/erract.ref b/examples/erract.ref new file mode 100644 index 0000000..338ffcf --- /dev/null +++ b/examples/erract.ref @@ -0,0 +1,4 @@ +fail at PLUS +fail at subtraction +got multiplication +fail at subtraction diff --git a/examples/localleg.leg b/examples/localleg.leg new file mode 100644 index 0000000..4d52d56 --- /dev/null +++ b/examples/localleg.leg @@ -0,0 +1,24 @@ +%{ +#define YY_CTX_LOCAL 1 +#define YY_CTX_MEMBERS \ + int count; +%} + +Char = ('\n' | '\r\n' | '\r') { yy->count++ } + | . + +%% + +#include +#include + +int main() +{ + yycontext yy; + memset(&yy, 0, sizeof(yy)); + while (yyparse(&yy)) + ; + printf("%d newlines\n", yy.count); + yyrelease(&yy); + return 0; +} diff --git a/examples/localleg.ref b/examples/localleg.ref new file mode 100644 index 0000000..f4a0919 --- /dev/null +++ b/examples/localleg.ref @@ -0,0 +1 @@ +24 newlines diff --git a/examples/localctx.c b/examples/localpeg.c similarity index 100% rename from examples/localctx.c rename to examples/localpeg.c diff --git a/examples/localctx.ref b/examples/localpeg.ref similarity index 100% rename from examples/localctx.ref rename to examples/localpeg.ref diff --git a/leg.c b/leg.c deleted file mode 100644 index 91b696d..0000000 --- a/leg.c +++ /dev/null @@ -1,1209 +0,0 @@ -/* A recursive-descent parser generated by peg 0.1.9 */ - -#include -#include -#include -#define YYRULECOUNT 36 - -# include "tree.h" -# include "version.h" - -# include -# include -# include -# include -# include -# include - - typedef struct Header Header; - - struct Header { - char *text; - Header *next; - }; - - FILE *input= 0; - - int verboseFlag= 0; - - static int lineNumber= 0; - static char *fileName= 0; - static char *trailer= 0; - static Header *headers= 0; - - void makeHeader(char *text); - void makeTrailer(char *text); - - void yyerror(char *message); - -# define YY_INPUT(buf, result, max) \ - { \ - int c= getc(input); \ - if ('\n' == c || '\r' == c) ++lineNumber; \ - result= (EOF == c) ? 0 : (*(buf)= c, 1); \ - } - -# define YY_LOCAL(T) static T -# define YY_RULE(T) static T - -#ifndef YY_LOCAL -#define YY_LOCAL(T) static T -#endif -#ifndef YY_ACTION -#define YY_ACTION(T) static T -#endif -#ifndef YY_RULE -#define YY_RULE(T) static T -#endif -#ifndef YY_PARSE -#define YY_PARSE(T) T -#endif -#ifndef YYPARSE -#define YYPARSE yyparse -#endif -#ifndef YYPARSEFROM -#define YYPARSEFROM yyparsefrom -#endif -#ifndef YY_INPUT -#define YY_INPUT(buf, result, max_size) \ - { \ - int yyc= getchar(); \ - result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \ - yyprintf((stderr, "<%c>", yyc)); \ - } -#endif -#ifndef YY_BEGIN -#define YY_BEGIN ( ctx->begin= ctx->pos, 1) -#endif -#ifndef YY_END -#define YY_END ( ctx->end= ctx->pos, 1) -#endif -#ifdef YY_DEBUG -# define yyprintf(args) fprintf args -#else -# define yyprintf(args) -#endif -#ifndef YYSTYPE -#define YYSTYPE int -#endif - -#ifndef YY_PART - -typedef struct _yycontext yycontext; -typedef void (*yyaction)(yycontext *ctx, char *yytext, int yyleng); -typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk; - -struct _yycontext { - char *buf; - int buflen; - int pos; - int limit; - char *text; - int textlen; - int begin; - int end; - int textmax; - yythunk *thunks; - int thunkslen; - int thunkpos; - YYSTYPE yy; - YYSTYPE *val; - YYSTYPE *vals; - int valslen; -#ifdef YY_CTX_MEMBERS - YY_CTX_MEMBERS -#endif -}; - -#ifdef YY_CTX_LOCAL -#define YY_CTX_PARAM_ yycontext *yyctx, -#define YY_CTX_PARAM yycontext *yyctx -#define YY_CTX_ARG_ yyctx, -#define YY_CTX_ARG yyctx -#else -#define YY_CTX_PARAM_ -#define YY_CTX_PARAM -#define YY_CTX_ARG_ -#define YY_CTX_ARG -yycontext yyctx0; -yycontext *yyctx= &yyctx0; -#endif - -YY_LOCAL(int) yyrefill(yycontext *ctx) -{ - int yyn; - while (ctx->buflen - ctx->pos < 512) - { - ctx->buflen *= 2; - ctx->buf= (char *)realloc(ctx->buf, ctx->buflen); - } - YY_INPUT((ctx->buf + ctx->pos), yyn, (ctx->buflen - ctx->pos)); - if (!yyn) return 0; - ctx->limit += yyn; - return 1; -} - -YY_LOCAL(int) yymatchDot(yycontext *ctx) -{ - if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; - ++ctx->pos; - return 1; -} - -YY_LOCAL(int) yymatchChar(yycontext *ctx, int c) -{ - if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; - if ((unsigned char)ctx->buf[ctx->pos] == c) - { - ++ctx->pos; - yyprintf((stderr, " ok yymatchChar(ctx, %c) @ %s\n", c, ctx->buf+ctx->pos)); - return 1; - } - yyprintf((stderr, " fail yymatchChar(ctx, %c) @ %s\n", c, ctx->buf+ctx->pos)); - return 0; -} - -YY_LOCAL(int) yymatchString(yycontext *ctx, char *s) -{ - int yysav= ctx->pos; - while (*s) - { - if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; - if (ctx->buf[ctx->pos] != *s) - { - ctx->pos= yysav; - return 0; - } - ++s; - ++ctx->pos; - } - return 1; -} - -YY_LOCAL(int) yymatchClass(yycontext *ctx, unsigned char *bits) -{ - int c; - if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; - c= (unsigned char)ctx->buf[ctx->pos]; - if (bits[c >> 3] & (1 << (c & 7))) - { - ++ctx->pos; - yyprintf((stderr, " ok yymatchClass @ %s\n", ctx->buf+ctx->pos)); - return 1; - } - yyprintf((stderr, " fail yymatchClass @ %s\n", ctx->buf+ctx->pos)); - return 0; -} - -YY_LOCAL(void) yyDo(yycontext *ctx, yyaction action, int begin, int end) -{ - while (ctx->thunkpos >= ctx->thunkslen) - { - ctx->thunkslen *= 2; - ctx->thunks= (yythunk *)realloc(ctx->thunks, sizeof(yythunk) * ctx->thunkslen); - } - ctx->thunks[ctx->thunkpos].begin= begin; - ctx->thunks[ctx->thunkpos].end= end; - ctx->thunks[ctx->thunkpos].action= action; - ++ctx->thunkpos; -} - -YY_LOCAL(int) yyText(yycontext *ctx, int begin, int end) -{ - int yyleng= end - begin; - if (yyleng <= 0) - yyleng= 0; - else - { - while (ctx->textlen < (yyleng + 1)) - { - ctx->textlen *= 2; - ctx->text= (char *)realloc(ctx->text, ctx->textlen); - } - memcpy(ctx->text, ctx->buf + begin, yyleng); - } - ctx->text[yyleng]= '\0'; - return yyleng; -} - -YY_LOCAL(void) yyDone(yycontext *ctx) -{ - int pos; - for (pos= 0; pos < ctx->thunkpos; ++pos) - { - yythunk *thunk= &ctx->thunks[pos]; - int yyleng= thunk->end ? yyText(ctx, thunk->begin, thunk->end) : thunk->begin; - yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, ctx->text)); - thunk->action(ctx, ctx->text, yyleng); - } - ctx->thunkpos= 0; -} - -YY_LOCAL(void) yyCommit(yycontext *ctx) -{ - if ((ctx->limit -= ctx->pos)) - { - memmove(ctx->buf, ctx->buf + ctx->pos, ctx->limit); - } - ctx->begin -= ctx->pos; - ctx->end -= ctx->pos; - ctx->pos= ctx->thunkpos= 0; -} - -YY_LOCAL(int) yyAccept(yycontext *ctx, int tp0) -{ - if (tp0) - { - fprintf(stderr, "accept denied at %d\n", tp0); - return 0; - } - else - { - yyDone(ctx); - yyCommit(ctx); - } - return 1; -} - -YY_LOCAL(void) yyPush(yycontext *ctx, char *text, int count) { ctx->val += count; } -YY_LOCAL(void) yyPop(yycontext *ctx, char *text, int count) { ctx->val -= count; } -YY_LOCAL(void) yySet(yycontext *ctx, char *text, int count) { ctx->val[count]= ctx->yy; } - -#endif /* YY_PART */ - -#define YYACCEPT yyAccept(ctx, yythunkpos0) - -YY_RULE(int) yy_end_of_line(yycontext *ctx); /* 36 */ -YY_RULE(int) yy_comment(yycontext *ctx); /* 35 */ -YY_RULE(int) yy_space(yycontext *ctx); /* 34 */ -YY_RULE(int) yy_braces(yycontext *ctx); /* 33 */ -YY_RULE(int) yy_range(yycontext *ctx); /* 32 */ -YY_RULE(int) yy_char(yycontext *ctx); /* 31 */ -YY_RULE(int) yy_END(yycontext *ctx); /* 30 */ -YY_RULE(int) yy_BEGIN(yycontext *ctx); /* 29 */ -YY_RULE(int) yy_DOT(yycontext *ctx); /* 28 */ -YY_RULE(int) yy_class(yycontext *ctx); /* 27 */ -YY_RULE(int) yy_literal(yycontext *ctx); /* 26 */ -YY_RULE(int) yy_CLOSE(yycontext *ctx); /* 25 */ -YY_RULE(int) yy_OPEN(yycontext *ctx); /* 24 */ -YY_RULE(int) yy_COLON(yycontext *ctx); /* 23 */ -YY_RULE(int) yy_PLUS(yycontext *ctx); /* 22 */ -YY_RULE(int) yy_STAR(yycontext *ctx); /* 21 */ -YY_RULE(int) yy_QUESTION(yycontext *ctx); /* 20 */ -YY_RULE(int) yy_primary(yycontext *ctx); /* 19 */ -YY_RULE(int) yy_NOT(yycontext *ctx); /* 18 */ -YY_RULE(int) yy_suffix(yycontext *ctx); /* 17 */ -YY_RULE(int) yy_action(yycontext *ctx); /* 16 */ -YY_RULE(int) yy_AND(yycontext *ctx); /* 15 */ -YY_RULE(int) yy_prefix(yycontext *ctx); /* 14 */ -YY_RULE(int) yy_BAR(yycontext *ctx); /* 13 */ -YY_RULE(int) yy_sequence(yycontext *ctx); /* 12 */ -YY_RULE(int) yy_SEMICOLON(yycontext *ctx); /* 11 */ -YY_RULE(int) yy_expression(yycontext *ctx); /* 10 */ -YY_RULE(int) yy_EQUAL(yycontext *ctx); /* 9 */ -YY_RULE(int) yy_identifier(yycontext *ctx); /* 8 */ -YY_RULE(int) yy_RPERCENT(yycontext *ctx); /* 7 */ -YY_RULE(int) yy_end_of_file(yycontext *ctx); /* 6 */ -YY_RULE(int) yy_trailer(yycontext *ctx); /* 5 */ -YY_RULE(int) yy_definition(yycontext *ctx); /* 4 */ -YY_RULE(int) yy_declaration(yycontext *ctx); /* 3 */ -YY_RULE(int) yy__(yycontext *ctx); /* 2 */ -YY_RULE(int) yy_grammar(yycontext *ctx); /* 1 */ - -YY_ACTION(void) yy_9_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_9_primary\n")); - push(makePredicate("YY_END")); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_8_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_8_primary\n")); - push(makePredicate("YY_BEGIN")); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_7_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_7_primary\n")); - push(makeAction(yytext)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_6_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_6_primary\n")); - push(makeDot()); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_5_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_5_primary\n")); - push(makeClass(yytext)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_4_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_4_primary\n")); - push(makeString(yytext)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_3_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_3_primary\n")); - push(makeName(findRule(yytext))); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_2_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_2_primary\n")); - Node *name= makeName(findRule(yytext)); name->name.variable= pop(); push(name); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_primary(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_primary\n")); - push(makeVariable(yytext)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_3_suffix(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_3_suffix\n")); - push(makePlus (pop())); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_2_suffix(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_2_suffix\n")); - push(makeStar (pop())); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_suffix(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_suffix\n")); - push(makeQuery(pop())); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_3_prefix(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_3_prefix\n")); - push(makePeekNot(pop())); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_2_prefix(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_2_prefix\n")); - push(makePeekFor(pop())); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_prefix(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_prefix\n")); - push(makePredicate(yytext)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_sequence(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_sequence\n")); - Node *f= pop(); push(Sequence_append(pop(), f)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_expression(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_expression\n")); - Node *f= pop(); push(Alternate_append(pop(), f)); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_2_definition(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_2_definition\n")); - Node *e= pop(); Rule_setExpression(pop(), e); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_definition(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_definition\n")); - if (push(beginRule(findRule(yytext)))->rule.expression) - fprintf(stderr, "rule '%s' redefined\n", yytext); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_trailer(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_trailer\n")); - makeTrailer(yytext); ; -#undef yythunkpos -#undef yypos -#undef yy -} -YY_ACTION(void) yy_1_declaration(yycontext *ctx, char *yytext, int yyleng) -{ -#define yy ctx->yy -#define yypos ctx->pos -#define yythunkpos ctx->thunkpos - yyprintf((stderr, "do yy_1_declaration\n")); - makeHeader(yytext); ; -#undef yythunkpos -#undef yypos -#undef yy -} - -YY_RULE(int) yy_end_of_line(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "end_of_line")); - { int yypos2= ctx->pos, yythunkpos2= ctx->thunkpos; if (!yymatchString(ctx, "\r\n")) goto l3; goto l2; - l3:; ctx->pos= yypos2; ctx->thunkpos= yythunkpos2; if (!yymatchChar(ctx, '\n')) goto l4; goto l2; - l4:; ctx->pos= yypos2; ctx->thunkpos= yythunkpos2; if (!yymatchChar(ctx, '\r')) goto l1; - } - l2:; - yyprintf((stderr, " ok %s @ %s\n", "end_of_line", ctx->buf+ctx->pos)); - return 1; - l1:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "end_of_line", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_comment(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "comment")); if (!yymatchChar(ctx, '#')) goto l5; - l6:; - { int yypos7= ctx->pos, yythunkpos7= ctx->thunkpos; - { int yypos8= ctx->pos, yythunkpos8= ctx->thunkpos; if (!yy_end_of_line(ctx)) goto l8; goto l7; - l8:; ctx->pos= yypos8; ctx->thunkpos= yythunkpos8; - } if (!yymatchDot(ctx)) goto l7; goto l6; - l7:; ctx->pos= yypos7; ctx->thunkpos= yythunkpos7; - } if (!yy_end_of_line(ctx)) goto l5; - yyprintf((stderr, " ok %s @ %s\n", "comment", ctx->buf+ctx->pos)); - return 1; - l5:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "comment", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_space(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "space")); - { int yypos10= ctx->pos, yythunkpos10= ctx->thunkpos; if (!yymatchChar(ctx, ' ')) goto l11; goto l10; - l11:; ctx->pos= yypos10; ctx->thunkpos= yythunkpos10; if (!yymatchChar(ctx, '\t')) goto l12; goto l10; - l12:; ctx->pos= yypos10; ctx->thunkpos= yythunkpos10; if (!yy_end_of_line(ctx)) goto l9; - } - l10:; - yyprintf((stderr, " ok %s @ %s\n", "space", ctx->buf+ctx->pos)); - return 1; - l9:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "space", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_braces(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "braces")); - { int yypos14= ctx->pos, yythunkpos14= ctx->thunkpos; if (!yymatchChar(ctx, '{')) goto l15; - l16:; - { int yypos17= ctx->pos, yythunkpos17= ctx->thunkpos; if (!yy_braces(ctx)) goto l17; goto l16; - l17:; ctx->pos= yypos17; ctx->thunkpos= yythunkpos17; - } if (!yymatchChar(ctx, '}')) goto l15; goto l14; - l15:; ctx->pos= yypos14; ctx->thunkpos= yythunkpos14; - { int yypos18= ctx->pos, yythunkpos18= ctx->thunkpos; if (!yymatchChar(ctx, '}')) goto l18; goto l13; - l18:; ctx->pos= yypos18; ctx->thunkpos= yythunkpos18; - } if (!yymatchDot(ctx)) goto l13; - } - l14:; - yyprintf((stderr, " ok %s @ %s\n", "braces", ctx->buf+ctx->pos)); - return 1; - l13:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "braces", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_range(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "range")); - { int yypos20= ctx->pos, yythunkpos20= ctx->thunkpos; if (!yy_char(ctx)) goto l21; if (!yymatchChar(ctx, '-')) goto l21; if (!yy_char(ctx)) goto l21; goto l20; - l21:; ctx->pos= yypos20; ctx->thunkpos= yythunkpos20; if (!yy_char(ctx)) goto l19; - } - l20:; - yyprintf((stderr, " ok %s @ %s\n", "range", ctx->buf+ctx->pos)); - return 1; - l19:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "range", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_char(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "char")); - { int yypos23= ctx->pos, yythunkpos23= ctx->thunkpos; if (!yymatchChar(ctx, '\\')) goto l24; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\204\040\000\000\000\000\000\070\146\100\124\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l24; goto l23; - l24:; ctx->pos= yypos23; ctx->thunkpos= yythunkpos23; if (!yymatchChar(ctx, '\\')) goto l25; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\017\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l25; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l25; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l25; goto l23; - l25:; ctx->pos= yypos23; ctx->thunkpos= yythunkpos23; if (!yymatchChar(ctx, '\\')) goto l26; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l26; - { int yypos27= ctx->pos, yythunkpos27= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l27; goto l28; - l27:; ctx->pos= yypos27; ctx->thunkpos= yythunkpos27; - } - l28:; goto l23; - l26:; ctx->pos= yypos23; ctx->thunkpos= yythunkpos23; - { int yypos29= ctx->pos, yythunkpos29= ctx->thunkpos; if (!yymatchChar(ctx, '\\')) goto l29; goto l22; - l29:; ctx->pos= yypos29; ctx->thunkpos= yythunkpos29; - } if (!yymatchDot(ctx)) goto l22; - } - l23:; - yyprintf((stderr, " ok %s @ %s\n", "char", ctx->buf+ctx->pos)); - return 1; - l22:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "char", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_END(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "END")); if (!yymatchChar(ctx, '>')) goto l30; if (!yy__(ctx)) goto l30; - yyprintf((stderr, " ok %s @ %s\n", "END", ctx->buf+ctx->pos)); - return 1; - l30:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "END", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_BEGIN(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "BEGIN")); if (!yymatchChar(ctx, '<')) goto l31; if (!yy__(ctx)) goto l31; - yyprintf((stderr, " ok %s @ %s\n", "BEGIN", ctx->buf+ctx->pos)); - return 1; - l31:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "BEGIN", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_DOT(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "DOT")); if (!yymatchChar(ctx, '.')) goto l32; if (!yy__(ctx)) goto l32; - yyprintf((stderr, " ok %s @ %s\n", "DOT", ctx->buf+ctx->pos)); - return 1; - l32:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "DOT", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_class(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(ctx, '[')) goto l33; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l33; - l34:; - { int yypos35= ctx->pos, yythunkpos35= ctx->thunkpos; - { int yypos36= ctx->pos, yythunkpos36= ctx->thunkpos; if (!yymatchChar(ctx, ']')) goto l36; goto l35; - l36:; ctx->pos= yypos36; ctx->thunkpos= yythunkpos36; - } if (!yy_range(ctx)) goto l35; goto l34; - l35:; ctx->pos= yypos35; ctx->thunkpos= yythunkpos35; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l33; if (!yymatchChar(ctx, ']')) goto l33; if (!yy__(ctx)) goto l33; - yyprintf((stderr, " ok %s @ %s\n", "class", ctx->buf+ctx->pos)); - return 1; - l33:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "class", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_literal(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "literal")); - { int yypos38= ctx->pos, yythunkpos38= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l39; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l39; - l40:; - { int yypos41= ctx->pos, yythunkpos41= ctx->thunkpos; - { int yypos42= ctx->pos, yythunkpos42= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l42; goto l41; - l42:; ctx->pos= yypos42; ctx->thunkpos= yythunkpos42; - } if (!yy_char(ctx)) goto l41; goto l40; - l41:; ctx->pos= yypos41; ctx->thunkpos= yythunkpos41; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l39; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l39; if (!yy__(ctx)) goto l39; goto l38; - l39:; ctx->pos= yypos38; ctx->thunkpos= yythunkpos38; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l37; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l37; - l43:; - { int yypos44= ctx->pos, yythunkpos44= ctx->thunkpos; - { int yypos45= ctx->pos, yythunkpos45= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l45; goto l44; - l45:; ctx->pos= yypos45; ctx->thunkpos= yythunkpos45; - } if (!yy_char(ctx)) goto l44; goto l43; - l44:; ctx->pos= yypos44; ctx->thunkpos= yythunkpos44; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l37; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l37; if (!yy__(ctx)) goto l37; - } - l38:; - yyprintf((stderr, " ok %s @ %s\n", "literal", ctx->buf+ctx->pos)); - return 1; - l37:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "literal", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_CLOSE(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "CLOSE")); if (!yymatchChar(ctx, ')')) goto l46; if (!yy__(ctx)) goto l46; - yyprintf((stderr, " ok %s @ %s\n", "CLOSE", ctx->buf+ctx->pos)); - return 1; - l46:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "CLOSE", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_OPEN(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "OPEN")); if (!yymatchChar(ctx, '(')) goto l47; if (!yy__(ctx)) goto l47; - yyprintf((stderr, " ok %s @ %s\n", "OPEN", ctx->buf+ctx->pos)); - return 1; - l47:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "OPEN", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_COLON(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "COLON")); if (!yymatchChar(ctx, ':')) goto l48; if (!yy__(ctx)) goto l48; - yyprintf((stderr, " ok %s @ %s\n", "COLON", ctx->buf+ctx->pos)); - return 1; - l48:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "COLON", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_PLUS(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "PLUS")); if (!yymatchChar(ctx, '+')) goto l49; if (!yy__(ctx)) goto l49; - yyprintf((stderr, " ok %s @ %s\n", "PLUS", ctx->buf+ctx->pos)); - return 1; - l49:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "PLUS", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_STAR(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "STAR")); if (!yymatchChar(ctx, '*')) goto l50; if (!yy__(ctx)) goto l50; - yyprintf((stderr, " ok %s @ %s\n", "STAR", ctx->buf+ctx->pos)); - return 1; - l50:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "STAR", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_QUESTION(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "QUESTION")); if (!yymatchChar(ctx, '?')) goto l51; if (!yy__(ctx)) goto l51; - yyprintf((stderr, " ok %s @ %s\n", "QUESTION", ctx->buf+ctx->pos)); - return 1; - l51:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "QUESTION", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_primary(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "primary")); - { int yypos53= ctx->pos, yythunkpos53= ctx->thunkpos; if (!yy_identifier(ctx)) goto l54; yyDo(ctx, yy_1_primary, ctx->begin, ctx->end); if (!yy_COLON(ctx)) goto l54; if (!yy_identifier(ctx)) goto l54; - { int yypos55= ctx->pos, yythunkpos55= ctx->thunkpos; if (!yy_EQUAL(ctx)) goto l55; goto l54; - l55:; ctx->pos= yypos55; ctx->thunkpos= yythunkpos55; - } yyDo(ctx, yy_2_primary, ctx->begin, ctx->end); goto l53; - l54:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_identifier(ctx)) goto l56; - { int yypos57= ctx->pos, yythunkpos57= ctx->thunkpos; if (!yy_EQUAL(ctx)) goto l57; goto l56; - l57:; ctx->pos= yypos57; ctx->thunkpos= yythunkpos57; - } yyDo(ctx, yy_3_primary, ctx->begin, ctx->end); goto l53; - l56:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_OPEN(ctx)) goto l58; if (!yy_expression(ctx)) goto l58; if (!yy_CLOSE(ctx)) goto l58; goto l53; - l58:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_literal(ctx)) goto l59; yyDo(ctx, yy_4_primary, ctx->begin, ctx->end); goto l53; - l59:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_class(ctx)) goto l60; yyDo(ctx, yy_5_primary, ctx->begin, ctx->end); goto l53; - l60:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_DOT(ctx)) goto l61; yyDo(ctx, yy_6_primary, ctx->begin, ctx->end); goto l53; - l61:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_action(ctx)) goto l62; yyDo(ctx, yy_7_primary, ctx->begin, ctx->end); goto l53; - l62:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_BEGIN(ctx)) goto l63; yyDo(ctx, yy_8_primary, ctx->begin, ctx->end); goto l53; - l63:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_END(ctx)) goto l52; yyDo(ctx, yy_9_primary, ctx->begin, ctx->end); - } - l53:; - yyprintf((stderr, " ok %s @ %s\n", "primary", ctx->buf+ctx->pos)); - return 1; - l52:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "primary", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_NOT(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "NOT")); if (!yymatchChar(ctx, '!')) goto l64; if (!yy__(ctx)) goto l64; - yyprintf((stderr, " ok %s @ %s\n", "NOT", ctx->buf+ctx->pos)); - return 1; - l64:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "NOT", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_suffix(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "suffix")); if (!yy_primary(ctx)) goto l65; - { int yypos66= ctx->pos, yythunkpos66= ctx->thunkpos; - { int yypos68= ctx->pos, yythunkpos68= ctx->thunkpos; if (!yy_QUESTION(ctx)) goto l69; yyDo(ctx, yy_1_suffix, ctx->begin, ctx->end); goto l68; - l69:; ctx->pos= yypos68; ctx->thunkpos= yythunkpos68; if (!yy_STAR(ctx)) goto l70; yyDo(ctx, yy_2_suffix, ctx->begin, ctx->end); goto l68; - l70:; ctx->pos= yypos68; ctx->thunkpos= yythunkpos68; if (!yy_PLUS(ctx)) goto l66; yyDo(ctx, yy_3_suffix, ctx->begin, ctx->end); - } - l68:; goto l67; - l66:; ctx->pos= yypos66; ctx->thunkpos= yythunkpos66; - } - l67:; - yyprintf((stderr, " ok %s @ %s\n", "suffix", ctx->buf+ctx->pos)); - return 1; - l65:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "suffix", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_action(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(ctx, '{')) goto l71; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l71; - l72:; - { int yypos73= ctx->pos, yythunkpos73= ctx->thunkpos; if (!yy_braces(ctx)) goto l73; goto l72; - l73:; ctx->pos= yypos73; ctx->thunkpos= yythunkpos73; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l71; if (!yymatchChar(ctx, '}')) goto l71; if (!yy__(ctx)) goto l71; - yyprintf((stderr, " ok %s @ %s\n", "action", ctx->buf+ctx->pos)); - return 1; - l71:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "action", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_AND(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "AND")); if (!yymatchChar(ctx, '&')) goto l74; if (!yy__(ctx)) goto l74; - yyprintf((stderr, " ok %s @ %s\n", "AND", ctx->buf+ctx->pos)); - return 1; - l74:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "AND", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_prefix(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "prefix")); - { int yypos76= ctx->pos, yythunkpos76= ctx->thunkpos; if (!yy_AND(ctx)) goto l77; if (!yy_action(ctx)) goto l77; yyDo(ctx, yy_1_prefix, ctx->begin, ctx->end); goto l76; - l77:; ctx->pos= yypos76; ctx->thunkpos= yythunkpos76; if (!yy_AND(ctx)) goto l78; if (!yy_suffix(ctx)) goto l78; yyDo(ctx, yy_2_prefix, ctx->begin, ctx->end); goto l76; - l78:; ctx->pos= yypos76; ctx->thunkpos= yythunkpos76; if (!yy_NOT(ctx)) goto l79; if (!yy_suffix(ctx)) goto l79; yyDo(ctx, yy_3_prefix, ctx->begin, ctx->end); goto l76; - l79:; ctx->pos= yypos76; ctx->thunkpos= yythunkpos76; if (!yy_suffix(ctx)) goto l75; - } - l76:; - yyprintf((stderr, " ok %s @ %s\n", "prefix", ctx->buf+ctx->pos)); - return 1; - l75:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "prefix", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_BAR(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "BAR")); if (!yymatchChar(ctx, '|')) goto l80; if (!yy__(ctx)) goto l80; - yyprintf((stderr, " ok %s @ %s\n", "BAR", ctx->buf+ctx->pos)); - return 1; - l80:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "BAR", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_sequence(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "sequence")); if (!yy_prefix(ctx)) goto l81; - l82:; - { int yypos83= ctx->pos, yythunkpos83= ctx->thunkpos; if (!yy_prefix(ctx)) goto l83; yyDo(ctx, yy_1_sequence, ctx->begin, ctx->end); goto l82; - l83:; ctx->pos= yypos83; ctx->thunkpos= yythunkpos83; - } - yyprintf((stderr, " ok %s @ %s\n", "sequence", ctx->buf+ctx->pos)); - return 1; - l81:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "sequence", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_SEMICOLON(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(ctx, ';')) goto l84; if (!yy__(ctx)) goto l84; - yyprintf((stderr, " ok %s @ %s\n", "SEMICOLON", ctx->buf+ctx->pos)); - return 1; - l84:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "SEMICOLON", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_expression(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "expression")); if (!yy_sequence(ctx)) goto l85; - l86:; - { int yypos87= ctx->pos, yythunkpos87= ctx->thunkpos; if (!yy_BAR(ctx)) goto l87; if (!yy_sequence(ctx)) goto l87; yyDo(ctx, yy_1_expression, ctx->begin, ctx->end); goto l86; - l87:; ctx->pos= yypos87; ctx->thunkpos= yythunkpos87; - } - yyprintf((stderr, " ok %s @ %s\n", "expression", ctx->buf+ctx->pos)); - return 1; - l85:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "expression", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_EQUAL(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar(ctx, '=')) goto l88; if (!yy__(ctx)) goto l88; - yyprintf((stderr, " ok %s @ %s\n", "EQUAL", ctx->buf+ctx->pos)); - return 1; - l88:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "EQUAL", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_identifier(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "identifier")); yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l89; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\040\000\000\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l89; - l90:; - { int yypos91= ctx->pos, yythunkpos91= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\040\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l91; goto l90; - l91:; ctx->pos= yypos91; ctx->thunkpos= yythunkpos91; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l89; if (!yy__(ctx)) goto l89; - yyprintf((stderr, " ok %s @ %s\n", "identifier", ctx->buf+ctx->pos)); - return 1; - l89:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "identifier", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_RPERCENT(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "RPERCENT")); if (!yymatchString(ctx, "%}")) goto l92; if (!yy__(ctx)) goto l92; - yyprintf((stderr, " ok %s @ %s\n", "RPERCENT", ctx->buf+ctx->pos)); - return 1; - l92:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "RPERCENT", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_end_of_file(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "end_of_file")); - { int yypos94= ctx->pos, yythunkpos94= ctx->thunkpos; if (!yymatchDot(ctx)) goto l94; goto l93; - l94:; ctx->pos= yypos94; ctx->thunkpos= yythunkpos94; - } - yyprintf((stderr, " ok %s @ %s\n", "end_of_file", ctx->buf+ctx->pos)); - return 1; - l93:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "end_of_file", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_trailer(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "trailer")); if (!yymatchString(ctx, "%%")) goto l95; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l95; - l96:; - { int yypos97= ctx->pos, yythunkpos97= ctx->thunkpos; if (!yymatchDot(ctx)) goto l97; goto l96; - l97:; ctx->pos= yypos97; ctx->thunkpos= yythunkpos97; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l95; yyDo(ctx, yy_1_trailer, ctx->begin, ctx->end); - yyprintf((stderr, " ok %s @ %s\n", "trailer", ctx->buf+ctx->pos)); - return 1; - l95:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "trailer", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_definition(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "definition")); if (!yy_identifier(ctx)) goto l98; yyDo(ctx, yy_1_definition, ctx->begin, ctx->end); if (!yy_EQUAL(ctx)) goto l98; if (!yy_expression(ctx)) goto l98; yyDo(ctx, yy_2_definition, ctx->begin, ctx->end); - { int yypos99= ctx->pos, yythunkpos99= ctx->thunkpos; if (!yy_SEMICOLON(ctx)) goto l99; goto l100; - l99:; ctx->pos= yypos99; ctx->thunkpos= yythunkpos99; - } - l100:; - yyprintf((stderr, " ok %s @ %s\n", "definition", ctx->buf+ctx->pos)); - return 1; - l98:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "definition", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy_declaration(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "declaration")); if (!yymatchString(ctx, "%{")) goto l101; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l101; - l102:; - { int yypos103= ctx->pos, yythunkpos103= ctx->thunkpos; - { int yypos104= ctx->pos, yythunkpos104= ctx->thunkpos; if (!yymatchString(ctx, "%}")) goto l104; goto l103; - l104:; ctx->pos= yypos104; ctx->thunkpos= yythunkpos104; - } if (!yymatchDot(ctx)) goto l103; goto l102; - l103:; ctx->pos= yypos103; ctx->thunkpos= yythunkpos103; - } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l101; if (!yy_RPERCENT(ctx)) goto l101; yyDo(ctx, yy_1_declaration, ctx->begin, ctx->end); - yyprintf((stderr, " ok %s @ %s\n", "declaration", ctx->buf+ctx->pos)); - return 1; - l101:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "declaration", ctx->buf+ctx->pos)); - return 0; -} -YY_RULE(int) yy__(yycontext *ctx) -{ - yyprintf((stderr, "%s\n", "_")); - l106:; - { int yypos107= ctx->pos, yythunkpos107= ctx->thunkpos; - { int yypos108= ctx->pos, yythunkpos108= ctx->thunkpos; if (!yy_space(ctx)) goto l109; goto l108; - l109:; ctx->pos= yypos108; ctx->thunkpos= yythunkpos108; if (!yy_comment(ctx)) goto l107; - } - l108:; goto l106; - l107:; ctx->pos= yypos107; ctx->thunkpos= yythunkpos107; - } - yyprintf((stderr, " ok %s @ %s\n", "_", ctx->buf+ctx->pos)); - return 1; -} -YY_RULE(int) yy_grammar(yycontext *ctx) -{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; - yyprintf((stderr, "%s\n", "grammar")); if (!yy__(ctx)) goto l110; - { int yypos113= ctx->pos, yythunkpos113= ctx->thunkpos; if (!yy_declaration(ctx)) goto l114; goto l113; - l114:; ctx->pos= yypos113; ctx->thunkpos= yythunkpos113; if (!yy_definition(ctx)) goto l110; - } - l113:; - l111:; - { int yypos112= ctx->pos, yythunkpos112= ctx->thunkpos; - { int yypos115= ctx->pos, yythunkpos115= ctx->thunkpos; if (!yy_declaration(ctx)) goto l116; goto l115; - l116:; ctx->pos= yypos115; ctx->thunkpos= yythunkpos115; if (!yy_definition(ctx)) goto l112; - } - l115:; goto l111; - l112:; ctx->pos= yypos112; ctx->thunkpos= yythunkpos112; - } - { int yypos117= ctx->pos, yythunkpos117= ctx->thunkpos; if (!yy_trailer(ctx)) goto l117; goto l118; - l117:; ctx->pos= yypos117; ctx->thunkpos= yythunkpos117; - } - l118:; if (!yy_end_of_file(ctx)) goto l110; - yyprintf((stderr, " ok %s @ %s\n", "grammar", ctx->buf+ctx->pos)); - return 1; - l110:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "grammar", ctx->buf+ctx->pos)); - return 0; -} - -#ifndef YY_PART - -typedef int (*yyrule)(yycontext *ctx); - -YY_PARSE(int) YYPARSEFROM(YY_CTX_PARAM_ yyrule yystart) -{ - int yyok; - if (!yyctx->buflen) - { - yyctx->buflen= 1024; - yyctx->buf= (char *)malloc(yyctx->buflen); - yyctx->textlen= 1024; - yyctx->text= (char *)malloc(yyctx->textlen); - yyctx->thunkslen= 32; - yyctx->thunks= (yythunk *)malloc(sizeof(yythunk) * yyctx->thunkslen); - yyctx->valslen= 32; - yyctx->vals= (YYSTYPE *)malloc(sizeof(YYSTYPE) * yyctx->valslen); - yyctx->begin= yyctx->end= yyctx->pos= yyctx->limit= yyctx->thunkpos= 0; - } - yyctx->begin= yyctx->end= yyctx->pos; - yyctx->thunkpos= 0; - yyctx->val= yyctx->vals; - yyok= yystart(yyctx); - if (yyok) yyDone(yyctx); - yyCommit(yyctx); - return yyok; -} - -YY_PARSE(int) YYPARSE(YY_CTX_PARAM) -{ - return YYPARSEFROM(YY_CTX_ARG_ yy_grammar); -} - -#endif - - -void yyerror(char *message) -{ - fprintf(stderr, "%s:%d: %s", fileName, lineNumber, message); - if (yyctx->text[0]) fprintf(stderr, " near token '%s'", yyctx->text); - if (yyctx->pos < yyctx->limit || !feof(input)) - { - yyctx->buf[yyctx->limit]= '\0'; - fprintf(stderr, " before text \""); - while (yyctx->pos < yyctx->limit) - { - if ('\n' == yyctx->buf[yyctx->pos] || '\r' == yyctx->buf[yyctx->pos]) break; - fputc(yyctx->buf[yyctx->pos++], stderr); - } - if (yyctx->pos == yyctx->limit) - { - int c; - while (EOF != (c= fgetc(input)) && '\n' != c && '\r' != c) - fputc(c, stderr); - } - fputc('\"', stderr); - } - fprintf(stderr, "\n"); - exit(1); -} - -void makeHeader(char *text) -{ - Header *header= (Header *)malloc(sizeof(Header)); - header->text= strdup(text); - header->next= headers; - headers= header; -} - -void makeTrailer(char *text) -{ - trailer= strdup(text); -} - -static void version(char *name) -{ - printf("%s version %d.%d.%d\n", name, PEG_MAJOR, PEG_MINOR, PEG_LEVEL); -} - -static void usage(char *name) -{ - version(name); - fprintf(stderr, "usage: %s [