From f22d2e9626d887c4d0387bc4698b7803a9a8e976 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Sat, 13 Apr 2013 21:50:49 -0500 Subject: [PATCH 01/13] free all nodes with greg The generated parsers do not leak. Since the nodes are cyclic, mark a freed node with -1. Also free temp yyqq buffers. Sequences and Alternates still leaking. Add a Variable node for the name --- .gitignore | 2 ++ Makefile | 16 +++++------- compile.c | 11 ++++++-- greg.c | 31 ++++++++++++++++++---- greg.g | 25 ++++++++++++++++-- greg.h | 1 + tree.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 143 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 8f314aa..2c150f3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ greg greg.exe samples/*.c +/.gdbinit +/.lldbinit diff --git a/Makefile b/Makefile index a0c7c83..0f6d56e 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,12 @@ CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) OFLAGS = -O3 -DNDEBUG #OFLAGS = -pg -OBJS = tree.o compile.o +SRCS = tree.c compile.c all : greg -greg : greg.o $(OBJS) - $(CC) $(CFLAGS) -o $@-new greg.o $(OBJS) +greg : greg.c $(SRCS) + $(CC) $(CFLAGS) -o $@-new greg.c $(SRCS) mv $@-new $@ ROOT = @@ -23,14 +23,12 @@ $(BINDIR)/% : % uninstall : .FORCE rm -f $(BINDIR)/greg -greg.o : greg.c - # bootstrap greg from greg.g greg.c : greg.g compile.c tree.c test -f greg && ./greg -o greg-new.c greg.g - $(CC) $(CFLAGS) -o greg-new greg-new.c $(OBJS) + $(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS) ./greg-new -o greg-new.c greg.g - $(CC) $(CFLAGS) -o greg-new greg-new.c $(OBJS) + $(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS) mv greg-new.c greg.c mv greg-new greg @@ -55,9 +53,9 @@ test: samples/calc run run: greg mkdir -p selftest ./greg -o testing1.c greg.g - $(CC) $(CFLAGS) -o selftest/testing1 testing1.c $(OBJS) + $(CC) $(CFLAGS) -o selftest/testing1 testing1.c $(SRCS) $(TOOL) ./selftest/testing1 -o testing2.c greg.g - $(CC) $(CFLAGS) -o selftest/testing2 testing2.c $(OBJS) + $(CC) $(CFLAGS) -o selftest/testing2 testing2.c $(SRCS) $(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 diff --git a/compile.c b/compile.c index f99f9f3..6373128 100644 --- a/compile.c +++ b/compile.c @@ -219,7 +219,11 @@ static void Node_compile_c_ko(Node *node, int ko) break; case Class: - fprintf(output, " if (!yymatchClass(G, (unsigned char *)\"%s\", \"%s\")) goto l%d;\n", makeCharClass(node->cclass.value), yyqq((char*)node->cclass.value), ko); + { + char *tmp = yyqq((char*)node->cclass.value); + fprintf(output, " if (!yymatchClass(G, (unsigned char *)\"%s\", \"%s\")) goto l%d;\n", makeCharClass(node->cclass.value), tmp, ko); + if (tmp != (char*)node->cclass.value) free(tmp); + } break; case Action: @@ -882,12 +886,15 @@ void Rule_compile_c(Node *node) for (n= actions; n; n= n->action.list) { char *block = n->action.text; + char *tmp; fprintf(output, "YY_ACTION(void) yy%s(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)\n{\n", n->action.name); defineVariables(n->action.rule->rule.variables); while (*block == 0x20 || *block == 0x9) block++; fprintf(output, " yyprintf((stderr, \"do yy%s\"));\n", n->action.name); fprintf(output, " yyprintfvTcontext(yytext);\n"); - fprintf(output, " yyprintf((stderr, \"\\n {%s}\\n\"));\n", yyqq(block)); + tmp = yyqq(block); + fprintf(output, " yyprintf((stderr, \"\\n {%s}\\n\"));\n", tmp); + if (tmp != block) free(tmp); fprintf(output, " %s;\n", block); undefineVariables(n->action.rule->rule.variables); fprintf(output, "}\n"); diff --git a/greg.c b/greg.c index 89df094..484ad10 100644 --- a/greg.c +++ b/greg.c @@ -36,9 +36,9 @@ struct _GREG; void yyerror(struct _GREG *, char *message); -# define YY_INPUT(buf, result, max, D) \ - { \ - int c= getc(input); \ +# define YY_INPUT(buf, result, max, D) \ + { \ + int c= getc(input); \ if ('\n' == c || '\r' == c) ++lineNumber; \ result= (EOF == c) ? 0 : (*(buf)= c, 1); \ } @@ -1559,14 +1559,35 @@ int main(int argc, char **argv) Rule_compile_c_header(); - for (; headers; headers= headers->next) + while (headers) { + Header *tmp = headers; fprintf(output, "%s\n", headers->text); + free(headers->text); + tmp= headers->next; + free(headers); + headers= tmp; + } if (rules) Rule_compile_c(rules); - if (trailer) + if (trailer) { fprintf(output, "%s\n", trailer); + free(trailer); + } + + for (n= rules; n; ) { + if (n->type > 0) { + Node *tmp= n->any.next; + Rule_free(n); + if (tmp) + n= tmp->any.next; + else + n= NULL; + } else { + n= n->any.next; + } + } return 0; } diff --git a/greg.g b/greg.g index dc612fb..9da225c 100644 --- a/greg.g +++ b/greg.g @@ -292,14 +292,35 @@ int main(int argc, char **argv) Rule_compile_c_header(); - for (; headers; headers= headers->next) + while (headers) { + Header *tmp = headers; fprintf(output, "%s\n", headers->text); + free(headers->text); + tmp= headers->next; + free(headers); + headers= tmp; + } if (rules) Rule_compile_c(rules); - if (trailer) + if (trailer) { fprintf(output, "%s\n", trailer); + free(trailer); + } + + for (n= rules; n; ) { + if (n->type > 0) { + Node *tmp= n->any.next; + Rule_free(n); + if (tmp) + n= tmp->any.next; + else + n= NULL; + } else { + n= n->any.next; + } + } return 0; } diff --git a/greg.h b/greg.h index e4a4ac5..acde030 100644 --- a/greg.h +++ b/greg.h @@ -112,3 +112,4 @@ extern void Rule_compile_c(Node *node); extern void Node_print(Node *node); extern void Rule_print(Node *node); +extern void Rule_free(Node *node); diff --git a/tree.c b/tree.c index a64724d..6642931 100644 --- a/tree.c +++ b/tree.c @@ -298,6 +298,7 @@ static void Node_fprint(FILE *stream, Node *node) switch (node->type) { case Rule: fprintf(stream, " %s", node->rule.name); break; + case Variable: fprintf(stream, " %s", node->variable.name); break; case Name: fprintf(stream, " %s", node->name.rule->rule.name); break; case Dot: fprintf(stream, " ."); break; case Character: fprintf(stream, " '%s'", node->character.value); break; @@ -351,3 +352,77 @@ static void Rule_fprint(FILE *stream, Node *node) } void Rule_print(Node *node) { Rule_fprint(stderr, node); } + +void Rule_free(Node *node) +{ + FILE *stream = stderr; + switch (node->type) + { + case -1: return; + case Rule: free(node->rule.name); break; + case Name: free(node->name.rule->rule.name); break; + case Variable: free(node->variable.name); break; + case Dot: break; + case Character: free(node->character.value); break; + case String: free(node->string.value); break; + case Class: free(node->cclass.value); break; + case Action: free(node->action.text); free(node->action.name); break; + case Predicate: free(node->predicate.text); break; + case Alternate: + { + Node *root= node; + node= node->alternate.first; + while (node->any.next) { + Node *tmp= node->any.next; + Rule_free(node); + node= tmp; + } + Rule_free(node); + node= root; + break; + } + case Sequence: + { + Node *root= node; + node= node->sequence.first; + while (node->any.next) { + Node *tmp= node->any.next; + Rule_free(node); + node= tmp; + } + Rule_free(node); + node= root; + break; + } + case PeekFor: break; + case PeekNot: break; + case Query: break; + case Star: break; + case Plus: break; + default: + fprintf(stream, "\nunknown node type %d\n", node->type); + return; + } + assert(node); + node->type = -1; + if (((struct Any *)node)->errblock) + free(((struct Any *)node)->errblock); + free(node); +} + +void freeRules (void) { + Node *n; + for (n= rules; n; ) { + if (n->type > 0) { + Node *tmp= n->any.next; + Rule_free(n); + if (tmp) + n= tmp->any.next; + else + n= NULL; + } + else { + n= n->any.next; + } + } +} From ed294079094db309d0a1fceaeff1b6b93ce0a266 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Mon, 30 Sep 2013 19:56:18 -0500 Subject: [PATCH 02/13] less memory leaks, default parse_new, ... provide a default yyparse_new create better indented c code cleanup parser memory add yyprintfokrule, yyprintfvokrule, yyprintfvfailrule fix greg.c bootstrap. edit greg-new.c and compile.c for bootstrapping and do make greg-new remaining leaks: 16kb in Alternates,Sequences default yyerror filename "" => "-" remove G from YY_ERROR and YY_INPUT 1st arg use G->input as new default input stream for YY_INPUT and YY_ERROR initialize input, filename, lineno in parse_new add filename to yyparse for diagnostics yyqq: escape % to %% add Node Variable for the variable names --- Makefile | 15 +- README | 9 +- compile.c | 434 +++++++------- greg.c | 1427 ++++++++++++++++++++++++++++------------------ greg.g | 111 +--- greg.h | 59 +- samples/calc.leg | 2 +- 7 files changed, 1172 insertions(+), 885 deletions(-) diff --git a/Makefile b/Makefile index 0f6d56e..4a739bb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) OFLAGS = -O3 -DNDEBUG +CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) #OFLAGS = -pg SRCS = tree.c compile.c @@ -8,7 +8,7 @@ all : greg greg : greg.c $(SRCS) $(CC) $(CFLAGS) -o $@-new greg.c $(SRCS) - mv $@-new $@ + cp $@-new $@ ROOT = PREFIX ?= /usr @@ -25,12 +25,15 @@ uninstall : .FORCE # bootstrap greg from greg.g greg.c : greg.g compile.c tree.c - test -f greg && ./greg -o greg-new.c greg.g - $(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS) + $(MAKE) greg-new ./greg-new -o greg-new.c greg.g $(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS) - mv greg-new.c greg.c - mv greg-new greg + cp greg-new.c greg.c + cp greg-new greg + +# bootstrap: call make greg-new when you updated compile.c and greg-new.c +greg-new : greg-new.c $(SRCS) + $(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS) grammar : .FORCE ./greg -o greg.c greg.g diff --git a/README b/README index 932e8c4..9367857 100644 --- a/README +++ b/README @@ -1,9 +1,10 @@ -greg is a re-entrant peg/leg, with some bug fixes. +greg is a re-entrant peg/leg, with some bug fixes and enhancements. -the most comprehensive example of greg usage is in -nagaqueen, an ooc grammar, used in rock, an ooc -compiler written in ooc. +greg derived from potion , +is used as perl5 and perl6 parser in +and in nagaqueen, an ooc grammar, used in rock, an ooc +compiler written in ooc, diff --git a/compile.c b/compile.c index 6373128..5d0a701 100644 --- a/compile.c +++ b/compile.c @@ -1,4 +1,6 @@ /* Copyright (c) 2007 by Ian Piumarta + * Copyright (c) 2011 by Amos Wenger nddrylliog@gmail.com + * Copyright (c) 2013 by perl11 org * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -13,7 +15,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: 2013-04-10 11:15:49 rurban */ #include @@ -23,14 +25,16 @@ #include "greg.h" +static int indent= 0; + static int yyl(void) { static int prev= 0; return ++prev; } -static void charClassSet (unsigned char bits[], int c) { bits[c >> 3] |= (1 << (c & 7)); } -static void charClassClear(unsigned char bits[], int c) { bits[c >> 3] &= ~(1 << (c & 7)); } +static void charClassSet (unsigned char bits[], int c) { bits[c >> 3] |= (1 << (c & 7)); } +static void charClassClear(unsigned char bits[], int c) { bits[c >> 3] &= ~(1 << (c & 7)); } typedef void (*setter)(unsigned char bits[], int c); @@ -39,7 +43,7 @@ static int readChar(unsigned char **cp) unsigned char *cclass = *cp; int c= *cclass++, i = 0; if ('\\' == c && *cclass) - { + { c= *cclass++; if (c >= '0' && c <= '9') { @@ -57,17 +61,17 @@ static int readChar(unsigned char **cp) switch (c) { - case 'a': c= '\a'; break; /* bel */ - case 'b': c= '\b'; break; /* bs */ - case 'e': c= '\e'; break; /* esc */ - case 'f': c= '\f'; break; /* ff */ - case 'n': c= '\n'; break; /* nl */ - case 'r': c= '\r'; break; /* cr */ - case 't': c= '\t'; break; /* ht */ - case 'v': c= '\v'; break; /* vt */ - default: break; + case 'a': c= '\a'; break; /* bel */ + case 'b': c= '\b'; break; /* bs */ + case 'e': c= '\e'; break; /* esc */ + case 'f': c= '\f'; break; /* ff */ + case 'n': c= '\n'; break; /* nl */ + case 'r': c= '\r'; break; /* cr */ + case 't': c= '\t'; break; /* ht */ + case 'v': c= '\v'; break; /* vt */ + default: break; } - } + } done: *cp = cclass; @@ -80,9 +84,9 @@ static char *yyqq(char* s) { int sl = 0, dl = 0; while (*s++) { dl++; sl++; - if (*s==7||*s==8||*s==9||*s==11||*s==12||*s==13||*s==27||*s==34||*s=='%'||*s==92) { dl++; } // escape with '\' + if (*s==7||*s==8||*s==9||*s==11||*s==12||*s==13||*s==27||*s==34||*s==92||*s=='%') { dl++; } // escape with '\' else if (*s==10) { dl += 3; } // \n\^J - else if (*(signed char*)s<32) { dl += 4; } // octal \000 + else if (*(signed char *)s<32) { dl += 4; } // octal \000 } if (dl == sl) return d; s = d; @@ -90,7 +94,7 @@ static char *yyqq(char* s) { while (*s) { if (*s == '"') { *d++ = '\\'; *d++ = *s++; - } else if (*s == '%') { // '%' in printf + } else if (*s == '%') { // % => %% *d++ = '%'; *d++ = *s++; } else if (*s == '\n') { // \n\^J *d++ = '\\'; *d++ = 'n'; *d++ = '\\'; *d++ = 10; s++; @@ -110,7 +114,7 @@ static char *yyqq(char* s) { *d++ = '\\'; *d++ = 'v'; s++; } else if (*s == 92) { // '\' *d++ = '\\'; *d++ = *s++; - } else if (*(signed char*)s<32) { + } else if (*(signed char *)s<32) { sprintf(d,"\\%03o", *s); // octal \000 d += 4; s++; } else { @@ -123,11 +127,11 @@ static char *yyqq(char* s) { static char *makeCharClass(unsigned char *cclass) { - unsigned char bits[32]; - setter set; - int c, prev= -1; - static char string[256]; - char *ptr; + unsigned char bits[32]; + setter set; + int c, prev= -1; + static char string[256]; + char *ptr; if ('^' == *cclass) { @@ -143,11 +147,11 @@ static char *makeCharClass(unsigned char *cclass) while (0 != (c= readChar(&cclass))) { if ('-' == c && *cclass && prev >= 0) - { - for (c= readChar(&cclass); prev <= c; ++prev) - set(bits, prev); - prev= -1; - } + { + for (c= readChar(&cclass); prev <= c; ++prev) + set(bits, prev); + prev= -1; + } else { set(bits, prev= c); @@ -161,12 +165,14 @@ static char *makeCharClass(unsigned char *cclass) return string; } -static void begin(void) { fprintf(output, "\n {"); } -static void end(void) { fprintf(output, "\n }"); } -static void label(int n) { fprintf(output, "\n l%d:;\t", n); } -static void jump(int n) { fprintf(output, " goto l%d;", n); } -static void save(int n) { fprintf(output, " int yypos%d= G->pos, yythunkpos%d= G->thunkpos;", n, n); } -static void restore(int n) { fprintf(output, " G->pos= yypos%d; G->thunkpos= yythunkpos%d;", n, n); } +static void nl(void) { fprintf(output, "\n"); } +static void pindent(void) { fprintf(output, "%*s", 2*indent, ""); } +static void begin(void) { indent++; pindent(); fprintf(output, "{"); } +static void save(int n) { nl(); pindent(); fprintf(output, " int yypos%d= G->pos, yythunkpos%d= G->thunkpos;\n", n, n); } +static void label(int n) { nl(); pindent(); fprintf(output, " l%d:\n", n); } +static void jump(int n) { pindent(); fprintf(output, " goto l%d;", n); } +static void restore(int n) { pindent(); fprintf(output, " G->pos= yypos%d; G->thunkpos= yythunkpos%d;\n", n, n); } +static void end(void) { pindent(); indent--; fprintf(output, "}\n"); } static void callErrBlock(Node * node) { fprintf(output, " { YY_XTYPE YY_XVAR = (YY_XTYPE) G->data; int yyindex = G->offset + G->pos; %s; }", ((struct Any*) node)->errblock); @@ -183,25 +189,32 @@ static void Node_compile_c_ko(Node *node, int ko) break; case Dot: - fprintf(output, " if (!yymatchDot(G)) goto l%d;", ko); + pindent(); + fprintf(output, " if (!yymatchDot(G)) goto l%d;\n", ko); break; case Name: + pindent(); fprintf(output, " if (!yy_%s(G)) ", node->name.rule->rule.name); if(((struct Any*) node)->errblock) { - fprintf(output, "{ "); + fprintf(output, "{ "); indent++; callErrBlock(node); - fprintf(output, " goto l%d; }\n", ko); + pindent(); + fprintf(output, " goto l%d; }\n", ko); indent--; } else { - fprintf(output, " goto l%d;\n", ko); + pindent(); + fprintf(output, " goto l%d;\n", ko); } - if (node->name.variable) + if (node->name.variable) { + pindent(); fprintf(output, " yyDo(G, yySet, %d, 0, \"yySet\");\n", node->name.variable->variable.offset); + } break; case Character: case String: { + pindent(); int len= strlen(node->string.value); if (1 == len) { @@ -220,6 +233,7 @@ static void Node_compile_c_ko(Node *node, int ko) case Class: { + pindent(); char *tmp = yyqq((char*)node->cclass.value); fprintf(output, " if (!yymatchClass(G, (unsigned char *)\"%s\", \"%s\")) goto l%d;\n", makeCharClass(node->cclass.value), tmp, ko); if (tmp != (char*)node->cclass.value) free(tmp); @@ -227,103 +241,106 @@ static void Node_compile_c_ko(Node *node, int ko) break; case Action: + pindent(); fprintf(output, " yyDo(G, yy%s, G->begin, G->end, \"yy%s\");\n", node->action.name, node->action.name); break; case Predicate: - fprintf(output, " yyText(G, G->begin, G->end); if (!(%s)) goto l%d;", node->action.text, ko); + pindent(); + fprintf(output, " yyText(G, G->begin, G->end);\n if (!(%s)) goto l%d;\n", node->action.text, ko); break; case Alternate: { - int ok= yyl(); - begin(); - save(ok); - for (node= node->alternate.first; node; node= node->alternate.next) - if (node->alternate.next) - { - int next= yyl(); - Node_compile_c_ko(node, next); - jump(ok); - label(next); - restore(ok); - } - else - Node_compile_c_ko(node, ko); - end(); - label(ok); + int ok= yyl(); + begin(); + save(ok); + for (node= node->alternate.first; node; node= node->alternate.next) + if (node->alternate.next) + { + int next= yyl(); + Node_compile_c_ko(node, next); + jump(ok); + label(next); + restore(ok); + } + else + Node_compile_c_ko(node, ko); + end(); + label(ok); } break; case Sequence: for (node= node->sequence.first; node; node= node->sequence.next) - Node_compile_c_ko(node, ko); + Node_compile_c_ko(node, ko); break; case PeekFor: { - int ok= yyl(); - begin(); - save(ok); - Node_compile_c_ko(node->peekFor.element, ko); - restore(ok); - end(); + int ok= yyl(); + begin(); + save(ok); + Node_compile_c_ko(node->peekFor.element, ko); + restore(ok); + end(); } break; case PeekNot: { - int ok= yyl(); - begin(); - save(ok); - Node_compile_c_ko(node->peekFor.element, ok); - jump(ko); - label(ok); - restore(ok); - end(); + int ok= yyl(); + begin(); + save(ok); + Node_compile_c_ko(node->peekFor.element, ok); + jump(ko); + label(ok); + restore(ok); + end(); } break; case Query: { - int qko= yyl(), qok= yyl(); - begin(); - save(qko); - Node_compile_c_ko(node->query.element, qko); - jump(qok); - label(qko); - restore(qko); - end(); - label(qok); + int qko= yyl(), qok= yyl(); + begin(); + save(qko); + Node_compile_c_ko(node->query.element, qko); + jump(qok); + label(qko); + restore(qko); + end(); + label(qok); + pindent(); fprintf(output, " ;\n"); } break; case Star: { - int again= yyl(), out= yyl(); - label(again); - begin(); - save(out); - Node_compile_c_ko(node->star.element, out); - jump(again); - label(out); - restore(out); - end(); + int again= yyl(), out= yyl(); + label(again); + begin(); + save(out); + Node_compile_c_ko(node->star.element, out); + jump(again); + label(out); + restore(out); + end(); } break; case Plus: { - int again= yyl(), out= yyl(); - Node_compile_c_ko(node->plus.element, ko); - label(again); - begin(); - save(out); - Node_compile_c_ko(node->plus.element, out); - jump(again); - label(out); - restore(out); - end(); + int again= yyl(), out= yyl(); + Node_compile_c_ko(node->plus.element, ko); + label(again); + begin(); + save(out); + Node_compile_c_ko(node->plus.element, out); + jump(again); + label(out); + restore(out); + end(); } break; @@ -350,7 +367,8 @@ static void defineVariables(Node *node) int count= 0; while (node) { - fprintf(output, "#define %s G->val[%d]\n", node->variable.name, --count); + pindent(); + fprintf(output, " #define %s G->val[%d]\n", node->variable.name, --count); node->variable.offset= count; node= node->variable.next; } @@ -360,7 +378,8 @@ static void undefineVariables(Node *node) { while (node) { - fprintf(output, "#undef %s\n", node->variable.name); + pindent(); + fprintf(output, " #undef %s\n", node->variable.name); node= node->variable.next; } } @@ -378,7 +397,7 @@ static void Rule_compile_c2(Node *node) int ko= yyl(), safe; if ((!(RuleUsed & node->rule.flags)) && (node != start)) - fprintf(stderr, "rule '%s' defined but not used\n", node->rule.name); + fprintf(stderr, "rule '%s' defined but not used\n", node->rule.name); safe= ((Query == node->rule.expression->type) || (Star == node->rule.expression->type)); @@ -392,8 +411,8 @@ static void Rule_compile_c2(Node *node) fprintf(output, " yyprintfGcontext;\n"); fprintf(output, " yyprintf((stderr, \"\\n\"));\n"); if (node->rule.variables) - fprintf(output, " yyDo(G, yyPop, %d, 0, \"yyPop\");", countVariables(node->rule.variables)); - fprintf(output, "\n return 1;"); + fprintf(output, " yyDo(G, yyPop, %d, 0, \"yyPop\");\n", countVariables(node->rule.variables)); + fprintf(output, " return 1;"); if (!safe) { label(ko); @@ -401,7 +420,7 @@ static void Rule_compile_c2(Node *node) fprintf(output, " yyprintfv((stderr, \" fail %%s\", \"%s\"));\n", node->rule.name); fprintf(output, " yyprintfvGcontext;\n"); fprintf(output, " yyprintfv((stderr, \"\\n\"));\n"); - fprintf(output, "\n return 0;"); + fprintf(output, " return 0;"); } fprintf(output, "\n}"); } @@ -410,21 +429,6 @@ static void Rule_compile_c2(Node *node) Rule_compile_c2(node->rule.next); } -#ifdef YY_DEBUG -static void yyprintcontext(FILE *stream, char *s) -{ - char *context = s; - char *nl = strchr(context, 10); - if (nl) { - context = (char*)malloc(nl-s+1); - strncpy(context, s, nl-s); - context[nl-s] = '\0'; /* replace nl by 0 */ - } - fprintf(stream, " @ \"%s\"", context); - if (nl) free(context); -} -#endif - static char *header= "\ #include \n\ #include \n\ @@ -446,47 +450,53 @@ static char *preamble= "\ #define YY_FREE free\n\ #endif\n\ #ifndef YY_LOCAL\n\ -#define YY_LOCAL(T) static T\n\ +#define YY_LOCAL(T) static T\n\ #endif\n\ #ifndef YY_ACTION\n\ -#define YY_ACTION(T) static T\n\ +#define YY_ACTION(T) static T\n\ #endif\n\ #ifndef YY_RULE\n\ -#define YY_RULE(T) static T\n\ +#define YY_RULE(T) static T\n\ #endif\n\ #ifndef YY_PARSE\n\ -#define YY_PARSE(T) T\n\ +#define YY_PARSE(T) T\n\ #endif\n\ #ifndef YY_NAME\n\ #define YY_NAME(N) yy##N\n\ #endif\n\ #ifndef YY_INPUT\n\ -#define YY_INPUT(buf, result, max_size, D) \\\n\ +#define YY_INPUT(buf, result, max_size) \\\n\ { \\\n\ - int yyc= getchar(); \\\n\ + int yyc= fgetc(G->input); \\\n\ + if ('\\n' == yyc) ++G->lineno; \\\n\ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \\\n\ - yyprintf((stderr, \"<%c>\", yyc)); \\\n\ + yyprintfv((stderr, \"<%c>\", yyc)); \\\n\ }\n\ #endif\n\ +#ifndef YY_ERROR\n\ +#define YY_ERROR(message) yyerror(G, message)\n\ +#endif\n\ #ifndef YY_BEGIN\n\ -#define YY_BEGIN ( G->begin= G->pos, 1)\n\ +#define YY_BEGIN ( G->begin= G->pos, 1)\n\ #endif\n\ #ifndef YY_END\n\ -#define YY_END ( G->end= G->pos, 1)\n\ +#define YY_END ( G->end= G->pos, 1)\n\ #endif\n\ #ifdef YY_DEBUG\n\ -# ifndef DEBUG_PARSE\n\ -# define DEBUG_PARSE 1\n\ +# define yydebug G->debug\n\ +# ifndef YYDEBUG_PARSE\n\ +# define YYDEBUG_PARSE 1\n\ # endif\n\ -# ifndef DEBUG_VERBOSE\n\ -# define DEBUG_VERBOSE 2\n\ +# ifndef YYDEBUG_VERBOSE\n\ +# define YYDEBUG_VERBOSE 2\n\ # endif\n\ -# define yyprintf(args) if (G->debug & DEBUG_PARSE) fprintf args\n\ -# define yyprintfv(args) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) fprintf args\n\ -# define yyprintfGcontext if (G->debug & DEBUG_PARSE) yyprintcontext(stderr,G->buf+G->pos)\n\ -# define yyprintfvGcontext if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,G->buf+G->pos)\n\ -# define yyprintfvTcontext(text) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,text)\n\ +# define yyprintf(args) if (G->debug & YYDEBUG_PARSE) fprintf args\n\ +# define yyprintfv(args) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) fprintf args\n\ +# define yyprintfGcontext if (G->debug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ +# define yyprintfvGcontext if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ +# define yyprintfvTcontext(text) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text)\n\ #else\n\ +# define yydebug 0\n\ # define yyprintf(args)\n\ # define yyprintfv(args)\n\ # define yyprintfGcontext\n\ @@ -494,7 +504,7 @@ static char *preamble= "\ # define yyprintfvTcontext(text)\n\ #endif\n\ #ifndef YYSTYPE\n\ -#define YYSTYPE int\n\ +#define YYSTYPE int\n\ #endif\n\ #ifndef YY_XTYPE\n\ #define YY_XTYPE void *\n\ @@ -504,11 +514,11 @@ static char *preamble= "\ #endif\n\ \n\ #ifndef YY_STACK_SIZE\n\ -#define YY_STACK_SIZE 128\n\ +#define YY_STACK_SIZE 1024\n\ #endif\n\ \n\ #ifndef YY_BUFFER_START_SIZE\n\ -#define YY_BUFFER_START_SIZE 1024\n\ +#define YY_BUFFER_START_SIZE 16384\n\ #endif\n\ \n\ #ifndef YY_PART\n\ @@ -521,17 +531,20 @@ typedef struct _yythunk { int begin, end; yyaction action; const char *name; s \n\ typedef struct _GREG {\n\ char *buf;\n\ - int buflen;\n\ + int buflen;\n\ int offset;\n\ int pos;\n\ int limit;\n\ char *text;\n\ - int textlen;\n\ - int begin;\n\ - int end;\n\ + int textlen;\n\ + int begin;\n\ + int end;\n\ yythunk *thunks;\n\ - int thunkslen;\n\ - int thunkpos;\n\ + int thunkslen;\n\ + int thunkpos;\n\ + int lineno;\n\ + char *filename;\n\ + FILE *input;\n\ YYSTYPE ss;\n\ YYSTYPE *val;\n\ YYSTYPE *vals;\n\ @@ -550,7 +563,7 @@ YY_LOCAL(int) yyrefill(GREG *G)\n\ G->buflen *= 2;\n\ G->buf= (char*)YY_REALLOC(G->buf, G->buflen, G->data);\n\ }\n\ - YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos), G->data);\n\ + YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos));\n\ if (!yyn) return 0;\n\ G->limit += yyn;\n\ return 1;\n\ @@ -564,7 +577,7 @@ YY_LOCAL(int) yymatchDot(GREG *G)\n\ }\n\ \n\ #ifdef YY_DEBUG\n\ -YY_LOCAL(void) yyprintcontext(FILE *stream, char *s)\n\ +YY_LOCAL(void) yyprintcontext(GREG *G, FILE *stream, char *s)\n\ {\n\ char *context = s;\n\ char *nl = strchr(context, 10);\n\ @@ -578,6 +591,31 @@ YY_LOCAL(void) yyprintcontext(FILE *stream, char *s)\n\ }\n\ #endif\n\ \n\ +YY_LOCAL(void) yyerror(struct _GREG *G, char *message)\n\ +{\n\ + fprintf(stderr, \"%s:%d: %s\", G->filename, G->lineno, message);\n\ + if (G->text[0]) fprintf(stderr, \" near token '%s'\", G->text);\n\ + if (G->pos < G->limit || !feof(G->input))\n\ + {\n\ + G->buf[G->limit]= '\\0';\n\ + fprintf(stderr, \" before text \\\"\");\n\ + while (G->pos < G->limit)\n\ + {\n\ + if ('\\n' == G->buf[G->pos] || '\\r' == G->buf[G->pos]) break;\n\ + fputc(G->buf[G->pos++], stderr);\n\ + }\n\ + if (G->pos == G->limit)\n\ + {\n\ + int c;\n\ + while (EOF != (c= fgetc(G->input)) && '\\n' != c && '\\r' != c)\n\ + fputc(c, stderr);\n\ + }\n\ + fputc('\\\"', stderr);\n\ + }\n\ + fprintf(stderr, \"\\n\");\n\ + exit(1);\n\ +}\n\ +\n\ YY_LOCAL(int) yymatchChar(GREG *G, int c)\n\ {\n\ if (G->pos >= G->limit && !yyrefill(G)) return 0;\n\ @@ -643,7 +681,7 @@ YY_LOCAL(void) yyDo(GREG *G, yyaction action, int begin, int end, const char *na G->thunks[G->thunkpos].begin= begin;\n\ G->thunks[G->thunkpos].end= end;\n\ G->thunks[G->thunkpos].action= action;\n\ - G->thunks[G->thunkpos].name= name;\n\ + G->thunks[G->thunkpos].name= name;\n\ ++G->thunkpos;\n\ }\n\ \n\ @@ -668,13 +706,13 @@ YY_LOCAL(int) yyText(GREG *G, int begin, int end)\n\ YY_LOCAL(void) yyDone(GREG *G)\n\ {\n\ int pos;\n\ - for (pos= 0; pos < G->thunkpos; ++pos)\n\ + for (pos= 0; pos < G->thunkpos; ++pos)\n\ {\n\ yythunk *thunk= &G->thunks[pos];\n\ int yyleng= thunk->end ? yyText(G, thunk->begin, thunk->end) : thunk->begin;\n\ - yyprintf((stderr, \"DO [%d] %s\", pos, thunk->name));\n\ + yyprintfv((stderr, \"DO [%d] %s %d\", pos, thunk->name, thunk->begin));\n\ yyprintfvTcontext(G->text);\n\ - yyprintf((stderr, \"\\n\"));\n\ + yyprintfv((stderr, \"\\n\"));\n\ thunk->action(G, G->text, yyleng, thunk, G->data);\n\ }\n\ G->thunkpos= 0;\n\ @@ -708,6 +746,7 @@ YY_LOCAL(int) yyAccept(GREG *G, int tp0)\n\ }\n\ \n\ YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) {\n\ + yyprintfv((stderr, \"yyPush %d\\n\", count));\n\ size_t off = (G->val - G->vals) + count;\n\ if (off > G->valslen) {\n\ while (G->valslen < off + 1)\n\ @@ -718,12 +757,18 @@ YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE Y G->val += count;\n\ }\n\ }\n\ -YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val -= count; }\n\ -YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { G->val[count]= G->ss; }\n\ +YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) {\n\ + yyprintfv((stderr, \"yyPop %d\\n\", count));\n\ + G->val -= count;\n\ +}\n\ +YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) {\n\ + yyprintf((stderr, \"yySet %d %p\\n\", count, (void*)yy));\n\ + G->val[count]= yy;\n\ +}\n\ \n\ #endif /* YY_PART */\n\ \n\ -#define YYACCEPT yyAccept(G, yythunkpos0)\n\ +#define YYACCEPT yyAccept(G, yythunkpos0)\n\ \n\ "; @@ -776,10 +821,20 @@ YY_PARSE(int) YY_NAME(parse)(GREG *G)\n\ return YY_NAME(parse_from)(G, yy_%s);\n\ }\n\ \n\ +YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data)\n\ +{\n\ + GREG *G= (GREG *)YY_CALLOC(1, sizeof(GREG), G->data);\n\ + G->data= data;\n\ + G->input= stdin;\n\ + G->lineno= 1;\n\ + G->filename= \"-\";\n\ + return G;\n\ +}\n\ YY_PARSE(void) YY_NAME(init)(GREG *G)\n\ {\n\ - memset(G, 0, sizeof(GREG));\n\ + memcpy(G,yyparse_new(NULL),sizeof(GREG));\n\ }\n\ +\n\ YY_PARSE(void) YY_NAME(deinit)(GREG *G)\n\ {\n\ if (G->buf) YY_FREE(G->buf);\n\ @@ -787,13 +842,6 @@ YY_PARSE(void) YY_NAME(deinit)(GREG *G)\n\ if (G->thunks) YY_FREE(G->thunks);\n\ if (G->vals) YY_FREE((void*)G->vals);\n\ }\n\ -YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data)\n\ -{\n\ - GREG *G = (GREG *)YY_CALLOC(1, sizeof(GREG), G->data);\n\ - G->data = data;\n\ - return G;\n\ -}\n\ -\n\ YY_PARSE(void) YY_NAME(parse_free)(GREG *G)\n\ {\n\ YY_NAME(deinit)(G);\n\ @@ -819,50 +867,50 @@ int consumesInput(Node *node) { case Rule: { - int result= 0; - if (RuleReached & node->rule.flags) - fprintf(stderr, "possible infinite left recursion in rule '%s'\n", node->rule.name); - else - { - node->rule.flags |= RuleReached; - result= consumesInput(node->rule.expression); - node->rule.flags &= ~RuleReached; - } - return result; + int result= 0; + if (RuleReached & node->rule.flags) + fprintf(stderr, "possible infinite left recursion in rule '%s'\n", node->rule.name); + else + { + node->rule.flags |= RuleReached; + result= consumesInput(node->rule.expression); + node->rule.flags &= ~RuleReached; + } + return result; } break; - case Dot: return 1; - case Name: return consumesInput(node->name.rule); + case Dot: return 1; + case Name: return consumesInput(node->name.rule); case Character: - case String: return strlen(node->string.value) > 0; - case Class: return 1; - case Action: return 0; - case Predicate: return 0; + case String: return strlen(node->string.value) > 0; + case Class: return 1; + case Action: return 0; + case Predicate: return 0; case Alternate: { - Node *n; - for (n= node->alternate.first; n; n= n->alternate.next) - if (!consumesInput(n)) - return 0; + Node *n; + for (n= node->alternate.first; n; n= n->alternate.next) + if (!consumesInput(n)) + return 0; } return 1; case Sequence: { - Node *n; - for (n= node->alternate.first; n; n= n->alternate.next) - if (consumesInput(n)) - return 1; + Node *n; + for (n= node->alternate.first; n; n= n->alternate.next) + if (consumesInput(n)) + return 1; } return 0; - case PeekFor: return 0; - case PeekNot: return 0; - case Query: return 0; - case Star: return 0; - case Plus: return consumesInput(node->plus.element); + case PeekFor: return 0; + case PeekNot: return 0; + case Query: return 0; + case Star: return 0; + case Plus: return consumesInput(node->plus.element); default: fprintf(stderr, "\nconsumesInput: illegal node type %d\n", node->type); diff --git a/greg.c b/greg.c index 484ad10..85f48f9 100644 --- a/greg.c +++ b/greg.c @@ -1,4 +1,4 @@ -/* A recursive-descent parser generated by greg 0.4.4 */ +/* A recursive-descent parser generated by greg 0.4.5 */ #include #include @@ -8,10 +8,7 @@ struct _GREG; # include "greg.h" -# include -# include # include -# include # include # include @@ -22,30 +19,14 @@ struct _GREG; Header *next; }; - FILE *input= 0; - int verboseFlag= 0; - static int lineNumber= 0; - static char *fileName= 0; static char *trailer= 0; static Header *headers= 0; void makeHeader(char *text); void makeTrailer(char *text); - void yyerror(struct _GREG *, 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 - #ifndef YY_ALLOC #define YY_ALLOC(N, D) malloc(N) #endif @@ -59,47 +40,53 @@ struct _GREG; #define YY_FREE free #endif #ifndef YY_LOCAL -#define YY_LOCAL(T) static T +#define YY_LOCAL(T) static T #endif #ifndef YY_ACTION -#define YY_ACTION(T) static T +#define YY_ACTION(T) static T #endif #ifndef YY_RULE -#define YY_RULE(T) static T +#define YY_RULE(T) static T #endif #ifndef YY_PARSE -#define YY_PARSE(T) T +#define YY_PARSE(T) T #endif #ifndef YY_NAME #define YY_NAME(N) yy##N #endif #ifndef YY_INPUT -#define YY_INPUT(buf, result, max_size, D) \ +#define YY_INPUT(buf, result, max_size) \ { \ - int yyc= getchar(); \ + int yyc= fgetc(G->input); \ + if ('\n' == yyc) ++G->lineno; \ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \ - yyprintf((stderr, "<%c>", yyc)); \ + yyprintfv((stderr, "<%c>", yyc)); \ } #endif +#ifndef YY_ERROR +#define YY_ERROR(message) yyerror(G, message) +#endif #ifndef YY_BEGIN -#define YY_BEGIN ( G->begin= G->pos, 1) +#define YY_BEGIN ( G->begin= G->pos, 1) #endif #ifndef YY_END -#define YY_END ( G->end= G->pos, 1) +#define YY_END ( G->end= G->pos, 1) #endif #ifdef YY_DEBUG -# ifndef DEBUG_PARSE -# define DEBUG_PARSE 1 +# define yydebug G->debug +# ifndef YYDEBUG_PARSE +# define YYDEBUG_PARSE 1 # endif -# ifndef DEBUG_VERBOSE -# define DEBUG_VERBOSE 2 +# ifndef YYDEBUG_VERBOSE +# define YYDEBUG_VERBOSE 2 # endif -# define yyprintf(args) if (G->debug & DEBUG_PARSE) fprintf args -# define yyprintfv(args) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) fprintf args -# define yyprintfGcontext if (G->debug & DEBUG_PARSE) yyprintcontext(stderr,G->buf+G->pos) -# define yyprintfvGcontext if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,G->buf+G->pos) -# define yyprintfvTcontext(text) if (G->debug == (DEBUG_PARSE|DEBUG_VERBOSE)) yyprintcontext(stderr,text) +# define yyprintf(args) if (G->debug & YYDEBUG_PARSE) fprintf args +# define yyprintfv(args) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) fprintf args +# define yyprintfGcontext if (G->debug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos) +# define yyprintfvGcontext if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos) +# define yyprintfvTcontext(text) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text) #else +# define yydebug 0 # define yyprintf(args) # define yyprintfv(args) # define yyprintfGcontext @@ -107,7 +94,7 @@ struct _GREG; # define yyprintfvTcontext(text) #endif #ifndef YYSTYPE -#define YYSTYPE int +#define YYSTYPE int #endif #ifndef YY_XTYPE #define YY_XTYPE void * @@ -117,11 +104,11 @@ struct _GREG; #endif #ifndef YY_STACK_SIZE -#define YY_STACK_SIZE 128 +#define YY_STACK_SIZE 1024 #endif #ifndef YY_BUFFER_START_SIZE -#define YY_BUFFER_START_SIZE 1024 +#define YY_BUFFER_START_SIZE 16384 #endif #ifndef YY_PART @@ -134,17 +121,20 @@ typedef struct _yythunk { int begin, end; yyaction action; const char *name; s typedef struct _GREG { char *buf; - int buflen; + int buflen; int offset; int pos; int limit; char *text; - int textlen; - int begin; - int end; + int textlen; + int begin; + int end; yythunk *thunks; - int thunkslen; - int thunkpos; + int thunkslen; + int thunkpos; + int lineno; + char *filename; + FILE *input; YYSTYPE ss; YYSTYPE *val; YYSTYPE *vals; @@ -163,7 +153,7 @@ YY_LOCAL(int) yyrefill(GREG *G) G->buflen *= 2; G->buf= (char*)YY_REALLOC(G->buf, G->buflen, G->data); } - YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos), G->data); + YY_INPUT((G->buf + G->pos), yyn, (G->buflen - G->pos)); if (!yyn) return 0; G->limit += yyn; return 1; @@ -177,7 +167,7 @@ YY_LOCAL(int) yymatchDot(GREG *G) } #ifdef YY_DEBUG -YY_LOCAL(void) yyprintcontext(FILE *stream, char *s) +YY_LOCAL(void) yyprintcontext(GREG *G, FILE *stream, char *s) { char *context = s; char *nl = strchr(context, 10); @@ -191,6 +181,31 @@ YY_LOCAL(void) yyprintcontext(FILE *stream, char *s) } #endif +YY_LOCAL(void) yyerror(struct _GREG *G, char *message) +{ + fprintf(stderr, "%s:%d: %s", G->filename, G->lineno, message); + if (G->text[0]) fprintf(stderr, " near token '%s'", G->text); + if (G->pos < G->limit || !feof(G->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(G->input)) && '\n' != c && '\r' != c) + fputc(c, stderr); + } + fputc('\"', stderr); + } + fprintf(stderr, "\n"); + exit(1); +} + YY_LOCAL(int) yymatchChar(GREG *G, int c) { if (G->pos >= G->limit && !yyrefill(G)) return 0; @@ -256,7 +271,7 @@ YY_LOCAL(void) yyDo(GREG *G, yyaction action, int begin, int end, const char *na G->thunks[G->thunkpos].begin= begin; G->thunks[G->thunkpos].end= end; G->thunks[G->thunkpos].action= action; - G->thunks[G->thunkpos].name= name; + G->thunks[G->thunkpos].name= name; ++G->thunkpos; } @@ -281,13 +296,13 @@ YY_LOCAL(int) yyText(GREG *G, int begin, int end) YY_LOCAL(void) yyDone(GREG *G) { int pos; - for (pos= 0; pos < G->thunkpos; ++pos) + for (pos= 0; pos < G->thunkpos; ++pos) { yythunk *thunk= &G->thunks[pos]; int yyleng= thunk->end ? yyText(G, thunk->begin, thunk->end) : thunk->begin; - yyprintf((stderr, "DO [%d] %s", pos, thunk->name)); + yyprintfv((stderr, "DO [%d] %s %d", pos, thunk->name, thunk->begin)); yyprintfvTcontext(G->text); - yyprintf((stderr, "\n")); + yyprintfv((stderr, "\n")); thunk->action(G, G->text, yyleng, thunk, G->data); } G->thunkpos= 0; @@ -321,6 +336,7 @@ YY_LOCAL(int) yyAccept(GREG *G, int tp0) } YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { + yyprintfv((stderr, "yyPush %d\n", count)); size_t off = (G->val - G->vals) + count; if (off > G->valslen) { while (G->valslen < off + 1) @@ -331,12 +347,18 @@ YY_LOCAL(void) yyPush(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE Y 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) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { + yyprintfv((stderr, "yyPop %d\n", count)); + G->val -= count; +} +YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { + yyprintf((stderr, "yySet %d %p\n", count, (void*)yy)); + G->val[count]= yy; +} #endif /* YY_PART */ -#define YYACCEPT yyAccept(G, yythunkpos0) +#define YYACCEPT yyAccept(G, yythunkpos0) YY_RULE(int) yy_end_of_line(GREG *G); /* 37 */ YY_RULE(int) yy_comment(GREG *G); /* 36 */ @@ -429,15 +451,15 @@ YY_ACTION(void) yy_3_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, { yyprintf((stderr, "do yy_3_primary")); yyprintfvTcontext(yytext); - yyprintf((stderr, "\n {push(makeName(findRule(yytext,0))); }\n")); - push(makeName(findRule(yytext,0))); ; + yyprintf((stderr, "\n {push(makeName(findRule(yytext, 0))); }\n")); + push(makeName(findRule(yytext, 0))); ; } YY_ACTION(void) yy_2_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_primary")); yyprintfvTcontext(yytext); - yyprintf((stderr, "\n {Node *name= makeName(findRule(yytext,0)); name->name.variable= pop(); push(name); }\n")); - Node *name= makeName(findRule(yytext,0)); name->name.variable= pop(); push(name); ; + yyprintf((stderr, "\n {Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); }\n")); + Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); ; } YY_ACTION(void) yy_1_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { @@ -504,23 +526,23 @@ YY_ACTION(void) yy_1_expression(GREG *G, char *yytext, int yyleng, yythunk *thun } YY_ACTION(void) yy_2_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { -#define s G->val[-1] + #define s G->val[-1] yyprintf((stderr, "do yy_2_definition")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {Node *e= pop(); Rule_setExpression(pop(), e); }\n")); Node *e= pop(); Rule_setExpression(pop(), e); ; -#undef s + #undef s } YY_ACTION(void) yy_1_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { -#define s G->val[-1] + #define s G->val[-1] yyprintf((stderr, "do yy_1_definition")); yyprintfvTcontext(yytext); - yyprintf((stderr, "\n {if (push(beginRule(findRule(yytext,1)))->rule.expression)\n\ + yyprintf((stderr, "\n {if (push(beginRule(findRule(yytext, s)))->rule.expression)\n\ \t\t\t\t\t\t\t fprintf(stderr, \"rule '%%s' redefined\\n\", yytext); }\n")); - if (push(beginRule(findRule(yytext,1)))->rule.expression) + if (push(beginRule(findRule(yytext, s)))->rule.expression) fprintf(stderr, "rule '%s' redefined\n", yytext); ; -#undef s + #undef s } YY_ACTION(void) yy_1_trailer(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { @@ -538,806 +560,1107 @@ YY_ACTION(void) yy_1_declaration(GREG *G, char *yytext, int yyleng, yythunk *thu } YY_RULE(int) yy_end_of_line(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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 yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; } - l2:; yyprintf((stderr, " ok end_of_line")); + + l2: + yyprintf((stderr, " ok end_of_line")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l1:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "end_of_line")); + l1: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "end_of_line")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_comment(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "comment")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "comment")); if (!yymatchChar(G, '#')) 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; + 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 comment")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l5:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "comment")); + l5: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "comment")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_space(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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 yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; } - l10:; yyprintf((stderr, " ok space")); + + l10: + yyprintf((stderr, " ok space")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l9:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "space")); + l9: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "space")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_braces(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "braces")); - - { int yypos14= G->pos, yythunkpos14= G->thunkpos; if (!yymatchChar(G, '{')) 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 yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "braces")); + { + int yypos14= G->pos, yythunkpos14= G->thunkpos; + if (!yymatchChar(G, '{')) 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; } - l14:; yyprintf((stderr, " ok braces")); + + l14: + yyprintf((stderr, " ok braces")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l13:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "braces")); + l13: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "braces")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_range(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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 yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; } - l21:; yyprintf((stderr, " ok range")); + + l21: + yyprintf((stderr, " ok range")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l20:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "range")); + l20: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "range")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_char(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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", "abefnrtv'\"\\[\\]\\\\")) 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", "0-3")) 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", "0-7")) 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", "0-7")) 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", "0-7")) 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", "0-7")) goto l28; - goto l29; - l28:; G->pos= yypos28; G->thunkpos= yythunkpos28; - } - 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; +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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", "abefnrtv'\"\\[\\]\\\\")) 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", "0-3")) 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", "0-7")) 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", "0-7")) 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", "0-7")) 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", "0-7")) goto l28; + goto l29; + l28: + G->pos= yypos28; G->thunkpos= yythunkpos28; + } + + 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; } - l24:; yyprintf((stderr, " ok char")); + + l24: + yyprintf((stderr, " ok char")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l23:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "char")); + l23: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "char")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_errblock(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "errblock")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; + 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 errblock")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l31:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "errblock")); + l31: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "errblock")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_END(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "END")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "END")); if (!yymatchChar(G, '>')) goto l34; - if (!yy__(G)) goto l34; + if (!yy__(G)) goto l34; yyprintf((stderr, " ok END")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l34:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "END")); + l34: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "END")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_BEGIN(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BEGIN")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "BEGIN")); if (!yymatchChar(G, '<')) goto l35; - if (!yy__(G)) goto l35; + if (!yy__(G)) goto l35; yyprintf((stderr, " ok BEGIN")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l35:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "BEGIN")); + l35: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "BEGIN")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_DOT(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "DOT")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "DOT")); if (!yymatchChar(G, '.')) goto l36; - if (!yy__(G)) goto l36; + if (!yy__(G)) goto l36; yyprintf((stderr, " ok DOT")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l36:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "DOT")); + l36: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "DOT")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_class(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "class")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; + 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 class")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l37:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "class")); + l37: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "class")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_literal(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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 yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; } - l42:; yyprintf((stderr, " ok literal")); + + l42: + yyprintf((stderr, " ok literal")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l41:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "literal")); + l41: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "literal")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_CLOSE(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "CLOSE")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "CLOSE")); if (!yymatchChar(G, ')')) goto l50; - if (!yy__(G)) goto l50; + if (!yy__(G)) goto l50; yyprintf((stderr, " ok CLOSE")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l50:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "CLOSE")); + l50: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "CLOSE")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_OPEN(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "OPEN")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "OPEN")); if (!yymatchChar(G, '(')) goto l51; - if (!yy__(G)) goto l51; + if (!yy__(G)) goto l51; yyprintf((stderr, " ok OPEN")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l51:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "OPEN")); + l51: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "OPEN")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_COLON(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "COLON")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "COLON")); if (!yymatchChar(G, ':')) goto l52; - if (!yy__(G)) goto l52; + if (!yy__(G)) goto l52; yyprintf((stderr, " ok COLON")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l52:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "COLON")); + l52: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "COLON")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_PLUS(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "PLUS")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "PLUS")); if (!yymatchChar(G, '+')) goto l53; - if (!yy__(G)) goto l53; + if (!yy__(G)) goto l53; yyprintf((stderr, " ok PLUS")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l53:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "PLUS")); + l53: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "PLUS")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_STAR(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "STAR")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "STAR")); if (!yymatchChar(G, '*')) goto l54; - if (!yy__(G)) goto l54; + if (!yy__(G)) goto l54; yyprintf((stderr, " ok STAR")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l54:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "STAR")); + l54: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "STAR")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_QUESTION(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "QUESTION")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "QUESTION")); if (!yymatchChar(G, '?')) goto l55; - if (!yy__(G)) goto l55; + if (!yy__(G)) goto l55; yyprintf((stderr, " ok QUESTION")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l55:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "QUESTION")); + l55: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "QUESTION")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_primary(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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, "yy_1_primary"); - 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, "yy_2_primary"); - 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, "yy_3_primary"); - 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, "yy_4_primary"); - goto l57; - l63:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_class(G)) goto l64; - yyDo(G, yy_5_primary, G->begin, G->end, "yy_5_primary"); - goto l57; - l64:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_DOT(G)) goto l65; - yyDo(G, yy_6_primary, G->begin, G->end, "yy_6_primary"); - goto l57; - l65:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_action(G)) goto l66; - yyDo(G, yy_7_primary, G->begin, G->end, "yy_7_primary"); - goto l57; - l66:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_BEGIN(G)) goto l67; - yyDo(G, yy_8_primary, G->begin, G->end, "yy_8_primary"); - goto l57; - l67:; G->pos= yypos57; G->thunkpos= yythunkpos57; if (!yy_END(G)) goto l56; - yyDo(G, yy_9_primary, G->begin, G->end, "yy_9_primary"); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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, "yy_1_primary"); + 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, "yy_2_primary"); + 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, "yy_3_primary"); + 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, "yy_4_primary"); + goto l57; + l63: + G->pos= yypos57; G->thunkpos= yythunkpos57; + if (!yy_class(G)) goto l64; + yyDo(G, yy_5_primary, G->begin, G->end, "yy_5_primary"); + goto l57; + l64: + G->pos= yypos57; G->thunkpos= yythunkpos57; + if (!yy_DOT(G)) goto l65; + yyDo(G, yy_6_primary, G->begin, G->end, "yy_6_primary"); + goto l57; + l65: + G->pos= yypos57; G->thunkpos= yythunkpos57; + if (!yy_action(G)) goto l66; + yyDo(G, yy_7_primary, G->begin, G->end, "yy_7_primary"); + goto l57; + l66: + G->pos= yypos57; G->thunkpos= yythunkpos57; + if (!yy_BEGIN(G)) goto l67; + yyDo(G, yy_8_primary, G->begin, G->end, "yy_8_primary"); + goto l57; + l67: + G->pos= yypos57; G->thunkpos= yythunkpos57; + if (!yy_END(G)) goto l56; + yyDo(G, yy_9_primary, G->begin, G->end, "yy_9_primary"); } - l57:; - { int yypos68= G->pos, yythunkpos68= G->thunkpos; if (!yy_errblock(G)) goto l68; - yyDo(G, yy_10_primary, G->begin, G->end, "yy_10_primary"); - goto l69; - l68:; G->pos= yypos68; G->thunkpos= yythunkpos68; + + l57: + { + int yypos68= G->pos, yythunkpos68= G->thunkpos; + if (!yy_errblock(G)) goto l68; + yyDo(G, yy_10_primary, G->begin, G->end, "yy_10_primary"); + goto l69; + l68: + G->pos= yypos68; G->thunkpos= yythunkpos68; } - l69:; yyprintf((stderr, " ok primary")); + + l69: + ; + yyprintf((stderr, " ok primary")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l56:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "primary")); + l56: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "primary")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_NOT(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "NOT")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "NOT")); if (!yymatchChar(G, '!')) goto l70; - if (!yy__(G)) goto l70; + if (!yy__(G)) goto l70; yyprintf((stderr, " ok NOT")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l70:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "NOT")); + l70: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "NOT")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_suffix(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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, "yy_1_suffix"); - goto l74; - l75:; G->pos= yypos74; G->thunkpos= yythunkpos74; if (!yy_STAR(G)) goto l76; - yyDo(G, yy_2_suffix, G->begin, G->end, "yy_2_suffix"); - 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_3_suffix"); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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, "yy_1_suffix"); + goto l74; + l75: + G->pos= yypos74; G->thunkpos= yythunkpos74; + if (!yy_STAR(G)) goto l76; + yyDo(G, yy_2_suffix, G->begin, G->end, "yy_2_suffix"); + 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_3_suffix"); + } + l74: + goto l73; + l72: + G->pos= yypos72; G->thunkpos= yythunkpos72; } - l74:; goto l73; - l72:; G->pos= yypos72; G->thunkpos= yythunkpos72; - } - l73:; yyprintf((stderr, " ok suffix")); + + l73: + ; + yyprintf((stderr, " ok suffix")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l71:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "suffix")); + l71: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "suffix")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_action(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "action")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; + 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 action")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l77:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "action")); + l77: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "action")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_AND(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "AND")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "AND")); if (!yymatchChar(G, '&')) goto l80; - if (!yy__(G)) goto l80; + if (!yy__(G)) goto l80; yyprintf((stderr, " ok AND")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l80:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "AND")); + l80: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "AND")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_prefix(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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, "yy_1_prefix"); - 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, "yy_2_prefix"); - 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, "yy_3_prefix"); - goto l82; - l85:; G->pos= yypos82; G->thunkpos= yythunkpos82; if (!yy_suffix(G)) goto l81; - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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, "yy_1_prefix"); + 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, "yy_2_prefix"); + 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, "yy_3_prefix"); + goto l82; + l85: + G->pos= yypos82; G->thunkpos= yythunkpos82; + if (!yy_suffix(G)) goto l81; } - l82:; yyprintf((stderr, " ok prefix")); + + l82: + yyprintf((stderr, " ok prefix")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l81:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "prefix")); + l81: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "prefix")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_BAR(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BAR")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "BAR")); if (!yymatchChar(G, '|')) goto l86; - if (!yy__(G)) goto l86; + if (!yy__(G)) goto l86; yyprintf((stderr, " ok BAR")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l86:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "BAR")); + l86: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "BAR")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_sequence(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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, "yy_1_sequence"); - goto l88; - l89:; G->pos= yypos89; G->thunkpos= yythunkpos89; - } yyprintf((stderr, " ok sequence")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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, "yy_1_sequence"); + goto l88; + l89: + G->pos= yypos89; G->thunkpos= yythunkpos89; + } + yyprintf((stderr, " ok sequence")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l87:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "sequence")); + l87: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "sequence")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_SEMICOLON(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "SEMICOLON")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(G, ';')) goto l90; - if (!yy__(G)) goto l90; + if (!yy__(G)) goto l90; yyprintf((stderr, " ok SEMICOLON")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l90:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "SEMICOLON")); + l90: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "SEMICOLON")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_expression(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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, "yy_1_expression"); - goto l92; - l93:; G->pos= yypos93; G->thunkpos= yythunkpos93; - } yyprintf((stderr, " ok expression")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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, "yy_1_expression"); + goto l92; + l93: + G->pos= yypos93; G->thunkpos= yythunkpos93; + } + yyprintf((stderr, " ok expression")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l91:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "expression")); + l91: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "expression")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_EQUAL(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "EQUAL")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "EQUAL")); if (!yymatchChar(G, '=')) goto l94; - if (!yy__(G)) goto l94; + if (!yy__(G)) goto l94; yyprintf((stderr, " ok EQUAL")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l94:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "EQUAL")); + l94: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "EQUAL")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_identifier(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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", "-a-zA-Z_")) 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", "-a-zA-Z_0-9")) 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; +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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", "-a-zA-Z_")) 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", "-a-zA-Z_0-9")) 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 identifier")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l95:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "identifier")); + l95: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "identifier")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_RPERCENT(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "RPERCENT")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "RPERCENT")); if (!yymatchString(G, "%}")) goto l98; - if (!yy__(G)) goto l98; + if (!yy__(G)) goto l98; yyprintf((stderr, " ok RPERCENT")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l98:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "RPERCENT")); + l98: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "RPERCENT")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_end_of_file(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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; - } yyprintf((stderr, " ok end_of_file")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; + } + yyprintf((stderr, " ok end_of_file")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l99:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "end_of_file")); + l99: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "end_of_file")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_trailer(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "trailer")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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, "yy_1_trailer"); + 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, "yy_1_trailer"); yyprintf((stderr, " ok trailer")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l101:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "trailer")); + l101: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "trailer")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_definition(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyDo(G, yyPush, 1, 0, "yyPush"); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyDo(G, yyPush, 1, 0, "yyPush"); yyprintfv((stderr, "%s\n", "definition")); - if (!yy_identifier(G)) goto l104; + if (!yy_identifier(G)) goto l104; yyDo(G, yySet, -1, 0, "yySet"); yyDo(G, yy_1_definition, G->begin, G->end, "yy_1_definition"); - if (!yy_EQUAL(G)) goto l104; - if (!yy_expression(G)) goto l104; + if (!yy_EQUAL(G)) goto l104; + if (!yy_expression(G)) goto l104; yyDo(G, yy_2_definition, G->begin, G->end, "yy_2_definition"); - - { int yypos105= G->pos, yythunkpos105= G->thunkpos; if (!yy_SEMICOLON(G)) goto l105; - goto l106; - l105:; G->pos= yypos105; G->thunkpos= yythunkpos105; + { + int yypos105= G->pos, yythunkpos105= G->thunkpos; + if (!yy_SEMICOLON(G)) goto l105; + goto l106; + l105: + G->pos= yypos105; G->thunkpos= yythunkpos105; } - l106:; yyprintf((stderr, " ok definition")); + + l106: + ; + yyprintf((stderr, " ok definition")); yyprintfGcontext; yyprintf((stderr, "\n")); yyDo(G, yyPop, 1, 0, "yyPop"); return 1; - l104:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "definition")); + l104: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "definition")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy_declaration(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "declaration")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; + 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, "yy_1_declaration"); yyprintf((stderr, " ok declaration")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l107:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "declaration")); + l107: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "declaration")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } YY_RULE(int) yy__(GREG *G) { yyprintfv((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; + 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; + } + l114: + goto l112; + l113: + G->pos= yypos113; G->thunkpos= yythunkpos113; } - l114:; goto l112; - l113:; G->pos= yypos113; G->thunkpos= yythunkpos113; - } yyprintf((stderr, " ok _")); + yyprintf((stderr, " ok _")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; } YY_RULE(int) yy_grammar(GREG *G) -{ int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "grammar")); - if (!yy__(G)) goto l116; +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((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; + } - { 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; + l119: - } - 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; + 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; + } + l121: + goto l117; + l118: + G->pos= yypos118; G->thunkpos= yythunkpos118; } - l121:; goto l117; - l118:; G->pos= yypos118; G->thunkpos= yythunkpos118; + { + int yypos123= G->pos, yythunkpos123= G->thunkpos; + if (!yy_trailer(G)) goto l123; + goto l124; + l123: + G->pos= yypos123; G->thunkpos= yythunkpos123; } - { int yypos123= G->pos, yythunkpos123= G->thunkpos; if (!yy_trailer(G)) goto l123; - goto l124; - l123:; G->pos= yypos123; G->thunkpos= yythunkpos123; - } - l124:; if (!yy_end_of_file(G)) goto l116; + + l124: + ; + if (!yy_end_of_file(G)) goto l116; yyprintf((stderr, " ok grammar")); yyprintfGcontext; yyprintf((stderr, "\n")); - return 1; - l116:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "grammar")); + l116: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfv((stderr, " fail %s", "grammar")); yyprintfvGcontext; yyprintfv((stderr, "\n")); - return 0; } @@ -1388,10 +1711,20 @@ YY_PARSE(int) YY_NAME(parse)(GREG *G) return YY_NAME(parse_from)(G, yy_grammar); } +YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data) +{ + GREG *G= (GREG *)YY_CALLOC(1, sizeof(GREG), G->data); + G->data= data; + G->input= stdin; + G->lineno= 1; + G->filename= "-"; + return G; +} YY_PARSE(void) YY_NAME(init)(GREG *G) { - memset(G, 0, sizeof(GREG)); + memcpy(G,yyparse_new(NULL),sizeof(GREG)); } + YY_PARSE(void) YY_NAME(deinit)(GREG *G) { if (G->buf) YY_FREE(G->buf); @@ -1399,13 +1732,6 @@ YY_PARSE(void) YY_NAME(deinit)(GREG *G) if (G->thunks) YY_FREE(G->thunks); if (G->vals) YY_FREE((void*)G->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; -} - YY_PARSE(void) YY_NAME(parse_free)(GREG *G) { YY_NAME(deinit)(G); @@ -1415,31 +1741,6 @@ YY_PARSE(void) YY_NAME(parse_free)(GREG *G) #endif -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); -} - void makeHeader(char *text) { Header *header= (Header *)malloc(sizeof(Header)); @@ -1466,6 +1767,9 @@ static void usage(char *name) fprintf(stderr, " -h print this help information\n"); fprintf(stderr, " -o write output to \n"); fprintf(stderr, " -v be verbose\n"); +#ifdef YY_DEBUG + fprintf(stderr, " -vv be more verbose\n"); +#endif fprintf(stderr, " -V print version number and exit\n"); fprintf(stderr, "if no is given, input is read from stdin\n"); fprintf(stderr, "if no is given, output is written to stdout\n"); @@ -1479,9 +1783,6 @@ int main(int argc, char **argv) int c; output= stdout; - input= stdin; - lineNumber= 1; - fileName= ""; while (-1 != (c= getopt(argc, argv, "Vho:v"))) { @@ -1516,41 +1817,38 @@ int main(int argc, char **argv) argv += optind; G = yyparse_new(NULL); + G->lineno= 1; + G->filename= "-"; #ifdef YY_DEBUG if (verboseFlag > 0) { - G->debug = DEBUG_PARSE; + yydebug = YYDEBUG_PARSE; if (verboseFlag > 1) - G->debug = DEBUG_PARSE + DEBUG_VERBOSE; + yydebug = YYDEBUG_PARSE + YYDEBUG_VERBOSE; } #endif + if (argc) { for (; argc; --argc, ++argv) { - if (!strcmp(*argv, "-")) - { - input= stdin; - fileName= ""; - } - else + if (strcmp(*argv, "-")) { - if (!(input= fopen(*argv, "r"))) + G->filename= *argv; + if (!(G->input= fopen(G->filename, "r"))) { - perror(*argv); + perror(G->filename); exit(1); } - fileName= *argv; } - lineNumber= 1; if (!yyparse(G)) - yyerror(G, "syntax error"); - if (input != stdin) - fclose(input); + YY_ERROR("syntax error"); + if (G->input != stdin) + fclose(G->input); } } else if (!yyparse(G)) - yyerror(G, "syntax error"); + YY_ERROR("syntax error"); yyparse_free(G); if (verboseFlag) @@ -1568,27 +1866,16 @@ int main(int argc, char **argv) headers= tmp; } - if (rules) + if (rules) { Rule_compile_c(rules); + freeRules(); + } if (trailer) { fprintf(output, "%s\n", trailer); free(trailer); } - for (n= rules; n; ) { - if (n->type > 0) { - Node *tmp= n->any.next; - Rule_free(n); - if (tmp) - n= tmp->any.next; - else - n= NULL; - } else { - n= n->any.next; - } - } - return 0; } diff --git a/greg.g b/greg.g index 9da225c..7a554a5 100644 --- a/greg.g +++ b/greg.g @@ -1,6 +1,9 @@ +# -*- mode: antlr; tab-width:8 -*- # LE Grammar for LE Grammars # # Copyright (c) 2007 by Ian Piumarta +# Copyright (c) 2011 by Amos Wenger nddrylliog@gmail.com +# Copyright (c) 2013 by perl11 org # All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a @@ -15,15 +18,12 @@ # # 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: 2013-04-11 15:58:07 rurban %{ # include "greg.h" -# include -# include # include -# include # include # include @@ -34,29 +34,13 @@ Header *next; }; - FILE *input= 0; - int verboseFlag= 0; - static int lineNumber= 0; - static char *fileName= 0; static char *trailer= 0; static Header *headers= 0; void makeHeader(char *text); void makeTrailer(char *text); - - void yyerror(struct _GREG *, 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 %} # Hierarchical syntax @@ -67,10 +51,10 @@ declaration= '%{' < ( !'%}' . )* > RPERCENT { makeHeader(yytext); } #{YYAC trailer= '%%' < .* > { makeTrailer(yytext); } #{YYACCEPT} -definition= s:identifier { if (push(beginRule(findRule(yytext,1)))->rule.expression) +definition= s:identifier { if (push(beginRule(findRule(yytext, s)))->rule.expression) fprintf(stderr, "rule '%s' redefined\n", yytext); } - EQUAL expression { Node *e= pop(); Rule_setExpression(pop(), e); } - SEMICOLON? #{YYACCEPT} + EQUAL expression { Node *e= pop(); Rule_setExpression(pop(), e); } + SEMICOLON? #{YYACCEPT} expression= sequence (BAR sequence { Node *f= pop(); push(Alternate_append(pop(), f)); } )* @@ -90,8 +74,8 @@ suffix= primary (QUESTION { push(makeQuery(pop())); } primary= ( identifier { push(makeVariable(yytext)); } - COLON identifier !EQUAL { Node *name= makeName(findRule(yytext,0)); name->name.variable= pop(); push(name); } -| identifier !EQUAL { push(makeName(findRule(yytext,0))); } + COLON identifier !EQUAL { Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); } +| identifier !EQUAL { push(makeName(findRule(yytext, 0))); } | OPEN expression CLOSE | literal { push(makeString(yytext)); } | class { push(makeClass(yytext)); } @@ -148,31 +132,6 @@ end-of-file= !. %% -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); -} - void makeHeader(char *text) { Header *header= (Header *)malloc(sizeof(Header)); @@ -199,6 +158,9 @@ static void usage(char *name) fprintf(stderr, " -h print this help information\n"); fprintf(stderr, " -o write output to \n"); fprintf(stderr, " -v be verbose\n"); +#ifdef YY_DEBUG + fprintf(stderr, " -vv be more verbose\n"); +#endif fprintf(stderr, " -V print version number and exit\n"); fprintf(stderr, "if no is given, input is read from stdin\n"); fprintf(stderr, "if no is given, output is written to stdout\n"); @@ -212,9 +174,6 @@ int main(int argc, char **argv) int c; output= stdout; - input= stdin; - lineNumber= 1; - fileName= ""; while (-1 != (c= getopt(argc, argv, "Vho:v"))) { @@ -249,41 +208,38 @@ int main(int argc, char **argv) argv += optind; G = yyparse_new(NULL); + G->lineno= 1; + G->filename= "-"; #ifdef YY_DEBUG if (verboseFlag > 0) { - G->debug = DEBUG_PARSE; + yydebug = YYDEBUG_PARSE; if (verboseFlag > 1) - G->debug = DEBUG_PARSE + DEBUG_VERBOSE; + yydebug = YYDEBUG_PARSE + YYDEBUG_VERBOSE; } #endif + if (argc) { for (; argc; --argc, ++argv) { - if (!strcmp(*argv, "-")) + if (strcmp(*argv, "-")) { - input= stdin; - fileName= ""; - } - else - { - if (!(input= fopen(*argv, "r"))) + G->filename= *argv; + if (!(G->input= fopen(G->filename, "r"))) { - perror(*argv); + perror(G->filename); exit(1); } - fileName= *argv; } - lineNumber= 1; if (!yyparse(G)) - yyerror(G, "syntax error"); - if (input != stdin) - fclose(input); + YY_ERROR("syntax error"); + if (G->input != stdin) + fclose(G->input); } } else if (!yyparse(G)) - yyerror(G, "syntax error"); + YY_ERROR("syntax error"); yyparse_free(G); if (verboseFlag) @@ -301,26 +257,15 @@ int main(int argc, char **argv) headers= tmp; } - if (rules) + if (rules) { Rule_compile_c(rules); + freeRules(); + } if (trailer) { fprintf(output, "%s\n", trailer); free(trailer); } - for (n= rules; n; ) { - if (n->type > 0) { - Node *tmp= n->any.next; - Rule_free(n); - if (tmp) - n= tmp->any.next; - else - n= NULL; - } else { - n= n->any.next; - } - } - return 0; } diff --git a/greg.h b/greg.h index acde030..b56c0a0 100644 --- a/greg.h +++ b/greg.h @@ -1,4 +1,6 @@ /* Copyright (c) 2007 by Ian Piumarta + * Copyright (c) 2011 by Amos Wenger nddrylliog@gmail.com + * Copyright (c) 2013 by perl11 org * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -13,25 +15,25 @@ * * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. * - * Last edited: 2007-05-15 10:32:05 by piumarta on emilia + * Last edited: 2013-04-11 11:10:34 rurban */ #include -#define GREG_MAJOR 0 -#define GREG_MINOR 4 -#define GREG_LEVEL 4 +#define GREG_MAJOR 0 +#define GREG_MINOR 4 +#define GREG_LEVEL 5 -enum { Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Predicate, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus }; +typedef enum { Freed = -1, Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Predicate, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus, Any } NodeType; enum { - RuleUsed = 1<<0, - RuleReached = 1<<1, + RuleUsed = 1<<0, + RuleReached = 1<<1, }; typedef union Node Node; -#define NODE_COMMON int type; Node *next; char *errblock +#define NODE_COMMON NodeType type; Node *next; char *errblock struct Rule { NODE_COMMON; char *name; Node *variables; Node *expression; int id; int flags; }; struct Variable { NODE_COMMON; char *name; Node *value; int offset; }; struct Name { NODE_COMMON; Node *rule; Node *variable; }; @@ -53,24 +55,24 @@ struct Any { NODE_COMMON; }; union Node { - int type; - struct Rule rule; - struct Variable variable; - struct Name name; - struct Dot dot; - struct Character character; - struct String string; - struct Class cclass; - struct Action action; - struct Predicate predicate; - struct Alternate alternate; - struct Sequence sequence; - struct PeekFor peekFor; - struct PeekNot peekNot; - struct Query query; - struct Star star; - struct Plus plus; - struct Any any; + NodeType type; + struct Rule rule; + struct Variable variable; + struct Name name; + struct Dot dot; + struct Character character; + struct String string; + struct Class cclass; + struct Action action; + struct Predicate predicate; + struct Alternate alternate; + struct Sequence sequence; + struct PeekFor peekFor; + struct PeekNot peekNot; + struct Query query; + struct Star star; + struct Plus plus; + struct Any any; }; extern Node *actions; @@ -81,8 +83,8 @@ extern int ruleCount; extern FILE *output; -extern Node *makeRule(char *name, int defined); -extern Node *findRule(char *name, int defined); +extern Node *makeRule(char *name, int starts); +extern Node *findRule(char *name, int starts); extern Node *beginRule(Node *rule); extern void Rule_setExpression(Node *rule, Node *expression); extern Node *Rule_beToken(Node *rule); @@ -113,3 +115,4 @@ extern void Rule_compile_c(Node *node); extern void Node_print(Node *node); extern void Rule_print(Node *node); extern void Rule_free(Node *node); +extern void freeRules(void); diff --git a/samples/calc.leg b/samples/calc.leg index 39fe04b..72ab8a9 100644 --- a/samples/calc.leg +++ b/samples/calc.leg @@ -4,7 +4,7 @@ int vars[26]; %} Stmt = - e:Expr EOL { printf("%d\n", e); } - | ( !EOL . )* EOL { printf("error\n"); } + | ( !EOL . )* EOL { YY_ERROR("error\n"); } Expr = i:ID ASSIGN s:Sum { $$= vars[i]= s; } | s:Sum { $$= s; } From 4dc52d0ce18021943a5993803d8e9e94ed7f1641 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Mon, 30 Sep 2013 21:42:34 -0500 Subject: [PATCH 03/13] simplify ok/fail rule debug printing in context skip -vv verbose printing for typical lexer rules --- compile.c | 123 ++++++++++++++---- greg.c | 377 ++++++++++++++++++++---------------------------------- 2 files changed, 234 insertions(+), 266 deletions(-) diff --git a/compile.c b/compile.c index 5d0a701..fec2025 100644 --- a/compile.c +++ b/compile.c @@ -15,7 +15,7 @@ * * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. * - * Last edited: 2013-04-10 11:15:49 rurban + * Last edited: 2013-09-30 20:44:59 rurban */ #include @@ -24,6 +24,18 @@ #include #include "greg.h" +#ifndef YY_ALLOC +#define YY_ALLOC(N, D) malloc(N) +#endif +#ifndef YY_CALLOC +#define YY_CALLOC(N, S, D) calloc(N, S) +#endif +#ifndef YY_REALLOC +#define YY_REALLOC(B, N, D) realloc(B, N) +#endif +#ifndef YY_FREE +#define YY_FREE free +#endif static int indent= 0; @@ -207,7 +219,8 @@ static void Node_compile_c_ko(Node *node, int ko) } if (node->name.variable) { pindent(); - fprintf(output, " yyDo(G, yySet, %d, 0, \"yySet\");\n", node->name.variable->variable.offset); + fprintf(output, " yyDo(G, yySet, %d, 0, \"yySet %s\");\n", + node->name.variable->variable.offset, node->name.rule->rule.name); } break; @@ -236,7 +249,7 @@ static void Node_compile_c_ko(Node *node, int ko) pindent(); char *tmp = yyqq((char*)node->cclass.value); fprintf(output, " if (!yymatchClass(G, (unsigned char *)\"%s\", \"%s\")) goto l%d;\n", makeCharClass(node->cclass.value), tmp, ko); - if (tmp != (char*)node->cclass.value) free(tmp); + if (tmp != (char*)node->cclass.value) YY_FREE(tmp); } break; @@ -407,9 +420,18 @@ static void Rule_compile_c2(Node *node) fprintf(output, " yyDo(G, yyPush, %d, 0, \"yyPush\");\n", countVariables(node->rule.variables)); fprintf(output, " yyprintfv((stderr, \"%%s\\n\", \"%s\"));\n", node->rule.name); Node_compile_c_ko(node->rule.expression, ko); - fprintf(output, " yyprintf((stderr, \" ok %s\"));\n", node->rule.name); - fprintf(output, " yyprintfGcontext;\n"); - fprintf(output, " yyprintf((stderr, \"\\n\"));\n"); + if (!memcmp("utf",node->rule.name,3) + || !memcmp("_",node->rule.name,1) + || !memcmp("end_of",node->rule.name,6) + || !strcmp("space",node->rule.name) + || !strcmp("sep",node->rule.name) + || !strcmp("comment",node->rule.name) + || !strcmp("IDFIRST",node->rule.name) + || !strcmp("id",node->rule.name) + ) + fprintf(output, " yyprintfvokrule(\"%s\");\n", node->rule.name); + else + fprintf(output, " yyprintfokrule(\"%s\");\n", node->rule.name); if (node->rule.variables) fprintf(output, " yyDo(G, yyPop, %d, 0, \"yyPop\");\n", countVariables(node->rule.variables)); fprintf(output, " return 1;"); @@ -417,9 +439,7 @@ static void Rule_compile_c2(Node *node) { label(ko); restore(0); - fprintf(output, " yyprintfv((stderr, \" fail %%s\", \"%s\"));\n", node->rule.name); - fprintf(output, " yyprintfvGcontext;\n"); - fprintf(output, " yyprintfv((stderr, \"\\n\"));\n"); + fprintf(output, " yyprintfvfailrule(\"%s\");\n", node->rule.name); fprintf(output, " return 0;"); } fprintf(output, "\n}"); @@ -468,7 +488,7 @@ static char *preamble= "\ #define YY_INPUT(buf, result, max_size) \\\n\ { \\\n\ int yyc= fgetc(G->input); \\\n\ - if ('\\n' == yyc) ++G->lineno; \\\n\ + if ('\\n' == yyc) ++G->lineno; \\\n\ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \\\n\ yyprintfv((stderr, \"<%c>\", yyc)); \\\n\ }\n\ @@ -490,11 +510,32 @@ static char *preamble= "\ # ifndef YYDEBUG_VERBOSE\n\ # define YYDEBUG_VERBOSE 2\n\ # endif\n\ -# define yyprintf(args) if (G->debug & YYDEBUG_PARSE) fprintf args\n\ -# define yyprintfv(args) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) fprintf args\n\ -# define yyprintfGcontext if (G->debug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ -# define yyprintfvGcontext if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ -# define yyprintfvTcontext(text) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text)\n\ +# define yyprintf(args) if (yydebug & YYDEBUG_PARSE) fprintf args\n\ +# define yyprintfv(args) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) fprintf args\n\ +# define yyprintfGcontext if (yydebug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ +# define yyprintfvGcontext if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ +# define yyprintfvTcontext(text) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text)\n\ +# define yyprintfokrule(rule) if (yydebug & YYDEBUG_PARSE) {\\\n\ + if (G->buf[G->pos]) {\\\n\ + fprintf(stderr, \" ok %s\", rule);\\\n\ + yyprintcontext(G,stderr,G->buf+G->pos);\\\n\ + fprintf(stderr, \"\\n\");\\\n\ + } else {\\\n\ + yyprintfv((stderr, \" ok %s @ \\\"\\\"\\n\", rule));\\\n\ + }}\n\ +# define yyprintfvokrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\\\n\ + if (G->buf[G->pos]) {\\\n\ + fprintf(stderr, \" ok %s\", rule);\\\n\ + yyprintcontext(G,stderr,G->buf+G->pos);\\\n\ + fprintf(stderr, \"\\n\");\\\n\ + } else {\\\n\ + yyprintfv((stderr, \" ok %s @ \\\"\\\"\\n\", rule));\\\n\ + }}\n\ +# define yyprintfvfailrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\\\n\ + fprintf(stderr, \" fail %s\", rule);\\\n\ + yyprintcontext(G,stderr,G->buf+G->pos);\\\n\ + fprintf(stderr, \"\\n\");\\\n\ + }\n\ #else\n\ # define yydebug 0\n\ # define yyprintf(args)\n\ @@ -502,6 +543,9 @@ static char *preamble= "\ # define yyprintfGcontext\n\ # define yyprintfvGcontext\n\ # define yyprintfvTcontext(text)\n\ +# define yyprintfokrule(rule)\n\ +# define yyprintfvokrule(rule)\n\ +# define yyprintfvfailrule(rule)\n\ #endif\n\ #ifndef YYSTYPE\n\ #define YYSTYPE int\n\ @@ -577,17 +621,24 @@ YY_LOCAL(int) yymatchDot(GREG *G)\n\ }\n\ \n\ #ifdef YY_DEBUG\n\ -YY_LOCAL(void) yyprintcontext(GREG *G, FILE *stream, char *s)\n\ +YY_LOCAL(char *) yycontextline(struct _GREG *G, char *s)\n\ {\n\ char *context = s;\n\ char *nl = strchr(context, 10);\n\ if (nl) {\n\ - context = (char*)malloc(nl-s+1);\n\ + context = (char*)YY_ALLOC(nl-s+1, G->data);\n\ strncpy(context, s, nl-s);\n\ context[nl-s] = '\\0'; /* replace nl by 0 */\n\ + return context;\n\ + } else return NULL;\n\ +}\n\ +YY_LOCAL(void) yyprintcontext(struct _GREG *G, FILE *stream, char *s)\n\ +{\n\ + char *context = yycontextline(G, s);\n\ + if (context) {\n\ + fprintf(stream, \" @ \\\"%s\\\"\", context);\n\ + YY_FREE(context);\n\ }\n\ - fprintf(stream, \" @ \\\"%s\\\"\", context);\n\ - if (nl) free(context);\n\ }\n\ #endif\n\ \n\ @@ -621,11 +672,17 @@ YY_LOCAL(int) yymatchChar(GREG *G, int c)\n\ if (G->pos >= G->limit && !yyrefill(G)) return 0;\n\ if ((unsigned char)G->buf[G->pos] == c)\n\ {\n\ +#ifdef YY_DEBUG\n\ + if (c) {\n\ + if (c<32) { yyprintfv((stderr, \" ok yymatchChar '0x%x'\", c));}\n\ + else { yyprintfv((stderr, \" ok yymatchChar '%c'\", c));}\n\ + yyprintfvGcontext;\n\ + yyprintfv((stderr, \"\\n\"));\n\ + } else {\n\ + yyprintfv((stderr, \" ok yymatchChar '0x0' @ \\\"\\\"\\n\"));\n\ + }\n\ +#endif\n\ ++G->pos;\n\ - if (c<32) { yyprintf((stderr, \" ok yymatchChar '0x%x'\", c));}\n\ - else { yyprintf((stderr, \" ok yymatchChar '%c'\", c));}\n\ - yyprintfGcontext;\n\ - yyprintf((stderr, \"\\n\"));\n\ return 1;\n\ }\n\ if (c<32) { yyprintfv((stderr, \" fail yymatchChar '0x%x'\", c));}\n\ @@ -659,10 +716,16 @@ YY_LOCAL(int) yymatchClass(GREG *G, unsigned char *bits, char *cclass)\n\ c= (unsigned char)G->buf[G->pos];\n\ if (bits[c >> 3] & (1 << (c & 7)))\n\ {\n\ +#ifdef YY_DEBUG\n\ + if (G->buf[G->pos]) {\n\ + yyprintfv((stderr, \" ok yymatchClass [%s]\", cclass));\n\ + yyprintfvGcontext;\n\ + yyprintfv((stderr, \"\\n\"));\n\ + } else {\n\ + yyprintfv((stderr, \" ok yymatchClass [%s] @ \\\"\\\"\\n\", cclass));\n\ + }\n\ +#endif\n\ ++G->pos;\n\ - yyprintf((stderr, \" ok yymatchClass [%s]\", cclass));\n\ - yyprintfGcontext;\n\ - yyprintf((stderr, \"\\n\"));\n\ return 1;\n\ }\n\ yyprintfv((stderr, \" fail yymatchClass [%s]\", cclass));\n\ @@ -762,8 +825,12 @@ YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY G->val -= count;\n\ }\n\ YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) {\n\ - yyprintf((stderr, \"yySet %d %p\\n\", count, (void*)yy));\n\ +#ifdef YY_SET\n\ + YY_SET(G,text,count,thunk,YY_XVAR);\n\ +#else\n\ + yyprintf((stderr, \"%s %d %p\\n\", thunk->name, count, (void *)yy));\n\ G->val[count]= yy;\n\ +#endif\n\ }\n\ \n\ #endif /* YY_PART */\n\ @@ -942,7 +1009,7 @@ void Rule_compile_c(Node *node) fprintf(output, " yyprintfvTcontext(yytext);\n"); tmp = yyqq(block); fprintf(output, " yyprintf((stderr, \"\\n {%s}\\n\"));\n", tmp); - if (tmp != block) free(tmp); + if (tmp != block) YY_FREE(tmp); fprintf(output, " %s;\n", block); undefineVariables(n->action.rule->rule.variables); fprintf(output, "}\n"); diff --git a/greg.c b/greg.c index 85f48f9..d361d7f 100644 --- a/greg.c +++ b/greg.c @@ -58,7 +58,7 @@ struct _GREG; #define YY_INPUT(buf, result, max_size) \ { \ int yyc= fgetc(G->input); \ - if ('\n' == yyc) ++G->lineno; \ + if ('\n' == yyc) ++G->lineno; \ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \ yyprintfv((stderr, "<%c>", yyc)); \ } @@ -80,11 +80,32 @@ struct _GREG; # ifndef YYDEBUG_VERBOSE # define YYDEBUG_VERBOSE 2 # endif -# define yyprintf(args) if (G->debug & YYDEBUG_PARSE) fprintf args -# define yyprintfv(args) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) fprintf args -# define yyprintfGcontext if (G->debug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos) -# define yyprintfvGcontext if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos) -# define yyprintfvTcontext(text) if (G->debug & YYDEBUG_PARSE && G->debug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text) +# define yyprintf(args) if (yydebug & YYDEBUG_PARSE) fprintf args +# define yyprintfv(args) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) fprintf args +# define yyprintfGcontext if (yydebug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos) +# define yyprintfvGcontext if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos) +# define yyprintfvTcontext(text) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text) +# define yyprintfokrule(rule) if (yydebug & YYDEBUG_PARSE) {\ + if (G->buf[G->pos]) {\ + fprintf(stderr, " ok %s", rule);\ + yyprintcontext(G,stderr,G->buf+G->pos);\ + fprintf(stderr, "\n");\ + } else {\ + yyprintfv((stderr, " ok %s @ \"\"\n", rule));\ + }} +# define yyprintfvokrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\ + if (G->buf[G->pos]) {\ + fprintf(stderr, " ok %s", rule);\ + yyprintcontext(G,stderr,G->buf+G->pos);\ + fprintf(stderr, "\n");\ + } else {\ + yyprintfv((stderr, " ok %s @ \"\"\n", rule));\ + }} +# define yyprintfvfailrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\ + fprintf(stderr, " fail %s", rule);\ + yyprintcontext(G,stderr,G->buf+G->pos);\ + fprintf(stderr, "\n");\ + } #else # define yydebug 0 # define yyprintf(args) @@ -92,6 +113,9 @@ struct _GREG; # define yyprintfGcontext # define yyprintfvGcontext # define yyprintfvTcontext(text) +# define yyprintfokrule(rule) +# define yyprintfvokrule(rule) +# define yyprintfvfailrule(rule) #endif #ifndef YYSTYPE #define YYSTYPE int @@ -167,17 +191,24 @@ YY_LOCAL(int) yymatchDot(GREG *G) } #ifdef YY_DEBUG -YY_LOCAL(void) yyprintcontext(GREG *G, FILE *stream, char *s) +YY_LOCAL(char *) yycontextline(struct _GREG *G, char *s) { char *context = s; char *nl = strchr(context, 10); if (nl) { - context = (char*)malloc(nl-s+1); + context = (char*)YY_ALLOC(nl-s+1, G->data); strncpy(context, s, nl-s); context[nl-s] = '\0'; /* replace nl by 0 */ + return context; + } else return NULL; +} +YY_LOCAL(void) yyprintcontext(struct _GREG *G, FILE *stream, char *s) +{ + char *context = yycontextline(G, s); + if (context) { + fprintf(stream, " @ \"%s\"", context); + YY_FREE(context); } - fprintf(stream, " @ \"%s\"", context); - if (nl) free(context); } #endif @@ -211,11 +242,17 @@ YY_LOCAL(int) yymatchChar(GREG *G, int c) if (G->pos >= G->limit && !yyrefill(G)) return 0; if ((unsigned char)G->buf[G->pos] == c) { +#ifdef YY_DEBUG + if (c) { + if (c<32) { yyprintfv((stderr, " ok yymatchChar '0x%x'", c));} + else { yyprintfv((stderr, " ok yymatchChar '%c'", c));} + yyprintfvGcontext; + yyprintfv((stderr, "\n")); + } else { + yyprintfv((stderr, " ok yymatchChar '0x0' @ \"\"\n")); + } +#endif ++G->pos; - if (c<32) { yyprintf((stderr, " ok yymatchChar '0x%x'", c));} - else { yyprintf((stderr, " ok yymatchChar '%c'", c));} - yyprintfGcontext; - yyprintf((stderr, "\n")); return 1; } if (c<32) { yyprintfv((stderr, " fail yymatchChar '0x%x'", c));} @@ -249,10 +286,16 @@ YY_LOCAL(int) yymatchClass(GREG *G, unsigned char *bits, char *cclass) c= (unsigned char)G->buf[G->pos]; if (bits[c >> 3] & (1 << (c & 7))) { +#ifdef YY_DEBUG + if (G->buf[G->pos]) { + yyprintfv((stderr, " ok yymatchClass [%s]", cclass)); + yyprintfvGcontext; + yyprintfv((stderr, "\n")); + } else { + yyprintfv((stderr, " ok yymatchClass [%s] @ \"\"\n", cclass)); + } +#endif ++G->pos; - yyprintf((stderr, " ok yymatchClass [%s]", cclass)); - yyprintfGcontext; - yyprintf((stderr, "\n")); return 1; } yyprintfv((stderr, " fail yymatchClass [%s]", cclass)); @@ -352,8 +395,12 @@ YY_LOCAL(void) yyPop(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY G->val -= count; } YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY_XVAR) { - yyprintf((stderr, "yySet %d %p\n", count, (void*)yy)); +#ifdef YY_SET + YY_SET(G,text,count,thunk,YY_XVAR); +#else + yyprintf((stderr, "%s %d %p\n", thunk->name, count, (void *)yy)); G->val[count]= yy; +#endif } #endif /* YY_PART */ @@ -577,15 +624,11 @@ YY_RULE(int) yy_end_of_line(GREG *G) } l2: - yyprintf((stderr, " ok end_of_line")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfvokrule("end_of_line"); return 1; l1: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "end_of_line")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("end_of_line"); return 0; } YY_RULE(int) yy_comment(GREG *G) @@ -610,15 +653,11 @@ YY_RULE(int) yy_comment(GREG *G) G->pos= yypos7; G->thunkpos= yythunkpos7; } if (!yy_end_of_line(G)) goto l5; - yyprintf((stderr, " ok comment")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfvokrule("comment"); return 1; l5: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "comment")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("comment"); return 0; } YY_RULE(int) yy_space(GREG *G) @@ -639,15 +678,11 @@ YY_RULE(int) yy_space(GREG *G) } l10: - yyprintf((stderr, " ok space")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfvokrule("space"); return 1; l9: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "space")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("space"); return 0; } YY_RULE(int) yy_braces(GREG *G) @@ -688,15 +723,11 @@ YY_RULE(int) yy_braces(GREG *G) } l14: - yyprintf((stderr, " ok braces")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("braces"); return 1; l13: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "braces")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("braces"); return 0; } YY_RULE(int) yy_range(GREG *G) @@ -715,15 +746,11 @@ YY_RULE(int) yy_range(GREG *G) } l21: - yyprintf((stderr, " ok range")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("range"); return 1; l20: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "range")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("range"); return 0; } YY_RULE(int) yy_char(GREG *G) @@ -770,15 +797,11 @@ YY_RULE(int) yy_char(GREG *G) } l24: - yyprintf((stderr, " ok char")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("char"); return 1; l23: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "char")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("char"); return 0; } YY_RULE(int) yy_errblock(GREG *G) @@ -801,15 +824,11 @@ YY_RULE(int) yy_errblock(GREG *G) if (!(YY_END)) goto l31; if (!yymatchChar(G, '}')) goto l31; if (!yy__(G)) goto l31; - yyprintf((stderr, " ok errblock")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("errblock"); return 1; l31: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "errblock")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("errblock"); return 0; } YY_RULE(int) yy_END(GREG *G) @@ -818,15 +837,11 @@ YY_RULE(int) yy_END(GREG *G) yyprintfv((stderr, "%s\n", "END")); if (!yymatchChar(G, '>')) goto l34; if (!yy__(G)) goto l34; - yyprintf((stderr, " ok END")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("END"); return 1; l34: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "END")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("END"); return 0; } YY_RULE(int) yy_BEGIN(GREG *G) @@ -835,15 +850,11 @@ YY_RULE(int) yy_BEGIN(GREG *G) yyprintfv((stderr, "%s\n", "BEGIN")); if (!yymatchChar(G, '<')) goto l35; if (!yy__(G)) goto l35; - yyprintf((stderr, " ok BEGIN")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("BEGIN"); return 1; l35: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "BEGIN")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("BEGIN"); return 0; } YY_RULE(int) yy_DOT(GREG *G) @@ -852,15 +863,11 @@ YY_RULE(int) yy_DOT(GREG *G) yyprintfv((stderr, "%s\n", "DOT")); if (!yymatchChar(G, '.')) goto l36; if (!yy__(G)) goto l36; - yyprintf((stderr, " ok DOT")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("DOT"); return 1; l36: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "DOT")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("DOT"); return 0; } YY_RULE(int) yy_class(GREG *G) @@ -890,15 +897,11 @@ YY_RULE(int) yy_class(GREG *G) if (!(YY_END)) goto l37; if (!yymatchChar(G, ']')) goto l37; if (!yy__(G)) goto l37; - yyprintf((stderr, " ok class")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("class"); return 1; l37: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "class")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("class"); return 0; } YY_RULE(int) yy_literal(GREG *G) @@ -959,15 +962,11 @@ YY_RULE(int) yy_literal(GREG *G) } l42: - yyprintf((stderr, " ok literal")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("literal"); return 1; l41: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "literal")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("literal"); return 0; } YY_RULE(int) yy_CLOSE(GREG *G) @@ -976,15 +975,11 @@ YY_RULE(int) yy_CLOSE(GREG *G) yyprintfv((stderr, "%s\n", "CLOSE")); if (!yymatchChar(G, ')')) goto l50; if (!yy__(G)) goto l50; - yyprintf((stderr, " ok CLOSE")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("CLOSE"); return 1; l50: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "CLOSE")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("CLOSE"); return 0; } YY_RULE(int) yy_OPEN(GREG *G) @@ -993,15 +988,11 @@ YY_RULE(int) yy_OPEN(GREG *G) yyprintfv((stderr, "%s\n", "OPEN")); if (!yymatchChar(G, '(')) goto l51; if (!yy__(G)) goto l51; - yyprintf((stderr, " ok OPEN")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("OPEN"); return 1; l51: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "OPEN")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("OPEN"); return 0; } YY_RULE(int) yy_COLON(GREG *G) @@ -1010,15 +1001,11 @@ YY_RULE(int) yy_COLON(GREG *G) yyprintfv((stderr, "%s\n", "COLON")); if (!yymatchChar(G, ':')) goto l52; if (!yy__(G)) goto l52; - yyprintf((stderr, " ok COLON")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("COLON"); return 1; l52: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "COLON")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("COLON"); return 0; } YY_RULE(int) yy_PLUS(GREG *G) @@ -1027,15 +1014,11 @@ YY_RULE(int) yy_PLUS(GREG *G) yyprintfv((stderr, "%s\n", "PLUS")); if (!yymatchChar(G, '+')) goto l53; if (!yy__(G)) goto l53; - yyprintf((stderr, " ok PLUS")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("PLUS"); return 1; l53: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "PLUS")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("PLUS"); return 0; } YY_RULE(int) yy_STAR(GREG *G) @@ -1044,15 +1027,11 @@ YY_RULE(int) yy_STAR(GREG *G) yyprintfv((stderr, "%s\n", "STAR")); if (!yymatchChar(G, '*')) goto l54; if (!yy__(G)) goto l54; - yyprintf((stderr, " ok STAR")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("STAR"); return 1; l54: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "STAR")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("STAR"); return 0; } YY_RULE(int) yy_QUESTION(GREG *G) @@ -1061,15 +1040,11 @@ YY_RULE(int) yy_QUESTION(GREG *G) yyprintfv((stderr, "%s\n", "QUESTION")); if (!yymatchChar(G, '?')) goto l55; if (!yy__(G)) goto l55; - yyprintf((stderr, " ok QUESTION")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("QUESTION"); return 1; l55: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "QUESTION")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("QUESTION"); return 0; } YY_RULE(int) yy_primary(GREG *G) @@ -1152,15 +1127,11 @@ YY_RULE(int) yy_primary(GREG *G) l69: ; - yyprintf((stderr, " ok primary")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("primary"); return 1; l56: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "primary")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("primary"); return 0; } YY_RULE(int) yy_NOT(GREG *G) @@ -1169,15 +1140,11 @@ YY_RULE(int) yy_NOT(GREG *G) yyprintfv((stderr, "%s\n", "NOT")); if (!yymatchChar(G, '!')) goto l70; if (!yy__(G)) goto l70; - yyprintf((stderr, " ok NOT")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("NOT"); return 1; l70: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "NOT")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("NOT"); return 0; } YY_RULE(int) yy_suffix(GREG *G) @@ -1211,15 +1178,11 @@ YY_RULE(int) yy_suffix(GREG *G) l73: ; - yyprintf((stderr, " ok suffix")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("suffix"); return 1; l71: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "suffix")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("suffix"); return 0; } YY_RULE(int) yy_action(GREG *G) @@ -1242,15 +1205,11 @@ YY_RULE(int) yy_action(GREG *G) if (!(YY_END)) goto l77; if (!yymatchChar(G, '}')) goto l77; if (!yy__(G)) goto l77; - yyprintf((stderr, " ok action")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("action"); return 1; l77: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "action")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("action"); return 0; } YY_RULE(int) yy_AND(GREG *G) @@ -1259,15 +1218,11 @@ YY_RULE(int) yy_AND(GREG *G) yyprintfv((stderr, "%s\n", "AND")); if (!yymatchChar(G, '&')) goto l80; if (!yy__(G)) goto l80; - yyprintf((stderr, " ok AND")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("AND"); return 1; l80: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "AND")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("AND"); return 0; } YY_RULE(int) yy_prefix(GREG *G) @@ -1298,15 +1253,11 @@ YY_RULE(int) yy_prefix(GREG *G) } l82: - yyprintf((stderr, " ok prefix")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("prefix"); return 1; l81: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "prefix")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("prefix"); return 0; } YY_RULE(int) yy_BAR(GREG *G) @@ -1315,15 +1266,11 @@ YY_RULE(int) yy_BAR(GREG *G) yyprintfv((stderr, "%s\n", "BAR")); if (!yymatchChar(G, '|')) goto l86; if (!yy__(G)) goto l86; - yyprintf((stderr, " ok BAR")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("BAR"); return 1; l86: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "BAR")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("BAR"); return 0; } YY_RULE(int) yy_sequence(GREG *G) @@ -1341,15 +1288,11 @@ YY_RULE(int) yy_sequence(GREG *G) l89: G->pos= yypos89; G->thunkpos= yythunkpos89; } - yyprintf((stderr, " ok sequence")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("sequence"); return 1; l87: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "sequence")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("sequence"); return 0; } YY_RULE(int) yy_SEMICOLON(GREG *G) @@ -1358,15 +1301,11 @@ YY_RULE(int) yy_SEMICOLON(GREG *G) yyprintfv((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(G, ';')) goto l90; if (!yy__(G)) goto l90; - yyprintf((stderr, " ok SEMICOLON")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("SEMICOLON"); return 1; l90: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "SEMICOLON")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("SEMICOLON"); return 0; } YY_RULE(int) yy_expression(GREG *G) @@ -1385,15 +1324,11 @@ YY_RULE(int) yy_expression(GREG *G) l93: G->pos= yypos93; G->thunkpos= yythunkpos93; } - yyprintf((stderr, " ok expression")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("expression"); return 1; l91: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "expression")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("expression"); return 0; } YY_RULE(int) yy_EQUAL(GREG *G) @@ -1402,15 +1337,11 @@ YY_RULE(int) yy_EQUAL(GREG *G) yyprintfv((stderr, "%s\n", "EQUAL")); if (!yymatchChar(G, '=')) goto l94; if (!yy__(G)) goto l94; - yyprintf((stderr, " ok EQUAL")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("EQUAL"); return 1; l94: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "EQUAL")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("EQUAL"); return 0; } YY_RULE(int) yy_identifier(GREG *G) @@ -1432,15 +1363,11 @@ YY_RULE(int) yy_identifier(GREG *G) yyText(G, G->begin, G->end); if (!(YY_END)) goto l95; if (!yy__(G)) goto l95; - yyprintf((stderr, " ok identifier")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("identifier"); return 1; l95: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "identifier")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("identifier"); return 0; } YY_RULE(int) yy_RPERCENT(GREG *G) @@ -1449,15 +1376,11 @@ YY_RULE(int) yy_RPERCENT(GREG *G) yyprintfv((stderr, "%s\n", "RPERCENT")); if (!yymatchString(G, "%}")) goto l98; if (!yy__(G)) goto l98; - yyprintf((stderr, " ok RPERCENT")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("RPERCENT"); return 1; l98: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "RPERCENT")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("RPERCENT"); return 0; } YY_RULE(int) yy_end_of_file(GREG *G) @@ -1471,15 +1394,11 @@ YY_RULE(int) yy_end_of_file(GREG *G) l100: G->pos= yypos100; G->thunkpos= yythunkpos100; } - yyprintf((stderr, " ok end_of_file")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfvokrule("end_of_file"); return 1; l99: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "end_of_file")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("end_of_file"); return 0; } YY_RULE(int) yy_trailer(GREG *G) @@ -1501,15 +1420,11 @@ YY_RULE(int) yy_trailer(GREG *G) yyText(G, G->begin, G->end); if (!(YY_END)) goto l101; yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer"); - yyprintf((stderr, " ok trailer")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("trailer"); return 1; l101: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "trailer")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("trailer"); return 0; } YY_RULE(int) yy_definition(GREG *G) @@ -1518,7 +1433,7 @@ YY_RULE(int) yy_definition(GREG *G) yyDo(G, yyPush, 1, 0, "yyPush"); yyprintfv((stderr, "%s\n", "definition")); if (!yy_identifier(G)) goto l104; - yyDo(G, yySet, -1, 0, "yySet"); + yyDo(G, yySet, -1, 0, "yySet identifier"); yyDo(G, yy_1_definition, G->begin, G->end, "yy_1_definition"); if (!yy_EQUAL(G)) goto l104; if (!yy_expression(G)) goto l104; @@ -1533,16 +1448,12 @@ YY_RULE(int) yy_definition(GREG *G) l106: ; - yyprintf((stderr, " ok definition")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("definition"); yyDo(G, yyPop, 1, 0, "yyPop"); return 1; l104: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "definition")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("definition"); return 0; } YY_RULE(int) yy_declaration(GREG *G) @@ -1572,15 +1483,11 @@ YY_RULE(int) yy_declaration(GREG *G) if (!(YY_END)) goto l107; if (!yy_RPERCENT(G)) goto l107; yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration"); - yyprintf((stderr, " ok declaration")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("declaration"); return 1; l107: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "declaration")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("declaration"); return 0; } YY_RULE(int) yy__(GREG *G) @@ -1603,9 +1510,7 @@ YY_RULE(int) yy__(GREG *G) l113: G->pos= yypos113; G->thunkpos= yythunkpos113; } - yyprintf((stderr, " ok _")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfvokrule("_"); return 1; } YY_RULE(int) yy_grammar(GREG *G) @@ -1652,15 +1557,11 @@ YY_RULE(int) yy_grammar(GREG *G) l124: ; if (!yy_end_of_file(G)) goto l116; - yyprintf((stderr, " ok grammar")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyprintfokrule("grammar"); return 1; l116: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfv((stderr, " fail %s", "grammar")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + yyprintfvfailrule("grammar"); return 0; } From 8ba430dbd50ac90820769a92bb54a49ed895ce2c Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Mon, 30 Sep 2013 22:23:57 -0500 Subject: [PATCH 04/13] use YY_NAME(parse_new) This fixes potion using a different prefix --- compile.c | 2 +- greg.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compile.c b/compile.c index fec2025..9806249 100644 --- a/compile.c +++ b/compile.c @@ -899,7 +899,7 @@ YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data)\n\ }\n\ YY_PARSE(void) YY_NAME(init)(GREG *G)\n\ {\n\ - memcpy(G,yyparse_new(NULL),sizeof(GREG));\n\ + memcpy(G,YY_NAME(parse_new)(NULL),sizeof(GREG));\n\ }\n\ \n\ YY_PARSE(void) YY_NAME(deinit)(GREG *G)\n\ diff --git a/greg.c b/greg.c index d361d7f..1676dc8 100644 --- a/greg.c +++ b/greg.c @@ -1623,7 +1623,7 @@ YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data) } YY_PARSE(void) YY_NAME(init)(GREG *G) { - memcpy(G,yyparse_new(NULL),sizeof(GREG)); + memcpy(G,YY_NAME(parse_new)(NULL),sizeof(GREG)); } YY_PARSE(void) YY_NAME(deinit)(GREG *G) From 49bb4796f6839eea7e825e8211b0ed1de10df404 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 1 Oct 2013 10:05:03 -0500 Subject: [PATCH 05/13] add main in default trailer with -DYY_MAIN, build samples almost all leg samples build and work now, just test.leg not add predicates have access to yytext from git-svn-id: http://piumarta.com/svn2/peg/trunk@92 4d4069a9-7f2f-0410-87d9-cbc5f9740c0a (peg-0.1.13) revert yyerror changes: now along peg/leg upstream, just file:line at the end (as in perl) improve yyinit(&g): memset(0), not memcpy malloced g so pair yyinit with yydeinit with stack allocated G, or yyparse_new/yyparse_free with heap allocated G --- Makefile | 14 +++- compile.c | 21 ++++-- greg.c | 174 +++++++++++++++++++++++++++++++++++---------- greg.g | 21 ++++-- samples/accept.leg | 2 +- samples/basic.leg | 2 +- samples/dc.leg | 29 +++++--- samples/dcv.leg | 30 +++++--- samples/left.leg | 10 +++ samples/rule.leg | 2 +- samples/test.leg | 12 ++-- 11 files changed, 240 insertions(+), 77 deletions(-) diff --git a/Makefile b/Makefile index 4a739bb..a64c4bd 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ -OFLAGS = -O3 -DNDEBUG -CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) +OFLAGS = -O3 -DNDEBUG -DYY_MAIN +CFLAGS = -g -Wall -Wno-unused-function $(OFLAGS) $(XFLAGS) #OFLAGS = -pg SRCS = tree.c compile.c +SAMPLES = $(wildcard samples/*.leg) all : greg @@ -39,7 +40,7 @@ grammar : .FORCE ./greg -o greg.c greg.g 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] greg ${SAMPLES:.leg=.o} ${SAMPLES:.leg=} ${SAMPLES:.leg=.c} samples/*.dSYM testing1.c testing2.c *.dSYM selftest/ spotless : clean .FORCE rm -f greg @@ -50,6 +51,13 @@ samples/calc.c: samples/calc.leg greg samples/calc: samples/calc.c $(CC) $(CFLAGS) -o $@ $< +samples: ${SAMPLES:.leg=} greg + +%.c: %.leg + ./greg $< > $@ +.leg.c: + ./greg $< > $@ + test: samples/calc run echo '21 * 2 + 0' | ./samples/calc | grep 42 diff --git a/compile.c b/compile.c index 9806249..55da25c 100644 --- a/compile.c +++ b/compile.c @@ -260,7 +260,15 @@ static void Node_compile_c_ko(Node *node, int ko) case Predicate: pindent(); - fprintf(output, " yyText(G, G->begin, G->end);\n if (!(%s)) goto l%d;\n", node->action.text, ko); + //fprintf(output, " yyText(G, G->begin, G->end);\n if (!(%s)) goto l%d;\n", node->action.text, ko); + /* predicates have access to yytext */ + fprintf(output, " yyText(G, G->begin, G->end);\n {\n"); + fprintf(output, " #define yytext G->text\n"); + fprintf(output, " #define yyleng G->textlen\n"); + fprintf(output, " if (!(%s)) goto l%d;\n", node->action.text, ko); + fprintf(output, " #undef yytext\n"); + fprintf(output, " #undef yyleng\n"); + fprintf(output, " }"); break; case Alternate: @@ -644,7 +652,7 @@ YY_LOCAL(void) yyprintcontext(struct _GREG *G, FILE *stream, char *s)\n\ \n\ YY_LOCAL(void) yyerror(struct _GREG *G, char *message)\n\ {\n\ - fprintf(stderr, \"%s:%d: %s\", G->filename, G->lineno, message);\n\ + fputs(message, stderr);\n\ if (G->text[0]) fprintf(stderr, \" near token '%s'\", G->text);\n\ if (G->pos < G->limit || !feof(G->input))\n\ {\n\ @@ -656,14 +664,14 @@ YY_LOCAL(void) yyerror(struct _GREG *G, char *message)\n\ fputc(G->buf[G->pos++], stderr);\n\ }\n\ if (G->pos == G->limit)\n\ - {\n\ + {\n\ int c;\n\ while (EOF != (c= fgetc(G->input)) && '\\n' != c && '\\r' != c)\n\ fputc(c, stderr);\n\ }\n\ fputc('\\\"', stderr);\n\ }\n\ - fprintf(stderr, \"\\n\");\n\ + fprintf(stderr, \" at %s:%d\\n\", G->filename, G->lineno);\n\ exit(1);\n\ }\n\ \n\ @@ -899,7 +907,10 @@ YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data)\n\ }\n\ YY_PARSE(void) YY_NAME(init)(GREG *G)\n\ {\n\ - memcpy(G,YY_NAME(parse_new)(NULL),sizeof(GREG));\n\ + memset(G, 0, sizeof(GREG));\n\ + G->input= stdin;\n\ + G->lineno= 1;\n\ + G->filename= \"-\";\n\ }\n\ \n\ YY_PARSE(void) YY_NAME(deinit)(GREG *G)\n\ diff --git a/greg.c b/greg.c index 1676dc8..cc8c81a 100644 --- a/greg.c +++ b/greg.c @@ -23,6 +23,18 @@ struct _GREG; static char *trailer= 0; static Header *headers= 0; + static char *deftrailer= "\n\ +#ifdef YY_MAIN\n\ +int main()\n\ +{\n\ + GREG g;\n\ + yyinit(&g);\n\ + while (yyparse(&g));\n\ + yydeinit(&g);\n\ + return 0;\n\ +}\n\ +#endif\n\ +"; void makeHeader(char *text); void makeTrailer(char *text); @@ -214,7 +226,7 @@ YY_LOCAL(void) yyprintcontext(struct _GREG *G, FILE *stream, char *s) YY_LOCAL(void) yyerror(struct _GREG *G, char *message) { - fprintf(stderr, "%s:%d: %s", G->filename, G->lineno, message); + fputs(message, stderr); if (G->text[0]) fprintf(stderr, " near token '%s'", G->text); if (G->pos < G->limit || !feof(G->input)) { @@ -226,14 +238,14 @@ YY_LOCAL(void) yyerror(struct _GREG *G, char *message) fputc(G->buf[G->pos++], stderr); } if (G->pos == G->limit) - { + { int c; while (EOF != (c= fgetc(G->input)) && '\n' != c && '\r' != c) fputc(c, stderr); } fputc('\"', stderr); } - fprintf(stderr, "\n"); + fprintf(stderr, " at %s:%d\n", G->filename, G->lineno); exit(1); } @@ -810,8 +822,13 @@ YY_RULE(int) yy_errblock(GREG *G) yyprintfv((stderr, "%s\n", "errblock")); if (!yymatchString(G, "~{")) goto l31; yyText(G, G->begin, G->end); - if (!(YY_BEGIN)) goto l31; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l31; + #undef yytext + #undef yyleng + } l32: { int yypos33= G->pos, yythunkpos33= G->thunkpos; @@ -821,8 +838,13 @@ YY_RULE(int) yy_errblock(GREG *G) G->pos= yypos33; G->thunkpos= yythunkpos33; } yyText(G, G->begin, G->end); - if (!(YY_END)) goto l31; - if (!yymatchChar(G, '}')) goto l31; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l31; + #undef yytext + #undef yyleng + } if (!yymatchChar(G, '}')) goto l31; if (!yy__(G)) goto l31; yyprintfokrule("errblock"); return 1; @@ -876,8 +898,13 @@ YY_RULE(int) yy_class(GREG *G) yyprintfv((stderr, "%s\n", "class")); if (!yymatchChar(G, '[')) goto l37; yyText(G, G->begin, G->end); - if (!(YY_BEGIN)) goto l37; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l37; + #undef yytext + #undef yyleng + } l38: { int yypos39= G->pos, yythunkpos39= G->thunkpos; @@ -894,8 +921,13 @@ YY_RULE(int) yy_class(GREG *G) G->pos= yypos39; G->thunkpos= yythunkpos39; } yyText(G, G->begin, G->end); - if (!(YY_END)) goto l37; - if (!yymatchChar(G, ']')) goto l37; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l37; + #undef yytext + #undef yyleng + } if (!yymatchChar(G, ']')) goto l37; if (!yy__(G)) goto l37; yyprintfokrule("class"); return 1; @@ -912,8 +944,13 @@ YY_RULE(int) yy_literal(GREG *G) 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; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l43; + #undef yytext + #undef yyleng + } l44: { int yypos45= G->pos, yythunkpos45= G->thunkpos; @@ -930,16 +967,26 @@ YY_RULE(int) yy_literal(GREG *G) 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; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l43; + #undef yytext + #undef yyleng + } 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; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l41; + #undef yytext + #undef yyleng + } l47: { int yypos48= G->pos, yythunkpos48= G->thunkpos; @@ -956,8 +1003,13 @@ YY_RULE(int) yy_literal(GREG *G) 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; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l41; + #undef yytext + #undef yyleng + } 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; } @@ -1191,8 +1243,13 @@ YY_RULE(int) yy_action(GREG *G) yyprintfv((stderr, "%s\n", "action")); if (!yymatchChar(G, '{')) goto l77; yyText(G, G->begin, G->end); - if (!(YY_BEGIN)) goto l77; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l77; + #undef yytext + #undef yyleng + } l78: { int yypos79= G->pos, yythunkpos79= G->thunkpos; @@ -1202,8 +1259,13 @@ YY_RULE(int) yy_action(GREG *G) G->pos= yypos79; G->thunkpos= yythunkpos79; } yyText(G, G->begin, G->end); - if (!(YY_END)) goto l77; - if (!yymatchChar(G, '}')) goto l77; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l77; + #undef yytext + #undef yyleng + } if (!yymatchChar(G, '}')) goto l77; if (!yy__(G)) goto l77; yyprintfokrule("action"); return 1; @@ -1349,8 +1411,13 @@ YY_RULE(int) yy_identifier(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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", "-a-zA-Z_")) goto l95; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l95; + #undef yytext + #undef yyleng + } 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", "-a-zA-Z_")) goto l95; l96: { @@ -1361,8 +1428,13 @@ YY_RULE(int) yy_identifier(GREG *G) G->pos= yypos97; G->thunkpos= yythunkpos97; } yyText(G, G->begin, G->end); - if (!(YY_END)) goto l95; - if (!yy__(G)) goto l95; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l95; + #undef yytext + #undef yyleng + } if (!yy__(G)) goto l95; yyprintfokrule("identifier"); return 1; l95: @@ -1407,8 +1479,13 @@ YY_RULE(int) yy_trailer(GREG *G) yyprintfv((stderr, "%s\n", "trailer")); if (!yymatchString(G, "%%")) goto l101; yyText(G, G->begin, G->end); - if (!(YY_BEGIN)) goto l101; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l101; + #undef yytext + #undef yyleng + } l102: { int yypos103= G->pos, yythunkpos103= G->thunkpos; @@ -1418,8 +1495,13 @@ YY_RULE(int) yy_trailer(GREG *G) 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, "yy_1_trailer"); + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l101; + #undef yytext + #undef yyleng + } yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer"); yyprintfokrule("trailer"); return 1; l101: @@ -1462,8 +1544,13 @@ YY_RULE(int) yy_declaration(GREG *G) yyprintfv((stderr, "%s\n", "declaration")); if (!yymatchString(G, "%{")) goto l107; yyText(G, G->begin, G->end); - if (!(YY_BEGIN)) goto l107; - + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l107; + #undef yytext + #undef yyleng + } l108: { int yypos109= G->pos, yythunkpos109= G->thunkpos; @@ -1480,8 +1567,13 @@ YY_RULE(int) yy_declaration(GREG *G) G->pos= yypos109; G->thunkpos= yythunkpos109; } yyText(G, G->begin, G->end); - if (!(YY_END)) goto l107; - if (!yy_RPERCENT(G)) goto l107; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l107; + #undef yytext + #undef yyleng + } if (!yy_RPERCENT(G)) goto l107; yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration"); yyprintfokrule("declaration"); return 1; @@ -1623,7 +1715,10 @@ YY_PARSE(GREG *) YY_NAME(parse_new)(YY_XTYPE data) } YY_PARSE(void) YY_NAME(init)(GREG *G) { - memcpy(G,YY_NAME(parse_new)(NULL),sizeof(GREG)); + memset(G, 0, sizeof(GREG)); + G->input= stdin; + G->lineno= 1; + G->filename= "-"; } YY_PARSE(void) YY_NAME(deinit)(GREG *G) @@ -1718,8 +1813,6 @@ int main(int argc, char **argv) argv += optind; G = yyparse_new(NULL); - G->lineno= 1; - G->filename= "-"; #ifdef YY_DEBUG if (verboseFlag > 0) { yydebug = YYDEBUG_PARSE; @@ -1773,9 +1866,12 @@ int main(int argc, char **argv) } if (trailer) { - fprintf(output, "%s\n", trailer); + fputs(trailer, output); + fputs("\n", output); free(trailer); } + else + fputs(deftrailer, output); return 0; } diff --git a/greg.g b/greg.g index 7a554a5..6df3b6b 100644 --- a/greg.g +++ b/greg.g @@ -38,6 +38,18 @@ static char *trailer= 0; static Header *headers= 0; + static char *deftrailer= "\n\ +#ifdef YY_MAIN\n\ +int main()\n\ +{\n\ + GREG g;\n\ + yyinit(&g);\n\ + while (yyparse(&g));\n\ + yydeinit(&g);\n\ + return 0;\n\ +}\n\ +#endif\n\ +"; void makeHeader(char *text); void makeTrailer(char *text); @@ -89,7 +101,7 @@ primary= ( identifier= < [-a-zA-Z_][-a-zA-Z_0-9]* > - -literal= ['] < ( !['] char )* > ['] - +literal= ['] < ( !['] char )* > ['] - #' | ["] < ( !["] char )* > ["] - class= '[' < ( !']' range )* > ']' - @@ -208,8 +220,6 @@ int main(int argc, char **argv) argv += optind; G = yyparse_new(NULL); - G->lineno= 1; - G->filename= "-"; #ifdef YY_DEBUG if (verboseFlag > 0) { yydebug = YYDEBUG_PARSE; @@ -263,9 +273,12 @@ int main(int argc, char **argv) } if (trailer) { - fprintf(output, "%s\n", trailer); + fputs(trailer, output); + fputs("\n", output); free(trailer); } + else + fputs(deftrailer, output); return 0; } diff --git a/samples/accept.leg b/samples/accept.leg index e549c56..af21a75 100644 --- a/samples/accept.leg +++ b/samples/accept.leg @@ -1,7 +1,7 @@ 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} + | '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); } diff --git a/samples/basic.leg b/samples/basic.leg index 61ff5b0..eb2468f 100644 --- a/samples/basic.leg +++ b/samples/basic.leg @@ -39,7 +39,7 @@ # define min(x, y) ((x) < (y) ? (x) : (y)) -# define YY_INPUT(buf, result, max_size, D) \ +# define YY_INPUT(buf, result, max_size) \ { \ if ((pc >= 0) && (pc < numLines)) \ { \ diff --git a/samples/dc.leg b/samples/dc.leg index 758be9f..5562d16 100644 --- a/samples/dc.leg +++ b/samples/dc.leg @@ -1,18 +1,29 @@ +%{ + #include + #include + + int stack[1024]; + int stackp= -1; + + int push(int n){ return stack[++stackp]= n; } + int pop(void) { return stack[stackp--]; } +%} + # Grammar -Expr = SPACE Sum EOL { printf("%d\n", pop()); } - | (!EOL .)* EOL { printf("error\n"); } +Expr = SPACE Sum EOL { printf("%d\n", pop()); } + | (!EOL .)* EOL { YY_ERROR("expr error") } -Sum = Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); } - | MINUS Product { int r= pop(), l= pop(); push(l - r); } - )* +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); } - )* +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 + | OPEN Sum CLOSE # Lexemes diff --git a/samples/dcv.leg b/samples/dcv.leg index b278c95..4b2b3dc 100644 --- a/samples/dcv.leg +++ b/samples/dcv.leg @@ -1,22 +1,36 @@ +%{ +#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]; } +%} + # Grammar Stmt = SPACE Expr EOL { printf("%d\n", pop()); } - | (!EOL .)* EOL { printf("error\n"); } + | (!EOL .)* EOL { printf("error\n"); } Expr = ID { var= yytext[0] } ASSIGN Sum { vars[var - 'a']= top(); } - | Sum + | Sum Sum = Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); } - | MINUS 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); } - )* + | 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 + | < ID > !ASSIGN { push(vars[yytext[0] - 'a']); } + | OPEN Expr CLOSE # Lexemes diff --git a/samples/left.leg b/samples/left.leg index 8485619..7d13295 100644 --- a/samples/left.leg +++ b/samples/left.leg @@ -1,3 +1,13 @@ # Grammar S = (S 'a' | 'a') !'a' + +%% + +int main() +{ + GREG g; + yyinit(&g); + printf(yyparse(&g) ? "success\n" : "failure\n"); + return 0; +} diff --git a/samples/rule.leg b/samples/rule.leg index d52fd8d..a27dcd8 100644 --- a/samples/rule.leg +++ b/samples/rule.leg @@ -1,7 +1,7 @@ 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); } + | '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); } diff --git a/samples/test.leg b/samples/test.leg index aa6871d..1106d72 100644 --- a/samples/test.leg +++ b/samples/test.leg @@ -2,12 +2,12 @@ start = body '.' { printf(".\n"); } body = 'a' { printf("a1 "); } 'b' { printf("ab1 "); } - | 'a' { printf("a2 "); } 'c' { printf("ac2 "); } + | 'a' { printf("a2 "); } 'c' { printf("ac2 "); } - | 'a' { printf("a3 "); } ( 'd' { printf("ad3 "); } | 'e' { printf("ae3 "); } ) + | '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("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 ") } ) + | 'a' { printf("a6 "); } ( 'f' &{ printf("af6 ") } 'i' &{ printf("afi6 ") } + | 'f' &{ printf("af7 ") } 'j' &{ printf("afj7 ") } ) From fd1a271ac0492467ede09421b60a05134ec8c88f Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 1 Oct 2013 10:42:40 -0500 Subject: [PATCH 06/13] fix test.leg, update Query, Predicate, allow hexadecimal escapes use readChar and helpers from peg-0.1.13 use __inline on Win32 improve Predicate layout update Query from peg: use readable names, fix test.leg: ending Alternate label --- compile.c | 114 ++++---- greg.c | 794 +++++++++++++++++++++++++++++------------------------- greg.g | 2 + greg.h | 4 + 4 files changed, 490 insertions(+), 424 deletions(-) diff --git a/compile.c b/compile.c index 55da25c..8c96566 100644 --- a/compile.c +++ b/compile.c @@ -50,43 +50,52 @@ 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) -{ - unsigned char *cclass = *cp; - int c= *cclass++, i = 0; - 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; - } +static inline int oigit(int c) { return ('0' <= c && c <= '7'); } +static inline int higit(int c) { return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); } - switch (c) - { - case 'a': c= '\a'; break; /* bel */ - case 'b': c= '\b'; break; /* bs */ - case 'e': c= '\e'; break; /* esc */ - case 'f': c= '\f'; break; /* ff */ - case 'n': c= '\n'; break; /* nl */ - case 'r': c= '\r'; break; /* cr */ - case 't': c= '\t'; break; /* ht */ - case 'v': c= '\v'; break; /* vt */ - default: break; - } - } +static inline int hexval(int c) +{ + if ('0' <= c && c <= '9') return c - '0'; + if ('A' <= c && c <= 'F') return 10 - 'A' + c; + if ('a' <= c && c <= 'f') return 10 - 'a' + c; + return 0; +} -done: - *cp = cclass; +static int readChar(unsigned char **cp) +{ + unsigned char *cclass= *cp; + int c= *cclass++; + if (c) + { + if ('\\' == c && *cclass) + { + switch (c= *cclass++) + { + case 'a': c= '\a'; break; /* bel */ + case 'b': c= '\b'; break; /* bs */ + case 'e': c= '\e'; break; /* esc */ + case 'f': c= '\f'; break; /* ff */ + case 'n': c= '\n'; break; /* nl */ + case 'r': c= '\r'; break; /* cr */ + case 't': c= '\t'; break; /* ht */ + case 'v': c= '\v'; break; /* vt */ + case 'x': + c= 0; + if (higit(*cclass)) c= (c << 4) + hexval(*cclass++); + if (higit(*cclass)) c= (c << 4) + hexval(*cclass++); + break; + default: + if (oigit(c)) + { + c -= '0'; + if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0'; + if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0'; + } + break; + } + } + *cp= cclass; + } return c; } @@ -181,7 +190,7 @@ static void nl(void) { fprintf(output, "\n"); } static void pindent(void) { fprintf(output, "%*s", 2*indent, ""); } static void begin(void) { indent++; pindent(); fprintf(output, "{"); } static void save(int n) { nl(); pindent(); fprintf(output, " int yypos%d= G->pos, yythunkpos%d= G->thunkpos;\n", n, n); } -static void label(int n) { nl(); pindent(); fprintf(output, " l%d:\n", n); } +static void label(int n) { nl(); pindent(); fprintf(output, " l%d:\n", n); } /* Note: ensure that there is an expr following */ static void jump(int n) { pindent(); fprintf(output, " goto l%d;", n); } static void restore(int n) { pindent(); fprintf(output, " G->pos= yypos%d; G->thunkpos= yythunkpos%d;\n", n, n); } static void end(void) { pindent(); indent--; fprintf(output, "}\n"); } @@ -259,16 +268,14 @@ static void Node_compile_c_ko(Node *node, int ko) break; case Predicate: - pindent(); - //fprintf(output, " yyText(G, G->begin, G->end);\n if (!(%s)) goto l%d;\n", node->action.text, ko); - /* predicates have access to yytext */ - fprintf(output, " yyText(G, G->begin, G->end);\n {\n"); - fprintf(output, " #define yytext G->text\n"); - fprintf(output, " #define yyleng G->textlen\n"); - fprintf(output, " if (!(%s)) goto l%d;\n", node->action.text, ko); - fprintf(output, " #undef yytext\n"); - fprintf(output, " #undef yyleng\n"); - fprintf(output, " }"); + pindent(); fprintf(output, " yyText(G, G->begin, G->end);\n"); + begin(); nl(); + pindent(); fprintf(output, " #define yytext G->text\n"); + pindent(); fprintf(output, " #define yyleng G->textlen\n"); + pindent(); fprintf(output, " if (!(%s)) goto l%d;\n", node->action.text, ko); + pindent(); fprintf(output, " #undef yytext\n"); + pindent(); fprintf(output, " #undef yyleng\n"); + end(); nl(); break; case Alternate: @@ -289,6 +296,7 @@ static void Node_compile_c_ko(Node *node, int ko) Node_compile_c_ko(node, ko); end(); label(ok); + pindent(); fprintf(output, " ;\n"); } break; @@ -323,15 +331,15 @@ static void Node_compile_c_ko(Node *node, int ko) case Query: { - int qko= yyl(), qok= yyl(); + int again= yyl(), out= yyl(); begin(); - save(qko); - Node_compile_c_ko(node->query.element, qko); - jump(qok); - label(qko); - restore(qko); + save(out); + Node_compile_c_ko(node->query.element, out); + jump(again); + label(out); + restore(out); end(); - label(qok); + label(again); pindent(); fprintf(output, " ;\n"); } break; diff --git a/greg.c b/greg.c index cc8c81a..777afcd 100644 --- a/greg.c +++ b/greg.c @@ -636,6 +636,7 @@ YY_RULE(int) yy_end_of_line(GREG *G) } l2: + ; yyprintfvokrule("end_of_line"); return 1; l1: @@ -690,6 +691,7 @@ YY_RULE(int) yy_space(GREG *G) } l10: + ; yyprintfvokrule("space"); return 1; l9: @@ -735,6 +737,7 @@ YY_RULE(int) yy_braces(GREG *G) } l14: + ; yyprintfokrule("braces"); return 1; l13: @@ -758,6 +761,7 @@ YY_RULE(int) yy_range(GREG *G) } l21: + ; yyprintfokrule("range"); return 1; l20: @@ -777,38 +781,51 @@ YY_RULE(int) yy_char(GREG *G) 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", "0-3")) 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", "0-7")) 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", "0-7")) goto l26; + if (!yymatchChar(G, 'x')) goto l26; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l26; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) 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", "0-7")) goto l27; + if (!yymatchChar(G, 'x')) goto l27; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l27; + goto l24; + l27: + G->pos= yypos24; G->thunkpos= yythunkpos24; + if (!yymatchChar(G, '\\')) goto l28; + 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", "0-3")) goto l28; + 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", "0-7")) goto l28; + 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", "0-7")) goto l28; + goto l24; + l28: + G->pos= yypos24; G->thunkpos= yythunkpos24; + if (!yymatchChar(G, '\\')) goto l29; + 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", "0-7")) goto l29; + + l30: { - 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", "0-7")) goto l28; - goto l29; - l28: - G->pos= yypos28; G->thunkpos= yythunkpos28; + int yypos31= G->pos, yythunkpos31= 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", "0-7")) goto l31; + goto l30; + l31: + G->pos= yypos31; G->thunkpos= yythunkpos31; } - - l29: - ; goto l24; - l27: + l29: G->pos= yypos24; G->thunkpos= yythunkpos24; { - int yypos30= G->pos, yythunkpos30= G->thunkpos; - if (!yymatchChar(G, '\\')) goto l30; + int yypos32= G->pos, yythunkpos32= G->thunkpos; + if (!yymatchChar(G, '\\')) goto l32; goto l23; - l30: - G->pos= yypos30; G->thunkpos= yythunkpos30; + l32: + G->pos= yypos32; G->thunkpos= yythunkpos32; } if (!yymatchDot(G)) goto l23; } l24: + ; yyprintfokrule("char"); return 1; l23: @@ -820,35 +837,39 @@ YY_RULE(int) yy_errblock(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "errblock")); - if (!yymatchString(G, "~{")) goto l31; + if (!yymatchString(G, "~{")) goto l33; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l31; + if (!(YY_BEGIN)) goto l33; #undef yytext #undef yyleng } - l32: + + + l34: { - int yypos33= G->pos, yythunkpos33= G->thunkpos; - if (!yy_braces(G)) goto l33; - goto l32; - l33: - G->pos= yypos33; G->thunkpos= yythunkpos33; + int yypos35= G->pos, yythunkpos35= G->thunkpos; + if (!yy_braces(G)) goto l35; + goto l34; + l35: + G->pos= yypos35; G->thunkpos= yythunkpos35; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l31; + if (!(YY_END)) goto l33; #undef yytext #undef yyleng - } if (!yymatchChar(G, '}')) goto l31; - if (!yy__(G)) goto l31; + } + + if (!yymatchChar(G, '}')) goto l33; + if (!yy__(G)) goto l33; yyprintfokrule("errblock"); return 1; - l31: + l33: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("errblock"); return 0; @@ -857,11 +878,11 @@ YY_RULE(int) yy_END(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "END")); - if (!yymatchChar(G, '>')) goto l34; - if (!yy__(G)) goto l34; + if (!yymatchChar(G, '>')) goto l36; + if (!yy__(G)) goto l36; yyprintfokrule("END"); return 1; - l34: + l36: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("END"); return 0; @@ -870,11 +891,11 @@ YY_RULE(int) yy_BEGIN(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BEGIN")); - if (!yymatchChar(G, '<')) goto l35; - if (!yy__(G)) goto l35; + if (!yymatchChar(G, '<')) goto l37; + if (!yy__(G)) goto l37; yyprintfokrule("BEGIN"); return 1; - l35: + l37: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("BEGIN"); return 0; @@ -883,11 +904,11 @@ YY_RULE(int) yy_DOT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "DOT")); - if (!yymatchChar(G, '.')) goto l36; - if (!yy__(G)) goto l36; + if (!yymatchChar(G, '.')) goto l38; + if (!yy__(G)) goto l38; yyprintfokrule("DOT"); return 1; - l36: + l38: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("DOT"); return 0; @@ -896,42 +917,46 @@ YY_RULE(int) yy_class(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "class")); - if (!yymatchChar(G, '[')) goto l37; + if (!yymatchChar(G, '[')) goto l39; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l37; + if (!(YY_BEGIN)) goto l39; #undef yytext #undef yyleng } - l38: + + + l40: { - int yypos39= G->pos, yythunkpos39= G->thunkpos; + int yypos41= G->pos, yythunkpos41= G->thunkpos; { - int yypos40= G->pos, yythunkpos40= G->thunkpos; - if (!yymatchChar(G, ']')) goto l40; - goto l39; - l40: - G->pos= yypos40; G->thunkpos= yythunkpos40; + int yypos42= G->pos, yythunkpos42= G->thunkpos; + if (!yymatchChar(G, ']')) goto l42; + goto l41; + l42: + G->pos= yypos42; G->thunkpos= yythunkpos42; } - if (!yy_range(G)) goto l39; - goto l38; - l39: - G->pos= yypos39; G->thunkpos= yythunkpos39; + if (!yy_range(G)) goto l41; + goto l40; + l41: + G->pos= yypos41; G->thunkpos= yythunkpos41; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l37; + if (!(YY_END)) goto l39; #undef yytext #undef yyleng - } if (!yymatchChar(G, ']')) goto l37; - if (!yy__(G)) goto l37; + } + + if (!yymatchChar(G, ']')) goto l39; + if (!yy__(G)) goto l39; yyprintfokrule("class"); return 1; - l37: + l39: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("class"); return 0; @@ -941,82 +966,91 @@ YY_RULE(int) yy_literal(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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; + int yypos44= G->pos, yythunkpos44= 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 l45; yyText(G, G->begin, G->end); - { - #define yytext G->text - #define yyleng G->textlen - if (!(YY_BEGIN)) goto l43; - #undef yytext - #undef yyleng - } - l44: { - int yypos45= G->pos, yythunkpos45= G->thunkpos; + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l45; + #undef yytext + #undef yyleng + } + + + l46: + { + int yypos47= G->pos, yythunkpos47= 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; + int yypos48= G->pos, yythunkpos48= 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 l48; + goto l47; + l48: + G->pos= yypos48; G->thunkpos= yythunkpos48; } - if (!yy_char(G)) goto l45; - goto l44; - l45: - G->pos= yypos45; G->thunkpos= yythunkpos45; + if (!yy_char(G)) goto l47; + goto l46; + l47: + G->pos= yypos47; G->thunkpos= yythunkpos47; } yyText(G, G->begin, G->end); - { - #define yytext G->text - #define yyleng G->textlen - if (!(YY_END)) goto l43; - #undef yytext - #undef yyleng - } 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; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l45; + #undef yytext + #undef yyleng + } + + 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 l45; + if (!yy__(G)) goto l45; + goto l44; + l45: + G->pos= yypos44; G->thunkpos= yythunkpos44; + 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 l43; yyText(G, G->begin, G->end); - { - #define yytext G->text - #define yyleng G->textlen - if (!(YY_BEGIN)) goto l41; - #undef yytext - #undef yyleng - } - l47: { - int yypos48= G->pos, yythunkpos48= G->thunkpos; + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l43; + #undef yytext + #undef yyleng + } + + + l49: + { + int yypos50= G->pos, yythunkpos50= 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; + int yypos51= G->pos, yythunkpos51= 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 l51; + goto l50; + l51: + G->pos= yypos51; G->thunkpos= yythunkpos51; } - if (!yy_char(G)) goto l48; - goto l47; - l48: - G->pos= yypos48; G->thunkpos= yythunkpos48; + if (!yy_char(G)) goto l50; + goto l49; + l50: + G->pos= yypos50; G->thunkpos= yythunkpos50; } yyText(G, G->begin, G->end); - { - #define yytext G->text - #define yyleng G->textlen - if (!(YY_END)) goto l41; - #undef yytext - #undef yyleng - } 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; + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_END)) goto l43; + #undef yytext + #undef yyleng + } + + 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 l43; + if (!yy__(G)) goto l43; } - l42: + l44: + ; yyprintfokrule("literal"); return 1; - l41: + l43: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("literal"); return 0; @@ -1025,11 +1059,11 @@ YY_RULE(int) yy_CLOSE(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "CLOSE")); - if (!yymatchChar(G, ')')) goto l50; - if (!yy__(G)) goto l50; + if (!yymatchChar(G, ')')) goto l52; + if (!yy__(G)) goto l52; yyprintfokrule("CLOSE"); return 1; - l50: + l52: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("CLOSE"); return 0; @@ -1038,11 +1072,11 @@ YY_RULE(int) yy_OPEN(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "OPEN")); - if (!yymatchChar(G, '(')) goto l51; - if (!yy__(G)) goto l51; + if (!yymatchChar(G, '(')) goto l53; + if (!yy__(G)) goto l53; yyprintfokrule("OPEN"); return 1; - l51: + l53: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("OPEN"); return 0; @@ -1051,11 +1085,11 @@ YY_RULE(int) yy_COLON(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "COLON")); - if (!yymatchChar(G, ':')) goto l52; - if (!yy__(G)) goto l52; + if (!yymatchChar(G, ':')) goto l54; + if (!yy__(G)) goto l54; yyprintfokrule("COLON"); return 1; - l52: + l54: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("COLON"); return 0; @@ -1064,11 +1098,11 @@ YY_RULE(int) yy_PLUS(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "PLUS")); - if (!yymatchChar(G, '+')) goto l53; - if (!yy__(G)) goto l53; + if (!yymatchChar(G, '+')) goto l55; + if (!yy__(G)) goto l55; yyprintfokrule("PLUS"); return 1; - l53: + l55: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("PLUS"); return 0; @@ -1077,11 +1111,11 @@ YY_RULE(int) yy_STAR(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "STAR")); - if (!yymatchChar(G, '*')) goto l54; - if (!yy__(G)) goto l54; + if (!yymatchChar(G, '*')) goto l56; + if (!yy__(G)) goto l56; yyprintfokrule("STAR"); return 1; - l54: + l56: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("STAR"); return 0; @@ -1090,11 +1124,11 @@ YY_RULE(int) yy_QUESTION(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "QUESTION")); - if (!yymatchChar(G, '?')) goto l55; - if (!yy__(G)) goto l55; + if (!yymatchChar(G, '?')) goto l57; + if (!yy__(G)) goto l57; yyprintfokrule("QUESTION"); return 1; - l55: + l57: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("QUESTION"); return 0; @@ -1104,22 +1138,10 @@ YY_RULE(int) yy_primary(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "primary")); { - int yypos57= G->pos, yythunkpos57= G->thunkpos; - if (!yy_identifier(G)) goto l58; + int yypos59= G->pos, yythunkpos59= G->thunkpos; + if (!yy_identifier(G)) goto l60; yyDo(G, yy_1_primary, G->begin, G->end, "yy_1_primary"); - 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, "yy_2_primary"); - goto l57; - l58: - G->pos= yypos57; G->thunkpos= yythunkpos57; + if (!yy_COLON(G)) goto l60; if (!yy_identifier(G)) goto l60; { int yypos61= G->pos, yythunkpos61= G->thunkpos; @@ -1128,60 +1150,72 @@ YY_RULE(int) yy_primary(GREG *G) l61: G->pos= yypos61; G->thunkpos= yythunkpos61; } - yyDo(G, yy_3_primary, G->begin, G->end, "yy_3_primary"); - goto l57; + yyDo(G, yy_2_primary, G->begin, G->end, "yy_2_primary"); + goto l59; 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; + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_identifier(G)) goto l62; + { + int yypos63= G->pos, yythunkpos63= G->thunkpos; + if (!yy_EQUAL(G)) goto l63; + goto l62; + l63: + G->pos= yypos63; G->thunkpos= yythunkpos63; + } + yyDo(G, yy_3_primary, G->begin, G->end, "yy_3_primary"); + goto l59; l62: - G->pos= yypos57; G->thunkpos= yythunkpos57; - if (!yy_literal(G)) goto l63; + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_OPEN(G)) goto l64; + if (!yy_expression(G)) goto l64; + if (!yy_CLOSE(G)) goto l64; + goto l59; + l64: + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_literal(G)) goto l65; yyDo(G, yy_4_primary, G->begin, G->end, "yy_4_primary"); - goto l57; - l63: - G->pos= yypos57; G->thunkpos= yythunkpos57; - if (!yy_class(G)) goto l64; + goto l59; + l65: + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_class(G)) goto l66; yyDo(G, yy_5_primary, G->begin, G->end, "yy_5_primary"); - goto l57; - l64: - G->pos= yypos57; G->thunkpos= yythunkpos57; - if (!yy_DOT(G)) goto l65; + goto l59; + l66: + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_DOT(G)) goto l67; yyDo(G, yy_6_primary, G->begin, G->end, "yy_6_primary"); - goto l57; - l65: - G->pos= yypos57; G->thunkpos= yythunkpos57; - if (!yy_action(G)) goto l66; + goto l59; + l67: + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_action(G)) goto l68; yyDo(G, yy_7_primary, G->begin, G->end, "yy_7_primary"); - goto l57; - l66: - G->pos= yypos57; G->thunkpos= yythunkpos57; - if (!yy_BEGIN(G)) goto l67; + goto l59; + l68: + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_BEGIN(G)) goto l69; yyDo(G, yy_8_primary, G->begin, G->end, "yy_8_primary"); - goto l57; - l67: - G->pos= yypos57; G->thunkpos= yythunkpos57; - if (!yy_END(G)) goto l56; + goto l59; + l69: + G->pos= yypos59; G->thunkpos= yythunkpos59; + if (!yy_END(G)) goto l58; yyDo(G, yy_9_primary, G->begin, G->end, "yy_9_primary"); } - l57: + l59: + ; + + l70: { - int yypos68= G->pos, yythunkpos68= G->thunkpos; - if (!yy_errblock(G)) goto l68; + int yypos71= G->pos, yythunkpos71= G->thunkpos; + if (!yy_errblock(G)) goto l71; yyDo(G, yy_10_primary, G->begin, G->end, "yy_10_primary"); - goto l69; - l68: - G->pos= yypos68; G->thunkpos= yythunkpos68; + goto l70; + l71: + G->pos= yypos71; G->thunkpos= yythunkpos71; } - - l69: - ; yyprintfokrule("primary"); return 1; - l56: + l58: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("primary"); return 0; @@ -1190,11 +1224,11 @@ YY_RULE(int) yy_NOT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "NOT")); - if (!yymatchChar(G, '!')) goto l70; - if (!yy__(G)) goto l70; + if (!yymatchChar(G, '!')) goto l72; + if (!yy__(G)) goto l72; yyprintfokrule("NOT"); return 1; - l70: + l72: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("NOT"); return 0; @@ -1203,36 +1237,36 @@ YY_RULE(int) yy_suffix(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "suffix")); - if (!yy_primary(G)) goto l71; + if (!yy_primary(G)) goto l73; + + l74: { - int yypos72= G->pos, yythunkpos72= G->thunkpos; + int yypos75= G->pos, yythunkpos75= G->thunkpos; { - int yypos74= G->pos, yythunkpos74= G->thunkpos; - if (!yy_QUESTION(G)) goto l75; + int yypos76= G->pos, yythunkpos76= G->thunkpos; + if (!yy_QUESTION(G)) goto l77; yyDo(G, yy_1_suffix, G->begin, G->end, "yy_1_suffix"); - goto l74; - l75: - G->pos= yypos74; G->thunkpos= yythunkpos74; - if (!yy_STAR(G)) goto l76; + goto l76; + l77: + G->pos= yypos76; G->thunkpos= yythunkpos76; + if (!yy_STAR(G)) goto l78; yyDo(G, yy_2_suffix, G->begin, G->end, "yy_2_suffix"); - goto l74; - l76: - G->pos= yypos74; G->thunkpos= yythunkpos74; - if (!yy_PLUS(G)) goto l72; + goto l76; + l78: + G->pos= yypos76; G->thunkpos= yythunkpos76; + if (!yy_PLUS(G)) goto l75; yyDo(G, yy_3_suffix, G->begin, G->end, "yy_3_suffix"); } - l74: - goto l73; - l72: - G->pos= yypos72; G->thunkpos= yythunkpos72; + l76: + ; + goto l74; + l75: + G->pos= yypos75; G->thunkpos= yythunkpos75; } - - l73: - ; yyprintfokrule("suffix"); return 1; - l71: + l73: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("suffix"); return 0; @@ -1241,35 +1275,39 @@ YY_RULE(int) yy_action(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "action")); - if (!yymatchChar(G, '{')) goto l77; + if (!yymatchChar(G, '{')) goto l79; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l77; + if (!(YY_BEGIN)) goto l79; #undef yytext #undef yyleng } - l78: + + + l80: { - int yypos79= G->pos, yythunkpos79= G->thunkpos; - if (!yy_braces(G)) goto l79; - goto l78; - l79: - G->pos= yypos79; G->thunkpos= yythunkpos79; + int yypos81= G->pos, yythunkpos81= G->thunkpos; + if (!yy_braces(G)) goto l81; + goto l80; + l81: + G->pos= yypos81; G->thunkpos= yythunkpos81; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l77; + if (!(YY_END)) goto l79; #undef yytext #undef yyleng - } if (!yymatchChar(G, '}')) goto l77; - if (!yy__(G)) goto l77; + } + + if (!yymatchChar(G, '}')) goto l79; + if (!yy__(G)) goto l79; yyprintfokrule("action"); return 1; - l77: + l79: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("action"); return 0; @@ -1278,11 +1316,11 @@ YY_RULE(int) yy_AND(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "AND")); - if (!yymatchChar(G, '&')) goto l80; - if (!yy__(G)) goto l80; + if (!yymatchChar(G, '&')) goto l82; + if (!yy__(G)) goto l82; yyprintfokrule("AND"); return 1; - l80: + l82: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("AND"); return 0; @@ -1292,32 +1330,33 @@ YY_RULE(int) yy_prefix(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "prefix")); { - int yypos82= G->pos, yythunkpos82= G->thunkpos; - if (!yy_AND(G)) goto l83; - if (!yy_action(G)) goto l83; + int yypos84= G->pos, yythunkpos84= G->thunkpos; + if (!yy_AND(G)) goto l85; + if (!yy_action(G)) goto l85; yyDo(G, yy_1_prefix, G->begin, G->end, "yy_1_prefix"); - goto l82; - l83: - G->pos= yypos82; G->thunkpos= yythunkpos82; - if (!yy_AND(G)) goto l84; - if (!yy_suffix(G)) goto l84; + goto l84; + l85: + G->pos= yypos84; G->thunkpos= yythunkpos84; + if (!yy_AND(G)) goto l86; + if (!yy_suffix(G)) goto l86; yyDo(G, yy_2_prefix, G->begin, G->end, "yy_2_prefix"); - goto l82; - l84: - G->pos= yypos82; G->thunkpos= yythunkpos82; - if (!yy_NOT(G)) goto l85; - if (!yy_suffix(G)) goto l85; + goto l84; + l86: + G->pos= yypos84; G->thunkpos= yythunkpos84; + if (!yy_NOT(G)) goto l87; + if (!yy_suffix(G)) goto l87; yyDo(G, yy_3_prefix, G->begin, G->end, "yy_3_prefix"); - goto l82; - l85: - G->pos= yypos82; G->thunkpos= yythunkpos82; - if (!yy_suffix(G)) goto l81; + goto l84; + l87: + G->pos= yypos84; G->thunkpos= yythunkpos84; + if (!yy_suffix(G)) goto l83; } - l82: + l84: + ; yyprintfokrule("prefix"); return 1; - l81: + l83: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("prefix"); return 0; @@ -1326,11 +1365,11 @@ YY_RULE(int) yy_BAR(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BAR")); - if (!yymatchChar(G, '|')) goto l86; - if (!yy__(G)) goto l86; + if (!yymatchChar(G, '|')) goto l88; + if (!yy__(G)) goto l88; yyprintfokrule("BAR"); return 1; - l86: + l88: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("BAR"); return 0; @@ -1339,20 +1378,20 @@ YY_RULE(int) yy_sequence(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "sequence")); - if (!yy_prefix(G)) goto l87; + if (!yy_prefix(G)) goto l89; - l88: + l90: { - int yypos89= G->pos, yythunkpos89= G->thunkpos; - if (!yy_prefix(G)) goto l89; + int yypos91= G->pos, yythunkpos91= G->thunkpos; + if (!yy_prefix(G)) goto l91; yyDo(G, yy_1_sequence, G->begin, G->end, "yy_1_sequence"); - goto l88; - l89: - G->pos= yypos89; G->thunkpos= yythunkpos89; + goto l90; + l91: + G->pos= yypos91; G->thunkpos= yythunkpos91; } yyprintfokrule("sequence"); return 1; - l87: + l89: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("sequence"); return 0; @@ -1361,11 +1400,11 @@ YY_RULE(int) yy_SEMICOLON(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "SEMICOLON")); - if (!yymatchChar(G, ';')) goto l90; - if (!yy__(G)) goto l90; + if (!yymatchChar(G, ';')) goto l92; + if (!yy__(G)) goto l92; yyprintfokrule("SEMICOLON"); return 1; - l90: + l92: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("SEMICOLON"); return 0; @@ -1374,21 +1413,21 @@ YY_RULE(int) yy_expression(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "expression")); - if (!yy_sequence(G)) goto l91; + if (!yy_sequence(G)) goto l93; - l92: + l94: { - int yypos93= G->pos, yythunkpos93= G->thunkpos; - if (!yy_BAR(G)) goto l93; - if (!yy_sequence(G)) goto l93; + int yypos95= G->pos, yythunkpos95= G->thunkpos; + if (!yy_BAR(G)) goto l95; + if (!yy_sequence(G)) goto l95; yyDo(G, yy_1_expression, G->begin, G->end, "yy_1_expression"); - goto l92; - l93: - G->pos= yypos93; G->thunkpos= yythunkpos93; + goto l94; + l95: + G->pos= yypos95; G->thunkpos= yythunkpos95; } yyprintfokrule("expression"); return 1; - l91: + l93: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("expression"); return 0; @@ -1397,11 +1436,11 @@ YY_RULE(int) yy_EQUAL(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "EQUAL")); - if (!yymatchChar(G, '=')) goto l94; - if (!yy__(G)) goto l94; + if (!yymatchChar(G, '=')) goto l96; + if (!yy__(G)) goto l96; yyprintfokrule("EQUAL"); return 1; - l94: + l96: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("EQUAL"); return 0; @@ -1414,30 +1453,34 @@ YY_RULE(int) yy_identifier(GREG *G) { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l95; + if (!(YY_BEGIN)) goto l97; #undef yytext #undef yyleng - } 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", "-a-zA-Z_")) goto l95; + } - l96: + 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", "-a-zA-Z_")) goto l97; + + l98: { - 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", "-a-zA-Z_0-9")) goto l97; - goto l96; - l97: - G->pos= yypos97; G->thunkpos= yythunkpos97; + int yypos99= G->pos, yythunkpos99= 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", "-a-zA-Z_0-9")) goto l99; + goto l98; + l99: + G->pos= yypos99; G->thunkpos= yythunkpos99; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l95; + if (!(YY_END)) goto l97; #undef yytext #undef yyleng - } if (!yy__(G)) goto l95; + } + + if (!yy__(G)) goto l97; yyprintfokrule("identifier"); return 1; - l95: + l97: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("identifier"); return 0; @@ -1446,11 +1489,11 @@ YY_RULE(int) yy_RPERCENT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "RPERCENT")); - if (!yymatchString(G, "%}")) goto l98; - if (!yy__(G)) goto l98; + if (!yymatchString(G, "%}")) goto l100; + if (!yy__(G)) goto l100; yyprintfokrule("RPERCENT"); return 1; - l98: + l100: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("RPERCENT"); return 0; @@ -1460,15 +1503,15 @@ YY_RULE(int) yy_end_of_file(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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 yypos102= G->pos, yythunkpos102= G->thunkpos; + if (!yymatchDot(G)) goto l102; + goto l101; + l102: + G->pos= yypos102; G->thunkpos= yythunkpos102; } yyprintfvokrule("end_of_file"); return 1; - l99: + l101: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("end_of_file"); return 0; @@ -1477,34 +1520,38 @@ YY_RULE(int) yy_trailer(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "trailer")); - if (!yymatchString(G, "%%")) goto l101; + if (!yymatchString(G, "%%")) goto l103; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l101; + if (!(YY_BEGIN)) goto l103; #undef yytext #undef yyleng } - l102: + + + l104: { - int yypos103= G->pos, yythunkpos103= G->thunkpos; - if (!yymatchDot(G)) goto l103; - goto l102; - l103: - G->pos= yypos103; G->thunkpos= yythunkpos103; + int yypos105= G->pos, yythunkpos105= G->thunkpos; + if (!yymatchDot(G)) goto l105; + goto l104; + l105: + G->pos= yypos105; G->thunkpos= yythunkpos105; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l101; + if (!(YY_END)) goto l103; #undef yytext #undef yyleng - } yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer"); + } + + yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer"); yyprintfokrule("trailer"); return 1; - l101: + l103: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("trailer"); return 0; @@ -1514,26 +1561,25 @@ YY_RULE(int) yy_definition(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyDo(G, yyPush, 1, 0, "yyPush"); yyprintfv((stderr, "%s\n", "definition")); - if (!yy_identifier(G)) goto l104; + if (!yy_identifier(G)) goto l106; yyDo(G, yySet, -1, 0, "yySet identifier"); yyDo(G, yy_1_definition, G->begin, G->end, "yy_1_definition"); - if (!yy_EQUAL(G)) goto l104; - if (!yy_expression(G)) goto l104; + if (!yy_EQUAL(G)) goto l106; + if (!yy_expression(G)) goto l106; yyDo(G, yy_2_definition, G->begin, G->end, "yy_2_definition"); + + l107: { - int yypos105= G->pos, yythunkpos105= G->thunkpos; - if (!yy_SEMICOLON(G)) goto l105; - goto l106; - l105: - G->pos= yypos105; G->thunkpos= yythunkpos105; + int yypos108= G->pos, yythunkpos108= G->thunkpos; + if (!yy_SEMICOLON(G)) goto l108; + goto l107; + l108: + G->pos= yypos108; G->thunkpos= yythunkpos108; } - - l106: - ; yyprintfokrule("definition"); yyDo(G, yyPop, 1, 0, "yyPop"); return 1; - l104: + l106: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("definition"); return 0; @@ -1542,42 +1588,46 @@ YY_RULE(int) yy_declaration(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "declaration")); - if (!yymatchString(G, "%{")) goto l107; + if (!yymatchString(G, "%{")) goto l109; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l107; + if (!(YY_BEGIN)) goto l109; #undef yytext #undef yyleng } - l108: + + + l110: { - int yypos109= G->pos, yythunkpos109= G->thunkpos; + int yypos111= G->pos, yythunkpos111= G->thunkpos; { - int yypos110= G->pos, yythunkpos110= G->thunkpos; - if (!yymatchString(G, "%}")) goto l110; - goto l109; - l110: - G->pos= yypos110; G->thunkpos= yythunkpos110; + int yypos112= G->pos, yythunkpos112= G->thunkpos; + if (!yymatchString(G, "%}")) goto l112; + goto l111; + l112: + G->pos= yypos112; G->thunkpos= yythunkpos112; } - if (!yymatchDot(G)) goto l109; - goto l108; - l109: - G->pos= yypos109; G->thunkpos= yythunkpos109; + if (!yymatchDot(G)) goto l111; + goto l110; + l111: + G->pos= yypos111; G->thunkpos= yythunkpos111; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l107; + if (!(YY_END)) goto l109; #undef yytext #undef yyleng - } if (!yy_RPERCENT(G)) goto l107; + } + + if (!yy_RPERCENT(G)) goto l109; yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration"); yyprintfokrule("declaration"); return 1; - l107: + l109: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("declaration"); return 0; @@ -1585,22 +1635,23 @@ YY_RULE(int) yy_declaration(GREG *G) YY_RULE(int) yy__(GREG *G) { yyprintfv((stderr, "%s\n", "_")); - l112: + l114: { - int yypos113= G->pos, yythunkpos113= G->thunkpos; + int yypos115= G->pos, yythunkpos115= 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; + int yypos116= G->pos, yythunkpos116= G->thunkpos; + if (!yy_space(G)) goto l117; + goto l116; + l117: + G->pos= yypos116; G->thunkpos= yythunkpos116; + if (!yy_comment(G)) goto l115; } - l114: - goto l112; - l113: - G->pos= yypos113; G->thunkpos= yythunkpos113; + l116: + ; + goto l114; + l115: + G->pos= yypos115; G->thunkpos= yythunkpos115; } yyprintfvokrule("_"); return 1; @@ -1609,49 +1660,50 @@ YY_RULE(int) yy_grammar(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "grammar")); - if (!yy__(G)) goto l116; + if (!yy__(G)) goto l118; { - 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; + 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; } - l119: + l121: + ; - l117: + l119: { - int yypos118= G->pos, yythunkpos118= G->thunkpos; + int yypos120= G->pos, yythunkpos120= 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; + int yypos123= G->pos, yythunkpos123= G->thunkpos; + if (!yy_declaration(G)) goto l124; + goto l123; + l124: + G->pos= yypos123; G->thunkpos= yythunkpos123; + if (!yy_definition(G)) goto l120; } - l121: - goto l117; - l118: - G->pos= yypos118; G->thunkpos= yythunkpos118; - } - { - int yypos123= G->pos, yythunkpos123= G->thunkpos; - if (!yy_trailer(G)) goto l123; - goto l124; l123: - G->pos= yypos123; G->thunkpos= yythunkpos123; + ; + goto l119; + l120: + G->pos= yypos120; G->thunkpos= yythunkpos120; } - l124: - ; - if (!yy_end_of_file(G)) goto l116; + l125: + { + int yypos126= G->pos, yythunkpos126= G->thunkpos; + if (!yy_trailer(G)) goto l126; + goto l125; + l126: + G->pos= yypos126; G->thunkpos= yythunkpos126; + } + if (!yy_end_of_file(G)) goto l118; yyprintfokrule("grammar"); return 1; - l116: + l118: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("grammar"); return 0; diff --git a/greg.g b/greg.g index 6df3b6b..184f731 100644 --- a/greg.g +++ b/greg.g @@ -109,6 +109,8 @@ class= '[' < ( !']' range )* > ']' - range= char '-' char | char char= '\\' [abefnrtv'"\[\]\\] +| '\\' 'x'[0-9A-Fa-f][0-9A-Fa-f] +| '\\' 'x'[0-9A-Fa-f] | '\\' [0-3][0-7][0-7] | '\\' [0-7][0-7]? | !'\\' . diff --git a/greg.h b/greg.h index b56c0a0..5c90490 100644 --- a/greg.h +++ b/greg.h @@ -19,6 +19,10 @@ */ #include +#ifdef WIN32 +# undef inline +# define inline __inline +#endif #define GREG_MAJOR 0 #define GREG_MINOR 4 From 97fa845becca1a390ae097ea18436bc0b9f6d38a Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 1 Oct 2013 11:07:29 -0500 Subject: [PATCH 07/13] add and fix more tests, update greg.c --- Makefile | 16 +- greg.c | 757 +++++++++++++++++++++++----------------------- greg.g | 2 +- samples/basic.leg | 5 +- 4 files changed, 393 insertions(+), 387 deletions(-) diff --git a/Makefile b/Makefile index a64c4bd..59279b3 100644 --- a/Makefile +++ b/Makefile @@ -58,8 +58,20 @@ samples: ${SAMPLES:.leg=} greg .leg.c: ./greg $< > $@ -test: samples/calc run - echo '21 * 2 + 0' | ./samples/calc | grep 42 +test: samples run + echo 'abcbcdabcbcdabcbcdabcbcd' | samples/accept | tee samples/accept.out + diff samples/accept.out samples/accept.ref + echo 'abcbcdabcbcdabcbcdabcbcd' | samples/rule | tee samples/rule.out + diff samples/rule.out samples/rule.ref + echo '21 * 2 + 0' | samples/calc | grep 42 + echo 'a = 6; b = 7; a * b' | samples/calc | grep 42 + echo ' 2 *3 *(3+ 4) ' | samples/dc | grep 42 + echo 'a = 6; b = 7; a * b' | samples/dcv | grep 42 + echo 'print 2 * 21 + 0' | samples/basic | grep 42 + echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | samples/test | tee samples/test.out + diff samples/test.out samples/test.ref + cat samples/wc.leg | samples/wc > samples/wc.out + diff samples/wc.out samples/wc.ref run: greg mkdir -p selftest diff --git a/greg.c b/greg.c index 777afcd..86defa6 100644 --- a/greg.c +++ b/greg.c @@ -710,14 +710,7 @@ YY_RULE(int) yy_braces(GREG *G) 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; + if (!yy_braces(G)) goto l17; goto l16; l17: G->pos= yypos17; G->thunkpos= yythunkpos17; @@ -727,11 +720,11 @@ YY_RULE(int) yy_braces(GREG *G) l15: G->pos= yypos14; G->thunkpos= yythunkpos14; { - int yypos19= G->pos, yythunkpos19= G->thunkpos; - if (!yymatchChar(G, '}')) goto l19; + int yypos18= G->pos, yythunkpos18= G->thunkpos; + if (!yymatchChar(G, '}')) goto l18; goto l13; - l19: - G->pos= yypos19; G->thunkpos= yythunkpos19; + l18: + G->pos= yypos18; G->thunkpos= yythunkpos18; } if (!yymatchDot(G)) goto l13; } @@ -750,21 +743,21 @@ YY_RULE(int) yy_range(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((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= G->pos, yythunkpos20= G->thunkpos; + if (!yy_char(G)) goto l21; + if (!yymatchChar(G, '-')) goto l21; + if (!yy_char(G)) goto l21; + goto l20; + l21: + G->pos= yypos20; G->thunkpos= yythunkpos20; + if (!yy_char(G)) goto l19; } - l21: + l20: ; yyprintfokrule("range"); return 1; - l20: + l19: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("range"); return 0; @@ -774,61 +767,61 @@ YY_RULE(int) yy_char(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "char")); { - int yypos24= G->pos, yythunkpos24= G->thunkpos; + int yypos23= G->pos, yythunkpos23= G->thunkpos; + if (!yymatchChar(G, '\\')) goto l24; + 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", "abefnrtv'\"\\[\\]\\\\")) goto l24; + goto l23; + l24: + G->pos= yypos23; G->thunkpos= yythunkpos23; 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", "abefnrtv'\"\\[\\]\\\\")) goto l25; - goto l24; + if (!yymatchChar(G, 'x')) goto l25; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l25; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l25; + goto l23; l25: - G->pos= yypos24; G->thunkpos= yythunkpos24; + G->pos= yypos23; G->thunkpos= yythunkpos23; if (!yymatchChar(G, '\\')) goto l26; if (!yymatchChar(G, 'x')) goto l26; if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l26; - if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l26; - goto l24; + goto l23; l26: - G->pos= yypos24; G->thunkpos= yythunkpos24; + G->pos= yypos23; G->thunkpos= yythunkpos23; if (!yymatchChar(G, '\\')) goto l27; - if (!yymatchChar(G, 'x')) goto l27; - if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l27; - goto l24; + 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", "0-3")) 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", "0-7")) 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", "0-7")) goto l27; + goto l23; l27: - G->pos= yypos24; G->thunkpos= yythunkpos24; + G->pos= yypos23; G->thunkpos= yythunkpos23; if (!yymatchChar(G, '\\')) goto l28; - 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", "0-3")) goto l28; - 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", "0-7")) goto l28; 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", "0-7")) goto l28; - goto l24; - l28: - G->pos= yypos24; G->thunkpos= yythunkpos24; - if (!yymatchChar(G, '\\')) goto l29; - 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", "0-7")) goto l29; - l30: + l29: + { + int yypos30= G->pos, yythunkpos30= 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", "0-7")) goto l30; + goto l29; + l30: + G->pos= yypos30; G->thunkpos= yythunkpos30; + } + goto l23; + l28: + G->pos= yypos23; G->thunkpos= yythunkpos23; { int yypos31= G->pos, yythunkpos31= 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", "0-7")) goto l31; - goto l30; + if (!yymatchChar(G, '\\')) goto l31; + goto l22; l31: G->pos= yypos31; G->thunkpos= yythunkpos31; } - goto l24; - l29: - G->pos= yypos24; G->thunkpos= yythunkpos24; - { - int yypos32= G->pos, yythunkpos32= G->thunkpos; - if (!yymatchChar(G, '\\')) goto l32; - goto l23; - l32: - G->pos= yypos32; G->thunkpos= yythunkpos32; - } - if (!yymatchDot(G)) goto l23; + if (!yymatchDot(G)) goto l22; } - l24: + l23: ; yyprintfokrule("char"); return 1; - l23: + l22: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("char"); return 0; @@ -837,39 +830,39 @@ YY_RULE(int) yy_errblock(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "errblock")); - if (!yymatchString(G, "~{")) goto l33; + if (!yymatchString(G, "~{")) goto l32; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l33; + if (!(YY_BEGIN)) goto l32; #undef yytext #undef yyleng } - l34: + l33: { - int yypos35= G->pos, yythunkpos35= G->thunkpos; - if (!yy_braces(G)) goto l35; - goto l34; - l35: - G->pos= yypos35; G->thunkpos= yythunkpos35; + int yypos34= G->pos, yythunkpos34= G->thunkpos; + if (!yy_braces(G)) goto l34; + goto l33; + l34: + G->pos= yypos34; G->thunkpos= yythunkpos34; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l33; + if (!(YY_END)) goto l32; #undef yytext #undef yyleng } - if (!yymatchChar(G, '}')) goto l33; - if (!yy__(G)) goto l33; + if (!yymatchChar(G, '}')) goto l32; + if (!yy__(G)) goto l32; yyprintfokrule("errblock"); return 1; - l33: + l32: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("errblock"); return 0; @@ -878,11 +871,11 @@ YY_RULE(int) yy_END(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "END")); - if (!yymatchChar(G, '>')) goto l36; - if (!yy__(G)) goto l36; + if (!yymatchChar(G, '>')) goto l35; + if (!yy__(G)) goto l35; yyprintfokrule("END"); return 1; - l36: + l35: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("END"); return 0; @@ -891,11 +884,11 @@ YY_RULE(int) yy_BEGIN(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BEGIN")); - if (!yymatchChar(G, '<')) goto l37; - if (!yy__(G)) goto l37; + if (!yymatchChar(G, '<')) goto l36; + if (!yy__(G)) goto l36; yyprintfokrule("BEGIN"); return 1; - l37: + l36: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("BEGIN"); return 0; @@ -904,11 +897,11 @@ YY_RULE(int) yy_DOT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "DOT")); - if (!yymatchChar(G, '.')) goto l38; - if (!yy__(G)) goto l38; + if (!yymatchChar(G, '.')) goto l37; + if (!yy__(G)) goto l37; yyprintfokrule("DOT"); return 1; - l38: + l37: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("DOT"); return 0; @@ -917,46 +910,46 @@ YY_RULE(int) yy_class(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "class")); - if (!yymatchChar(G, '[')) goto l39; + if (!yymatchChar(G, '[')) goto l38; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l39; + if (!(YY_BEGIN)) goto l38; #undef yytext #undef yyleng } - l40: + l39: { - int yypos41= G->pos, yythunkpos41= G->thunkpos; + int yypos40= G->pos, yythunkpos40= G->thunkpos; { - int yypos42= G->pos, yythunkpos42= G->thunkpos; - if (!yymatchChar(G, ']')) goto l42; - goto l41; - l42: - G->pos= yypos42; G->thunkpos= yythunkpos42; + int yypos41= G->pos, yythunkpos41= G->thunkpos; + if (!yymatchChar(G, ']')) goto l41; + goto l40; + l41: + G->pos= yypos41; G->thunkpos= yythunkpos41; } - if (!yy_range(G)) goto l41; - goto l40; - l41: - G->pos= yypos41; G->thunkpos= yythunkpos41; + if (!yy_range(G)) goto l40; + goto l39; + l40: + G->pos= yypos40; G->thunkpos= yythunkpos40; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l39; + if (!(YY_END)) goto l38; #undef yytext #undef yyleng } - if (!yymatchChar(G, ']')) goto l39; - if (!yy__(G)) goto l39; + if (!yymatchChar(G, ']')) goto l38; + if (!yy__(G)) goto l38; yyprintfokrule("class"); return 1; - l39: + l38: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("class"); return 0; @@ -966,91 +959,91 @@ YY_RULE(int) yy_literal(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "literal")); { - int yypos44= G->pos, yythunkpos44= 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 l45; + int yypos43= G->pos, yythunkpos43= 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 l44; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l45; + if (!(YY_BEGIN)) goto l44; #undef yytext #undef yyleng } - l46: + l45: { - int yypos47= G->pos, yythunkpos47= G->thunkpos; + int yypos46= G->pos, yythunkpos46= G->thunkpos; { - int yypos48= G->pos, yythunkpos48= 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 l48; - goto l47; - l48: - G->pos= yypos48; G->thunkpos= yythunkpos48; + int yypos47= G->pos, yythunkpos47= 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 l47; + goto l46; + l47: + G->pos= yypos47; G->thunkpos= yythunkpos47; } - if (!yy_char(G)) goto l47; - goto l46; - l47: - G->pos= yypos47; G->thunkpos= yythunkpos47; + if (!yy_char(G)) goto l46; + goto l45; + l46: + G->pos= yypos46; G->thunkpos= yythunkpos46; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l45; + if (!(YY_END)) goto l44; #undef yytext #undef yyleng } - 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 l45; - if (!yy__(G)) goto l45; - goto l44; - l45: - G->pos= yypos44; G->thunkpos= yythunkpos44; - 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 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 l44; + if (!yy__(G)) goto l44; + goto l43; + l44: + G->pos= yypos43; G->thunkpos= yythunkpos43; + 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 l42; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l43; + if (!(YY_BEGIN)) goto l42; #undef yytext #undef yyleng } - l49: + l48: { - int yypos50= G->pos, yythunkpos50= G->thunkpos; + int yypos49= G->pos, yythunkpos49= G->thunkpos; { - int yypos51= G->pos, yythunkpos51= 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 l51; - goto l50; - l51: - G->pos= yypos51; G->thunkpos= yythunkpos51; + int yypos50= G->pos, yythunkpos50= 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 l50; + goto l49; + l50: + G->pos= yypos50; G->thunkpos= yythunkpos50; } - if (!yy_char(G)) goto l50; - goto l49; - l50: - G->pos= yypos50; G->thunkpos= yythunkpos50; + if (!yy_char(G)) goto l49; + goto l48; + l49: + G->pos= yypos49; G->thunkpos= yythunkpos49; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l43; + if (!(YY_END)) goto l42; #undef yytext #undef yyleng } - 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 l43; - if (!yy__(G)) goto l43; + 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 l42; + if (!yy__(G)) goto l42; } - l44: + l43: ; yyprintfokrule("literal"); return 1; - l43: + l42: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("literal"); return 0; @@ -1059,11 +1052,11 @@ YY_RULE(int) yy_CLOSE(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "CLOSE")); - if (!yymatchChar(G, ')')) goto l52; - if (!yy__(G)) goto l52; + if (!yymatchChar(G, ')')) goto l51; + if (!yy__(G)) goto l51; yyprintfokrule("CLOSE"); return 1; - l52: + l51: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("CLOSE"); return 0; @@ -1072,11 +1065,11 @@ YY_RULE(int) yy_OPEN(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "OPEN")); - if (!yymatchChar(G, '(')) goto l53; - if (!yy__(G)) goto l53; + if (!yymatchChar(G, '(')) goto l52; + if (!yy__(G)) goto l52; yyprintfokrule("OPEN"); return 1; - l53: + l52: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("OPEN"); return 0; @@ -1085,11 +1078,11 @@ YY_RULE(int) yy_COLON(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "COLON")); - if (!yymatchChar(G, ':')) goto l54; - if (!yy__(G)) goto l54; + if (!yymatchChar(G, ':')) goto l53; + if (!yy__(G)) goto l53; yyprintfokrule("COLON"); return 1; - l54: + l53: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("COLON"); return 0; @@ -1098,11 +1091,11 @@ YY_RULE(int) yy_PLUS(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "PLUS")); - if (!yymatchChar(G, '+')) goto l55; - if (!yy__(G)) goto l55; + if (!yymatchChar(G, '+')) goto l54; + if (!yy__(G)) goto l54; yyprintfokrule("PLUS"); return 1; - l55: + l54: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("PLUS"); return 0; @@ -1111,11 +1104,11 @@ YY_RULE(int) yy_STAR(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "STAR")); - if (!yymatchChar(G, '*')) goto l56; - if (!yy__(G)) goto l56; + if (!yymatchChar(G, '*')) goto l55; + if (!yy__(G)) goto l55; yyprintfokrule("STAR"); return 1; - l56: + l55: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("STAR"); return 0; @@ -1124,11 +1117,11 @@ YY_RULE(int) yy_QUESTION(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "QUESTION")); - if (!yymatchChar(G, '?')) goto l57; - if (!yy__(G)) goto l57; + if (!yymatchChar(G, '?')) goto l56; + if (!yy__(G)) goto l56; yyprintfokrule("QUESTION"); return 1; - l57: + l56: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("QUESTION"); return 0; @@ -1138,84 +1131,84 @@ YY_RULE(int) yy_primary(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "primary")); { - int yypos59= G->pos, yythunkpos59= G->thunkpos; - if (!yy_identifier(G)) goto l60; + int yypos58= G->pos, yythunkpos58= G->thunkpos; + if (!yy_identifier(G)) goto l59; yyDo(G, yy_1_primary, G->begin, G->end, "yy_1_primary"); - if (!yy_COLON(G)) goto l60; - if (!yy_identifier(G)) goto l60; + if (!yy_COLON(G)) goto l59; + if (!yy_identifier(G)) goto l59; { - int yypos61= G->pos, yythunkpos61= G->thunkpos; - if (!yy_EQUAL(G)) goto l61; - goto l60; - l61: - G->pos= yypos61; G->thunkpos= yythunkpos61; + int yypos60= G->pos, yythunkpos60= G->thunkpos; + if (!yy_EQUAL(G)) goto l60; + goto l59; + l60: + G->pos= yypos60; G->thunkpos= yythunkpos60; } yyDo(G, yy_2_primary, G->begin, G->end, "yy_2_primary"); - goto l59; - l60: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_identifier(G)) goto l62; + goto l58; + l59: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_identifier(G)) goto l61; { - int yypos63= G->pos, yythunkpos63= G->thunkpos; - if (!yy_EQUAL(G)) goto l63; - goto l62; - l63: - G->pos= yypos63; G->thunkpos= yythunkpos63; + int yypos62= G->pos, yythunkpos62= G->thunkpos; + if (!yy_EQUAL(G)) goto l62; + goto l61; + l62: + G->pos= yypos62; G->thunkpos= yythunkpos62; } yyDo(G, yy_3_primary, G->begin, G->end, "yy_3_primary"); - goto l59; - l62: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_OPEN(G)) goto l64; - if (!yy_expression(G)) goto l64; - if (!yy_CLOSE(G)) goto l64; - goto l59; - l64: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_literal(G)) goto l65; + goto l58; + l61: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_OPEN(G)) goto l63; + if (!yy_expression(G)) goto l63; + if (!yy_CLOSE(G)) goto l63; + goto l58; + l63: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_literal(G)) goto l64; yyDo(G, yy_4_primary, G->begin, G->end, "yy_4_primary"); - goto l59; - l65: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_class(G)) goto l66; + goto l58; + l64: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_class(G)) goto l65; yyDo(G, yy_5_primary, G->begin, G->end, "yy_5_primary"); - goto l59; - l66: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_DOT(G)) goto l67; + goto l58; + l65: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_DOT(G)) goto l66; yyDo(G, yy_6_primary, G->begin, G->end, "yy_6_primary"); - goto l59; - l67: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_action(G)) goto l68; + goto l58; + l66: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_action(G)) goto l67; yyDo(G, yy_7_primary, G->begin, G->end, "yy_7_primary"); - goto l59; - l68: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_BEGIN(G)) goto l69; + goto l58; + l67: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_BEGIN(G)) goto l68; yyDo(G, yy_8_primary, G->begin, G->end, "yy_8_primary"); - goto l59; - l69: - G->pos= yypos59; G->thunkpos= yythunkpos59; - if (!yy_END(G)) goto l58; + goto l58; + l68: + G->pos= yypos58; G->thunkpos= yythunkpos58; + if (!yy_END(G)) goto l57; yyDo(G, yy_9_primary, G->begin, G->end, "yy_9_primary"); } - l59: + l58: ; - l70: + l69: { - int yypos71= G->pos, yythunkpos71= G->thunkpos; - if (!yy_errblock(G)) goto l71; + int yypos70= G->pos, yythunkpos70= G->thunkpos; + if (!yy_errblock(G)) goto l70; yyDo(G, yy_10_primary, G->begin, G->end, "yy_10_primary"); - goto l70; - l71: - G->pos= yypos71; G->thunkpos= yythunkpos71; + goto l69; + l70: + G->pos= yypos70; G->thunkpos= yythunkpos70; } yyprintfokrule("primary"); return 1; - l58: + l57: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("primary"); return 0; @@ -1224,11 +1217,11 @@ YY_RULE(int) yy_NOT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "NOT")); - if (!yymatchChar(G, '!')) goto l72; - if (!yy__(G)) goto l72; + if (!yymatchChar(G, '!')) goto l71; + if (!yy__(G)) goto l71; yyprintfokrule("NOT"); return 1; - l72: + l71: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("NOT"); return 0; @@ -1237,36 +1230,36 @@ YY_RULE(int) yy_suffix(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "suffix")); - if (!yy_primary(G)) goto l73; + if (!yy_primary(G)) goto l72; - l74: + l73: { - int yypos75= G->pos, yythunkpos75= G->thunkpos; + int yypos74= G->pos, yythunkpos74= G->thunkpos; { - int yypos76= G->pos, yythunkpos76= G->thunkpos; - if (!yy_QUESTION(G)) goto l77; + int yypos75= G->pos, yythunkpos75= G->thunkpos; + if (!yy_QUESTION(G)) goto l76; yyDo(G, yy_1_suffix, G->begin, G->end, "yy_1_suffix"); - goto l76; - l77: - G->pos= yypos76; G->thunkpos= yythunkpos76; - if (!yy_STAR(G)) goto l78; + goto l75; + l76: + G->pos= yypos75; G->thunkpos= yythunkpos75; + if (!yy_STAR(G)) goto l77; yyDo(G, yy_2_suffix, G->begin, G->end, "yy_2_suffix"); - goto l76; - l78: - G->pos= yypos76; G->thunkpos= yythunkpos76; - if (!yy_PLUS(G)) goto l75; + goto l75; + l77: + G->pos= yypos75; G->thunkpos= yythunkpos75; + if (!yy_PLUS(G)) goto l74; yyDo(G, yy_3_suffix, G->begin, G->end, "yy_3_suffix"); } - l76: - ; - goto l74; l75: - G->pos= yypos75; G->thunkpos= yythunkpos75; + ; + goto l73; + l74: + G->pos= yypos74; G->thunkpos= yythunkpos74; } yyprintfokrule("suffix"); return 1; - l73: + l72: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("suffix"); return 0; @@ -1275,39 +1268,39 @@ YY_RULE(int) yy_action(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "action")); - if (!yymatchChar(G, '{')) goto l79; + if (!yymatchChar(G, '{')) goto l78; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l79; + if (!(YY_BEGIN)) goto l78; #undef yytext #undef yyleng } - l80: + l79: { - int yypos81= G->pos, yythunkpos81= G->thunkpos; - if (!yy_braces(G)) goto l81; - goto l80; - l81: - G->pos= yypos81; G->thunkpos= yythunkpos81; + int yypos80= G->pos, yythunkpos80= G->thunkpos; + if (!yy_braces(G)) goto l80; + goto l79; + l80: + G->pos= yypos80; G->thunkpos= yythunkpos80; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l79; + if (!(YY_END)) goto l78; #undef yytext #undef yyleng } - if (!yymatchChar(G, '}')) goto l79; - if (!yy__(G)) goto l79; + if (!yymatchChar(G, '}')) goto l78; + if (!yy__(G)) goto l78; yyprintfokrule("action"); return 1; - l79: + l78: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("action"); return 0; @@ -1316,11 +1309,11 @@ YY_RULE(int) yy_AND(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "AND")); - if (!yymatchChar(G, '&')) goto l82; - if (!yy__(G)) goto l82; + if (!yymatchChar(G, '&')) goto l81; + if (!yy__(G)) goto l81; yyprintfokrule("AND"); return 1; - l82: + l81: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("AND"); return 0; @@ -1330,33 +1323,33 @@ YY_RULE(int) yy_prefix(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "prefix")); { - int yypos84= G->pos, yythunkpos84= G->thunkpos; - if (!yy_AND(G)) goto l85; - if (!yy_action(G)) goto l85; + int yypos83= G->pos, yythunkpos83= G->thunkpos; + if (!yy_AND(G)) goto l84; + if (!yy_action(G)) goto l84; yyDo(G, yy_1_prefix, G->begin, G->end, "yy_1_prefix"); - goto l84; + goto l83; + l84: + G->pos= yypos83; G->thunkpos= yythunkpos83; + if (!yy_AND(G)) goto l85; + if (!yy_suffix(G)) goto l85; + yyDo(G, yy_2_prefix, G->begin, G->end, "yy_2_prefix"); + goto l83; l85: - G->pos= yypos84; G->thunkpos= yythunkpos84; - if (!yy_AND(G)) goto l86; + G->pos= yypos83; G->thunkpos= yythunkpos83; + if (!yy_NOT(G)) goto l86; if (!yy_suffix(G)) goto l86; - yyDo(G, yy_2_prefix, G->begin, G->end, "yy_2_prefix"); - goto l84; - l86: - G->pos= yypos84; G->thunkpos= yythunkpos84; - if (!yy_NOT(G)) goto l87; - if (!yy_suffix(G)) goto l87; yyDo(G, yy_3_prefix, G->begin, G->end, "yy_3_prefix"); - goto l84; - l87: - G->pos= yypos84; G->thunkpos= yythunkpos84; - if (!yy_suffix(G)) goto l83; + goto l83; + l86: + G->pos= yypos83; G->thunkpos= yythunkpos83; + if (!yy_suffix(G)) goto l82; } - l84: + l83: ; yyprintfokrule("prefix"); return 1; - l83: + l82: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("prefix"); return 0; @@ -1365,11 +1358,11 @@ YY_RULE(int) yy_BAR(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BAR")); - if (!yymatchChar(G, '|')) goto l88; - if (!yy__(G)) goto l88; + if (!yymatchChar(G, '|')) goto l87; + if (!yy__(G)) goto l87; yyprintfokrule("BAR"); return 1; - l88: + l87: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("BAR"); return 0; @@ -1378,20 +1371,20 @@ YY_RULE(int) yy_sequence(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "sequence")); - if (!yy_prefix(G)) goto l89; + if (!yy_prefix(G)) goto l88; - l90: + l89: { - int yypos91= G->pos, yythunkpos91= G->thunkpos; - if (!yy_prefix(G)) goto l91; + int yypos90= G->pos, yythunkpos90= G->thunkpos; + if (!yy_prefix(G)) goto l90; yyDo(G, yy_1_sequence, G->begin, G->end, "yy_1_sequence"); - goto l90; - l91: - G->pos= yypos91; G->thunkpos= yythunkpos91; + goto l89; + l90: + G->pos= yypos90; G->thunkpos= yythunkpos90; } yyprintfokrule("sequence"); return 1; - l89: + l88: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("sequence"); return 0; @@ -1400,11 +1393,11 @@ YY_RULE(int) yy_SEMICOLON(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "SEMICOLON")); - if (!yymatchChar(G, ';')) goto l92; - if (!yy__(G)) goto l92; + if (!yymatchChar(G, ';')) goto l91; + if (!yy__(G)) goto l91; yyprintfokrule("SEMICOLON"); return 1; - l92: + l91: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("SEMICOLON"); return 0; @@ -1413,21 +1406,21 @@ YY_RULE(int) yy_expression(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "expression")); - if (!yy_sequence(G)) goto l93; + if (!yy_sequence(G)) goto l92; - l94: + l93: { - int yypos95= G->pos, yythunkpos95= G->thunkpos; - if (!yy_BAR(G)) goto l95; - if (!yy_sequence(G)) goto l95; + int yypos94= G->pos, yythunkpos94= G->thunkpos; + if (!yy_BAR(G)) goto l94; + if (!yy_sequence(G)) goto l94; yyDo(G, yy_1_expression, G->begin, G->end, "yy_1_expression"); - goto l94; - l95: - G->pos= yypos95; G->thunkpos= yythunkpos95; + goto l93; + l94: + G->pos= yypos94; G->thunkpos= yythunkpos94; } yyprintfokrule("expression"); return 1; - l93: + l92: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("expression"); return 0; @@ -1436,11 +1429,11 @@ YY_RULE(int) yy_EQUAL(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "EQUAL")); - if (!yymatchChar(G, '=')) goto l96; - if (!yy__(G)) goto l96; + if (!yymatchChar(G, '=')) goto l95; + if (!yy__(G)) goto l95; yyprintfokrule("EQUAL"); return 1; - l96: + l95: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("EQUAL"); return 0; @@ -1453,34 +1446,34 @@ YY_RULE(int) yy_identifier(GREG *G) { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l97; + if (!(YY_BEGIN)) goto l96; #undef yytext #undef yyleng } - 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", "-a-zA-Z_")) goto l97; + 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", "-a-zA-Z_")) goto l96; - l98: + l97: { - int yypos99= G->pos, yythunkpos99= 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", "-a-zA-Z_0-9")) goto l99; - goto l98; - l99: - G->pos= yypos99; G->thunkpos= yythunkpos99; + int yypos98= G->pos, yythunkpos98= 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", "-a-zA-Z_0-9")) goto l98; + goto l97; + l98: + G->pos= yypos98; G->thunkpos= yythunkpos98; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l97; + if (!(YY_END)) goto l96; #undef yytext #undef yyleng } - if (!yy__(G)) goto l97; + if (!yy__(G)) goto l96; yyprintfokrule("identifier"); return 1; - l97: + l96: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("identifier"); return 0; @@ -1489,11 +1482,11 @@ YY_RULE(int) yy_RPERCENT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "RPERCENT")); - if (!yymatchString(G, "%}")) goto l100; - if (!yy__(G)) goto l100; + if (!yymatchString(G, "%}")) goto l99; + if (!yy__(G)) goto l99; yyprintfokrule("RPERCENT"); return 1; - l100: + l99: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("RPERCENT"); return 0; @@ -1503,15 +1496,15 @@ YY_RULE(int) yy_end_of_file(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "end_of_file")); { - int yypos102= G->pos, yythunkpos102= G->thunkpos; - if (!yymatchDot(G)) goto l102; - goto l101; - l102: - G->pos= yypos102; G->thunkpos= yythunkpos102; + int yypos101= G->pos, yythunkpos101= G->thunkpos; + if (!yymatchDot(G)) goto l101; + goto l100; + l101: + G->pos= yypos101; G->thunkpos= yythunkpos101; } yyprintfvokrule("end_of_file"); return 1; - l101: + l100: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("end_of_file"); return 0; @@ -1520,30 +1513,30 @@ YY_RULE(int) yy_trailer(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "trailer")); - if (!yymatchString(G, "%%")) goto l103; + if (!yymatchString(G, "%%")) goto l102; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l103; + if (!(YY_BEGIN)) goto l102; #undef yytext #undef yyleng } - l104: + l103: { - int yypos105= G->pos, yythunkpos105= G->thunkpos; - if (!yymatchDot(G)) goto l105; - goto l104; - l105: - G->pos= yypos105; G->thunkpos= yythunkpos105; + int yypos104= G->pos, yythunkpos104= G->thunkpos; + if (!yymatchDot(G)) goto l104; + goto l103; + l104: + G->pos= yypos104; G->thunkpos= yythunkpos104; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l103; + if (!(YY_END)) goto l102; #undef yytext #undef yyleng } @@ -1551,7 +1544,7 @@ YY_RULE(int) yy_trailer(GREG *G) yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer"); yyprintfokrule("trailer"); return 1; - l103: + l102: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("trailer"); return 0; @@ -1561,25 +1554,25 @@ YY_RULE(int) yy_definition(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyDo(G, yyPush, 1, 0, "yyPush"); yyprintfv((stderr, "%s\n", "definition")); - if (!yy_identifier(G)) goto l106; + if (!yy_identifier(G)) goto l105; yyDo(G, yySet, -1, 0, "yySet identifier"); yyDo(G, yy_1_definition, G->begin, G->end, "yy_1_definition"); - if (!yy_EQUAL(G)) goto l106; - if (!yy_expression(G)) goto l106; + if (!yy_EQUAL(G)) goto l105; + if (!yy_expression(G)) goto l105; yyDo(G, yy_2_definition, G->begin, G->end, "yy_2_definition"); - l107: + l106: { - int yypos108= G->pos, yythunkpos108= G->thunkpos; - if (!yy_SEMICOLON(G)) goto l108; - goto l107; - l108: - G->pos= yypos108; G->thunkpos= yythunkpos108; + int yypos107= G->pos, yythunkpos107= G->thunkpos; + if (!yy_SEMICOLON(G)) goto l107; + goto l106; + l107: + G->pos= yypos107; G->thunkpos= yythunkpos107; } yyprintfokrule("definition"); yyDo(G, yyPop, 1, 0, "yyPop"); return 1; - l106: + l105: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("definition"); return 0; @@ -1588,46 +1581,46 @@ YY_RULE(int) yy_declaration(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "declaration")); - if (!yymatchString(G, "%{")) goto l109; + if (!yymatchString(G, "%{")) goto l108; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l109; + if (!(YY_BEGIN)) goto l108; #undef yytext #undef yyleng } - l110: + l109: { - int yypos111= G->pos, yythunkpos111= G->thunkpos; + int yypos110= G->pos, yythunkpos110= G->thunkpos; { - int yypos112= G->pos, yythunkpos112= G->thunkpos; - if (!yymatchString(G, "%}")) goto l112; - goto l111; - l112: - G->pos= yypos112; G->thunkpos= yythunkpos112; + int yypos111= G->pos, yythunkpos111= G->thunkpos; + if (!yymatchString(G, "%}")) goto l111; + goto l110; + l111: + G->pos= yypos111; G->thunkpos= yythunkpos111; } - if (!yymatchDot(G)) goto l111; - goto l110; - l111: - G->pos= yypos111; G->thunkpos= yythunkpos111; + if (!yymatchDot(G)) goto l110; + goto l109; + l110: + G->pos= yypos110; G->thunkpos= yythunkpos110; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l109; + if (!(YY_END)) goto l108; #undef yytext #undef yyleng } - if (!yy_RPERCENT(G)) goto l109; + if (!yy_RPERCENT(G)) goto l108; yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration"); yyprintfokrule("declaration"); return 1; - l109: + l108: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("declaration"); return 0; @@ -1635,23 +1628,23 @@ YY_RULE(int) yy_declaration(GREG *G) YY_RULE(int) yy__(GREG *G) { yyprintfv((stderr, "%s\n", "_")); - l114: + l113: { - int yypos115= G->pos, yythunkpos115= G->thunkpos; + int yypos114= G->pos, yythunkpos114= G->thunkpos; { - int yypos116= G->pos, yythunkpos116= G->thunkpos; - if (!yy_space(G)) goto l117; - goto l116; - l117: - G->pos= yypos116; G->thunkpos= yythunkpos116; - if (!yy_comment(G)) goto l115; + int yypos115= G->pos, yythunkpos115= G->thunkpos; + if (!yy_space(G)) goto l116; + goto l115; + l116: + G->pos= yypos115; G->thunkpos= yythunkpos115; + if (!yy_comment(G)) goto l114; } - l116: - ; - goto l114; l115: - G->pos= yypos115; G->thunkpos= yythunkpos115; + ; + goto l113; + l114: + G->pos= yypos114; G->thunkpos= yythunkpos114; } yyprintfvokrule("_"); return 1; @@ -1660,50 +1653,50 @@ YY_RULE(int) yy_grammar(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "grammar")); - if (!yy__(G)) goto l118; + if (!yy__(G)) goto l117; { - 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; + int yypos120= G->pos, yythunkpos120= G->thunkpos; + if (!yy_declaration(G)) goto l121; + goto l120; + l121: + G->pos= yypos120; G->thunkpos= yythunkpos120; + if (!yy_definition(G)) goto l117; } - l121: + l120: ; - l119: + l118: { - int yypos120= G->pos, yythunkpos120= G->thunkpos; + int yypos119= G->pos, yythunkpos119= G->thunkpos; { - int yypos123= G->pos, yythunkpos123= G->thunkpos; - if (!yy_declaration(G)) goto l124; - goto l123; - l124: - G->pos= yypos123; G->thunkpos= yythunkpos123; - if (!yy_definition(G)) goto l120; + int yypos122= G->pos, yythunkpos122= G->thunkpos; + if (!yy_declaration(G)) goto l123; + goto l122; + l123: + G->pos= yypos122; G->thunkpos= yythunkpos122; + if (!yy_definition(G)) goto l119; } - l123: + l122: ; - goto l119; - l120: - G->pos= yypos120; G->thunkpos= yythunkpos120; + goto l118; + l119: + G->pos= yypos119; G->thunkpos= yythunkpos119; } - l125: + l124: { - int yypos126= G->pos, yythunkpos126= G->thunkpos; - if (!yy_trailer(G)) goto l126; - goto l125; - l126: - G->pos= yypos126; G->thunkpos= yythunkpos126; + int yypos125= G->pos, yythunkpos125= G->thunkpos; + if (!yy_trailer(G)) goto l125; + goto l124; + l125: + G->pos= yypos125; G->thunkpos= yythunkpos125; } - if (!yy_end_of_file(G)) goto l118; + if (!yy_end_of_file(G)) goto l117; yyprintfokrule("grammar"); return 1; - l118: + l117: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("grammar"); return 0; diff --git a/greg.g b/greg.g index 184f731..7112848 100644 --- a/greg.g +++ b/greg.g @@ -119,7 +119,7 @@ char= '\\' [abefnrtv'"\[\]\\] errblock= '~{' < braces* > '}' - action= '{' < braces* > '}' - -braces= '{' (!'}' .)* '}' +braces= '{' braces* '}' | !'}' . EQUAL= '=' - diff --git a/samples/basic.leg b/samples/basic.leg index eb2468f..c22d625 100644 --- a/samples/basic.leg +++ b/samples/basic.leg @@ -81,6 +81,7 @@ char *help; void error(char *fmt, ...); + int findLine(int n, int create); %} line = - s:statement CR @@ -95,7 +96,7 @@ statement = 'print'- expr-list | 'goto'- e:expression { epc= pc; if ((pc= findLine(e.number, 0)) < 0) error("no such line"); } | 'input'- var-list | 'let'- v:var EQUAL e:expression { variables[v.number]= e.number; } -| 'gosub'- e:expression { epc= pc; if (sp < 1024) stack[sp++]= pc, pc= findLine(e.number); else error("too many gosubs"); +| 'gosub'- e:expression { epc= pc; if (sp < 1024) stack[sp++]= pc, pc= findLine(e.number, 0); else error("too many gosubs"); if (pc < 0) error("no such line"); } | 'return'- { epc= pc; if ((pc= sp ? stack[--sp] : -1) < 0) error("no gosub"); } | 'clear'- { while (numLines) accept(lines->number, "\n"); } @@ -325,7 +326,7 @@ void type(char *name) perror(name); else { - int c, d; + int c, d= 0; while ((c= getc(f)) >= 0) putchar(d= c); fclose(f); From 14437ffda072d0e287d8c82002ed4d4c3b2b8643 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 1 Oct 2013 11:44:31 -0500 Subject: [PATCH 08/13] replace errblock impl with upstream use the upstream peg error Action block feature, get rid of the added errblock field from every node. add erract sample and testcase --- Makefile | 2 + compile.c | 56 ++-- greg.c | 786 ++++++++++++++++++++++----------------------- greg.g | 21 +- greg.h | 7 +- samples/erract.leg | 14 + samples/erract.ref | 4 + tree.c | 15 +- 8 files changed, 461 insertions(+), 444 deletions(-) create mode 100644 samples/erract.leg create mode 100644 samples/erract.ref diff --git a/Makefile b/Makefile index 59279b3..39bc913 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,8 @@ test: samples run diff samples/test.out samples/test.ref cat samples/wc.leg | samples/wc > samples/wc.out diff samples/wc.out samples/wc.ref + echo '6*9' | samples/erract | tee samples/erract.out + diff samples/erract.out samples/erract.ref run: greg mkdir -p selftest diff --git a/compile.c b/compile.c index 8c96566..226e495 100644 --- a/compile.c +++ b/compile.c @@ -195,10 +195,6 @@ static void jump(int n) { pindent(); fprintf(output, " goto l%d;", n); } static void restore(int n) { pindent(); fprintf(output, " G->pos= yypos%d; G->thunkpos= yythunkpos%d;\n", n, n); } static void end(void) { pindent(); indent--; fprintf(output, "}\n"); } -static void callErrBlock(Node * node) { - fprintf(output, " { YY_XTYPE YY_XVAR = (YY_XTYPE) G->data; int yyindex = G->offset + G->pos; %s; }", ((struct Any*) node)->errblock); -} - static void Node_compile_c_ko(Node *node, int ko) { assert(node); @@ -210,26 +206,15 @@ static void Node_compile_c_ko(Node *node, int ko) break; case Dot: - pindent(); - fprintf(output, " if (!yymatchDot(G)) goto l%d;\n", ko); + pindent(); fprintf(output, " if (!yymatchDot(G)) goto l%d;\n", ko); break; case Name: - pindent(); - fprintf(output, " if (!yy_%s(G)) ", node->name.rule->rule.name); - if(((struct Any*) node)->errblock) { - fprintf(output, "{ "); indent++; - callErrBlock(node); - pindent(); - fprintf(output, " goto l%d; }\n", ko); indent--; - } else { - pindent(); - fprintf(output, " goto l%d;\n", ko); - } + pindent(); fprintf(output, " if (!yy_%s(G)) ", node->name.rule->rule.name); + pindent(); fprintf(output, " goto l%d;\n", ko); if (node->name.variable) { - pindent(); - fprintf(output, " yyDo(G, yySet, %d, 0, \"yySet %s\");\n", - node->name.variable->variable.offset, node->name.rule->rule.name); + pindent(); fprintf(output, " yyDo(G, yySet, %d, 0, \"yySet %s\");\n", + node->name.variable->variable.offset, node->name.rule->rule.name); } break; @@ -263,8 +248,8 @@ static void Node_compile_c_ko(Node *node, int ko) break; case Action: - pindent(); - fprintf(output, " yyDo(G, yy%s, G->begin, G->end, \"yy%s\");\n", node->action.name, node->action.name); + pindent(); fprintf(output, " yyDo(G, yy%s, G->begin, G->end, \"yy%s\");\n", + node->action.name, node->action.name); break; case Predicate: @@ -278,6 +263,26 @@ static void Node_compile_c_ko(Node *node, int ko) end(); nl(); break; + + case Error: + { + int eok= yyl(), eko= yyl(); + Node_compile_c_ko(node->error.element, eko); + jump(eok); + label(eko); + pindent(); fprintf(output, " yyText(G, G->begin, G->end);\n"); + begin(); nl(); + pindent(); fprintf(output, " #define yytext G->text\n"); + pindent(); fprintf(output, " #define yyleng G->textlen\n"); + pindent(); fprintf(output, " %s;\n", node->error.text); + pindent(); fprintf(output, " #undef yytext\n"); + pindent(); fprintf(output, " #undef yyleng\n"); + end(); nl(); + jump(ko); + label(eok); + } + break; + case Alternate: { int ok= yyl(); @@ -396,8 +401,7 @@ static void defineVariables(Node *node) int count= 0; while (node) { - pindent(); - fprintf(output, " #define %s G->val[%d]\n", node->variable.name, --count); + pindent(); fprintf(output, " #define %s G->val[%d]\n", node->variable.name, --count); node->variable.offset= count; node= node->variable.next; } @@ -407,8 +411,7 @@ static void undefineVariables(Node *node) { while (node) { - pindent(); - fprintf(output, " #undef %s\n", node->variable.name); + pindent(); fprintf(output, " #undef %s\n", node->variable.name); node= node->variable.next; } } @@ -973,6 +976,7 @@ int consumesInput(Node *node) case Class: return 1; case Action: return 0; case Predicate: return 0; + case Error: return consumesInput(node->error.element); case Alternate: { diff --git a/greg.c b/greg.c index 86defa6..3a3bfe0 100644 --- a/greg.c +++ b/greg.c @@ -4,7 +4,7 @@ #include #include struct _GREG; -#define YYRULECOUNT 37 +#define YYRULECOUNT 38 # include "greg.h" @@ -419,30 +419,31 @@ YY_LOCAL(void) yySet(GREG *G, char *text, int count, yythunk *thunk, YY_XTYPE YY #define YYACCEPT yyAccept(G, 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_end_of_line(GREG *G); /* 38 */ +YY_RULE(int) yy_comment(GREG *G); /* 37 */ +YY_RULE(int) yy_space(GREG *G); /* 36 */ +YY_RULE(int) yy_braces(GREG *G); /* 35 */ +YY_RULE(int) yy_range(GREG *G); /* 34 */ +YY_RULE(int) yy_char(GREG *G); /* 33 */ +YY_RULE(int) yy_END(GREG *G); /* 32 */ +YY_RULE(int) yy_BEGIN(GREG *G); /* 31 */ +YY_RULE(int) yy_DOT(GREG *G); /* 30 */ +YY_RULE(int) yy_class(GREG *G); /* 29 */ +YY_RULE(int) yy_literal(GREG *G); /* 28 */ +YY_RULE(int) yy_CLOSE(GREG *G); /* 27 */ +YY_RULE(int) yy_OPEN(GREG *G); /* 26 */ +YY_RULE(int) yy_COLON(GREG *G); /* 25 */ +YY_RULE(int) yy_PLUS(GREG *G); /* 24 */ +YY_RULE(int) yy_STAR(GREG *G); /* 23 */ +YY_RULE(int) yy_QUESTION(GREG *G); /* 22 */ +YY_RULE(int) yy_primary(GREG *G); /* 21 */ +YY_RULE(int) yy_NOT(GREG *G); /* 20 */ +YY_RULE(int) yy_suffix(GREG *G); /* 19 */ +YY_RULE(int) yy_AND(GREG *G); /* 18 */ +YY_RULE(int) yy_action(GREG *G); /* 17 */ +YY_RULE(int) yy_TILDE(GREG *G); /* 16 */ +YY_RULE(int) yy_prefix(GREG *G); /* 15 */ +YY_RULE(int) yy_error(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 */ @@ -457,13 +458,6 @@ YY_RULE(int) yy_declaration(GREG *G); /* 3 */ YY_RULE(int) yy__(GREG *G); /* 2 */ YY_RULE(int) yy_grammar(GREG *G); /* 1 */ -YY_ACTION(void) yy_10_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) -{ - yyprintf((stderr, "do yy_10_primary")); - yyprintfvTcontext(yytext); - yyprintf((stderr, "\n {Node *node = pop(); ((struct Any *) node)->errblock = strdup(yytext); push(node); }\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) { yyprintf((stderr, "do yy_9_primary")); @@ -569,6 +563,13 @@ YY_ACTION(void) yy_1_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, Y yyprintf((stderr, "\n {push(makePredicate(yytext)); }\n")); push(makePredicate(yytext)); ; } +YY_ACTION(void) yy_1_error(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) +{ + yyprintf((stderr, "do yy_1_error")); + yyprintfvTcontext(yytext); + yyprintf((stderr, "\n {push(makeError(pop(), yytext)); }\n")); + push(makeError(pop(), yytext)); ; +} YY_ACTION(void) yy_1_sequence(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_sequence")); @@ -769,7 +770,7 @@ YY_RULE(int) yy_char(GREG *G) { int yypos23= G->pos, yythunkpos23= G->thunkpos; if (!yymatchChar(G, '\\')) goto l24; - 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", "abefnrtv'\"\\[\\]\\\\")) goto l24; + if (!yymatchClass(G, (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", "-abefnrtv'\"\\[\\]\\\\")) goto l24; goto l23; l24: G->pos= yypos23; G->thunkpos= yythunkpos23; @@ -826,56 +827,15 @@ YY_RULE(int) yy_char(GREG *G) yyprintfvfailrule("char"); return 0; } -YY_RULE(int) yy_errblock(GREG *G) -{ - int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintfv((stderr, "%s\n", "errblock")); - if (!yymatchString(G, "~{")) goto l32; - yyText(G, G->begin, G->end); - { - #define yytext G->text - #define yyleng G->textlen - if (!(YY_BEGIN)) goto l32; - #undef yytext - #undef yyleng - } - - - l33: - { - int yypos34= G->pos, yythunkpos34= G->thunkpos; - if (!yy_braces(G)) goto l34; - goto l33; - l34: - G->pos= yypos34; G->thunkpos= yythunkpos34; - } - yyText(G, G->begin, G->end); - { - #define yytext G->text - #define yyleng G->textlen - if (!(YY_END)) goto l32; - #undef yytext - #undef yyleng - } - - if (!yymatchChar(G, '}')) goto l32; - if (!yy__(G)) goto l32; - yyprintfokrule("errblock"); - return 1; - l32: - G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfvfailrule("errblock"); - return 0; -} YY_RULE(int) yy_END(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "END")); - if (!yymatchChar(G, '>')) goto l35; - if (!yy__(G)) goto l35; + if (!yymatchChar(G, '>')) goto l32; + if (!yy__(G)) goto l32; yyprintfokrule("END"); return 1; - l35: + l32: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("END"); return 0; @@ -884,11 +844,11 @@ YY_RULE(int) yy_BEGIN(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BEGIN")); - if (!yymatchChar(G, '<')) goto l36; - if (!yy__(G)) goto l36; + if (!yymatchChar(G, '<')) goto l33; + if (!yy__(G)) goto l33; yyprintfokrule("BEGIN"); return 1; - l36: + l33: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("BEGIN"); return 0; @@ -897,11 +857,11 @@ YY_RULE(int) yy_DOT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "DOT")); - if (!yymatchChar(G, '.')) goto l37; - if (!yy__(G)) goto l37; + if (!yymatchChar(G, '.')) goto l34; + if (!yy__(G)) goto l34; yyprintfokrule("DOT"); return 1; - l37: + l34: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("DOT"); return 0; @@ -910,46 +870,46 @@ YY_RULE(int) yy_class(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "class")); - if (!yymatchChar(G, '[')) goto l38; + if (!yymatchChar(G, '[')) goto l35; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l38; + if (!(YY_BEGIN)) goto l35; #undef yytext #undef yyleng } - l39: + l36: { - int yypos40= G->pos, yythunkpos40= G->thunkpos; + int yypos37= G->pos, yythunkpos37= G->thunkpos; { - int yypos41= G->pos, yythunkpos41= G->thunkpos; - if (!yymatchChar(G, ']')) goto l41; - goto l40; - l41: - G->pos= yypos41; G->thunkpos= yythunkpos41; + int yypos38= G->pos, yythunkpos38= G->thunkpos; + if (!yymatchChar(G, ']')) goto l38; + goto l37; + l38: + G->pos= yypos38; G->thunkpos= yythunkpos38; } - if (!yy_range(G)) goto l40; - goto l39; - l40: - G->pos= yypos40; G->thunkpos= yythunkpos40; + if (!yy_range(G)) goto l37; + goto l36; + l37: + G->pos= yypos37; G->thunkpos= yythunkpos37; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l38; + if (!(YY_END)) goto l35; #undef yytext #undef yyleng } - if (!yymatchChar(G, ']')) goto l38; - if (!yy__(G)) goto l38; + if (!yymatchChar(G, ']')) goto l35; + if (!yy__(G)) goto l35; yyprintfokrule("class"); return 1; - l38: + l35: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("class"); return 0; @@ -959,91 +919,91 @@ YY_RULE(int) yy_literal(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "literal")); { - int yypos43= G->pos, yythunkpos43= 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 l44; + int yypos40= G->pos, yythunkpos40= 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 l41; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l44; + if (!(YY_BEGIN)) goto l41; #undef yytext #undef yyleng } - l45: + l42: { - int yypos46= G->pos, yythunkpos46= G->thunkpos; + int yypos43= G->pos, yythunkpos43= G->thunkpos; { - int yypos47= G->pos, yythunkpos47= 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 l47; - goto l46; - l47: - G->pos= yypos47; G->thunkpos= yythunkpos47; + int yypos44= G->pos, yythunkpos44= 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 l44; + goto l43; + l44: + G->pos= yypos44; G->thunkpos= yythunkpos44; } - if (!yy_char(G)) goto l46; - goto l45; - l46: - G->pos= yypos46; G->thunkpos= yythunkpos46; + if (!yy_char(G)) goto l43; + goto l42; + l43: + G->pos= yypos43; G->thunkpos= yythunkpos43; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l44; + if (!(YY_END)) goto l41; #undef yytext #undef yyleng } - 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 l44; - if (!yy__(G)) goto l44; - goto l43; - l44: - G->pos= yypos43; G->thunkpos= yythunkpos43; - 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 l42; + 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 l41; + if (!yy__(G)) goto l41; + goto l40; + l41: + G->pos= yypos40; G->thunkpos= yythunkpos40; + 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 l39; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l42; + if (!(YY_BEGIN)) goto l39; #undef yytext #undef yyleng } - l48: + l45: { - int yypos49= G->pos, yythunkpos49= G->thunkpos; + int yypos46= G->pos, yythunkpos46= G->thunkpos; { - int yypos50= G->pos, yythunkpos50= 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 l50; - goto l49; - l50: - G->pos= yypos50; G->thunkpos= yythunkpos50; + int yypos47= G->pos, yythunkpos47= 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 l47; + goto l46; + l47: + G->pos= yypos47; G->thunkpos= yythunkpos47; } - if (!yy_char(G)) goto l49; - goto l48; - l49: - G->pos= yypos49; G->thunkpos= yythunkpos49; + if (!yy_char(G)) goto l46; + goto l45; + l46: + G->pos= yypos46; G->thunkpos= yythunkpos46; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l42; + if (!(YY_END)) goto l39; #undef yytext #undef yyleng } - 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 l42; - if (!yy__(G)) goto l42; + 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 l39; + if (!yy__(G)) goto l39; } - l43: + l40: ; yyprintfokrule("literal"); return 1; - l42: + l39: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("literal"); return 0; @@ -1052,11 +1012,11 @@ YY_RULE(int) yy_CLOSE(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "CLOSE")); - if (!yymatchChar(G, ')')) goto l51; - if (!yy__(G)) goto l51; + if (!yymatchChar(G, ')')) goto l48; + if (!yy__(G)) goto l48; yyprintfokrule("CLOSE"); return 1; - l51: + l48: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("CLOSE"); return 0; @@ -1065,11 +1025,11 @@ YY_RULE(int) yy_OPEN(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "OPEN")); - if (!yymatchChar(G, '(')) goto l52; - if (!yy__(G)) goto l52; + if (!yymatchChar(G, '(')) goto l49; + if (!yy__(G)) goto l49; yyprintfokrule("OPEN"); return 1; - l52: + l49: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("OPEN"); return 0; @@ -1078,11 +1038,11 @@ YY_RULE(int) yy_COLON(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "COLON")); - if (!yymatchChar(G, ':')) goto l53; - if (!yy__(G)) goto l53; + if (!yymatchChar(G, ':')) goto l50; + if (!yy__(G)) goto l50; yyprintfokrule("COLON"); return 1; - l53: + l50: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("COLON"); return 0; @@ -1091,11 +1051,11 @@ YY_RULE(int) yy_PLUS(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "PLUS")); - if (!yymatchChar(G, '+')) goto l54; - if (!yy__(G)) goto l54; + if (!yymatchChar(G, '+')) goto l51; + if (!yy__(G)) goto l51; yyprintfokrule("PLUS"); return 1; - l54: + l51: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("PLUS"); return 0; @@ -1104,11 +1064,11 @@ YY_RULE(int) yy_STAR(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "STAR")); - if (!yymatchChar(G, '*')) goto l55; - if (!yy__(G)) goto l55; + if (!yymatchChar(G, '*')) goto l52; + if (!yy__(G)) goto l52; yyprintfokrule("STAR"); return 1; - l55: + l52: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("STAR"); return 0; @@ -1117,11 +1077,11 @@ YY_RULE(int) yy_QUESTION(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "QUESTION")); - if (!yymatchChar(G, '?')) goto l56; - if (!yy__(G)) goto l56; + if (!yymatchChar(G, '?')) goto l53; + if (!yy__(G)) goto l53; yyprintfokrule("QUESTION"); return 1; - l56: + l53: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("QUESTION"); return 0; @@ -1131,84 +1091,74 @@ YY_RULE(int) yy_primary(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "primary")); { - int yypos58= G->pos, yythunkpos58= G->thunkpos; - if (!yy_identifier(G)) goto l59; + int yypos55= G->pos, yythunkpos55= G->thunkpos; + if (!yy_identifier(G)) goto l56; yyDo(G, yy_1_primary, G->begin, G->end, "yy_1_primary"); - if (!yy_COLON(G)) goto l59; - if (!yy_identifier(G)) goto l59; + if (!yy_COLON(G)) goto l56; + if (!yy_identifier(G)) goto l56; { - int yypos60= G->pos, yythunkpos60= G->thunkpos; - if (!yy_EQUAL(G)) goto l60; - goto l59; - l60: - G->pos= yypos60; G->thunkpos= yythunkpos60; + int yypos57= G->pos, yythunkpos57= G->thunkpos; + if (!yy_EQUAL(G)) goto l57; + goto l56; + l57: + G->pos= yypos57; G->thunkpos= yythunkpos57; } yyDo(G, yy_2_primary, G->begin, G->end, "yy_2_primary"); - goto l58; - l59: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_identifier(G)) goto l61; + goto l55; + l56: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_identifier(G)) goto l58; { - int yypos62= G->pos, yythunkpos62= G->thunkpos; - if (!yy_EQUAL(G)) goto l62; - goto l61; - l62: - G->pos= yypos62; G->thunkpos= yythunkpos62; + 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_3_primary, G->begin, G->end, "yy_3_primary"); - goto l58; - l61: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_OPEN(G)) goto l63; - if (!yy_expression(G)) goto l63; - if (!yy_CLOSE(G)) goto l63; - goto l58; - l63: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_literal(G)) goto l64; + goto l55; + l58: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_OPEN(G)) goto l60; + if (!yy_expression(G)) goto l60; + if (!yy_CLOSE(G)) goto l60; + goto l55; + l60: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_literal(G)) goto l61; yyDo(G, yy_4_primary, G->begin, G->end, "yy_4_primary"); - goto l58; - l64: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_class(G)) goto l65; + goto l55; + l61: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_class(G)) goto l62; yyDo(G, yy_5_primary, G->begin, G->end, "yy_5_primary"); - goto l58; - l65: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_DOT(G)) goto l66; + goto l55; + l62: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_DOT(G)) goto l63; yyDo(G, yy_6_primary, G->begin, G->end, "yy_6_primary"); - goto l58; - l66: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_action(G)) goto l67; + goto l55; + l63: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_action(G)) goto l64; yyDo(G, yy_7_primary, G->begin, G->end, "yy_7_primary"); - goto l58; - l67: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_BEGIN(G)) goto l68; + goto l55; + l64: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_BEGIN(G)) goto l65; yyDo(G, yy_8_primary, G->begin, G->end, "yy_8_primary"); - goto l58; - l68: - G->pos= yypos58; G->thunkpos= yythunkpos58; - if (!yy_END(G)) goto l57; + goto l55; + l65: + G->pos= yypos55; G->thunkpos= yythunkpos55; + if (!yy_END(G)) goto l54; yyDo(G, yy_9_primary, G->begin, G->end, "yy_9_primary"); } - l58: + l55: ; - - l69: - { - int yypos70= G->pos, yythunkpos70= G->thunkpos; - if (!yy_errblock(G)) goto l70; - yyDo(G, yy_10_primary, G->begin, G->end, "yy_10_primary"); - goto l69; - l70: - G->pos= yypos70; G->thunkpos= yythunkpos70; - } yyprintfokrule("primary"); return 1; - l57: + l54: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("primary"); return 0; @@ -1217,11 +1167,11 @@ YY_RULE(int) yy_NOT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "NOT")); - if (!yymatchChar(G, '!')) goto l71; - if (!yy__(G)) goto l71; + if (!yymatchChar(G, '!')) goto l66; + if (!yy__(G)) goto l66; yyprintfokrule("NOT"); return 1; - l71: + l66: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("NOT"); return 0; @@ -1230,92 +1180,105 @@ YY_RULE(int) yy_suffix(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "suffix")); - if (!yy_primary(G)) goto l72; + if (!yy_primary(G)) goto l67; - l73: + l68: { - int yypos74= G->pos, yythunkpos74= G->thunkpos; + int yypos69= G->pos, yythunkpos69= G->thunkpos; { - int yypos75= G->pos, yythunkpos75= G->thunkpos; - if (!yy_QUESTION(G)) goto l76; + int yypos70= G->pos, yythunkpos70= G->thunkpos; + if (!yy_QUESTION(G)) goto l71; yyDo(G, yy_1_suffix, G->begin, G->end, "yy_1_suffix"); - goto l75; - l76: - G->pos= yypos75; G->thunkpos= yythunkpos75; - if (!yy_STAR(G)) goto l77; + goto l70; + l71: + G->pos= yypos70; G->thunkpos= yythunkpos70; + if (!yy_STAR(G)) goto l72; yyDo(G, yy_2_suffix, G->begin, G->end, "yy_2_suffix"); - goto l75; - l77: - G->pos= yypos75; G->thunkpos= yythunkpos75; - if (!yy_PLUS(G)) goto l74; + goto l70; + l72: + G->pos= yypos70; G->thunkpos= yythunkpos70; + if (!yy_PLUS(G)) goto l69; yyDo(G, yy_3_suffix, G->begin, G->end, "yy_3_suffix"); } - l75: + l70: ; - goto l73; - l74: - G->pos= yypos74; G->thunkpos= yythunkpos74; + goto l68; + l69: + G->pos= yypos69; G->thunkpos= yythunkpos69; } yyprintfokrule("suffix"); return 1; - l72: + l67: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("suffix"); return 0; } +YY_RULE(int) yy_AND(GREG *G) +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "AND")); + if (!yymatchChar(G, '&')) goto l73; + if (!yy__(G)) goto l73; + yyprintfokrule("AND"); + return 1; + l73: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("AND"); + return 0; +} YY_RULE(int) yy_action(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "action")); - if (!yymatchChar(G, '{')) goto l78; + if (!yymatchChar(G, '{')) goto l74; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l78; + if (!(YY_BEGIN)) goto l74; #undef yytext #undef yyleng } - l79: + l75: { - int yypos80= G->pos, yythunkpos80= G->thunkpos; - if (!yy_braces(G)) goto l80; - goto l79; - l80: - G->pos= yypos80; G->thunkpos= yythunkpos80; + int yypos76= G->pos, yythunkpos76= G->thunkpos; + if (!yy_braces(G)) goto l76; + goto l75; + l76: + G->pos= yypos76; G->thunkpos= yythunkpos76; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l78; + if (!(YY_END)) goto l74; #undef yytext #undef yyleng } - if (!yymatchChar(G, '}')) goto l78; - if (!yy__(G)) goto l78; + if (!yymatchChar(G, '}')) goto l74; + if (!yy__(G)) goto l74; yyprintfokrule("action"); return 1; - l78: + l74: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("action"); return 0; } -YY_RULE(int) yy_AND(GREG *G) +YY_RULE(int) yy_TILDE(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; - yyprintfv((stderr, "%s\n", "AND")); - if (!yymatchChar(G, '&')) goto l81; - if (!yy__(G)) goto l81; - yyprintfokrule("AND"); + yyprintfv((stderr, "%s\n", "TILDE")); + if (!yymatchChar(G, '~')) goto l77; + if (!yy__(G)) goto l77; + yyprintfokrule("TILDE"); return 1; - l81: + l77: G->pos= yypos0; G->thunkpos= yythunkpos0; - yyprintfvfailrule("AND"); + yyprintfvfailrule("TILDE"); return 0; } YY_RULE(int) yy_prefix(GREG *G) @@ -1323,46 +1286,69 @@ YY_RULE(int) yy_prefix(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "prefix")); { - int yypos83= G->pos, yythunkpos83= G->thunkpos; - if (!yy_AND(G)) goto l84; - if (!yy_action(G)) goto l84; + int yypos79= G->pos, yythunkpos79= G->thunkpos; + if (!yy_AND(G)) goto l80; + if (!yy_action(G)) goto l80; yyDo(G, yy_1_prefix, G->begin, G->end, "yy_1_prefix"); - goto l83; - l84: - G->pos= yypos83; G->thunkpos= yythunkpos83; - if (!yy_AND(G)) goto l85; - if (!yy_suffix(G)) goto l85; + goto l79; + l80: + G->pos= yypos79; G->thunkpos= yythunkpos79; + if (!yy_AND(G)) goto l81; + if (!yy_suffix(G)) goto l81; yyDo(G, yy_2_prefix, G->begin, G->end, "yy_2_prefix"); - goto l83; - l85: - G->pos= yypos83; G->thunkpos= yythunkpos83; - if (!yy_NOT(G)) goto l86; - if (!yy_suffix(G)) goto l86; - yyDo(G, yy_3_prefix, G->begin, G->end, "yy_3_prefix"); - goto l83; - l86: - G->pos= yypos83; G->thunkpos= yythunkpos83; + goto l79; + l81: + G->pos= yypos79; G->thunkpos= yythunkpos79; + if (!yy_NOT(G)) goto l82; if (!yy_suffix(G)) goto l82; + yyDo(G, yy_3_prefix, G->begin, G->end, "yy_3_prefix"); + goto l79; + l82: + G->pos= yypos79; G->thunkpos= yythunkpos79; + if (!yy_suffix(G)) goto l78; } - l83: + l79: ; yyprintfokrule("prefix"); return 1; - l82: + l78: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("prefix"); return 0; } +YY_RULE(int) yy_error(GREG *G) +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "error")); + if (!yy_prefix(G)) goto l83; + + l84: + { + int yypos85= G->pos, yythunkpos85= G->thunkpos; + if (!yy_TILDE(G)) goto l85; + if (!yy_action(G)) goto l85; + yyDo(G, yy_1_error, G->begin, G->end, "yy_1_error"); + goto l84; + l85: + G->pos= yypos85; G->thunkpos= yythunkpos85; + } + yyprintfokrule("error"); + return 1; + l83: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("error"); + return 0; +} YY_RULE(int) yy_BAR(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "BAR")); - if (!yymatchChar(G, '|')) goto l87; - if (!yy__(G)) goto l87; + if (!yymatchChar(G, '|')) goto l86; + if (!yy__(G)) goto l86; yyprintfokrule("BAR"); return 1; - l87: + l86: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("BAR"); return 0; @@ -1371,20 +1357,20 @@ YY_RULE(int) yy_sequence(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "sequence")); - if (!yy_prefix(G)) goto l88; + if (!yy_error(G)) goto l87; - l89: + l88: { - int yypos90= G->pos, yythunkpos90= G->thunkpos; - if (!yy_prefix(G)) goto l90; + int yypos89= G->pos, yythunkpos89= G->thunkpos; + if (!yy_error(G)) goto l89; yyDo(G, yy_1_sequence, G->begin, G->end, "yy_1_sequence"); - goto l89; - l90: - G->pos= yypos90; G->thunkpos= yythunkpos90; + goto l88; + l89: + G->pos= yypos89; G->thunkpos= yythunkpos89; } yyprintfokrule("sequence"); return 1; - l88: + l87: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("sequence"); return 0; @@ -1393,11 +1379,11 @@ YY_RULE(int) yy_SEMICOLON(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "SEMICOLON")); - if (!yymatchChar(G, ';')) goto l91; - if (!yy__(G)) goto l91; + if (!yymatchChar(G, ';')) goto l90; + if (!yy__(G)) goto l90; yyprintfokrule("SEMICOLON"); return 1; - l91: + l90: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("SEMICOLON"); return 0; @@ -1406,21 +1392,21 @@ YY_RULE(int) yy_expression(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "expression")); - if (!yy_sequence(G)) goto l92; + if (!yy_sequence(G)) goto l91; - l93: + l92: { - int yypos94= G->pos, yythunkpos94= G->thunkpos; - if (!yy_BAR(G)) goto l94; - if (!yy_sequence(G)) goto l94; + 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, "yy_1_expression"); - goto l93; - l94: - G->pos= yypos94; G->thunkpos= yythunkpos94; + goto l92; + l93: + G->pos= yypos93; G->thunkpos= yythunkpos93; } yyprintfokrule("expression"); return 1; - l92: + l91: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("expression"); return 0; @@ -1429,11 +1415,11 @@ YY_RULE(int) yy_EQUAL(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "EQUAL")); - if (!yymatchChar(G, '=')) goto l95; - if (!yy__(G)) goto l95; + if (!yymatchChar(G, '=')) goto l94; + if (!yy__(G)) goto l94; yyprintfokrule("EQUAL"); return 1; - l95: + l94: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("EQUAL"); return 0; @@ -1446,34 +1432,34 @@ YY_RULE(int) yy_identifier(GREG *G) { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l96; + if (!(YY_BEGIN)) goto l95; #undef yytext #undef yyleng } - 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", "-a-zA-Z_")) goto l96; + 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", "-a-zA-Z_")) goto l95; - l97: + l96: { - int yypos98= G->pos, yythunkpos98= 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", "-a-zA-Z_0-9")) goto l98; - goto l97; - l98: - G->pos= yypos98; G->thunkpos= yythunkpos98; + 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", "-a-zA-Z_0-9")) goto l97; + goto l96; + l97: + G->pos= yypos97; G->thunkpos= yythunkpos97; } yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l96; + if (!(YY_END)) goto l95; #undef yytext #undef yyleng } - if (!yy__(G)) goto l96; + if (!yy__(G)) goto l95; yyprintfokrule("identifier"); return 1; - l96: + l95: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("identifier"); return 0; @@ -1482,11 +1468,11 @@ YY_RULE(int) yy_RPERCENT(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "RPERCENT")); - if (!yymatchString(G, "%}")) goto l99; - if (!yy__(G)) goto l99; + if (!yymatchString(G, "%}")) goto l98; + if (!yy__(G)) goto l98; yyprintfokrule("RPERCENT"); return 1; - l99: + l98: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("RPERCENT"); return 0; @@ -1496,15 +1482,15 @@ YY_RULE(int) yy_end_of_file(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "end_of_file")); { - int yypos101= G->pos, yythunkpos101= G->thunkpos; - if (!yymatchDot(G)) goto l101; - goto l100; - l101: - G->pos= yypos101; G->thunkpos= yythunkpos101; + int yypos100= G->pos, yythunkpos100= G->thunkpos; + if (!yymatchDot(G)) goto l100; + goto l99; + l100: + G->pos= yypos100; G->thunkpos= yythunkpos100; } yyprintfvokrule("end_of_file"); return 1; - l100: + l99: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("end_of_file"); return 0; @@ -1513,30 +1499,30 @@ YY_RULE(int) yy_trailer(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "trailer")); - if (!yymatchString(G, "%%")) goto l102; + if (!yymatchString(G, "%%")) goto l101; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l102; + if (!(YY_BEGIN)) goto l101; #undef yytext #undef yyleng } - l103: + l102: { - int yypos104= G->pos, yythunkpos104= G->thunkpos; - if (!yymatchDot(G)) goto l104; - goto l103; - l104: - G->pos= yypos104; G->thunkpos= yythunkpos104; + 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); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l102; + if (!(YY_END)) goto l101; #undef yytext #undef yyleng } @@ -1544,7 +1530,7 @@ YY_RULE(int) yy_trailer(GREG *G) yyDo(G, yy_1_trailer, G->begin, G->end, "yy_1_trailer"); yyprintfokrule("trailer"); return 1; - l102: + l101: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("trailer"); return 0; @@ -1554,25 +1540,25 @@ YY_RULE(int) yy_definition(GREG *G) int yypos0= G->pos, yythunkpos0= G->thunkpos; yyDo(G, yyPush, 1, 0, "yyPush"); yyprintfv((stderr, "%s\n", "definition")); - if (!yy_identifier(G)) goto l105; + if (!yy_identifier(G)) goto l104; yyDo(G, yySet, -1, 0, "yySet identifier"); yyDo(G, yy_1_definition, G->begin, G->end, "yy_1_definition"); - if (!yy_EQUAL(G)) goto l105; - if (!yy_expression(G)) goto l105; + if (!yy_EQUAL(G)) goto l104; + if (!yy_expression(G)) goto l104; yyDo(G, yy_2_definition, G->begin, G->end, "yy_2_definition"); - l106: + l105: { - int yypos107= G->pos, yythunkpos107= G->thunkpos; - if (!yy_SEMICOLON(G)) goto l107; - goto l106; - l107: - G->pos= yypos107; G->thunkpos= yythunkpos107; + int yypos106= G->pos, yythunkpos106= G->thunkpos; + if (!yy_SEMICOLON(G)) goto l106; + goto l105; + l106: + G->pos= yypos106; G->thunkpos= yythunkpos106; } yyprintfokrule("definition"); yyDo(G, yyPop, 1, 0, "yyPop"); return 1; - l105: + l104: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("definition"); return 0; @@ -1581,46 +1567,46 @@ YY_RULE(int) yy_declaration(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "declaration")); - if (!yymatchString(G, "%{")) goto l108; + if (!yymatchString(G, "%{")) goto l107; yyText(G, G->begin, G->end); { #define yytext G->text #define yyleng G->textlen - if (!(YY_BEGIN)) goto l108; + if (!(YY_BEGIN)) goto l107; #undef yytext #undef yyleng } - l109: + l108: { - int yypos110= G->pos, yythunkpos110= G->thunkpos; + int yypos109= G->pos, yythunkpos109= G->thunkpos; { - int yypos111= G->pos, yythunkpos111= G->thunkpos; - if (!yymatchString(G, "%}")) goto l111; - goto l110; - l111: - G->pos= yypos111; G->thunkpos= yythunkpos111; + 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 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); { #define yytext G->text #define yyleng G->textlen - if (!(YY_END)) goto l108; + if (!(YY_END)) goto l107; #undef yytext #undef yyleng } - if (!yy_RPERCENT(G)) goto l108; + if (!yy_RPERCENT(G)) goto l107; yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration"); yyprintfokrule("declaration"); return 1; - l108: + l107: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("declaration"); return 0; @@ -1628,23 +1614,23 @@ YY_RULE(int) yy_declaration(GREG *G) YY_RULE(int) yy__(GREG *G) { yyprintfv((stderr, "%s\n", "_")); - l113: + l112: { - int yypos114= G->pos, yythunkpos114= G->thunkpos; + int yypos113= G->pos, yythunkpos113= G->thunkpos; { - int yypos115= G->pos, yythunkpos115= G->thunkpos; - if (!yy_space(G)) goto l116; - goto l115; - l116: - G->pos= yypos115; G->thunkpos= yythunkpos115; - if (!yy_comment(G)) goto l114; + 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; } - l115: - ; - goto l113; l114: - G->pos= yypos114; G->thunkpos= yythunkpos114; + ; + goto l112; + l113: + G->pos= yypos113; G->thunkpos= yythunkpos113; } yyprintfvokrule("_"); return 1; @@ -1653,50 +1639,50 @@ YY_RULE(int) yy_grammar(GREG *G) { int yypos0= G->pos, yythunkpos0= G->thunkpos; yyprintfv((stderr, "%s\n", "grammar")); - if (!yy__(G)) goto l117; + if (!yy__(G)) goto l116; { - int yypos120= G->pos, yythunkpos120= G->thunkpos; - if (!yy_declaration(G)) goto l121; - goto l120; - l121: - G->pos= yypos120; G->thunkpos= yythunkpos120; - if (!yy_definition(G)) goto l117; + 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; } - l120: + l119: ; - l118: + l117: { - int yypos119= G->pos, yythunkpos119= G->thunkpos; + int yypos118= G->pos, yythunkpos118= G->thunkpos; { - int yypos122= G->pos, yythunkpos122= G->thunkpos; - if (!yy_declaration(G)) goto l123; - goto l122; - l123: - G->pos= yypos122; G->thunkpos= yythunkpos122; - if (!yy_definition(G)) goto l119; + 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; } - l122: + l121: ; - goto l118; - l119: - G->pos= yypos119; G->thunkpos= yythunkpos119; + goto l117; + l118: + G->pos= yypos118; G->thunkpos= yythunkpos118; } - l124: + l123: { - int yypos125= G->pos, yythunkpos125= G->thunkpos; - if (!yy_trailer(G)) goto l125; - goto l124; - l125: - G->pos= yypos125; G->thunkpos= yythunkpos125; + int yypos124= G->pos, yythunkpos124= G->thunkpos; + if (!yy_trailer(G)) goto l124; + goto l123; + l124: + G->pos= yypos124; G->thunkpos= yythunkpos124; } - if (!yy_end_of_file(G)) goto l117; + if (!yy_end_of_file(G)) goto l116; yyprintfokrule("grammar"); return 1; - l117: + l116: G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfvfailrule("grammar"); return 0; @@ -1859,10 +1845,8 @@ int main(int argc, char **argv) G = yyparse_new(NULL); #ifdef YY_DEBUG - if (verboseFlag > 0) { - yydebug = YYDEBUG_PARSE; - if (verboseFlag > 1) - yydebug = YYDEBUG_PARSE + YYDEBUG_VERBOSE; + if (verboseFlag > 0) { yydebug = YYDEBUG_PARSE; + if (verboseFlag > 1) yydebug = YYDEBUG_PARSE + YYDEBUG_VERBOSE; } #endif diff --git a/greg.g b/greg.g index 7112848..3bbb758 100644 --- a/greg.g +++ b/greg.g @@ -18,7 +18,7 @@ # # THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. # -# Last edited: 2013-04-11 15:58:07 rurban +# Last edited: 2013-10-01 11:36:41 rurban %{ # include "greg.h" @@ -71,9 +71,12 @@ definition= s:identifier { if (push(beginRule(findRule(yytext, s)))->rule.ex expression= sequence (BAR sequence { Node *f= pop(); push(Alternate_append(pop(), f)); } )* -sequence= prefix (prefix { Node *f= pop(); push(Sequence_append(pop(), f)); } +sequence= error (error { Node *f= pop(); push(Sequence_append(pop(), f)); } )* +error= prefix (TILDE action { push(makeError(pop(), yytext)); } + )? + prefix= AND action { push(makePredicate(yytext)); } | AND suffix { push(makePeekFor(pop())); } | NOT suffix { push(makePeekNot(pop())); } @@ -84,8 +87,7 @@ suffix= primary (QUESTION { push(makeQuery(pop())); } | PLUS { push(makePlus (pop())); } )? -primary= ( - identifier { push(makeVariable(yytext)); } +primary= identifier { push(makeVariable(yytext)); } COLON identifier !EQUAL { Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); } | identifier !EQUAL { push(makeName(findRule(yytext, 0))); } | OPEN expression CLOSE @@ -95,7 +97,6 @@ primary= ( | action { push(makeAction(yytext)); } | BEGIN { push(makePredicate("YY_BEGIN")); } | END { push(makePredicate("YY_END")); } - ) (errblock { Node *node = pop(); ((struct Any *) node)->errblock = strdup(yytext); push(node); })? # Lexical syntax @@ -108,7 +109,7 @@ class= '[' < ( !']' range )* > ']' - range= char '-' char | char -char= '\\' [abefnrtv'"\[\]\\] +char= '\\' [-abefnrtv'"\[\]\\] | '\\' 'x'[0-9A-Fa-f][0-9A-Fa-f] | '\\' 'x'[0-9A-Fa-f] | '\\' [0-3][0-7][0-7] @@ -116,7 +117,6 @@ char= '\\' [abefnrtv'"\[\]\\] | !'\\' . -errblock= '~{' < braces* > '}' - action= '{' < braces* > '}' - braces= '{' braces* '}' @@ -136,6 +136,7 @@ CLOSE= ')' - DOT= '.' - BEGIN= '<' - END= '>' - +TILDE= '~' - RPERCENT= '%}' - -= (space | comment)* @@ -223,10 +224,8 @@ int main(int argc, char **argv) G = yyparse_new(NULL); #ifdef YY_DEBUG - if (verboseFlag > 0) { - yydebug = YYDEBUG_PARSE; - if (verboseFlag > 1) - yydebug = YYDEBUG_PARSE + YYDEBUG_VERBOSE; + if (verboseFlag > 0) { yydebug = YYDEBUG_PARSE; + if (verboseFlag > 1) yydebug = YYDEBUG_PARSE + YYDEBUG_VERBOSE; } #endif diff --git a/greg.h b/greg.h index 5c90490..43b2482 100644 --- a/greg.h +++ b/greg.h @@ -28,7 +28,7 @@ #define GREG_MINOR 4 #define GREG_LEVEL 5 -typedef enum { Freed = -1, Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Predicate, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus, Any } NodeType; +typedef enum { Freed = -1, Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Predicate, Error, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus, Any } NodeType; enum { RuleUsed = 1<<0, @@ -37,7 +37,7 @@ enum { typedef union Node Node; -#define NODE_COMMON NodeType type; Node *next; char *errblock +#define NODE_COMMON NodeType type; Node *next struct Rule { NODE_COMMON; char *name; Node *variables; Node *expression; int id; int flags; }; struct Variable { NODE_COMMON; char *name; Node *value; int offset; }; struct Name { NODE_COMMON; Node *rule; Node *variable; }; @@ -47,6 +47,7 @@ struct String { NODE_COMMON; char *value; }; struct Class { NODE_COMMON; unsigned char *value; }; struct Action { NODE_COMMON; char *text; Node *list; char *name; Node *rule; }; struct Predicate { NODE_COMMON; char *text; }; +struct Error { NODE_COMMON; Node *element; char *text; }; struct Alternate { NODE_COMMON; Node *first; Node *last; }; struct Sequence { NODE_COMMON; Node *first; Node *last; }; struct PeekFor { NODE_COMMON; Node *element; }; @@ -69,6 +70,7 @@ union Node struct Class cclass; struct Action action; struct Predicate predicate; + struct Error error; struct Alternate alternate; struct Sequence sequence; struct PeekFor peekFor; @@ -100,6 +102,7 @@ extern Node *makeString(char *text); extern Node *makeClass(char *text); extern Node *makeAction(char *text); extern Node *makePredicate(char *text); +extern Node *makeError(Node *e, char *text); extern Node *makeAlternate(Node *e); extern Node *Alternate_append(Node *e, Node *f); extern Node *makeSequence(Node *e); diff --git a/samples/erract.leg b/samples/erract.leg new file mode 100644 index 0000000..4e61205 --- /dev/null +++ b/samples/erract.leg @@ -0,0 +1,14 @@ +Expr = a:NUMBER PLUS ~{ printf("fail at PLUS\n") } b:NUMBER { printf("got addition\n"); } + | ( a:NUMBER MINUS b:NUMBER { printf("got subtraction\n"); } ) ~{ printf("fail at subtraction\n") } + | a:NUMBER TIMES b:NUMBER { printf("got multiplication\n"); } + | a:NUMBER DIVIDE b:NUMBER { printf("got division\n"); } + +NUMBER = < [0-9]+ > - { $$= atoi(yytext); } +PLUS = '+' - +MINUS = '-' - +TIMES = '*' - +DIVIDE = '/' - + +- = (SPACE | EOL)* +SPACE = [ \t] +EOL = '\n' | '\r\n' | '\r' | ';' diff --git a/samples/erract.ref b/samples/erract.ref new file mode 100644 index 0000000..338ffcf --- /dev/null +++ b/samples/erract.ref @@ -0,0 +1,4 @@ +fail at PLUS +fail at subtraction +got multiplication +fail at subtraction diff --git a/tree.c b/tree.c index 6642931..4e1c55b 100644 --- a/tree.c +++ b/tree.c @@ -38,7 +38,6 @@ static inline Node *_newNode(int type, int size) { Node *node= calloc(1, size); node->type= type; - ((struct Any *) node)->errblock= NULL; return node; } @@ -163,6 +162,14 @@ Node *makePredicate(char *text) return node; } +Node *makeError(Node *e, char *text) +{ + Node *node= newNode(Error); + node->error.element= e; + node->error.text= strdup(text); + return node; +} + Node *makeAlternate(Node *e) { if (Alternate != e->type) @@ -306,6 +313,7 @@ static void Node_fprint(FILE *stream, Node *node) case Class: fprintf(stream, " [%s]", node->cclass.value); break; case Action: fprintf(stream, " { %s }", node->action.text); break; case Predicate: fprintf(stream, " ?{ %s }", node->action.text); break; + case Error: fprintf(stream, " ~{ %s }", node->error.text); break; case Alternate: node= node->alternate.first; fprintf(stream, " ("); @@ -368,6 +376,7 @@ void Rule_free(Node *node) case Class: free(node->cclass.value); break; case Action: free(node->action.text); free(node->action.name); break; case Predicate: free(node->predicate.text); break; + case Error: free(node->error.text); break; case Alternate: { Node *root= node; @@ -404,9 +413,7 @@ void Rule_free(Node *node) return; } assert(node); - node->type = -1; - if (((struct Any *)node)->errblock) - free(((struct Any *)node)->errblock); + node->type = Freed; free(node); } From 859134b313c0d0a00356cf1bf7e7cade175b1d34 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 1 Oct 2013 12:04:51 -0500 Subject: [PATCH 09/13] use C89 escape for ESC from git-svn-id: http://piumarta.com/svn2/peg/trunk@52 4d4069a9-7f2f-0410-87d9-cbc5f9740c0a --- compile.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compile.c b/compile.c index 226e495..23f9a7e 100644 --- a/compile.c +++ b/compile.c @@ -71,14 +71,14 @@ static int readChar(unsigned char **cp) { switch (c= *cclass++) { - case 'a': c= '\a'; break; /* bel */ - case 'b': c= '\b'; break; /* bs */ - case 'e': c= '\e'; break; /* esc */ - case 'f': c= '\f'; break; /* ff */ - case 'n': c= '\n'; break; /* nl */ - case 'r': c= '\r'; break; /* cr */ - case 't': c= '\t'; break; /* ht */ - case 'v': c= '\v'; break; /* vt */ + case 'a': c= '\a'; break; /* bel */ + case 'b': c= '\b'; break; /* bs */ + case 'e': c= '\033'; break; /* esc */ + case 'f': c= '\f'; break; /* ff */ + case 'n': c= '\n'; break; /* nl */ + case 'r': c= '\r'; break; /* cr */ + case 't': c= '\t'; break; /* ht */ + case 'v': c= '\v'; break; /* vt */ case 'x': c= 0; if (higit(*cclass)) c= (c << 4) + hexval(*cclass++); From c4f849436e21f57accf661c790267cfe199ae673 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 1 Oct 2013 12:07:39 -0500 Subject: [PATCH 10/13] greg 0.4.5: enclose user actions in braces to allow local variables to be declared in C89 from git-svn-id: http://piumarta.com/svn2/peg/trunk@51 4d4069a9-7f2f-0410-87d9-cbc5f9740c0a This is now matching peg-0.1.13 --- compile.c | 4 ++- greg.c | 88 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/compile.c b/compile.c index 23f9a7e..7fe1ee3 100644 --- a/compile.c +++ b/compile.c @@ -1033,7 +1033,9 @@ void Rule_compile_c(Node *node) tmp = yyqq(block); fprintf(output, " yyprintf((stderr, \"\\n {%s}\\n\"));\n", tmp); if (tmp != block) YY_FREE(tmp); - fprintf(output, " %s;\n", block); + fprintf(output, " {\n"); + fprintf(output, " %s;\n", block); + fprintf(output, " }\n"); undefineVariables(n->action.rule->rule.variables); fprintf(output, "}\n"); } diff --git a/greg.c b/greg.c index 3a3bfe0..9b57a56 100644 --- a/greg.c +++ b/greg.c @@ -463,126 +463,162 @@ YY_ACTION(void) yy_9_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, yyprintf((stderr, "do yy_9_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makePredicate(\"YY_END\")); }\n")); - push(makePredicate("YY_END")); ; + { + push(makePredicate("YY_END")); ; + } } YY_ACTION(void) yy_8_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_8_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makePredicate(\"YY_BEGIN\")); }\n")); - push(makePredicate("YY_BEGIN")); ; + { + push(makePredicate("YY_BEGIN")); ; + } } YY_ACTION(void) yy_7_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_7_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeAction(yytext)); }\n")); - push(makeAction(yytext)); ; + { + push(makeAction(yytext)); ; + } } YY_ACTION(void) yy_6_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_6_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeDot()); }\n")); - push(makeDot()); ; + { + push(makeDot()); ; + } } YY_ACTION(void) yy_5_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_5_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeClass(yytext)); }\n")); - push(makeClass(yytext)); ; + { + push(makeClass(yytext)); ; + } } YY_ACTION(void) yy_4_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_4_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeString(yytext)); }\n")); - push(makeString(yytext)); ; + { + push(makeString(yytext)); ; + } } YY_ACTION(void) yy_3_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_3_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeName(findRule(yytext, 0))); }\n")); - push(makeName(findRule(yytext, 0))); ; + { + push(makeName(findRule(yytext, 0))); ; + } } YY_ACTION(void) yy_2_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); }\n")); - Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); ; + { + Node *name= makeName(findRule(yytext, 0)); name->name.variable= pop(); push(name); ; + } } YY_ACTION(void) yy_1_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_primary")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeVariable(yytext)); }\n")); - push(makeVariable(yytext)); ; + { + push(makeVariable(yytext)); ; + } } YY_ACTION(void) yy_3_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_3_suffix")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makePlus (pop())); }\n")); - push(makePlus (pop())); ; + { + push(makePlus (pop())); ; + } } YY_ACTION(void) yy_2_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_suffix")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeStar (pop())); }\n")); - push(makeStar (pop())); ; + { + push(makeStar (pop())); ; + } } YY_ACTION(void) yy_1_suffix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_suffix")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeQuery(pop())); }\n")); - push(makeQuery(pop())); ; + { + push(makeQuery(pop())); ; + } } YY_ACTION(void) yy_3_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_3_prefix")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makePeekNot(pop())); }\n")); - push(makePeekNot(pop())); ; + { + push(makePeekNot(pop())); ; + } } YY_ACTION(void) yy_2_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_2_prefix")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makePeekFor(pop())); }\n")); - push(makePeekFor(pop())); ; + { + push(makePeekFor(pop())); ; + } } YY_ACTION(void) yy_1_prefix(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_prefix")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makePredicate(yytext)); }\n")); - push(makePredicate(yytext)); ; + { + push(makePredicate(yytext)); ; + } } YY_ACTION(void) yy_1_error(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_error")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {push(makeError(pop(), yytext)); }\n")); - push(makeError(pop(), yytext)); ; + { + push(makeError(pop(), yytext)); ; + } } YY_ACTION(void) yy_1_sequence(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_sequence")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {Node *f= pop(); push(Sequence_append(pop(), f)); }\n")); - Node *f= pop(); push(Sequence_append(pop(), f)); ; + { + 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) { yyprintf((stderr, "do yy_1_expression")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {Node *f= pop(); push(Alternate_append(pop(), f)); }\n")); - Node *f= pop(); push(Alternate_append(pop(), f)); ; + { + 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) { @@ -590,7 +626,9 @@ YY_ACTION(void) yy_2_definition(GREG *G, char *yytext, int yyleng, yythunk *thun yyprintf((stderr, "do yy_2_definition")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {Node *e= pop(); Rule_setExpression(pop(), e); }\n")); - Node *e= pop(); Rule_setExpression(pop(), e); ; + { + Node *e= pop(); Rule_setExpression(pop(), e); ; + } #undef s } YY_ACTION(void) yy_1_definition(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) @@ -600,8 +638,10 @@ YY_ACTION(void) yy_1_definition(GREG *G, char *yytext, int yyleng, yythunk *thun yyprintfvTcontext(yytext); yyprintf((stderr, "\n {if (push(beginRule(findRule(yytext, s)))->rule.expression)\n\ \t\t\t\t\t\t\t fprintf(stderr, \"rule '%%s' redefined\\n\", yytext); }\n")); - if (push(beginRule(findRule(yytext, s)))->rule.expression) + { + if (push(beginRule(findRule(yytext, s)))->rule.expression) fprintf(stderr, "rule '%s' redefined\n", yytext); ; + } #undef s } YY_ACTION(void) yy_1_trailer(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) @@ -609,14 +649,18 @@ YY_ACTION(void) yy_1_trailer(GREG *G, char *yytext, int yyleng, yythunk *thunk, yyprintf((stderr, "do yy_1_trailer")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {makeTrailer(yytext); }\n")); - makeTrailer(yytext); ; + { + makeTrailer(yytext); ; + } } YY_ACTION(void) yy_1_declaration(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR) { yyprintf((stderr, "do yy_1_declaration")); yyprintfvTcontext(yytext); yyprintf((stderr, "\n {makeHeader(yytext); }\n")); - makeHeader(yytext); ; + { + makeHeader(yytext); ; + } } YY_RULE(int) yy_end_of_line(GREG *G) From 6f038eba93df8471cc3328b5fba8eb5fdfba7846 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Wed, 2 Oct 2013 14:05:27 -0500 Subject: [PATCH 11/13] DD_CYCLE: more cyclic data, DEBUG print, add define/undef helpers --- compile.c | 16 ++++++-------- tree.c | 66 +++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/compile.c b/compile.c index 7fe1ee3..d103f40 100644 --- a/compile.c +++ b/compile.c @@ -189,6 +189,8 @@ static char *makeCharClass(unsigned char *cclass) static void nl(void) { fprintf(output, "\n"); } static void pindent(void) { fprintf(output, "%*s", 2*indent, ""); } static void begin(void) { indent++; pindent(); fprintf(output, "{"); } +static void define(const char* const def, const char* const v) { pindent(); fprintf(output, " #define %s %s\n", def, v); } +static void undef(const char* const def) { pindent(); fprintf(output, " #undef %s\n", def); } static void save(int n) { nl(); pindent(); fprintf(output, " int yypos%d= G->pos, yythunkpos%d= G->thunkpos;\n", n, n); } static void label(int n) { nl(); pindent(); fprintf(output, " l%d:\n", n); } /* Note: ensure that there is an expr following */ static void jump(int n) { pindent(); fprintf(output, " goto l%d;", n); } @@ -255,11 +257,9 @@ static void Node_compile_c_ko(Node *node, int ko) case Predicate: pindent(); fprintf(output, " yyText(G, G->begin, G->end);\n"); begin(); nl(); - pindent(); fprintf(output, " #define yytext G->text\n"); - pindent(); fprintf(output, " #define yyleng G->textlen\n"); + define("yytext", "G->text"); define("yyleng", "G->textlen"); pindent(); fprintf(output, " if (!(%s)) goto l%d;\n", node->action.text, ko); - pindent(); fprintf(output, " #undef yytext\n"); - pindent(); fprintf(output, " #undef yyleng\n"); + undef("yytext"); undef("yyleng"); end(); nl(); break; @@ -272,11 +272,9 @@ static void Node_compile_c_ko(Node *node, int ko) label(eko); pindent(); fprintf(output, " yyText(G, G->begin, G->end);\n"); begin(); nl(); - pindent(); fprintf(output, " #define yytext G->text\n"); - pindent(); fprintf(output, " #define yyleng G->textlen\n"); + define("yytext", "G->text"); define("yyleng", "G->textlen"); pindent(); fprintf(output, " %s;\n", node->error.text); - pindent(); fprintf(output, " #undef yytext\n"); - pindent(); fprintf(output, " #undef yyleng\n"); + undef("yytext"); undef("yyleng"); end(); nl(); jump(ko); label(eok); @@ -411,7 +409,7 @@ static void undefineVariables(Node *node) { while (node) { - pindent(); fprintf(output, " #undef %s\n", node->variable.name); + undef(node->variable.name); node= node->variable.next; } } diff --git a/tree.c b/tree.c index 4e1c55b..a35a4e2 100644 --- a/tree.c +++ b/tree.c @@ -1,4 +1,5 @@ /* Copyright (c) 2007 by Ian Piumarta + * Copyright (c) 2013 by perl11 org * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -13,7 +14,7 @@ * * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. * - * Last edited: 2007-05-15 10:32:09 by piumarta on emilia + * Last edited: 2013-10-01 12:19:49 rurban */ #include @@ -34,7 +35,7 @@ int actionCount= 0; int ruleCount= 0; int lastToken= -1; -static inline Node *_newNode(int type, int size) +static inline Node *_newNode(NodeType type, int size) { Node *node= calloc(1, size); node->type= type; @@ -304,6 +305,7 @@ static void Node_fprint(FILE *stream, Node *node) assert(node); switch (node->type) { + case Freed: return; case Rule: fprintf(stream, " %s", node->rule.name); break; case Variable: fprintf(stream, " %s", node->variable.name); break; case Name: fprintf(stream, " %s", node->name.rule->rule.name); break; @@ -363,28 +365,46 @@ void Rule_print(Node *node) { Rule_fprint(stderr, node); } void Rule_free(Node *node) { - FILE *stream = stderr; switch (node->type) { - case -1: return; - case Rule: free(node->rule.name); break; - case Name: free(node->name.rule->rule.name); break; + case Freed: return; + case Rule: + { + Node *var= node->rule.variables; +#ifdef DEBUG + //Rule_print(node); + fprintf(stderr, "free Rule %s.%d\n", node->rule.name, node->rule.id); +#endif + free(node->rule.name); + while (var) { + Node *tmp= var->any.next; Rule_free(var); var= tmp; + } + if (node->rule.expression) + Rule_free(node->rule.expression); + break; + } + case Name: break; case Variable: free(node->variable.name); break; case Dot: break; case Character: free(node->character.value); break; case String: free(node->string.value); break; case Class: free(node->cclass.value); break; - case Action: free(node->action.text); free(node->action.name); break; + case Action: +#ifdef DEBUG + fprintf(stderr, "free Action %s\n", node->action.name); +#endif + free(node->action.text); free(node->action.name); break; case Predicate: free(node->predicate.text); break; case Error: free(node->error.text); break; case Alternate: { Node *root= node; +#ifdef DEBUG + fprintf(stderr, "free Alternate %p\n", node); +#endif node= node->alternate.first; while (node->any.next) { - Node *tmp= node->any.next; - Rule_free(node); - node= tmp; + Node *tmp= node->any.next; Rule_free(node); node= tmp; } Rule_free(node); node= root; @@ -393,11 +413,12 @@ void Rule_free(Node *node) case Sequence: { Node *root= node; +#ifdef DEBUG + fprintf(stderr, "free Sequence %p\n", node); +#endif node= node->sequence.first; while (node->any.next) { - Node *tmp= node->any.next; - Rule_free(node); - node= tmp; + Node *tmp= node->any.next; Rule_free(node); node= tmp; } Rule_free(node); node= root; @@ -409,12 +430,14 @@ void Rule_free(Node *node) case Star: break; case Plus: break; default: - fprintf(stream, "\nunknown node type %d\n", node->type); + fprintf(stderr, "\nunknown node type %d\n", node->type); return; } assert(node); node->type = Freed; +#ifndef DD_CYCLE free(node); +#endif } void freeRules (void) { @@ -432,4 +455,19 @@ void freeRules (void) { n= n->any.next; } } +#ifdef DD_CYCLE + for (n= rules; n; ) { + if (n->type == Freed) { + Node *tmp= n->any.next; + free(n); + if (tmp) + n= tmp->any.next; + else + n= NULL; + } + else { + n= n->any.next; + } + } +#endif } From 9a74d3e6f53f020207ee891356635da6fc713879 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Wed, 2 Oct 2013 14:13:00 -0500 Subject: [PATCH 12/13] -vv only checks for YYDEBUG_VERBOSE seperates -DP from -Dp in frontends (parser rules, from parser matches, from lexer matches) --- compile.c | 14 +++++++------- greg.c | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compile.c b/compile.c index d103f40..c206603 100644 --- a/compile.c +++ b/compile.c @@ -527,11 +527,11 @@ static char *preamble= "\ # ifndef YYDEBUG_VERBOSE\n\ # define YYDEBUG_VERBOSE 2\n\ # endif\n\ -# define yyprintf(args) if (yydebug & YYDEBUG_PARSE) fprintf args\n\ -# define yyprintfv(args) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) fprintf args\n\ -# define yyprintfGcontext if (yydebug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ -# define yyprintfvGcontext if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ -# define yyprintfvTcontext(text) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text)\n\ +# define yyprintf(args) if (yydebug & YYDEBUG_PARSE) fprintf args\n\ +# define yyprintfv(args) if (yydebug & YYDEBUG_VERBOSE) fprintf args\n\ +# define yyprintfGcontext if (yydebug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ +# define yyprintfvGcontext if (yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos)\n\ +# define yyprintfvTcontext(text) if (yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text)\n\ # define yyprintfokrule(rule) if (yydebug & YYDEBUG_PARSE) {\\\n\ if (G->buf[G->pos]) {\\\n\ fprintf(stderr, \" ok %s\", rule);\\\n\ @@ -540,7 +540,7 @@ static char *preamble= "\ } else {\\\n\ yyprintfv((stderr, \" ok %s @ \\\"\\\"\\n\", rule));\\\n\ }}\n\ -# define yyprintfvokrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\\\n\ +# define yyprintfvokrule(rule) if (yydebug & YYDEBUG_VERBOSE) {\\\n\ if (G->buf[G->pos]) {\\\n\ fprintf(stderr, \" ok %s\", rule);\\\n\ yyprintcontext(G,stderr,G->buf+G->pos);\\\n\ @@ -548,7 +548,7 @@ static char *preamble= "\ } else {\\\n\ yyprintfv((stderr, \" ok %s @ \\\"\\\"\\n\", rule));\\\n\ }}\n\ -# define yyprintfvfailrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\\\n\ +# define yyprintfvfailrule(rule) if (yydebug & YYDEBUG_VERBOSE) {\\\n\ fprintf(stderr, \" fail %s\", rule);\\\n\ yyprintcontext(G,stderr,G->buf+G->pos);\\\n\ fprintf(stderr, \"\\n\");\\\n\ diff --git a/greg.c b/greg.c index 9b57a56..b622441 100644 --- a/greg.c +++ b/greg.c @@ -92,11 +92,11 @@ int main()\n\ # ifndef YYDEBUG_VERBOSE # define YYDEBUG_VERBOSE 2 # endif -# define yyprintf(args) if (yydebug & YYDEBUG_PARSE) fprintf args -# define yyprintfv(args) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) fprintf args -# define yyprintfGcontext if (yydebug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos) -# define yyprintfvGcontext if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos) -# define yyprintfvTcontext(text) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text) +# define yyprintf(args) if (yydebug & YYDEBUG_PARSE) fprintf args +# define yyprintfv(args) if (yydebug & YYDEBUG_VERBOSE) fprintf args +# define yyprintfGcontext if (yydebug & YYDEBUG_PARSE) yyprintcontext(G,stderr,G->buf+G->pos) +# define yyprintfvGcontext if (yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,G->buf+G->pos) +# define yyprintfvTcontext(text) if (yydebug & YYDEBUG_VERBOSE) yyprintcontext(G,stderr,text) # define yyprintfokrule(rule) if (yydebug & YYDEBUG_PARSE) {\ if (G->buf[G->pos]) {\ fprintf(stderr, " ok %s", rule);\ @@ -105,7 +105,7 @@ int main()\n\ } else {\ yyprintfv((stderr, " ok %s @ \"\"\n", rule));\ }} -# define yyprintfvokrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\ +# define yyprintfvokrule(rule) if (yydebug & YYDEBUG_VERBOSE) {\ if (G->buf[G->pos]) {\ fprintf(stderr, " ok %s", rule);\ yyprintcontext(G,stderr,G->buf+G->pos);\ @@ -113,7 +113,7 @@ int main()\n\ } else {\ yyprintfv((stderr, " ok %s @ \"\"\n", rule));\ }} -# define yyprintfvfailrule(rule) if (yydebug & YYDEBUG_PARSE && yydebug & YYDEBUG_VERBOSE) {\ +# define yyprintfvfailrule(rule) if (yydebug & YYDEBUG_VERBOSE) {\ fprintf(stderr, " fail %s", rule);\ yyprintcontext(G,stderr,G->buf+G->pos);\ fprintf(stderr, "\n");\ From 937a9b1ab0f465e574caf8ee8945d390c0e274f4 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Wed, 2 Oct 2013 14:34:33 -0500 Subject: [PATCH 13/13] update README: equivalent to leg from peg-0.1.13 --- README | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README b/README index 9367857..746e4ad 100644 --- a/README +++ b/README @@ -1,12 +1,11 @@ -greg is a re-entrant peg/leg, with some bug fixes and enhancements. +greg is a re-entrant leg, with some bug fixes and enhancements. +This version is equivalent to leg from peg-0.1.13. greg derived from potion , -is used as perl5 and perl6 parser in -and in nagaqueen, an ooc grammar, used in rock, an ooc -compiler written in ooc, - - +is used as perl5 and perl6 parser in . +And in nagaqueen, an ooc grammar , +used in rock, an ooc compiler written in ooc . peg/leg is copyright (c) 2007 by Ian Piumarta released under an MIT license. as is greg.