diff --git a/.gitignore b/.gitignore index 8f314aa..1310191 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.[oa] greg greg.exe -samples/*.c +rpeg +rpeg.exe +samples/*.leg.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..40ab720 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Ian Piumarta (Original author of peg/leg) +_why (Original author of greg, derived from leg) +Amos Wenger (Improved error reporting) +Onne Gortner +Amos Wenger +Ali Rantakari +Steve White (leg samples for greg derived from peg samples) +Giulio Paci (Original author of rpeg, derived from peg and greg) diff --git a/Makefile b/Makefile index 7cfecb4..d835b6a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,11 @@ OFLAGS = -O3 -DNDEBUG OBJS = tree.o compile.o -all : greg +all : greg rpeg + +rpeg : rpeg.o $(OBJS) + $(CC) $(CFLAGS) -o $@-new rpeg.o $(OBJS) + mv $@-new $@ greg : greg.o $(OBJS) $(CC) $(CFLAGS) -o $@-new greg.o $(OBJS) @@ -14,43 +18,41 @@ ROOT = PREFIX = /usr BINDIR = $(ROOT)$(PREFIX)/bin -install : $(BINDIR)/greg +install : $(BINDIR)/rpeg $(BINDIR)/greg $(BINDIR)/% : % cp -p $< $@ strip $@ uninstall : .FORCE + rm -f $(BINDIR)/rpeg rm -f $(BINDIR)/greg +rpeg.o : rpeg.c rpeg.peg-c + +%.peg-c : %.peg + ./rpeg -o $@ $< + greg.o : greg.c -grammar : .FORCE - ./greg -o greg.c greg.g +greg.c : greg.g + ./greg -o $@ $< + +check : rpeg .FORCE + ./rpeg < rpeg.peg > rpeg.out + diff rpeg.peg-c rpeg.out + rm rpeg.out + +test examples : .FORCE + $(SHELL) -ec '(cd examples; $(MAKE))' clean : .FORCE - rm -rf *~ *.o *.greg.[cd] greg samples/*.o samples/calc samples/*.dSYM testing1.c testing2.c *.dSYM selftest/ + rm -rf *~ *.o *.greg.[cd] *.rpeg.[cd] + $(SHELL) -ec '(cd examples; $(MAKE) $@)' spotless : clean .FORCE + rm -f rpeg rm -f greg - -samples/calc.c: samples/calc.leg greg - ./greg -o $@ $< - -samples/calc: samples/calc.c - $(CC) $(CFLAGS) -o $@ $< - -test: samples/calc greg-testing - echo '21 * 2 + 0' | ./samples/calc | grep 42 - -run: greg.g greg - mkdir -p selftest - ./greg -o testing1.c greg.g - $(CC) $(CFLAGS) -o selftest/testing1 testing1.c $(OBJS) - $(TOOL) ./selftest/testing1 -o testing2.c greg.g - $(CC) $(CFLAGS) -o selftest/testing2 testing2.c $(OBJS) - $(TOOL) ./selftest/testing2 -o selftest/calc.c ./samples/calc.leg - $(CC) $(CFLAGS) -o selftest/calc selftest/calc.c - $(TOOL) echo '21 * 2 + 0' | ./selftest/calc | grep 42 + $(SHELL) -ec '(cd examples; $(MAKE) $@)' .FORCE : diff --git a/README b/README index 932e8c4..246c022 100644 --- a/README +++ b/README @@ -1,11 +1,15 @@ greg is a re-entrant peg/leg, with some bug fixes. + +The original peg/leg 0.1.9 was released with re-entrant capabilities. + +And now most relevant features of greg (e.g., error handling) are +being integrated into the original peg/leg software -the most comprehensive example of greg usage is in -nagaqueen, an ooc grammar, used in rock, an ooc -compiler written in ooc. +The most comprehensive example of greg usage is in nagaqueen, an ooc +grammar, used in rock, an ooc compiler written in ooc. -peg/leg is copyright (c) 2007 by Ian Piumarta +peg/leg is copyright (c) 2007-2012 by Ian Piumarta released under an MIT license. as is greg. diff --git a/compile.c b/compile.c index 31df7b9..70af528 100644 --- a/compile.c +++ b/compile.c @@ -13,7 +13,7 @@ * * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. * - * Last edited: 2007-08-31 13:55:23 by piumarta on emilia.local + * Last edited: 2011-11-25 11:16:57 by piumarta on emilia */ #include @@ -21,7 +21,8 @@ #include #include -#include "greg.h" +#include "version.h" +#include "tree.h" static int yyl(void) { @@ -34,28 +35,17 @@ static void charClassClear(unsigned char bits[], int c) { bits[c >> 3] &= ~(1 << typedef void (*setter)(unsigned char bits[], int c); -static int readChar(unsigned char **cp) +static inline int oigit(int c) { return '0' <= c && c <= '7'; } + +static int cnext(unsigned char **ccp) { - unsigned char *cclass = *cp; - int c= *cclass++, i = 0; + unsigned char *cclass = *ccp; + int c= *cclass++; + if (c) + { if ('\\' == c && *cclass) { - c= *cclass++; - if (c >= '0' && c <= '9') - { - unsigned char oct= 0; - for (i= 2; i >= 0; i--) { - if (!(c >= '0' && c <= '9')) - break; - oct= (oct * 8) + (c - '0'); - c= *cclass++; - } - cclass--; - c= oct; - goto done; - } - - switch (c) + switch (c= *cclass++) { case 'a': c= '\a'; break; /* bel */ case 'b': c= '\b'; break; /* bs */ @@ -65,12 +55,18 @@ static int readChar(unsigned char **cp) case 'r': c= '\r'; break; /* cr */ case 't': c= '\t'; break; /* ht */ case 'v': c= '\v'; break; /* vt */ - default: break; + default: + if (oigit(c)) + { + c -= '0'; + if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0'; + if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0'; + } + break; } } - -done: - *cp = cclass; + *ccp = cclass; + } return c; } @@ -93,16 +89,19 @@ static char *makeCharClass(unsigned char *cclass) memset(bits, 0, 32); set= charClassSet; } - while (0 != (c= readChar(&cclass))) + + while (*cclass) { - if ('-' == c && *cclass && prev >= 0) + if ('-' == *cclass && cclass[1] && prev >= 0) { - for (c= readChar(&cclass); prev <= c; ++prev) + ++cclass; + for (c= cnext(&cclass); prev <= c; ++prev) set(bits, prev); prev= -1; } else { + c= cnext(&cclass); set(bits, prev= c); } } @@ -155,10 +154,18 @@ static void Node_compile_c_ko(Node *node, int ko) case String: { int len= strlen(node->string.value); - if (1 == len || (2 == len && '\\' == node->string.value[0])) - fprintf(output, " if (!yymatchChar(G, '%s')) goto l%d;", node->string.value, ko); + if (1 == len) + { + if ('\'' == node->string.value[0]) + fprintf(output, " if (!yymatchChar(G, '\\'')) goto l%d;", ko); + else + fprintf(output, " if (!yymatchChar(G, '%s')) goto l%d;", node->string.value, ko); + } else - fprintf(output, " if (!yymatchString(G, \"%s\")) goto l%d;", node->string.value, ko); + if (2 == len && '\\' == node->string.value[0]) + fprintf(output, " if (!yymatchChar(G, '%s')) goto l%d;", node->string.value, ko); + else + fprintf(output, " if (!yymatchString(G, \"%s\")) goto l%d;", node->string.value, ko); } break; diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..6de66cc --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,125 @@ +EXAMPLES = test test-greg rule rule-greg accept accept-greg wc dc-greg dc dcv dcv-greg calc basic + +CFLAGS = -g -O3 + +DIFF = diff +TEE = cat > + +all : $(EXAMPLES) + +test : .FORCE + ../rpeg -o test.peg.c test.peg + $(CC) $(CFLAGS) -o test test.c + echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | ./$@ | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +test-greg : .FORCE + ../greg -o $(@:-greg=.leg).c $(@:-greg=.leg) + sed -e 's/[.]peg[.]c/.leg.c/g' $(@:-greg=.c) > $@.c + $(CC) $(CFLAGS) -o $@ $@.c + echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | ./$@ | $(TEE) $@.out + $(DIFF) $(@:-greg=.ref) $@.out + rm -f $@.out + @echo + +rule : .FORCE + ../rpeg -o rule.peg.c rule.peg + $(CC) $(CFLAGS) -o rule rule.c + echo 'abcbcdabcbcdabcbcdabcbcd' | ./$@ | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +rule-greg : .FORCE + ../greg -o $(@:-greg=.leg).c $(@:-greg=.leg) + sed -e 's/[.]peg[.]c/.leg.c/g' $(@:-greg=.c) > $@.c + $(CC) $(CFLAGS) -o $@ $@.c + echo 'abcbcdabcbcdabcbcdabcbcd' | ./$@ | $(TEE) $@.out + $(DIFF) $(@:-greg=.ref) $@.out + rm -f $@.out + @echo + +accept : .FORCE + ../rpeg -o accept.peg.c accept.peg + $(CC) $(CFLAGS) -o accept accept.c + echo 'abcbcdabcbcdabcbcdabcbcd' | ./$@ | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +accept-greg : .FORCE + ../greg -o $(@:-greg=.leg).c $(@:-greg=.leg) + sed -e 's/[.]peg[.]c/.leg.c/g' $(@:-greg=.c) > $@.c + $(CC) $(CFLAGS) -o $@ $@.c + echo 'abcbcdabcbcdabcbcdabcbcd' | ./$@ | $(TEE) $@.out + $(DIFF) $(@:-greg=.ref) $@.out + rm -f $@.out + @echo + +wc : .FORCE + ../greg -o wc.leg.c wc.leg + $(CC) $(CFLAGS) -o wc wc.leg.c + cat wc.leg | ./$@ | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +dc : .FORCE + ../rpeg -o dc.peg.c dc.peg + $(CC) $(CFLAGS) -o dc dc.c + echo ' 2 *3 *(3+ 4) ' | ./dc | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +dc-greg : .FORCE + ../greg -o $(@:-greg=.leg).c $(@:-greg=.leg) + sed -e 's/[.]peg[.]c/.leg.c/g' $(@:-greg=.c) > $@.c + $(CC) $(CFLAGS) -o $@ $@.c + echo ' 2 *3 *(3+ 4) ' | ./$@ | $(TEE) $@.out + $(DIFF) $(@:-greg=.ref) $@.out + rm -f $@.out + @echo + +dcv : .FORCE + ../rpeg -o dcv.peg.c dcv.peg + $(CC) $(CFLAGS) -o dcv dcv.c + echo 'a = 6; b = 7; a * b' | ./dcv | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +dcv-greg : .FORCE + ../greg -o $(@:-greg=.leg).c $(@:-greg=.leg) + sed -e 's/[.]peg[.]c/.leg.c/g' $(@:-greg=.c) > $@.c + $(CC) $(CFLAGS) -o $@ $@.c + echo 'a = 6; b = 7; a * b' | ./$@ | $(TEE) $@.out + $(DIFF) $(@:-greg=.ref) $@.out + rm -f $@.out + @echo + +calc : .FORCE + ../greg -o calc.leg.c calc.leg + $(CC) $(CFLAGS) -o calc calc.leg.c + echo 'a = 6; b = 7; a * b' | ./calc | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +basic : .FORCE + ../greg -o basic.leg.c basic.leg + $(CC) $(CFLAGS) -o basic basic.leg.c + ( echo 'load "test"'; echo "run" ) | ./basic | $(TEE) $@.out + $(DIFF) $@.ref $@.out + rm -f $@.out + @echo + +clean : .FORCE + rm -f *~ *.o *.[pl]eg.[cd] $(EXAMPLES) *-greg.c + rm -rf *.dSYM + +spotless : clean + +.FORCE : diff --git a/examples/accept.c b/examples/accept.c new file mode 100644 index 0000000..d208abd --- /dev/null +++ b/examples/accept.c @@ -0,0 +1,14 @@ +#include +#include + +#include "accept.peg.c" + +int main() +{ + GREG g; + yyinit(&g); + while (yyparse(&g)); + yydeinit(&g); + + return 0; +} diff --git a/samples/accept.leg b/examples/accept.leg similarity index 100% rename from samples/accept.leg rename to examples/accept.leg diff --git a/examples/accept.peg b/examples/accept.peg new file mode 100644 index 0000000..7c6f742 --- /dev/null +++ b/examples/accept.peg @@ -0,0 +1,8 @@ +start <- abcd+ + +abcd <- 'a' { printf("A %d\n", G->pos); } bc { printf("ABC %d\n", G->pos); } &{YYACCEPT} + / 'b' { printf("B %d\n", G->pos); } cd { printf("BCD %d\n", G->pos); } &{YYACCEPT} + +bc <- 'b' { printf("B %d\n", G->pos); } 'c' { printf("C %d\n", G->pos); } + +cd <- 'c' { printf("C %d\n", G->pos); } 'd' { printf("D %d\n", G->pos); } diff --git a/samples/accept.ref b/examples/accept.ref similarity index 100% rename from samples/accept.ref rename to examples/accept.ref diff --git a/samples/basic.leg b/examples/basic.leg similarity index 100% rename from samples/basic.leg rename to examples/basic.leg diff --git a/samples/basic.ref b/examples/basic.ref similarity index 100% rename from samples/basic.ref rename to examples/basic.ref diff --git a/samples/bench.bas b/examples/bench.bas similarity index 100% rename from samples/bench.bas rename to examples/bench.bas diff --git a/samples/calc.leg b/examples/calc.leg similarity index 100% rename from samples/calc.leg rename to examples/calc.leg diff --git a/samples/calc.ref b/examples/calc.ref similarity index 100% rename from samples/calc.ref rename to examples/calc.ref diff --git a/examples/dc.c b/examples/dc.c new file mode 100644 index 0000000..9ae8dc6 --- /dev/null +++ b/examples/dc.c @@ -0,0 +1,20 @@ +#include +#include + +int stack[1024]; +int stackp= -1; + +int push(int n) { return stack[++stackp]= n; } +int pop(void) { return stack[stackp--]; } + +#include "dc.peg.c" + +int main() +{ + GREG g; + yyinit(&g); + while (yyparse(&g)); + yydeinit(&g); + + return 0; +} diff --git a/samples/dc.leg b/examples/dc.leg similarity index 100% rename from samples/dc.leg rename to examples/dc.leg diff --git a/examples/dc.peg b/examples/dc.peg new file mode 100644 index 0000000..75dcb67 --- /dev/null +++ b/examples/dc.peg @@ -0,0 +1,27 @@ +# Grammar + +Expr <- SPACE Sum EOL { printf("%d\n", pop()); } + / (!EOL .)* EOL { printf("error\n"); } + +Sum <- Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); } + / MINUS Product { int r= pop(), l= pop(); push(l - r); } + )* + +Product <- Value ( TIMES Value { int r= pop(), l= pop(); push(l * r); } + / DIVIDE Value { int r= pop(), l= pop(); push(l / r); } + )* + +Value <- NUMBER { push(atoi(yytext)); } + / OPEN Sum CLOSE + +# Lexemes + +NUMBER <- < [0-9]+ > SPACE +PLUS <- '+' SPACE +MINUS <- '-' SPACE +TIMES <- '*' SPACE +DIVIDE <- '/' SPACE +OPEN <- '(' SPACE +CLOSE <- ')' SPACE +SPACE <- [ \t]* +EOL <- '\n' / '\r\n' / '\r' diff --git a/samples/dc.ref b/examples/dc.ref similarity index 100% rename from samples/dc.ref rename to examples/dc.ref diff --git a/examples/dcv.c b/examples/dcv.c new file mode 100644 index 0000000..77667cd --- /dev/null +++ b/examples/dcv.c @@ -0,0 +1,23 @@ +#include +#include + +int stack[1024]; +int stackp= -1; +int var= 0; +int vars[26]; + +int push(int n) { return stack[++stackp]= n; } +int pop(void) { return stack[stackp--]; } +int top(void) { return stack[stackp]; } + +#include "dcv.peg.c" + +int main() +{ + GREG g; + yyinit(&g); + while (yyparse(&g)); + yydeinit(&g); + + return 0; +} diff --git a/samples/dcv.leg b/examples/dcv.leg similarity index 100% rename from samples/dcv.leg rename to examples/dcv.leg diff --git a/examples/dcv.peg b/examples/dcv.peg new file mode 100644 index 0000000..2ae3a8c --- /dev/null +++ b/examples/dcv.peg @@ -0,0 +1,34 @@ +# Grammar + +Stmt <- SPACE Expr EOL { printf("%d\n", pop()); } + / (!EOL .)* EOL { printf("error\n"); } + +Expr <- ID { var= yytext[0] } ASSIGN Sum { vars[var - 'a']= top(); } + / Sum + +Sum <- Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); } + / MINUS Product { int r= pop(), l= pop(); push(l - r); } + )* + +Product <- Value ( TIMES Value { int r= pop(), l= pop(); push(l * r); } + / DIVIDE Value { int r= pop(), l= pop(); push(l / r); } + )* + +Value <- NUMBER { push(atoi(yytext)); } + / < ID > !ASSIGN { push(vars[yytext[0] - 'a']); } + / OPEN Expr CLOSE + +# Lexemes + +NUMBER <- < [0-9]+ > SPACE +ID <- < [a-z] > SPACE +ASSIGN <- '=' SPACE +PLUS <- '+' SPACE +MINUS <- '-' SPACE +TIMES <- '*' SPACE +DIVIDE <- '/' SPACE +OPEN <- '(' SPACE +CLOSE <- ')' SPACE + +SPACE <- [ \t]* +EOL <- '\n' / '\r\n' / '\r' / ';' diff --git a/samples/dcv.ref b/examples/dcv.ref similarity index 100% rename from samples/dcv.ref rename to examples/dcv.ref diff --git a/samples/fibonacci.bas b/examples/fibonacci.bas similarity index 100% rename from samples/fibonacci.bas rename to examples/fibonacci.bas diff --git a/examples/left.c b/examples/left.c new file mode 100644 index 0000000..2545cb6 --- /dev/null +++ b/examples/left.c @@ -0,0 +1,20 @@ +#include + +#define YY_INPUT(buf, result, max, D) \ +{ \ + int c= getchar(); \ + result= (EOF == c) ? 0 : (*(buf)= c, 1); \ + if (EOF != c) printf("<%c>\n", c); \ +} + +#include "left.peg.c" + +int main() +{ + GREG g; + yyinit(&g); + printf(yyparse(&g) ? "success\n" : "failure\n"); + yydeinit(&g); + + return 0; +} diff --git a/samples/left.leg b/examples/left.leg similarity index 100% rename from samples/left.leg rename to examples/left.leg diff --git a/examples/left.peg b/examples/left.peg new file mode 100644 index 0000000..f282227 --- /dev/null +++ b/examples/left.peg @@ -0,0 +1,3 @@ +# Grammar + +S <- (S 'a' / 'a') !'a' diff --git a/examples/rule.c b/examples/rule.c new file mode 100644 index 0000000..fdeee35 --- /dev/null +++ b/examples/rule.c @@ -0,0 +1,14 @@ +#include +#include + +#include "rule.peg.c" + +int main() +{ + GREG g; + yyinit(&g); + while (yyparse(&g)); + yydeinit(&g); + + return 0; +} diff --git a/samples/rule.leg b/examples/rule.leg similarity index 100% rename from samples/rule.leg rename to examples/rule.leg diff --git a/examples/rule.peg b/examples/rule.peg new file mode 100644 index 0000000..f263fc8 --- /dev/null +++ b/examples/rule.peg @@ -0,0 +1,8 @@ +start <- abcd+ + +abcd <- 'a' { printf("A %d\n", G->pos); } bc { printf("ABC %d\n", G->pos); } + / 'b' { printf("B %d\n", G->pos); } cd { printf("BCD %d\n", G->pos); } + +bc <- 'b' { printf("B %d\n", G->pos); } 'c' { printf("C %d\n", G->pos); } + +cd <- 'c' { printf("C %d\n", G->pos); } 'd' { printf("D %d\n", G->pos); } diff --git a/samples/rule.ref b/examples/rule.ref similarity index 100% rename from samples/rule.ref rename to examples/rule.ref diff --git a/samples/test.bas b/examples/test.bas similarity index 100% rename from samples/test.bas rename to examples/test.bas diff --git a/examples/test.c b/examples/test.c new file mode 100644 index 0000000..e77e9a1 --- /dev/null +++ b/examples/test.c @@ -0,0 +1,11 @@ +#include +#include "test.peg.c" + +int main() +{ + GREG g; + yyinit(&g); + while (yyparse(&g)); + yydeinit(&g); + return 0; +} diff --git a/samples/test.leg b/examples/test.leg similarity index 100% rename from samples/test.leg rename to examples/test.leg diff --git a/examples/test.peg b/examples/test.peg new file mode 100644 index 0000000..716d523 --- /dev/null +++ b/examples/test.peg @@ -0,0 +1,13 @@ +start <- body '.' { printf(".\n"); } + +body <- 'a' { printf("a1 "); } 'b' { printf("ab1 "); } + + / 'a' { printf("a2 "); } 'c' { printf("ac2 "); } + + / 'a' { printf("a3 "); } ( 'd' { printf("ad3 "); } / 'e' { printf("ae3 "); } ) + + / 'a' { printf("a4 "); } ( 'f' { printf("af4 "); } 'g' { printf("afg4 "); } + / 'f' { printf("af5 "); } 'h' { printf("afh5 "); } ) + + / 'a' { printf("a6 "); } ( 'f' &{ printf("af6 ") } 'i' &{ printf("afi6 ") } + / 'f' &{ printf("af7 ") } 'j' &{ printf("afj7 ") } ) diff --git a/samples/test.ref b/examples/test.ref similarity index 100% rename from samples/test.ref rename to examples/test.ref diff --git a/samples/username.leg b/examples/username.leg similarity index 100% rename from samples/username.leg rename to examples/username.leg diff --git a/samples/wc.leg b/examples/wc.leg similarity index 100% rename from samples/wc.leg rename to examples/wc.leg diff --git a/samples/wc.ref b/examples/wc.ref similarity index 100% rename from samples/wc.ref rename to examples/wc.ref diff --git a/greg.1 b/greg.1 new file mode 100644 index 0000000..ffd9fdd --- /dev/null +++ b/greg.1 @@ -0,0 +1,952 @@ +.\" Copyright (c) 2007 by Ian Piumarta +.\" Copyright (c) 2012 by Giulio Paci +.\" All rights reserved. +.\" +.\" Permission is hereby granted, free of charge, to any person obtaining a +.\" copy of this software and associated documentation files (the 'Software'), +.\" to deal in the Software without restriction, including without limitation +.\" the rights to use, copy, modify, merge, publish, distribute, and/or sell +.\" copies of the Software, and to permit persons to whom the Software is +.\" furnished to do so, provided that the above copyright notice(s) and this +.\" permission notice appear in all copies of the Software. Acknowledgement +.\" of the use of this Software in supporting documentation would be +.\" appreciated but is not required. +.\" +.\" THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. +.\" +.\" Last edited: 2007-09-13 08:40:20 by piumarta on emilia.local +.\" +.TH GREG 1 "May 2012" "Version 0.44" +.SH NAME +rpeg, greg \- parser generators +.SH SYNOPSIS +.B rpeg +.B [\-hvV \-ooutput] +.I [filename ...] +.sp 0 +.B greg +.B [\-hvV \-ooutput] +.I [filename ...] +.SH DESCRIPTION +.I rpeg +and +.I greg +are tools for generating recursive\-descent parsers: programs that +perform pattern matching on text. They process a Parsing Expression +Grammar (PEG) [Ford 2004] to produce a program that recognises legal +sentences of that grammar. +.I rpeg +processes PEGs written using the original syntax described by Ford; +.I greg +processes PEGs written using slightly different syntax and conventions +that are intended to make it an attractive replacement for parsers +built with +.IR lex (1) +and +.IR yacc (1). +Unlike +.I lex +and +.IR yacc , +.I rpeg +and +.I greg +support unlimited backtracking, provide ordered choice as a means for +disambiguation, and can combine scanning (lexical analysis) and +parsing (syntactic analysis) into a single activity. +.PP +.I rpeg +and +.I greg +are modified versions of +.I peg +and +.IR leg , +two tools developed by Ian Piumarta. +Unlike +.I peg +and +.IR leg , +.I rpeg +and +.I greg +generate re\-entrant parsers with enhanced error reporting capabilities. Programs developed using +.I peg +and +.I leg +requires small adaptations to be used with +.I rpeg +and +.IR greg . + + + +.PP +.I rpeg +reads the specified +.IR filename s, +or standard input if no +.IR filename s +are given, for a grammar describing the parser to generate. +.I rpeg +then generates a C source file that defines a parser object type +.I GREG +and a function +.IR yyparse( +.I GREG +*G ). +This C source file can be included in, or compiled and then linked +with, a client program. Each time the client program calls +.IR yyparse () +the parser consumes input text according to the parsing rules, +starting from the first rule in the grammar. +.IR yyparse () +returns non\-zero if the input could be parsed according to the +grammar; it returns zero if the input could not be parsed. +.PP +The prefix 'yy' or 'YY' is prepended to all externally\-visible symbols +in the generated parser. This is intended to reduce the risk of +namespace pollution in client programs. (The choice of 'yy' is +historical; see +.IR lex (1) +and +.IR yacc (1), +for example.) +.SH OPTIONS +.I rpeg +and +.I greg +provide the following options: +.TP +.B \-h +prints a summary of available options and then exits. +.TP +.B \-ooutput +writes the generated parser to the file +.B output +instead of the standard output. +.TP +.B \-v +writes verbose information to standard error while working. +.TP +.B \-V +writes version information to standard error then exits. +.SH A SIMPLE EXAMPLE +The following +.I rpeg +input specifies a grammar with a single rule (called 'start') that is +satisfied when the input contains the string "username". +.nf + + start <\- "username" + +.fi +(The quotation marks are +.I not +part of the matched text; they serve to indicate a literal string to +be matched.) In other words, +.IR yyparse () +in the generated C source will return non\-zero only if the next eight +characters read from the input spell the word "username". If the +input contains anything else, +.IR yyparse () +returns zero and no input will have been consumed. (Subsequent calls +to +.IR yyparse () +will also return zero, since the parser is effectively blocked looking +for the string "username".) To ensure progress we can add an +alternative clause to the 'start' rule that will match any single +character if "username" is not found. +.nf + + start <\- "username" + / . + +.fi +.IR yyparse () +now always returns non\-zero (except at the very end of the input). To +do something useful we can add actions to the rules. These actions +are performed after a complete match is found (starting from the first +rule) and are chosen according to the 'path' taken through the grammar +to match the input. (Linguists would call this path a 'phrase +marker'.) +.nf + + start <\- "username" { printf("%s\\n", getlogin()); } + / < . > { putchar(G\->text[0]); } + +.fi +The first line instructs the parser to print the user's login name +whenever it sees "username" in the input. If that match fails, the +second line tells the parser to echo the next character on the input +the standard output. Our parser is now performing useful work: it +will copy the input to the output, replacing all occurrences of +"username" with the user's account name. +.PP +Note the angle brackets ('<' and '>') that were added to the second +alternative. These have no effect on the meaning of the rule, but +serve to delimit the text made available to the following action in +the variable +.IR G\->text . +.PP +If the above grammar is placed in the file +.BR username.peg , +running the command +.nf + + rpeg \-o username.c username.peg + +.fi +will save the corresponding parser in the file +.BR username.c . +To create a complete program this parser could be included by a C +program as follows. +.nf + + #include /* printf(), putchar() */ + #include /* getlogin() */ + + #include "username.c" /* yyparse() */ + + int main() + { + GREG g; /* Allocate a GREG parser */ + yyinit(&g); /* Init the GREG parser */ + while (yyparse(&g)); /* repeat until EOF */ + yydeinit(&g); /* De\-init the GREG parser */ + return 0; + } +.fi +.SH PEG GRAMMARS +A grammar consists of a set of named rules. +.nf + + name <\- pattern + +.fi +The +.B pattern +contains one or more of the following elements. +.TP +.B name +The element stands for the entire pattern in the rule with the given +.BR name . +.TP +.BR \(dq characters \(dq +A character or string enclosed in double quotes is matched literally. +The ANSI C escape sequences are recognised within the +.IR characters . +.TP +.BR ' characters ' +A character or string enclosed in single quotes is matched literally, as above. +.TP +.BR [ characters ] +A set of characters enclosed in square brackets matches any single +character from the set, with escape characters recognised as above. +If the set begins with an uparrow (^) then the set is negated (the +element matches any character +.I not +in the set). Any pair of characters separated with a dash (\-) +represents the range of characters from the first to the second, +inclusive. A single alphabetic character or underscore is matched by +the following set. +.nf + + [a\-zA\-Z_] + +.fi +Similarly, the following matches any single non\-digit character. +.nf + + [^0\-9] + +.fi +.TP +.B . +A dot matches any character. Note that the only time this fails is at +the end of file, where there is no character to match. +.TP +.BR ( \ pattern\ ) +Parentheses are used for grouping (modifying the precedence of the +operators described below). +.TP +.BR { \ action\ } +Curly braces surround actions. The action is arbitrary C source code +to be executed at the end of matching. Any braces within the action +must be properly nested. Any input text that was matched before the +action and delimited by angle brackets (see below) is made available +within the action as the contents of the character array +.IR G\->text . +The length of (number of characters in) +.I G\->text +is available in the variable +.IR G\->leng . +(These variable names are historical; see +.IR lex (1).) +.TP +.B < +An opening angle bracket always matches (consuming no input) and +causes the parser to begin accumulating matched text. This text will +be made available to actions in the variable +.IR G\->text . +.TP +.B > +A closing angle bracket always matches (consuming no input) and causes +the parser to stop accumulating text for +.IR G\->text . +.PP +The above +.IR element s +can be made optional and/or repeatable with the following suffixes: +.TP +.RB element\ ? +The element is optional. If present on the input, it is consumed and +the match succeeds. If not present on the input, no text is consumed +and the match succeeds anyway. +.TP +.RB element\ + +The element is repeatable. If present on the input, one or more +occurrences of +.I element +are consumed and the match succeeds. If no occurrences of +.I element +are present on the input, the match fails. +.TP +.RB element\ * +The element is optional and repeatable. If present on the input, one or more +occurrences of +.I element +are consumed and the match succeeds. If no occurrences of +.I element +are present on the input, the match succeeds anyway. +.PP +The above elements and suffixes can be converted into predicates (that +match arbitrary input text and subsequently succeed or fail +.I without +consuming that input) with the following prefixes: +.TP +.BR & \ element +The predicate succeeds only if +.I element +can be matched. Input text scanned while matching +.I element +is not consumed from the input and remains available for subsequent +matching. +.TP +.BR ! \ element +The predicate succeeds only if +.I element +cannot be matched. Input text scanned while matching +.I element +is not consumed from the input and remains available for subsequent +matching. A popular idiom is +.nf + + !. + +.fi +which matches the end of file, after the last character of the input +has already been consumed. +.PP +A special form of the '&' predicate is provided: +.TP +.BR & {\ expression\ } +In this predicate the simple C +.I expression +.RB ( not +statement) is evaluated immediately when the parser reaches the +predicate. If the +.I expression +yields non\-zero (true) the 'match' succeeds and the parser continues +with the next element in the pattern. If the +.I expression +yields zero (false) the 'match' fails and the parser backs up to look +for an alternative parse of the input. +.PP +Several elements (with or without prefixes and suffixes) can be +combined into a +.I sequence +by writing them one after the other. The entire sequence matches only +if each individual element within it matches, from left to right. +.PP +Sequences can be separated into disjoint alternatives by the +alternation operator '/'. +.TP +.RB sequence\-1\ / \ sequence\-2\ / \ ...\ / \ sequence\-N +Each sequence is tried in turn until one of them matches, at which +time matching for the overall pattern succeeds. If none of the +sequences matches then the match of the overall pattern fails. +.PP +Finally, the pound sign (#) introduces a comment (discarded) that +continues until the end of the line. +.PP +To summarise the above, the parser tries to match the input text +against a pattern containing literals, names (representing other +rules), and various operators (written as prefixes, suffixes, +juxtaposition for sequencing and and infix alternation operator) that +modify how the elements within the pattern are matched. Matches are +made from left to right, 'descending' into named sub\-rules as they are +encountered. If the matching process fails, the parser 'back tracks' +('rewinding' the input appropriately in the process) to find the +nearest alternative 'path' through the grammar. In other words the +parser performs a depth\-first, left\-to\-right search for the first +successfully\-matching path through the rules. If found, the actions +along the successful path are executed (in the order they were +encountered). +.PP +Note that predicates are evaluated +.I immediately +during the search for a successful match, since they contribute to the +success or failure of the search. Actions, however, are evaluated +only after a successful match has been found. +.SH PEG GRAMMAR FOR PEG GRAMMARS +The grammar for +.I peg +grammars is shown below. This will both illustrate and formalise +the above description. +.nf + + Grammar <\- Spacing Definition+ EndOfFile + + Definition <\- Identifier LEFTARROW Expression + Expression <\- Sequence ( SLASH Sequence )* + Sequence <\- Prefix* + Prefix <\- AND Action + / ( AND | NOT )? Suffix + Suffix <\- Primary ( QUERY / STAR / PLUS )? + Primary <\- Identifier !LEFTARROW + / OPEN Expression CLOSE + / Literal + / Class + / DOT + / Action + / BEGIN + / END + + Identifier <\- < IdentStart IdentCont* > Spacing + IdentStart <\- [a\-zA\-Z_] + IdentCont <\- IdentStart / [0\-9] + Literal <\- ['] < ( !['] Char )* > ['] Spacing + / ["] < ( !["] Char )* > ["] Spacing + Class <\- '[' < ( !']' Range )* > ']' Spacing + Range <\- Char '\-' Char / Char + Char <\- '\\\\' [abefnrtv'"\\[\\]\\\\] + / '\\\\' [0\-3][0\-7][0\-7] + / '\\\\' [0\-7][0\-7]? + / '\\\\' '\-' + / !'\\\\' . + LEFTARROW <\- '<\-' Spacing + SLASH <\- '/' Spacing + AND <\- '&' Spacing + NOT <\- '!' Spacing + QUERY <\- '?' Spacing + STAR <\- '*' Spacing + PLUS <\- '+' Spacing + OPEN <\- '(' Spacing + CLOSE <\- ')' Spacing + DOT <\- '.' Spacing + Spacing <\- ( Space / Comment )* + Comment <\- '#' ( !EndOfLine . )* EndOfLine + Space <\- ' ' / '\\t' / EndOfLine + EndOfLine <\- '\\r\\n' / '\\n' / '\\r' + EndOfFile <\- !. + Action <\- '{' < [^}]* > '}' Spacing + BEGIN <\- '<' Spacing + END <\- '>' Spacing + +.fi +.SH LEG GRAMMARS +.I leg +is a variant of +.I peg +that adds some features of +.IR lex (1) +and +.IR yacc (1). +It differs from +.I peg +in the following ways. +.TP +.BI %{\ text... \ %} +A declaration section can appear anywhere that a rule definition is +expected. The +.I text +between the delimiters '%{' and '%}' is copied verbatim to the +generated C parser code +.I before +the code that implements the parser itself. +.TP +.IB name\ = \ pattern +The 'assignment' operator replaces the left arrow operator '<\-'. +.TP +.B rule\-name +Hyphens can appear as letters in the names of rules. Each hyphen is +converted into an underscore in the generated C source code. A single +single hyphen '\-' is a legal rule name. +.nf + + \- = [ \\t\\n\\r]* + number = [0\-9]+ \- + name = [a\-zA\-Z_][a\-zA_Z_0\-9]* \- + l\-paren = '(' \- + r\-paren = ')' \- + +.fi +This example shows how ignored whitespace can be obvious when reading +the grammar and yet unobtrusive when placed liberally at the end of +every rule associated with a lexical element. +.TP +.IB seq\-1\ | \ seq\-2 +The alternation operator is vertical bar '|' rather than forward +slash '/'. The +.I peg +rule +.nf + + name <\- sequence\-1 + / sequence\-2 + / sequence\-3 + +.fi +is therefore written +.nf + + name = sequence\-1 + | sequence\-2 + | sequence\-3 + ; + +.fi +in +.I leg +(with the final semicolon being optional, as described next). +.TP +.IB pattern\ ; +A semicolon punctuator can optionally terminate a +.IR pattern . +.TP +.BI %% \ text... +A double percent '%%' terminates the rules (and declarations) section of +the grammar. All +.I text +following '%%' is copied verbatim to the generated C parser code +.I after +the parser implementation code. +.TP +.BI $$\ = \ value +A sub\-rule can return a semantic +.I value +from an action by assigning it to the pseudo\-variable '$$'. All +semantic values must have the same type (which defaults to 'int'). +This type can be changed by defining YYSTYPE in a declaration section. +.TP +.IB identifier : name +The semantic value returned (by assigning to '$$') from the sub\-rule +.I name +is associated with the +.I identifier +and can be referred to in subsequent actions. +.PP +The desk calculator example below illustrates the use of '$$' and ':'. +.SH LEG EXAMPLE: A DESK CALCULATOR +The extensions in +.I leg +described above allow useful parsers and evaluators (including +declarations, grammar rules, and supporting C functions such +as 'main') to be kept within a single source file. To illustrate this +we show a simple desk calculator supporting the four common arithmetic +operators and named variables. The intermediate results of arithmetic +evaluation will be accumulated on an implicit stack by returning them +as semantic values from sub\-rules. +.nf + + %{ + #include /* printf() */ + #include /* atoi() */ + int vars[26]; + %} + + Stmt = \- e:Expr EOL { printf("%d\\n", e); } + | ( !EOL . )* EOL { printf("error\\n"); } + + Expr = i:ID ASSIGN s:Sum { $$ = vars[i] = s; } + | s:Sum { $$ = s; } + + Sum = l:Product + ( PLUS r:Product { l += r; } + | MINUS r:Product { l \-= r; } + )* { $$ = l; } + + Product = l:Value + ( TIMES r:Value { l *= r; } + | DIVIDE r:Value { l /= r; } + )* { $$ = l; } + + Value = i:NUMBER { $$ = atoi(G\->text); } + | i:ID !ASSIGN { $$ = vars[i]; } + | OPEN i:Expr CLOSE { $$ = i; } + + NUMBER = < [0\-9]+ > \- { $$ = atoi(G\->text); } + ID = < [a\-z] > \- { $$ = G\->text[0] \- 'a'; } + ASSIGN = '=' \- + PLUS = '+' \- + MINUS = '\-' \- + TIMES = '*' \- + DIVIDE = '/' \- + OPEN = '(' \- + CLOSE = ')' \- + + \- = [ \\t]* + EOL = '\\n' | '\\r\\n' | '\\r' | ';' + + %% + + int main() + { + GREG g; + yyinit(&g); + while (yyparse(&g)); + yydeinit(&g); + return 0; + } + +.fi +.SH LEG GRAMMAR FOR LEG GRAMMARS +The grammar for +.I leg +grammars is shown below. This will both illustrate and formalise the +above description. +.nf + + grammar = \- + ( declaration | definition )+ + trailer? end\-of\-file + + declaration = '%{' < ( !'%}' . )* > RPERCENT + + trailer = '%%' < .* > + + definition = identifier EQUAL expression SEMICOLON? + + expression = sequence ( BAR sequence )* + + sequence = prefix+ + + prefix = AND action + | ( AND | NOT )? suffix + + suffix = primary ( QUERY | STAR | PLUS )? + + primary = identifier COLON identifier !EQUAL + | identifier !EQUAL + | OPEN expression CLOSE + | literal + | class + | DOT + | action + | BEGIN + | END + + identifier = < [\-a\-zA\-Z_][\-a\-zA\-Z_0\-9]* > \- + + literal = ['] < ( !['] char )* > ['] \- + | ["] < ( !["] char )* > ["] \- + + class = '[' < ( !']' range )* > ']' \- + + range = char '\-' char | char + + char = '\\\\' [abefnrtv'"\\[\\]\\\\] + | '\\\\' [0\-3][0\-7][0\-7] + | '\\\\' [0\-7][0\-7]? + | !'\\\\' . + + action = '{' < [^}]* > '}' \- + + EQUAL = '=' \- + COLON = ':' \- + SEMICOLON = ';' \- + BAR = '|' \- + AND = '&' \- + NOT = '!' \- + QUERY = '?' \- + STAR = '*' \- + PLUS = '+' \- + OPEN = '(' \- + CLOSE = ')' \- + DOT = '.' \- + BEGIN = '<' \- + END = '>' \- + RPERCENT = '%}' \- + + \- = ( space | comment )* + space = ' ' | '\\t' | end\-of\-line + comment = '#' ( !end\-of\-line . )* end\-of\-line + end\-of\-line = '\\r\\n' | '\\n' | '\\r' + end\-of\-file = !. + +.fi +.SH CUSTOMISING THE PARSER +The following symbols can be redefined in declaration sections to +modify the generated parser code. +.TP +.B YYSTYPE +The semantic value type. The pseudo\-variable '$$' and the +identifiers 'bound' to rule results with the colon operator ':' should +all be considered as being declared to have this type. The default +value is 'int'. +.TP +.B YYPARSE +The name of the main entry point to the parser. The default value +is 'yyparse'. +.TP +.B YYPARSEFROM +The name of an alternative entry point to the parser. This function +expects one argument: the function corresponding to the rule from +which the search for a match should begin. The default +is 'yyparsefrom'. Note that yyparse() is defined as +.nf + + int yyparse(GREG *G) { return yyparsefrom(G, yy_foo); } + +.fi +where 'foo' is the name of the first rule in the grammar. +.TP +.BI YY_INPUT( buf , \ result , \ max_size , \ D ) +This macro is invoked by the parser to obtain more input text. +.I buf +points to an area of memory that can hold at most +.I max_size +characters. The macro should copy input text to +.I buf +and then assign the integer variable +.I result +to indicate the number of characters copied. If no more input is available, +the macro should assign 0 to +.IR result . +By default, the YY_INPUT macro is defined as follows. +.nf + + #define YY_INPUT(buf, result, max_size) \\ + { \\ + int yyc= getchar(); \\ + result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \\ + yyprintf((stderr, "<%c>", yyc)); \\ + } + +.fi +.TP +.B YY_DEBUG +If this symbols is defined then additional code will be included in +the parser that prints vast quantities of arcane information to the +standard error while the parser is running. +.TP +.B YY_BEGIN +This macro is invoked to mark the start of input text that will be +made available in actions as 'G\->text'. This corresponds to +occurrences of '<' in the grammar. These are converted into +predicates that are expected to succeed. The default definition +.nf + + #define YY_BEGIN (G\->begin= G\->pos, 1) + +.fi +therefore saves the current input position and returns 1 ('true') as +the result of the predicate. +.TP +.B YY_END +This macros corresponds to '>' in the grammar. Again, it is a +predicate so the default definition saves the input position +before 'succeeding'. +.nf + + #define YY_END (G\->end= G\->pos, 1) + +.fi +.TP +.BI YY_PARSE( T ) +This macro declares the parser entry points (yyparse and yyparsefrom) +to be of type +.IR T . +The default definition +.nf + + #define YY_PARSE(T) T + +.fi +leaves yyparse() and yyparsefrom() with global visibility. If they +should not be externally visible in other source files, this macro can +be redefined to declare them 'static'. +.nf + + #define YY_PARSE(T) static T + +.fi +.PP +The following variables can be referred to within actions. +.TP +.B char *G\->buf +This variable points to the parser's input buffer used to store input +text that has not yet been matched. +.TP +.B int G\->pos +This is the offset (in G\->buf) of the next character to be matched and +consumed. +.TP +.B char *G\->text +The most recent matched text delimited by '<' and '>' is stored in this variable. +.TP +.B int G\->leng +This variable indicates the number of characters in 'G\->text'. +.SH DIAGNOSTICS +.I rpeg +and +.I greg +warn about the following conditions while converting a grammar into a parser. +.TP +.B syntax error +The input grammar was malformed in some way. The error message will +include the text about to be matched (often backed up a huge amount +from the actual location of the error) and the line number of the most +recently considered character (which is often the real location of the +problem). +.TP +.B rule 'foo' used but not defined +The grammar referred to a rule named 'foo' but no definition for it +was given. Attempting to use the generated parser will likely result +in errors from the linker due to undefined symbols associated with the +missing rule. +.TP +.B rule 'foo' defined but not used +The grammar defined a rule named 'foo' and then ignored it. The code +associated with the rule is included in the generated parser which +will in all other respects be healthy. +.TP +.B possible infinite left recursion in rule 'foo' +There exists at least one path through the grammar that leads from the +rule 'foo' back to (a recursive invocation of) the same rule without +consuming any input. +.PP +Left recursion, especially that found in standards documents, is +often 'direct' and implies trivial repetition. +.nf + + # (6.7.6) + direct\-abstract\-declarator = + LPAREN abstract\-declarator RPAREN + | direct\-abstract\-declarator? LBRACKET assign\-expr? RBRACKET + | direct\-abstract\-declarator? LBRACKET STAR RBRACKET + | direct\-abstract\-declarator? LPAREN param\-type\-list? RPAREN + +.fi +The recursion can easily be eliminated by converting the parts of the +pattern following the recursion into a repeatable suffix. +.nf + + # (6.7.6) + direct\-abstract\-declarator = + direct\-abstract\-declarator\-head? + direct\-abstract\-declarator\-tail* + + direct\-abstract\-declarator\-head = + LPAREN abstract\-declarator RPAREN + + direct\-abstract\-declarator\-tail = + LBRACKET assign\-expr? RBRACKET + | LBRACKET STAR RBRACKET + | LPAREN param\-type\-list? RPAREN + +.fi +.SH BUGS +The 'yy' and 'YY' prefixes cannot be changed. +.PP +Left recursion is detected in the input grammar but is not handled +correctly in the generated parser. +.PP +Diagnostics for errors in the input grammar are obscure and not +particularly helpful. +.PP +Several commonly\-used +.IR lex (1) +features (yywrap(), yyin, etc.) are completely absent. +.PP +The generated parser foes not contain '#line' directives to direct C +compiler errors back to the grammar description when appropriate. +.IR lex (1) +features (yywrap(), yyin, etc.) are completely absent. +.SH SEE ALSO +D. Val Schorre, +.I META II, a syntax\-oriented compiler writing language, +19th ACM National Conference, 1964, pp.\ 41.301\-\-41.311. Describes a +self\-implementing parser generator for analytic grammars with no +backtracking. +.PP +Alexander Birman, +.I The TMG Recognition Schema, +Ph.D. dissertation, Princeton, 1970. A mathematical treatment of the +power and complexity of recursive\-descent parsing with backtracking. +.PP +Bryan Ford, +.I Parsing Expression Grammars: A Recognition\-Based Syntactic Foundation, +ACM SIGPLAN Symposium on Principles of Programming Languages, 2004. +Defines PEGs and analyses them in relation to context\-free and regular +grammars. Introduces the syntax adopted in +.IR rpeg . +.PP +The standard Unix utilities +.IR lex (1) +and +.IR yacc (1) +which influenced the syntax and features of +.IR greg . +.PP +The source code for +.I rpeg +and +.I greg +whose grammar parsers are written using themselves. +The latest version can be found on github. +.PP +The latest version of +.I peg +and +.I leg + and their documentation: +.nf + + http://piumarta.com/software/peg + +.fi + +.SH AUTHOR +.IR rpeg , +.I greg +were created by _why upon +.I peg +and +.I leg +and then updated by several other contributors. +.PP +.IR peg , +.I leg +and this manual page were written by Ian Piumarta (first\-name at +last\-name dot com) while investigating the viability of regular and +parsing\-expression grammars for efficiently extracting type and +signature information from C header files. This manual page has been +adapted to describe +.I rpeg +and +.IR greg , +by Giulio Paci (first\-name last\-name at gmail dot com). + +.PP +Please send bug reports and suggestions for improvements to the authors +of the modified versions at the above addresses. + +\" LocalWords: Ian Piumarta Paci Giulio piumarta emilia rpeg greg +\" LocalWords: hvV ooutput filename sp parsers PEGs lex yacc yy YY +\" LocalWords: yyparse prepended namespace TP username nf fi printf +\" LocalWords: getlogin putchar login unistd yyinit Init EOF init +\" LocalWords: dq uparrow zA leng EndOfFile LEFTARROW whitespace +\" LocalWords: YYSTYPE evaluators yyparsefrom parser's declarator +\" LocalWords: github diff --git a/greg.c b/greg.c index dab8815..9c53e28 100644 --- a/greg.c +++ b/greg.c @@ -1,12 +1,14 @@ -/* A recursive-descent parser generated by greg 0.4.3 */ +/* A recursive-descent parser generated by greg 0.4.4 */ #include #include #include struct _GREG; +#define G ctx #define YYRULECOUNT 37 -# include "greg.h" +# include "tree.h" +# include "version.h" # include # include @@ -82,10 +84,10 @@ struct _GREG; } #endif #ifndef YY_BEGIN -#define YY_BEGIN ( G->begin= G->pos, 1) +#define YY_BEGIN ( ctx->begin= ctx->pos, 1) #endif #ifndef YY_END -#define YY_END ( G->end= G->pos, 1) +#define YY_END ( ctx->end= ctx->pos, 1) #endif #ifdef YY_DEBUG # define yyprintf(args) fprintf args @@ -111,11 +113,11 @@ struct _GREG; #endif #ifndef YY_PART -#define yydata G->data -#define yy G->ss +#define yydata ctx->data +#define yy ctx->ss struct _yythunk; // forward declaration -typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR); +typedef void (*yyaction)(struct _GREG *ctx, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR); typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk; typedef struct _GREG { @@ -138,129 +140,129 @@ typedef struct _GREG { YY_XTYPE data; } GREG; -YY_LOCAL(int) yyrefill(GREG *G) +YY_LOCAL(int) yyrefill(GREG *ctx) { int yyn; - while (G->buflen - G->pos < 512) + while (ctx->buflen - ctx->pos < 512) { - G->buflen *= 2; - G->buf= (char*)YY_REALLOC(G->buf, G->buflen, G->data); + ctx->buflen *= 2; + ctx->buf= (char*)YY_REALLOC(ctx->buf, ctx->buflen, ctx->data); } - YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos), G->data); + YY_INPUT((ctx->buf + ctx->pos), yyn, (ctx->buflen - ctx->pos), ctx->data); if (!yyn) return 0; - G->limit += yyn; + ctx->limit += yyn; return 1; } -YY_LOCAL(int) yymatchDot(GREG *G) +YY_LOCAL(int) yymatchDot(GREG *ctx) { - if (G->pos >= G->limit && !yyrefill(G)) return 0; - ++G->pos; + if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; + ++ctx->pos; return 1; } -YY_LOCAL(int) yymatchChar(GREG *G, int c) +YY_LOCAL(int) yymatchChar(GREG *ctx, int c) { - if (G->pos >= G->limit && !yyrefill(G)) return 0; - if ((unsigned char)G->buf[G->pos] == c) + if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; + if ((unsigned char)ctx->buf[ctx->pos] == c) { - ++G->pos; - yyprintf((stderr, " ok yymatchChar(%c) @ %s\n", c, G->buf+G->pos)); + ++ctx->pos; + yyprintf((stderr, " ok yymatchChar(%c) @ %s\n", c, ctx->buf+ctx->pos)); return 1; } - yyprintf((stderr, " fail yymatchChar(%c) @ %s\n", c, G->buf+G->pos)); + yyprintf((stderr, " fail yymatchChar(%c) @ %s\n", c, ctx->buf+ctx->pos)); return 0; } -YY_LOCAL(int) yymatchString(GREG *G, const char *s) +YY_LOCAL(int) yymatchString(GREG *ctx, const char *s) { - int yysav= G->pos; + int yysav= ctx->pos; while (*s) { - if (G->pos >= G->limit && !yyrefill(G)) return 0; - if (G->buf[G->pos] != *s) + if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; + if (ctx->buf[ctx->pos] != *s) { - G->pos= yysav; + ctx->pos= yysav; return 0; } ++s; - ++G->pos; + ++ctx->pos; } return 1; } -YY_LOCAL(int) yymatchClass(GREG *G, unsigned char *bits) +YY_LOCAL(int) yymatchClass(GREG *ctx, unsigned char *bits) { int c; - if (G->pos >= G->limit && !yyrefill(G)) return 0; - c= (unsigned char)G->buf[G->pos]; + if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0; + c= (unsigned char)ctx->buf[ctx->pos]; if (bits[c >> 3] & (1 << (c & 7))) { - ++G->pos; - yyprintf((stderr, " ok yymatchClass @ %s\n", G->buf+G->pos)); + ++ctx->pos; + yyprintf((stderr, " ok yymatchClass @ %s\n", ctx->buf+ctx->pos)); return 1; } - yyprintf((stderr, " fail yymatchClass @ %s\n", G->buf+G->pos)); + yyprintf((stderr, " fail yymatchClass @ %s\n", ctx->buf+ctx->pos)); return 0; } -YY_LOCAL(void) yyDo(GREG *G, yyaction action, int begin, int end) +YY_LOCAL(void) yyDo(GREG *ctx, yyaction action, int begin, int end) { - while (G->thunkpos >= G->thunkslen) + while (ctx->thunkpos >= ctx->thunkslen) { - G->thunkslen *= 2; - G->thunks= (yythunk*)YY_REALLOC(G->thunks, sizeof(yythunk) * G->thunkslen, G->data); + ctx->thunkslen *= 2; + ctx->thunks= (yythunk*)YY_REALLOC(ctx->thunks, sizeof(yythunk) * ctx->thunkslen, ctx->data); } - G->thunks[G->thunkpos].begin= begin; - G->thunks[G->thunkpos].end= end; - G->thunks[G->thunkpos].action= action; - ++G->thunkpos; + ctx->thunks[ctx->thunkpos].begin= begin; + ctx->thunks[ctx->thunkpos].end= end; + ctx->thunks[ctx->thunkpos].action= action; + ++ctx->thunkpos; } -YY_LOCAL(int) yyText(GREG *G, int begin, int end) +YY_LOCAL(int) yyText(GREG *ctx, int begin, int end) { int yyleng= end - begin; if (yyleng <= 0) yyleng= 0; else { - while (G->textlen < (yyleng - 1)) + while (ctx->textlen < (yyleng + 1)) { - G->textlen *= 2; - G->text= (char*)YY_REALLOC(G->text, G->textlen, G->data); + ctx->textlen *= 2; + ctx->text= (char*)YY_REALLOC(ctx->text, ctx->textlen, ctx->data); } - memcpy(G->text, G->buf + begin, yyleng); + memcpy(ctx->text, ctx->buf + begin, yyleng); } - G->text[yyleng]= '\0'; + ctx->text[yyleng]= '\0'; return yyleng; } -YY_LOCAL(void) yyDone(GREG *G) +YY_LOCAL(void) yyDone(GREG *ctx) { int pos; - for (pos= 0; pos < G->thunkpos; ++pos) + for (pos= 0; pos < ctx->thunkpos; ++pos) { - yythunk *thunk= &G->thunks[pos]; - int yyleng= thunk->end ? yyText(G, thunk->begin, thunk->end) : thunk->begin; - yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, G->text)); - thunk->action(G, G->text, yyleng, thunk, G->data); + 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, thunk, ctx->data); } - G->thunkpos= 0; + ctx->thunkpos= 0; } -YY_LOCAL(void) yyCommit(GREG *G) +YY_LOCAL(void) yyCommit(GREG *ctx) { - if ((G->limit -= G->pos)) + if ((ctx->limit -= ctx->pos)) { - memmove(G->buf, G->buf + G->pos, G->limit); + memmove(ctx->buf, ctx->buf + ctx->pos, ctx->limit); } - G->offset += G->pos; - G->begin -= G->pos; - G->end -= G->pos; - G->pos= G->thunkpos= 0; + ctx->offset += ctx->pos; + ctx->begin -= ctx->pos; + ctx->end -= ctx->pos; + ctx->pos= ctx->thunkpos= 0; } -YY_LOCAL(int) yyAccept(GREG *G, int tp0) +YY_LOCAL(int) yyAccept(GREG *ctx, int tp0) { if (tp0) { @@ -269,698 +271,695 @@ YY_LOCAL(int) yyAccept(GREG *G, int tp0) } else { - yyDone(G); - yyCommit(G); + yyDone(ctx); + yyCommit(ctx); } return 1; } -YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val += count; } -YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val -= count; } -YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val[count]= G->ss; } +YY_LOCAL(void) yyPush(GREG *ctx, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { ctx->val += count; } +YY_LOCAL(void) yyPop(GREG *ctx, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { ctx->val -= count; } +YY_LOCAL(void) yySet(GREG *ctx, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { ctx->val[count]= ctx->ss; } #endif /* YY_PART */ -#define YYACCEPT yyAccept(G, yythunkpos0) +#define YYACCEPT yyAccept(ctx, yythunkpos0) -YY_RULE(int) yy_end_of_line(GREG *G); /* 37 */ -YY_RULE(int) yy_comment(GREG *G); /* 36 */ -YY_RULE(int) yy_space(GREG *G); /* 35 */ -YY_RULE(int) yy_braces(GREG *G); /* 34 */ -YY_RULE(int) yy_range(GREG *G); /* 33 */ -YY_RULE(int) yy_char(GREG *G); /* 32 */ -YY_RULE(int) yy_errblock(GREG *G); /* 31 */ -YY_RULE(int) yy_END(GREG *G); /* 30 */ -YY_RULE(int) yy_BEGIN(GREG *G); /* 29 */ -YY_RULE(int) yy_DOT(GREG *G); /* 28 */ -YY_RULE(int) yy_class(GREG *G); /* 27 */ -YY_RULE(int) yy_literal(GREG *G); /* 26 */ -YY_RULE(int) yy_CLOSE(GREG *G); /* 25 */ -YY_RULE(int) yy_OPEN(GREG *G); /* 24 */ -YY_RULE(int) yy_COLON(GREG *G); /* 23 */ -YY_RULE(int) yy_PLUS(GREG *G); /* 22 */ -YY_RULE(int) yy_STAR(GREG *G); /* 21 */ -YY_RULE(int) yy_QUESTION(GREG *G); /* 20 */ -YY_RULE(int) yy_primary(GREG *G); /* 19 */ -YY_RULE(int) yy_NOT(GREG *G); /* 18 */ -YY_RULE(int) yy_suffix(GREG *G); /* 17 */ -YY_RULE(int) yy_action(GREG *G); /* 16 */ -YY_RULE(int) yy_AND(GREG *G); /* 15 */ -YY_RULE(int) yy_prefix(GREG *G); /* 14 */ -YY_RULE(int) yy_BAR(GREG *G); /* 13 */ -YY_RULE(int) yy_sequence(GREG *G); /* 12 */ -YY_RULE(int) yy_SEMICOLON(GREG *G); /* 11 */ -YY_RULE(int) yy_expression(GREG *G); /* 10 */ -YY_RULE(int) yy_EQUAL(GREG *G); /* 9 */ -YY_RULE(int) yy_identifier(GREG *G); /* 8 */ -YY_RULE(int) yy_RPERCENT(GREG *G); /* 7 */ -YY_RULE(int) yy_end_of_file(GREG *G); /* 6 */ -YY_RULE(int) yy_trailer(GREG *G); /* 5 */ -YY_RULE(int) yy_definition(GREG *G); /* 4 */ -YY_RULE(int) yy_declaration(GREG *G); /* 3 */ -YY_RULE(int) yy__(GREG *G); /* 2 */ -YY_RULE(int) yy_grammar(GREG *G); /* 1 */ +YY_RULE(int) yy_end_of_line(GREG *ctx); /* 37 */ +YY_RULE(int) yy_comment(GREG *ctx); /* 36 */ +YY_RULE(int) yy_space(GREG *ctx); /* 35 */ +YY_RULE(int) yy_braces(GREG *ctx); /* 34 */ +YY_RULE(int) yy_range(GREG *ctx); /* 33 */ +YY_RULE(int) yy_char(GREG *ctx); /* 32 */ +YY_RULE(int) yy_errblock(GREG *ctx); /* 31 */ +YY_RULE(int) yy_END(GREG *ctx); /* 30 */ +YY_RULE(int) yy_BEGIN(GREG *ctx); /* 29 */ +YY_RULE(int) yy_DOT(GREG *ctx); /* 28 */ +YY_RULE(int) yy_class(GREG *ctx); /* 27 */ +YY_RULE(int) yy_literal(GREG *ctx); /* 26 */ +YY_RULE(int) yy_CLOSE(GREG *ctx); /* 25 */ +YY_RULE(int) yy_OPEN(GREG *ctx); /* 24 */ +YY_RULE(int) yy_COLON(GREG *ctx); /* 23 */ +YY_RULE(int) yy_PLUS(GREG *ctx); /* 22 */ +YY_RULE(int) yy_STAR(GREG *ctx); /* 21 */ +YY_RULE(int) yy_QUESTION(GREG *ctx); /* 20 */ +YY_RULE(int) yy_primary(GREG *ctx); /* 19 */ +YY_RULE(int) yy_NOT(GREG *ctx); /* 18 */ +YY_RULE(int) yy_suffix(GREG *ctx); /* 17 */ +YY_RULE(int) yy_action(GREG *ctx); /* 16 */ +YY_RULE(int) yy_AND(GREG *ctx); /* 15 */ +YY_RULE(int) yy_prefix(GREG *ctx); /* 14 */ +YY_RULE(int) yy_BAR(GREG *ctx); /* 13 */ +YY_RULE(int) yy_sequence(GREG *ctx); /* 12 */ +YY_RULE(int) yy_SEMICOLON(GREG *ctx); /* 11 */ +YY_RULE(int) yy_expression(GREG *ctx); /* 10 */ +YY_RULE(int) yy_EQUAL(GREG *ctx); /* 9 */ +YY_RULE(int) yy_identifier(GREG *ctx); /* 8 */ +YY_RULE(int) yy_RPERCENT(GREG *ctx); /* 7 */ +YY_RULE(int) yy_end_of_file(GREG *ctx); /* 6 */ +YY_RULE(int) yy_trailer(GREG *ctx); /* 5 */ +YY_RULE(int) yy_definition(GREG *ctx); /* 4 */ +YY_RULE(int) yy_declaration(GREG *ctx); /* 3 */ +YY_RULE(int) yy__(GREG *ctx); /* 2 */ +YY_RULE(int) yy_grammar(GREG *ctx); /* 1 */ -YY_ACTION(void) yy_10_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_10_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_10_primary\n")); Node *node = pop(); ((struct Any *) node)->errblock = strdup(yytext); push(node); ; } -YY_ACTION(void) yy_9_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_9_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_9_primary\n")); push(makePredicate("YY_END")); ; } -YY_ACTION(void) yy_8_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_8_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_8_primary\n")); push(makePredicate("YY_BEGIN")); ; } -YY_ACTION(void) yy_7_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_7_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_7_primary\n")); push(makeAction(yytext)); ; } -YY_ACTION(void) yy_6_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_6_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_6_primary\n")); push(makeDot()); ; } -YY_ACTION(void) yy_5_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_5_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_5_primary\n")); push(makeClass(yytext)); ; } -YY_ACTION(void) yy_4_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_4_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_4_primary\n")); push(makeString(yytext)); ; } -YY_ACTION(void) yy_3_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_3_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_3_primary\n")); push(makeName(findRule(yytext))); ; } -YY_ACTION(void) yy_2_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_2_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_primary\n")); Node *name= makeName(findRule(yytext)); name->name.variable= pop(); push(name); ; } -YY_ACTION(void) yy_1_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_primary(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_primary\n")); push(makeVariable(yytext)); ; } -YY_ACTION(void) yy_3_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_3_suffix(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_3_suffix\n")); push(makePlus (pop())); ; } -YY_ACTION(void) yy_2_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_2_suffix(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_suffix\n")); push(makeStar (pop())); ; } -YY_ACTION(void) yy_1_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_suffix(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_suffix\n")); push(makeQuery(pop())); ; } -YY_ACTION(void) yy_3_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_3_prefix(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_3_prefix\n")); push(makePeekNot(pop())); ; } -YY_ACTION(void) yy_2_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_2_prefix(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_prefix\n")); push(makePeekFor(pop())); ; } -YY_ACTION(void) yy_1_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_prefix(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_prefix\n")); push(makePredicate(yytext)); ; } -YY_ACTION(void) yy_1_sequence(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_sequence(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_sequence\n")); Node *f= pop(); push(Sequence_append(pop(), f)); ; } -YY_ACTION(void) yy_1_expression(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_expression(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_expression\n")); Node *f= pop(); push(Alternate_append(pop(), f)); ; } -YY_ACTION(void) yy_2_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_2_definition(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_definition\n")); Node *e= pop(); Rule_setExpression(pop(), e); ; } -YY_ACTION(void) yy_1_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_definition(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_definition\n")); if (push(beginRule(findRule(yytext)))->rule.expression) fprintf(stderr, "rule '%s' redefined\n", yytext); ; } -YY_ACTION(void) yy_1_trailer(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_trailer(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_trailer\n")); makeTrailer(yytext); ; } -YY_ACTION(void) yy_1_declaration(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +YY_ACTION(void) yy_1_declaration(GREG *ctx, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_declaration\n")); makeHeader(yytext); ; } -YY_RULE(int) yy_end_of_line(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_end_of_line(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "end_of_line")); - { int yypos2= G->pos, yythunkpos2= G->thunkpos; if (!yymatchString(G, "\r\n")) goto l3; goto l2; - l3:; G->pos= yypos2; G->thunkpos= yythunkpos2; if (!yymatchChar(G, '\n')) goto l4; goto l2; - l4:; G->pos= yypos2; G->thunkpos= yythunkpos2; if (!yymatchChar(G, '\r')) goto l1; + { 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", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "end_of_line", ctx->buf+ctx->pos)); return 1; - l1:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "end_of_line", G->buf+G->pos)); + 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "comment")); if (!yymatchChar(G, '#')) goto l5; +YY_RULE(int) yy_comment(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "comment")); if (!yymatchChar(ctx, '#')) goto l5; l6:; - { int yypos7= G->pos, yythunkpos7= G->thunkpos; - { int yypos8= G->pos, yythunkpos8= G->thunkpos; if (!yy_end_of_line(G)) { goto l8; } goto l7; - l8:; G->pos= yypos8; G->thunkpos= yythunkpos8; - } if (!yymatchDot(G)) goto l7; goto l6; - l7:; G->pos= yypos7; G->thunkpos= yythunkpos7; - } if (!yy_end_of_line(G)) { goto l5; } - yyprintf((stderr, " ok %s @ %s\n", "comment", G->buf+G->pos)); + { 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:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "comment", G->buf+G->pos)); + 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_space(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "space")); - { int yypos10= G->pos, yythunkpos10= G->thunkpos; if (!yymatchChar(G, ' ')) goto l11; goto l10; - l11:; G->pos= yypos10; G->thunkpos= yythunkpos10; if (!yymatchChar(G, '\t')) goto l12; goto l10; - l12:; G->pos= yypos10; G->thunkpos= yythunkpos10; if (!yy_end_of_line(G)) { goto l9; } + { 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", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "space", ctx->buf+ctx->pos)); return 1; - l9:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "space", G->buf+G->pos)); + 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_braces(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "braces")); - { int yypos14= G->pos, yythunkpos14= G->thunkpos; if (!yymatchChar(G, '{')) goto l15; + { int yypos14= ctx->pos, yythunkpos14= ctx->thunkpos; if (!yymatchChar(ctx, '{')) goto l15; l16:; - { int yypos17= G->pos, yythunkpos17= G->thunkpos; - { int yypos18= G->pos, yythunkpos18= G->thunkpos; if (!yymatchChar(G, '}')) goto l18; goto l17; - l18:; G->pos= yypos18; G->thunkpos= yythunkpos18; - } if (!yymatchDot(G)) goto l17; goto l16; - l17:; G->pos= yypos17; G->thunkpos= yythunkpos17; - } if (!yymatchChar(G, '}')) goto l15; goto l14; - l15:; G->pos= yypos14; G->thunkpos= yythunkpos14; - { int yypos19= G->pos, yythunkpos19= G->thunkpos; if (!yymatchChar(G, '}')) goto l19; goto l13; - l19:; G->pos= yypos19; G->thunkpos= yythunkpos19; - } if (!yymatchDot(G)) goto l13; + { 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", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "braces", ctx->buf+ctx->pos)); return 1; - l13:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "braces", G->buf+G->pos)); + 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_range(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "range")); - { int yypos21= G->pos, yythunkpos21= G->thunkpos; if (!yy_char(G)) { goto l22; } if (!yymatchChar(G, '-')) goto l22; if (!yy_char(G)) { goto l22; } goto l21; - l22:; G->pos= yypos21; G->thunkpos= yythunkpos21; if (!yy_char(G)) { goto l20; } + { 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; } } - l21:; - yyprintf((stderr, " ok %s @ %s\n", "range", G->buf+G->pos)); + l20:; + yyprintf((stderr, " ok %s @ %s\n", "range", ctx->buf+ctx->pos)); return 1; - l20:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "range", G->buf+G->pos)); + 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_char(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "char")); - { int yypos24= G->pos, yythunkpos24= G->thunkpos; if (!yymatchChar(G, '\\')) goto l25; if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\204\000\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 l25; goto l24; - l25:; G->pos= yypos24; G->thunkpos= yythunkpos24; if (!yymatchChar(G, '\\')) goto l26; if (!yymatchClass(G, (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 l26; if (!yymatchClass(G, (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; if (!yymatchClass(G, (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; goto l24; - l26:; G->pos= yypos24; G->thunkpos= yythunkpos24; if (!yymatchChar(G, '\\')) goto l27; if (!yymatchClass(G, (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; - { int yypos28= G->pos, yythunkpos28= G->thunkpos; if (!yymatchClass(G, (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 l28; goto l29; - l28:; G->pos= yypos28; G->thunkpos= yythunkpos28; + { 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; } - l29:; goto l24; - l27:; G->pos= yypos24; G->thunkpos= yythunkpos24; - { int yypos30= G->pos, yythunkpos30= G->thunkpos; if (!yymatchChar(G, '\\')) goto l30; goto l23; - l30:; G->pos= yypos30; G->thunkpos= yythunkpos30; - } if (!yymatchDot(G)) goto l23; + 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; } - l24:; - yyprintf((stderr, " ok %s @ %s\n", "char", G->buf+G->pos)); + l23:; + yyprintf((stderr, " ok %s @ %s\n", "char", ctx->buf+ctx->pos)); return 1; - l23:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "char", G->buf+G->pos)); + l22:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "char", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_errblock(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "errblock")); if (!yymatchString(G, "~{")) goto l31; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l31; - l32:; - { int yypos33= G->pos, yythunkpos33= G->thunkpos; if (!yy_braces(G)) { goto l33; } goto l32; - l33:; G->pos= yypos33; G->thunkpos= yythunkpos33; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l31; if (!yymatchChar(G, '}')) goto l31; if (!yy__(G)) { goto l31; } - yyprintf((stderr, " ok %s @ %s\n", "errblock", G->buf+G->pos)); +YY_RULE(int) yy_errblock(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "errblock")); if (!yymatchString(ctx, "~{")) goto l30; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l30; + l31:; + { int yypos32= ctx->pos, yythunkpos32= ctx->thunkpos; if (!yy_braces(ctx)) { goto l32; } goto l31; + l32:; ctx->pos= yypos32; ctx->thunkpos= yythunkpos32; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l30; if (!yymatchChar(ctx, '}')) goto l30; if (!yy__(ctx)) { goto l30; } + yyprintf((stderr, " ok %s @ %s\n", "errblock", ctx->buf+ctx->pos)); return 1; - l31:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "errblock", G->buf+G->pos)); + l30:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "errblock", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_END(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "END")); if (!yymatchChar(G, '>')) goto l34; if (!yy__(G)) { goto l34; } - yyprintf((stderr, " ok %s @ %s\n", "END", G->buf+G->pos)); +YY_RULE(int) yy_END(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "END")); if (!yymatchChar(ctx, '>')) goto l33; if (!yy__(ctx)) { goto l33; } + yyprintf((stderr, " ok %s @ %s\n", "END", ctx->buf+ctx->pos)); return 1; - l34:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "END", G->buf+G->pos)); + l33:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "END", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_BEGIN(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "BEGIN")); if (!yymatchChar(G, '<')) goto l35; if (!yy__(G)) { goto l35; } - yyprintf((stderr, " ok %s @ %s\n", "BEGIN", G->buf+G->pos)); +YY_RULE(int) yy_BEGIN(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "BEGIN")); if (!yymatchChar(ctx, '<')) goto l34; if (!yy__(ctx)) { goto l34; } + yyprintf((stderr, " ok %s @ %s\n", "BEGIN", ctx->buf+ctx->pos)); return 1; - l35:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "BEGIN", G->buf+G->pos)); + l34:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "BEGIN", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_DOT(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "DOT")); if (!yymatchChar(G, '.')) goto l36; if (!yy__(G)) { goto l36; } - yyprintf((stderr, " ok %s @ %s\n", "DOT", G->buf+G->pos)); +YY_RULE(int) yy_DOT(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "DOT")); if (!yymatchChar(ctx, '.')) goto l35; if (!yy__(ctx)) { goto l35; } + yyprintf((stderr, " ok %s @ %s\n", "DOT", ctx->buf+ctx->pos)); return 1; - l36:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "DOT", G->buf+G->pos)); + l35:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "DOT", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_class(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(G, '[')) goto l37; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l37; - l38:; - { int yypos39= G->pos, yythunkpos39= G->thunkpos; - { int yypos40= G->pos, yythunkpos40= G->thunkpos; if (!yymatchChar(G, ']')) goto l40; goto l39; - l40:; G->pos= yypos40; G->thunkpos= yythunkpos40; - } if (!yy_range(G)) { goto l39; } goto l38; - l39:; G->pos= yypos39; G->thunkpos= yythunkpos39; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l37; if (!yymatchChar(G, ']')) goto l37; if (!yy__(G)) { goto l37; } - yyprintf((stderr, " ok %s @ %s\n", "class", G->buf+G->pos)); +YY_RULE(int) yy_class(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(ctx, '[')) goto l36; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l36; + l37:; + { int yypos38= ctx->pos, yythunkpos38= ctx->thunkpos; + { int yypos39= ctx->pos, yythunkpos39= ctx->thunkpos; if (!yymatchChar(ctx, ']')) goto l39; goto l38; + l39:; ctx->pos= yypos39; ctx->thunkpos= yythunkpos39; + } if (!yy_range(ctx)) { goto l38; } goto l37; + l38:; ctx->pos= yypos38; ctx->thunkpos= yythunkpos38; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l36; if (!yymatchChar(ctx, ']')) goto l36; if (!yy__(ctx)) { goto l36; } + yyprintf((stderr, " ok %s @ %s\n", "class", ctx->buf+ctx->pos)); return 1; - l37:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "class", G->buf+G->pos)); + l36:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "class", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_literal(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_literal(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "literal")); - { int yypos42= G->pos, yythunkpos42= G->thunkpos; if (!yymatchClass(G, (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 l43; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l43; - l44:; - { int yypos45= G->pos, yythunkpos45= G->thunkpos; - { int yypos46= G->pos, yythunkpos46= G->thunkpos; if (!yymatchClass(G, (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 l46; goto l45; - l46:; G->pos= yypos46; G->thunkpos= yythunkpos46; - } if (!yy_char(G)) { goto l45; } goto l44; - l45:; G->pos= yypos45; G->thunkpos= yythunkpos45; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l43; if (!yymatchClass(G, (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 l43; if (!yy__(G)) { goto l43; } goto l42; - l43:; G->pos= yypos42; G->thunkpos= yythunkpos42; if (!yymatchClass(G, (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 l41; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l41; - l47:; - { int yypos48= G->pos, yythunkpos48= G->thunkpos; - { int yypos49= G->pos, yythunkpos49= G->thunkpos; if (!yymatchClass(G, (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 l49; goto l48; - l49:; G->pos= yypos49; G->thunkpos= yythunkpos49; - } if (!yy_char(G)) { goto l48; } goto l47; - l48:; G->pos= yypos48; G->thunkpos= yythunkpos48; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l41; if (!yymatchClass(G, (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 l41; if (!yy__(G)) { goto l41; } + { int yypos41= ctx->pos, yythunkpos41= 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; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l42; + l43:; + { int yypos44= ctx->pos, yythunkpos44= ctx->thunkpos; + { int yypos45= ctx->pos, yythunkpos45= 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 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 l42; 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; if (!yy__(ctx)) { goto l42; } goto l41; + l42:; ctx->pos= yypos41; ctx->thunkpos= yythunkpos41; 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 l40; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l40; + l46:; + { int yypos47= ctx->pos, yythunkpos47= ctx->thunkpos; + { int yypos48= ctx->pos, yythunkpos48= 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 l48; goto l47; + l48:; ctx->pos= yypos48; ctx->thunkpos= yythunkpos48; + } if (!yy_char(ctx)) { goto l47; } goto l46; + l47:; ctx->pos= yypos47; ctx->thunkpos= yythunkpos47; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l40; 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 l40; if (!yy__(ctx)) { goto l40; } } - l42:; - yyprintf((stderr, " ok %s @ %s\n", "literal", G->buf+G->pos)); + l41:; + yyprintf((stderr, " ok %s @ %s\n", "literal", ctx->buf+ctx->pos)); return 1; - l41:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "literal", G->buf+G->pos)); + l40:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "literal", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_CLOSE(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "CLOSE")); if (!yymatchChar(G, ')')) goto l50; if (!yy__(G)) { goto l50; } - yyprintf((stderr, " ok %s @ %s\n", "CLOSE", G->buf+G->pos)); +YY_RULE(int) yy_CLOSE(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "CLOSE")); if (!yymatchChar(ctx, ')')) goto l49; if (!yy__(ctx)) { goto l49; } + yyprintf((stderr, " ok %s @ %s\n", "CLOSE", ctx->buf+ctx->pos)); return 1; - l50:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "CLOSE", G->buf+G->pos)); + l49:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "CLOSE", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_OPEN(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "OPEN")); if (!yymatchChar(G, '(')) goto l51; if (!yy__(G)) { goto l51; } - yyprintf((stderr, " ok %s @ %s\n", "OPEN", G->buf+G->pos)); +YY_RULE(int) yy_OPEN(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "OPEN")); if (!yymatchChar(ctx, '(')) goto l50; if (!yy__(ctx)) { goto l50; } + yyprintf((stderr, " ok %s @ %s\n", "OPEN", ctx->buf+ctx->pos)); return 1; - l51:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "OPEN", G->buf+G->pos)); + l50:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "OPEN", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_COLON(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "COLON")); if (!yymatchChar(G, ':')) goto l52; if (!yy__(G)) { goto l52; } - yyprintf((stderr, " ok %s @ %s\n", "COLON", G->buf+G->pos)); +YY_RULE(int) yy_COLON(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "COLON")); if (!yymatchChar(ctx, ':')) goto l51; if (!yy__(ctx)) { goto l51; } + yyprintf((stderr, " ok %s @ %s\n", "COLON", ctx->buf+ctx->pos)); return 1; - l52:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "COLON", G->buf+G->pos)); + l51:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "COLON", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_PLUS(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "PLUS")); if (!yymatchChar(G, '+')) goto l53; if (!yy__(G)) { goto l53; } - yyprintf((stderr, " ok %s @ %s\n", "PLUS", G->buf+G->pos)); +YY_RULE(int) yy_PLUS(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "PLUS")); if (!yymatchChar(ctx, '+')) goto l52; if (!yy__(ctx)) { goto l52; } + yyprintf((stderr, " ok %s @ %s\n", "PLUS", ctx->buf+ctx->pos)); return 1; - l53:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "PLUS", G->buf+G->pos)); + l52:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "PLUS", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_STAR(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "STAR")); if (!yymatchChar(G, '*')) goto l54; if (!yy__(G)) { goto l54; } - yyprintf((stderr, " ok %s @ %s\n", "STAR", G->buf+G->pos)); +YY_RULE(int) yy_STAR(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "STAR")); if (!yymatchChar(ctx, '*')) goto l53; if (!yy__(ctx)) { goto l53; } + yyprintf((stderr, " ok %s @ %s\n", "STAR", ctx->buf+ctx->pos)); return 1; - l54:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "STAR", G->buf+G->pos)); + l53:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "STAR", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_QUESTION(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "QUESTION")); if (!yymatchChar(G, '?')) goto l55; if (!yy__(G)) { goto l55; } - yyprintf((stderr, " ok %s @ %s\n", "QUESTION", G->buf+G->pos)); +YY_RULE(int) yy_QUESTION(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "QUESTION")); if (!yymatchChar(ctx, '?')) goto l54; if (!yy__(ctx)) { goto l54; } + yyprintf((stderr, " ok %s @ %s\n", "QUESTION", ctx->buf+ctx->pos)); return 1; - l55:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "QUESTION", G->buf+G->pos)); + l54:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "QUESTION", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_primary(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_primary(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "primary")); - { int yypos57= G->pos, yythunkpos57= G->thunkpos; if (!yy_identifier(G)) { goto l58; } yyDo(G, yy_1_primary, G->begin, G->end); if (!yy_COLON(G)) { goto l58; } if (!yy_identifier(G)) { goto l58; } - { int yypos59= G->pos, yythunkpos59= G->thunkpos; if (!yy_EQUAL(G)) { goto l59; } goto l58; - l59:; G->pos= yypos59; G->thunkpos= yythunkpos59; - } yyDo(G, yy_2_primary, G->begin, G->end); goto l57; - l58:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_identifier(G)) { goto l60; } - { int yypos61= G->pos, yythunkpos61= G->thunkpos; if (!yy_EQUAL(G)) { goto l61; } goto l60; - l61:; G->pos= yypos61; G->thunkpos= yythunkpos61; - } yyDo(G, yy_3_primary, G->begin, G->end); goto l57; - l60:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_OPEN(G)) { goto l62; } if (!yy_expression(G)) { goto l62; } if (!yy_CLOSE(G)) { goto l62; } goto l57; - l62:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_literal(G)) { goto l63; } yyDo(G, yy_4_primary, G->begin, G->end); goto l57; - l63:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_class(G)) { goto l64; } yyDo(G, yy_5_primary, G->begin, G->end); goto l57; - l64:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_DOT(G)) { goto l65; } yyDo(G, yy_6_primary, G->begin, G->end); goto l57; - l65:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_action(G)) { goto l66; } yyDo(G, yy_7_primary, G->begin, G->end); goto l57; - l66:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_BEGIN(G)) { goto l67; } yyDo(G, yy_8_primary, G->begin, G->end); goto l57; - l67:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_END(G)) { goto l56; } yyDo(G, yy_9_primary, G->begin, G->end); + { int yypos56= ctx->pos, yythunkpos56= ctx->thunkpos; if (!yy_identifier(ctx)) { goto l57; } yyDo(ctx, yy_1_primary, ctx->begin, ctx->end); if (!yy_COLON(ctx)) { goto l57; } if (!yy_identifier(ctx)) { goto l57; } + { int yypos58= ctx->pos, yythunkpos58= ctx->thunkpos; if (!yy_EQUAL(ctx)) { goto l58; } goto l57; + l58:; ctx->pos= yypos58; ctx->thunkpos= yythunkpos58; + } yyDo(ctx, yy_2_primary, ctx->begin, ctx->end); goto l56; + l57:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_identifier(ctx)) { goto l59; } + { int yypos60= ctx->pos, yythunkpos60= ctx->thunkpos; if (!yy_EQUAL(ctx)) { goto l60; } goto l59; + l60:; ctx->pos= yypos60; ctx->thunkpos= yythunkpos60; + } yyDo(ctx, yy_3_primary, ctx->begin, ctx->end); goto l56; + l59:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_OPEN(ctx)) { goto l61; } if (!yy_expression(ctx)) { goto l61; } if (!yy_CLOSE(ctx)) { goto l61; } goto l56; + l61:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_literal(ctx)) { goto l62; } yyDo(ctx, yy_4_primary, ctx->begin, ctx->end); goto l56; + l62:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_class(ctx)) { goto l63; } yyDo(ctx, yy_5_primary, ctx->begin, ctx->end); goto l56; + l63:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_DOT(ctx)) { goto l64; } yyDo(ctx, yy_6_primary, ctx->begin, ctx->end); goto l56; + l64:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_action(ctx)) { goto l65; } yyDo(ctx, yy_7_primary, ctx->begin, ctx->end); goto l56; + l65:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_BEGIN(ctx)) { goto l66; } yyDo(ctx, yy_8_primary, ctx->begin, ctx->end); goto l56; + l66:; ctx->pos= yypos56; ctx->thunkpos= yythunkpos56; if (!yy_END(ctx)) { goto l55; } yyDo(ctx, yy_9_primary, ctx->begin, ctx->end); } - l57:; - { int yypos68= G->pos, yythunkpos68= G->thunkpos; if (!yy_errblock(G)) { goto l68; } yyDo(G, yy_10_primary, G->begin, G->end); goto l69; - l68:; G->pos= yypos68; G->thunkpos= yythunkpos68; + l56:; + { int yypos67= ctx->pos, yythunkpos67= ctx->thunkpos; if (!yy_errblock(ctx)) { goto l67; } yyDo(ctx, yy_10_primary, ctx->begin, ctx->end); goto l68; + l67:; ctx->pos= yypos67; ctx->thunkpos= yythunkpos67; } - l69:; - yyprintf((stderr, " ok %s @ %s\n", "primary", G->buf+G->pos)); + l68:; + yyprintf((stderr, " ok %s @ %s\n", "primary", ctx->buf+ctx->pos)); return 1; - l56:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "primary", G->buf+G->pos)); + l55:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "primary", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_NOT(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "NOT")); if (!yymatchChar(G, '!')) goto l70; if (!yy__(G)) { goto l70; } - yyprintf((stderr, " ok %s @ %s\n", "NOT", G->buf+G->pos)); +YY_RULE(int) yy_NOT(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "NOT")); if (!yymatchChar(ctx, '!')) goto l69; if (!yy__(ctx)) { goto l69; } + yyprintf((stderr, " ok %s @ %s\n", "NOT", ctx->buf+ctx->pos)); return 1; - l70:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "NOT", G->buf+G->pos)); + l69:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "NOT", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_suffix(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "suffix")); if (!yy_primary(G)) { goto l71; } - { int yypos72= G->pos, yythunkpos72= G->thunkpos; - { int yypos74= G->pos, yythunkpos74= G->thunkpos; if (!yy_QUESTION(G)) { goto l75; } yyDo(G, yy_1_suffix, G->begin, G->end); goto l74; - l75:; G->pos= yypos74; G->thunkpos= yythunkpos74; if (!yy_STAR(G)) { goto l76; } yyDo(G, yy_2_suffix, G->begin, G->end); goto l74; - l76:; G->pos= yypos74; G->thunkpos= yythunkpos74; if (!yy_PLUS(G)) { goto l72; } yyDo(G, yy_3_suffix, G->begin, G->end); +YY_RULE(int) yy_suffix(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "suffix")); if (!yy_primary(ctx)) { goto l70; } + { int yypos71= ctx->pos, yythunkpos71= ctx->thunkpos; + { int yypos73= ctx->pos, yythunkpos73= ctx->thunkpos; if (!yy_QUESTION(ctx)) { goto l74; } yyDo(ctx, yy_1_suffix, ctx->begin, ctx->end); goto l73; + l74:; ctx->pos= yypos73; ctx->thunkpos= yythunkpos73; if (!yy_STAR(ctx)) { goto l75; } yyDo(ctx, yy_2_suffix, ctx->begin, ctx->end); goto l73; + l75:; ctx->pos= yypos73; ctx->thunkpos= yythunkpos73; if (!yy_PLUS(ctx)) { goto l71; } yyDo(ctx, yy_3_suffix, ctx->begin, ctx->end); } - l74:; goto l73; - l72:; G->pos= yypos72; G->thunkpos= yythunkpos72; + l73:; goto l72; + l71:; ctx->pos= yypos71; ctx->thunkpos= yythunkpos71; } - l73:; - yyprintf((stderr, " ok %s @ %s\n", "suffix", G->buf+G->pos)); + l72:; + yyprintf((stderr, " ok %s @ %s\n", "suffix", ctx->buf+ctx->pos)); return 1; - l71:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "suffix", G->buf+G->pos)); + l70:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "suffix", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_action(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(G, '{')) goto l77; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l77; - l78:; - { int yypos79= G->pos, yythunkpos79= G->thunkpos; if (!yy_braces(G)) { goto l79; } goto l78; - l79:; G->pos= yypos79; G->thunkpos= yythunkpos79; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l77; if (!yymatchChar(G, '}')) goto l77; if (!yy__(G)) { goto l77; } - yyprintf((stderr, " ok %s @ %s\n", "action", G->buf+G->pos)); +YY_RULE(int) yy_action(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(ctx, '{')) goto l76; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l76; + l77:; + { int yypos78= ctx->pos, yythunkpos78= ctx->thunkpos; if (!yy_braces(ctx)) { goto l78; } goto l77; + l78:; ctx->pos= yypos78; ctx->thunkpos= yythunkpos78; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l76; if (!yymatchChar(ctx, '}')) goto l76; if (!yy__(ctx)) { goto l76; } + yyprintf((stderr, " ok %s @ %s\n", "action", ctx->buf+ctx->pos)); return 1; - l77:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "action", G->buf+G->pos)); + l76:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "action", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_AND(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "AND")); if (!yymatchChar(G, '&')) goto l80; if (!yy__(G)) { goto l80; } - yyprintf((stderr, " ok %s @ %s\n", "AND", G->buf+G->pos)); +YY_RULE(int) yy_AND(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "AND")); if (!yymatchChar(ctx, '&')) goto l79; if (!yy__(ctx)) { goto l79; } + yyprintf((stderr, " ok %s @ %s\n", "AND", ctx->buf+ctx->pos)); return 1; - l80:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "AND", G->buf+G->pos)); + l79:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "AND", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_prefix(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_prefix(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "prefix")); - { int yypos82= G->pos, yythunkpos82= G->thunkpos; if (!yy_AND(G)) { goto l83; } if (!yy_action(G)) { goto l83; } yyDo(G, yy_1_prefix, G->begin, G->end); goto l82; - l83:; G->pos= yypos82; G->thunkpos= yythunkpos82; if (!yy_AND(G)) { goto l84; } if (!yy_suffix(G)) { goto l84; } yyDo(G, yy_2_prefix, G->begin, G->end); goto l82; - l84:; G->pos= yypos82; G->thunkpos= yythunkpos82; if (!yy_NOT(G)) { goto l85; } if (!yy_suffix(G)) { goto l85; } yyDo(G, yy_3_prefix, G->begin, G->end); goto l82; - l85:; G->pos= yypos82; G->thunkpos= yythunkpos82; if (!yy_suffix(G)) { goto l81; } + { int yypos81= ctx->pos, yythunkpos81= ctx->thunkpos; if (!yy_AND(ctx)) { goto l82; } if (!yy_action(ctx)) { goto l82; } yyDo(ctx, yy_1_prefix, ctx->begin, ctx->end); goto l81; + l82:; ctx->pos= yypos81; ctx->thunkpos= yythunkpos81; if (!yy_AND(ctx)) { goto l83; } if (!yy_suffix(ctx)) { goto l83; } yyDo(ctx, yy_2_prefix, ctx->begin, ctx->end); goto l81; + l83:; ctx->pos= yypos81; ctx->thunkpos= yythunkpos81; if (!yy_NOT(ctx)) { goto l84; } if (!yy_suffix(ctx)) { goto l84; } yyDo(ctx, yy_3_prefix, ctx->begin, ctx->end); goto l81; + l84:; ctx->pos= yypos81; ctx->thunkpos= yythunkpos81; if (!yy_suffix(ctx)) { goto l80; } } - l82:; - yyprintf((stderr, " ok %s @ %s\n", "prefix", G->buf+G->pos)); + l81:; + yyprintf((stderr, " ok %s @ %s\n", "prefix", ctx->buf+ctx->pos)); return 1; - l81:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "prefix", G->buf+G->pos)); + l80:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "prefix", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_BAR(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "BAR")); if (!yymatchChar(G, '|')) goto l86; if (!yy__(G)) { goto l86; } - yyprintf((stderr, " ok %s @ %s\n", "BAR", G->buf+G->pos)); +YY_RULE(int) yy_BAR(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "BAR")); if (!yymatchChar(ctx, '|')) goto l85; if (!yy__(ctx)) { goto l85; } + yyprintf((stderr, " ok %s @ %s\n", "BAR", ctx->buf+ctx->pos)); return 1; - l86:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "BAR", G->buf+G->pos)); + l85:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "BAR", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_sequence(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "sequence")); if (!yy_prefix(G)) { goto l87; } - l88:; - { int yypos89= G->pos, yythunkpos89= G->thunkpos; if (!yy_prefix(G)) { goto l89; } yyDo(G, yy_1_sequence, G->begin, G->end); goto l88; - l89:; G->pos= yypos89; G->thunkpos= yythunkpos89; +YY_RULE(int) yy_sequence(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "sequence")); if (!yy_prefix(ctx)) { goto l86; } + l87:; + { int yypos88= ctx->pos, yythunkpos88= ctx->thunkpos; if (!yy_prefix(ctx)) { goto l88; } yyDo(ctx, yy_1_sequence, ctx->begin, ctx->end); goto l87; + l88:; ctx->pos= yypos88; ctx->thunkpos= yythunkpos88; } - yyprintf((stderr, " ok %s @ %s\n", "sequence", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "sequence", ctx->buf+ctx->pos)); return 1; - l87:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "sequence", G->buf+G->pos)); + l86:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "sequence", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_SEMICOLON(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(G, ';')) goto l90; if (!yy__(G)) { goto l90; } - yyprintf((stderr, " ok %s @ %s\n", "SEMICOLON", G->buf+G->pos)); +YY_RULE(int) yy_SEMICOLON(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(ctx, ';')) goto l89; if (!yy__(ctx)) { goto l89; } + yyprintf((stderr, " ok %s @ %s\n", "SEMICOLON", ctx->buf+ctx->pos)); return 1; - l90:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "SEMICOLON", G->buf+G->pos)); + l89:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "SEMICOLON", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_expression(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "expression")); if (!yy_sequence(G)) { goto l91; } - l92:; - { int yypos93= G->pos, yythunkpos93= G->thunkpos; if (!yy_BAR(G)) { goto l93; } if (!yy_sequence(G)) { goto l93; } yyDo(G, yy_1_expression, G->begin, G->end); goto l92; - l93:; G->pos= yypos93; G->thunkpos= yythunkpos93; +YY_RULE(int) yy_expression(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "expression")); if (!yy_sequence(ctx)) { goto l90; } + l91:; + { int yypos92= ctx->pos, yythunkpos92= ctx->thunkpos; if (!yy_BAR(ctx)) { goto l92; } if (!yy_sequence(ctx)) { goto l92; } yyDo(ctx, yy_1_expression, ctx->begin, ctx->end); goto l91; + l92:; ctx->pos= yypos92; ctx->thunkpos= yythunkpos92; } - yyprintf((stderr, " ok %s @ %s\n", "expression", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "expression", ctx->buf+ctx->pos)); return 1; - l91:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "expression", G->buf+G->pos)); + l90:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "expression", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_EQUAL(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar(G, '=')) goto l94; if (!yy__(G)) { goto l94; } - yyprintf((stderr, " ok %s @ %s\n", "EQUAL", G->buf+G->pos)); +YY_RULE(int) yy_EQUAL(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar(ctx, '=')) goto l93; if (!yy__(ctx)) { goto l93; } + yyprintf((stderr, " ok %s @ %s\n", "EQUAL", ctx->buf+ctx->pos)); return 1; - l94:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "EQUAL", G->buf+G->pos)); + l93:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "EQUAL", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_identifier(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "identifier")); yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l95; if (!yymatchClass(G, (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 l95; - l96:; - { int yypos97= G->pos, yythunkpos97= G->thunkpos; if (!yymatchClass(G, (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 l97; goto l96; - l97:; G->pos= yypos97; G->thunkpos= yythunkpos97; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l95; if (!yy__(G)) { goto l95; } - yyprintf((stderr, " ok %s @ %s\n", "identifier", G->buf+G->pos)); +YY_RULE(int) yy_identifier(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "identifier")); yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l94; 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 l94; + l95:; + { int yypos96= ctx->pos, yythunkpos96= 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 l96; goto l95; + l96:; ctx->pos= yypos96; ctx->thunkpos= yythunkpos96; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l94; if (!yy__(ctx)) { goto l94; } + yyprintf((stderr, " ok %s @ %s\n", "identifier", ctx->buf+ctx->pos)); return 1; - l95:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "identifier", G->buf+G->pos)); + l94:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "identifier", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_RPERCENT(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "RPERCENT")); if (!yymatchString(G, "%}")) goto l98; if (!yy__(G)) { goto l98; } - yyprintf((stderr, " ok %s @ %s\n", "RPERCENT", G->buf+G->pos)); +YY_RULE(int) yy_RPERCENT(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "RPERCENT")); if (!yymatchString(ctx, "%}")) goto l97; if (!yy__(ctx)) { goto l97; } + yyprintf((stderr, " ok %s @ %s\n", "RPERCENT", ctx->buf+ctx->pos)); return 1; - l98:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "RPERCENT", G->buf+G->pos)); + l97:; 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; +YY_RULE(int) yy_end_of_file(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyprintf((stderr, "%s\n", "end_of_file")); - { int yypos100= G->pos, yythunkpos100= G->thunkpos; if (!yymatchDot(G)) goto l100; goto l99; - l100:; G->pos= yypos100; G->thunkpos= yythunkpos100; + { int yypos99= ctx->pos, yythunkpos99= ctx->thunkpos; if (!yymatchDot(ctx)) goto l99; goto l98; + l99:; ctx->pos= yypos99; ctx->thunkpos= yythunkpos99; } - yyprintf((stderr, " ok %s @ %s\n", "end_of_file", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "end_of_file", ctx->buf+ctx->pos)); return 1; - l99:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "end_of_file", G->buf+G->pos)); + l98:; 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(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "trailer")); if (!yymatchString(G, "%%")) goto l101; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l101; - l102:; - { int yypos103= G->pos, yythunkpos103= G->thunkpos; if (!yymatchDot(G)) goto l103; goto l102; - l103:; G->pos= yypos103; G->thunkpos= yythunkpos103; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l101; yyDo(G, yy_1_trailer, G->begin, G->end); - yyprintf((stderr, " ok %s @ %s\n", "trailer", G->buf+G->pos)); +YY_RULE(int) yy_trailer(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "trailer")); if (!yymatchString(ctx, "%%")) goto l100; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l100; + l101:; + { int yypos102= ctx->pos, yythunkpos102= ctx->thunkpos; if (!yymatchDot(ctx)) goto l102; goto l101; + l102:; ctx->pos= yypos102; ctx->thunkpos= yythunkpos102; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l100; yyDo(ctx, yy_1_trailer, ctx->begin, ctx->end); + yyprintf((stderr, " ok %s @ %s\n", "trailer", ctx->buf+ctx->pos)); return 1; - l101:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "trailer", G->buf+G->pos)); + l100:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "trailer", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_definition(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "definition")); if (!yy_identifier(G)) { goto l104; } yyDo(G, yy_1_definition, G->begin, G->end); if (!yy_EQUAL(G)) { goto l104; } if (!yy_expression(G)) { goto l104; } yyDo(G, yy_2_definition, G->begin, G->end); - { int yypos105= G->pos, yythunkpos105= G->thunkpos; if (!yy_SEMICOLON(G)) { goto l105; } goto l106; - l105:; G->pos= yypos105; G->thunkpos= yythunkpos105; +YY_RULE(int) yy_definition(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "definition")); if (!yy_identifier(ctx)) { goto l103; } yyDo(ctx, yy_1_definition, ctx->begin, ctx->end); if (!yy_EQUAL(ctx)) { goto l103; } if (!yy_expression(ctx)) { goto l103; } yyDo(ctx, yy_2_definition, ctx->begin, ctx->end); + { int yypos104= ctx->pos, yythunkpos104= ctx->thunkpos; if (!yy_SEMICOLON(ctx)) { goto l104; } goto l105; + l104:; ctx->pos= yypos104; ctx->thunkpos= yythunkpos104; } - l106:; - yyprintf((stderr, " ok %s @ %s\n", "definition", G->buf+G->pos)); + l105:; + yyprintf((stderr, " ok %s @ %s\n", "definition", ctx->buf+ctx->pos)); return 1; - l104:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "definition", G->buf+G->pos)); + l103:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "definition", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy_declaration(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "declaration")); if (!yymatchString(G, "%{")) goto l107; yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l107; - l108:; - { int yypos109= G->pos, yythunkpos109= G->thunkpos; - { int yypos110= G->pos, yythunkpos110= G->thunkpos; if (!yymatchString(G, "%}")) goto l110; goto l109; - l110:; G->pos= yypos110; G->thunkpos= yythunkpos110; - } if (!yymatchDot(G)) goto l109; goto l108; - l109:; G->pos= yypos109; G->thunkpos= yythunkpos109; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l107; if (!yy_RPERCENT(G)) { goto l107; } yyDo(G, yy_1_declaration, G->begin, G->end); - yyprintf((stderr, " ok %s @ %s\n", "declaration", G->buf+G->pos)); +YY_RULE(int) yy_declaration(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "declaration")); if (!yymatchString(ctx, "%{")) goto l106; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l106; + l107:; + { int yypos108= ctx->pos, yythunkpos108= ctx->thunkpos; + { int yypos109= ctx->pos, yythunkpos109= ctx->thunkpos; if (!yymatchString(ctx, "%}")) goto l109; goto l108; + l109:; ctx->pos= yypos109; ctx->thunkpos= yythunkpos109; + } if (!yymatchDot(ctx)) goto l108; goto l107; + l108:; ctx->pos= yypos108; ctx->thunkpos= yythunkpos108; + } yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l106; if (!yy_RPERCENT(ctx)) { goto l106; } yyDo(ctx, yy_1_declaration, ctx->begin, ctx->end); + yyprintf((stderr, " ok %s @ %s\n", "declaration", ctx->buf+ctx->pos)); return 1; - l107:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "declaration", G->buf+G->pos)); + l106:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "declaration", ctx->buf+ctx->pos)); return 0; } -YY_RULE(int) yy__(GREG *G) +YY_RULE(int) yy__(GREG *ctx) { yyprintf((stderr, "%s\n", "_")); - l112:; - { int yypos113= G->pos, yythunkpos113= G->thunkpos; - { int yypos114= G->pos, yythunkpos114= G->thunkpos; if (!yy_space(G)) { goto l115; } goto l114; - l115:; G->pos= yypos114; G->thunkpos= yythunkpos114; if (!yy_comment(G)) { goto l113; } + l111:; + { int yypos112= ctx->pos, yythunkpos112= ctx->thunkpos; + { int yypos113= ctx->pos, yythunkpos113= ctx->thunkpos; if (!yy_space(ctx)) { goto l114; } goto l113; + l114:; ctx->pos= yypos113; ctx->thunkpos= yythunkpos113; if (!yy_comment(ctx)) { goto l112; } } - l114:; goto l112; - l113:; G->pos= yypos113; G->thunkpos= yythunkpos113; + l113:; goto l111; + l112:; ctx->pos= yypos112; ctx->thunkpos= yythunkpos112; } - yyprintf((stderr, " ok %s @ %s\n", "_", G->buf+G->pos)); + yyprintf((stderr, " ok %s @ %s\n", "_", ctx->buf+ctx->pos)); return 1; } -YY_RULE(int) yy_grammar(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintf((stderr, "%s\n", "grammar")); if (!yy__(G)) { goto l116; } - { int yypos119= G->pos, yythunkpos119= G->thunkpos; if (!yy_declaration(G)) { goto l120; } goto l119; - l120:; G->pos= yypos119; G->thunkpos= yythunkpos119; if (!yy_definition(G)) { goto l116; } +YY_RULE(int) yy_grammar(GREG *ctx) +{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; + yyprintf((stderr, "%s\n", "grammar")); if (!yy__(ctx)) { goto l115; } + { int yypos118= ctx->pos, yythunkpos118= ctx->thunkpos; if (!yy_declaration(ctx)) { goto l119; } goto l118; + l119:; ctx->pos= yypos118; ctx->thunkpos= yythunkpos118; if (!yy_definition(ctx)) { goto l115; } } - l119:; - l117:; - { int yypos118= G->pos, yythunkpos118= G->thunkpos; - { int yypos121= G->pos, yythunkpos121= G->thunkpos; if (!yy_declaration(G)) { goto l122; } goto l121; - l122:; G->pos= yypos121; G->thunkpos= yythunkpos121; if (!yy_definition(G)) { goto l118; } + l118:; + l116:; + { int yypos117= ctx->pos, yythunkpos117= ctx->thunkpos; + { int yypos120= ctx->pos, yythunkpos120= ctx->thunkpos; if (!yy_declaration(ctx)) { goto l121; } goto l120; + l121:; ctx->pos= yypos120; ctx->thunkpos= yythunkpos120; if (!yy_definition(ctx)) { goto l117; } } - l121:; goto l117; - l118:; G->pos= yypos118; G->thunkpos= yythunkpos118; + l120:; goto l116; + l117:; ctx->pos= yypos117; ctx->thunkpos= yythunkpos117; } - { int yypos123= G->pos, yythunkpos123= G->thunkpos; if (!yy_trailer(G)) { goto l123; } goto l124; - l123:; G->pos= yypos123; G->thunkpos= yythunkpos123; + { int yypos122= ctx->pos, yythunkpos122= ctx->thunkpos; if (!yy_trailer(ctx)) { goto l122; } goto l123; + l122:; ctx->pos= yypos122; ctx->thunkpos= yythunkpos122; } - l124:; if (!yy_end_of_file(G)) { goto l116; } - yyprintf((stderr, " ok %s @ %s\n", "grammar", G->buf+G->pos)); + l123:; if (!yy_end_of_file(ctx)) { goto l115; } + yyprintf((stderr, " ok %s @ %s\n", "grammar", ctx->buf+ctx->pos)); return 1; - l116:; G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintf((stderr, " fail %s @ %s\n", "grammar", G->buf+G->pos)); + l115:; 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)(GREG *G); +typedef int (*yyrule)(GREG *ctx); -YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart) +YY_PARSE(int) YY_NAME(parse_from)(GREG *ctx, yyrule yystart) { int yyok; - if (!G->buflen) + if (!ctx->buflen) { - G->buflen= YY_BUFFER_START_SIZE; - G->buf= (char*)YY_ALLOC(G->buflen, G->data); - G->textlen= YY_BUFFER_START_SIZE; - G->text= (char*)YY_ALLOC(G->textlen, G->data); - G->thunkslen= YY_STACK_SIZE; - G->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * G->thunkslen, G->data); - G->valslen= YY_STACK_SIZE; - G->vals= (YYSTYPE*)YY_ALLOC(sizeof(YYSTYPE) * G->valslen, G->data); - G->begin= G->end= G->pos= G->limit= G->thunkpos= 0; + ctx->buflen= YY_BUFFER_START_SIZE; + ctx->buf= (char*)YY_ALLOC(ctx->buflen, ctx->data); + ctx->textlen= YY_BUFFER_START_SIZE; + ctx->text= (char*)YY_ALLOC(ctx->textlen, ctx->data); + ctx->thunkslen= YY_STACK_SIZE; + ctx->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * ctx->thunkslen, ctx->data); + ctx->valslen= YY_STACK_SIZE; + ctx->vals= (YYSTYPE*)YY_ALLOC(sizeof(YYSTYPE) * ctx->valslen, ctx->data); + ctx->begin= ctx->end= ctx->pos= ctx->limit= ctx->thunkpos= 0; } - G->pos = 0; - G->begin= G->end= G->pos; - G->thunkpos= 0; - G->val= G->vals; - yyok= yystart(G); - if (yyok) yyDone(G); - yyCommit(G); + ctx->pos = 0; + ctx->begin= ctx->end= ctx->pos; + ctx->thunkpos= 0; + ctx->val= ctx->vals; + yyok= yystart(ctx); + if (yyok) yyDone(ctx); + yyCommit(ctx); return yyok; (void)yyrefill; (void)yymatchDot; @@ -977,33 +976,33 @@ YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart) (void)yySet; } -YY_PARSE(int) YY_NAME(parse)(GREG *G) +YY_PARSE(int) YY_NAME(parse)(GREG *ctx) { - return YY_NAME(parse_from)(G, yy_grammar); + return YY_NAME(parse_from)(ctx, yy_grammar); } -YY_PARSE(void) YY_NAME(init)(GREG *G) +YY_PARSE(void) YY_NAME(init)(GREG *ctx) { - memset(G, 0, sizeof(GREG)); + memset(ctx, 0, sizeof(GREG)); } -YY_PARSE(void) YY_NAME(deinit)(GREG *G) +YY_PARSE(void) YY_NAME(deinit)(GREG *ctx) { - if (G->buf) YY_FREE(G->buf); - if (G->text) YY_FREE(G->text); - if (G->thunks) YY_FREE(G->thunks); - if (G->vals) YY_FREE(G->vals); + if (ctx->buf) YY_FREE(ctx->buf); + if (ctx->text) YY_FREE(ctx->text); + if (ctx->thunks) YY_FREE(ctx->thunks); + if (ctx->vals) YY_FREE(ctx->vals); } YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data) { - GREG *G = (GREG *)YY_CALLOC(1, sizeof(GREG), G->data); - G->data = data; - return G; + GREG *ctx = (GREG *)YY_CALLOC(1, sizeof(GREG), ctx->data); + ctx->data = data; + return ctx; } -YY_PARSE(void) YY_NAME(parse_free)(GREG *G) +YY_PARSE(void) YY_NAME(parse_free)(GREG *ctx) { - YY_NAME(deinit)(G); - YY_FREE(G); + YY_NAME(deinit)(ctx); + YY_FREE(ctx); } #endif diff --git a/greg.g b/greg.g index 02332e1..0543332 100644 --- a/greg.g +++ b/greg.g @@ -15,10 +15,11 @@ # # THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. # -# Last edited: 2007-09-13 08:12:17 by piumarta on emilia.local +# Last edited: 2012-03-23 03:16:17 by piumarta on emilia %{ -# include "greg.h" +# include "tree.h" +# include "version.h" # include # include @@ -84,9 +85,9 @@ prefix= AND action { push(makePredicate(yytext)); } | suffix suffix= primary (QUESTION { push(makeQuery(pop())); } - | STAR { push(makeStar (pop())); } - | PLUS { push(makePlus (pop())); } - )? + | STAR { push(makeStar (pop())); } + | PLUS { push(makePlus (pop())); } + )? primary= ( identifier { push(makeVariable(yytext)); } @@ -112,7 +113,7 @@ class= '[' < ( !']' range )* > ']' - range= char '-' char | char -char= '\\' [abefnrtv'"\[\]\\] +char= '\\' [-abefnrtv'"\[\]\\] | '\\' [0-3][0-7][0-7] | '\\' [0-7][0-7]? | !'\\' . @@ -121,7 +122,7 @@ char= '\\' [abefnrtv'"\[\]\\] errblock= '~{' < braces* > '}' - action= '{' < braces* > '}' - -braces= '{' (!'}' .)* '}' +braces= '{' braces* '}' | !'}' . EQUAL= '=' - diff --git a/rpeg.c b/rpeg.c new file mode 100644 index 0000000..c5492d2 --- /dev/null +++ b/rpeg.c @@ -0,0 +1,177 @@ +/* Copyright (c) 2007 by Ian Piumarta + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the 'Software'), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, provided that the above copyright notice(s) and this + * permission notice appear in all copies of the Software. Acknowledgement + * of the use of this Software in supporting documentation would be + * appreciated but is not required. + * + * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. + * + * Last edited: 2007-09-12 00:27:30 by piumarta on vps2.piumarta.com + */ + +#include "tree.h" +#include "version.h" + +#include +#include +#include +#include +#include +#include + +FILE *input= 0; + +int verboseFlag= 0; + +static int lineNumber= 0; +static char *fileName= 0; + +struct _GREG *G; +void yyerror(struct _GREG *G, char *message); + +#define YY_INPUT(buf, result, max, D) \ +{ \ + 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 + +#include "rpeg.peg-c" + +void yyerror(struct _GREG *G, char *message) +{ + fprintf(stderr, "%s:%d: %s", fileName, lineNumber, message); + if (G->text[0]) fprintf(stderr, " near token '%s'", G->text); + if (G->pos < G->limit || !feof(input)) + { + G->buf[G->limit]= '\0'; + fprintf(stderr, " before text \""); + while (G->pos < G->limit) + { + if ('\n' == G->buf[G->pos] || '\r' == G->buf[G->pos]) break; + fputc(G->buf[G->pos++], stderr); + } + if (G->pos == G->limit) + { + int c; + while (EOF != (c= fgetc(input)) && '\n' != c && '\r' != c) + fputc(c, stderr); + } + fputc('\"', stderr); + } + fprintf(stderr, "\n"); + exit(1); +} + +static void version(char *name) +{ + printf("%s version %d.%d.%d\n", name, GREG_MAJOR, GREG_MINOR, GREG_LEVEL); +} + +static void usage(char *name) +{ + version(name); + fprintf(stderr, "usage: %s [