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..39bc913 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,15 @@ -CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) -OFLAGS = -O3 -DNDEBUG +OFLAGS = -O3 -DNDEBUG -DYY_MAIN +CFLAGS = -g -Wall -Wno-unused-function $(OFLAGS) $(XFLAGS) #OFLAGS = -pg -OBJS = tree.o compile.o +SRCS = tree.c compile.c +SAMPLES = $(wildcard samples/*.leg) all : greg -greg : greg.o $(OBJS) - $(CC) $(CFLAGS) -o $@-new greg.o $(OBJS) - mv $@-new $@ +greg : greg.c $(SRCS) + $(CC) $(CFLAGS) -o $@-new greg.c $(SRCS) + cp $@-new $@ ROOT = PREFIX ?= /usr @@ -23,22 +24,23 @@ $(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) + $(MAKE) greg-new ./greg-new -o greg-new.c greg.g - $(CC) $(CFLAGS) -o greg-new greg-new.c $(OBJS) - mv greg-new.c greg.c - mv greg-new greg + $(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS) + 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 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 @@ -49,15 +51,36 @@ samples/calc.c: samples/calc.leg greg samples/calc: samples/calc.c $(CC) $(CFLAGS) -o $@ $< -test: samples/calc run - echo '21 * 2 + 0' | ./samples/calc | grep 42 +samples: ${SAMPLES:.leg=} greg + +%.c: %.leg + ./greg $< > $@ +.leg.c: + ./greg $< > $@ + +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 + echo '6*9' | samples/erract | tee samples/erract.out + diff samples/erract.out samples/erract.ref 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/README b/README index 932e8c4..746e4ad 100644 --- a/README +++ b/README @@ -1,11 +1,11 @@ -greg is a re-entrant peg/leg, with some bug fixes. +greg is a re-entrant leg, with some bug fixes and enhancements. +This version is equivalent to leg from peg-0.1.13. -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 . peg/leg is copyright (c) 2007 by Ian Piumarta released under an MIT license. as is greg. diff --git a/compile.c b/compile.c index f99f9f3..c206603 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-09-30 20:44:59 rurban */ #include @@ -22,6 +24,20 @@ #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; static int yyl(void) { @@ -29,48 +45,57 @@ static int yyl(void) 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); -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= '\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++); + 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; } @@ -80,9 +105,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 +115,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 +135,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 +148,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 +168,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,16 +186,16 @@ 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 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 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); } +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 Node_compile_c_ko(Node *node, int ko) { @@ -183,25 +208,22 @@ 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: - fprintf(output, " if (!yy_%s(G)) ", node->name.rule->rule.name); - if(((struct Any*) node)->errblock) { - fprintf(output, "{ "); - callErrBlock(node); - fprintf(output, " goto l%d; }\n", ko); - } else { - 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); } - if (node->name.variable) - 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) { @@ -219,107 +241,138 @@ 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); + { + 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) YY_FREE(tmp); + } break; case Action: - 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: - 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"); + begin(); nl(); + define("yytext", "G->text"); define("yyleng", "G->textlen"); + pindent(); fprintf(output, " if (!(%s)) goto l%d;\n", node->action.text, ko); + undef("yytext"); undef("yyleng"); + 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(); + define("yytext", "G->text"); define("yyleng", "G->textlen"); + pindent(); fprintf(output, " %s;\n", node->error.text); + undef("yytext"); undef("yyleng"); + end(); nl(); + jump(ko); + label(eok); + } 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); + pindent(); fprintf(output, " ;\n"); } 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 again= yyl(), out= yyl(); + begin(); + save(out); + Node_compile_c_ko(node->query.element, out); + jump(again); + label(out); + restore(out); + end(); + label(again); + 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; @@ -346,7 +399,7 @@ 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; } @@ -356,7 +409,7 @@ static void undefineVariables(Node *node) { while (node) { - fprintf(output, "#undef %s\n", node->variable.name); + undef(node->variable.name); node= node->variable.next; } } @@ -374,7 +427,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)); @@ -384,20 +437,27 @@ 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\");", 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); 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, "\n return 0;"); + fprintf(output, " yyprintfvfailrule(\"%s\");\n", node->rule.name); + fprintf(output, " return 0;"); } fprintf(output, "\n}"); } @@ -406,21 +466,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\ @@ -442,55 +487,85 @@ 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 (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\ + 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_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_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\ # define yyprintfv(args)\n\ # 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\ +#define YYSTYPE int\n\ #endif\n\ #ifndef YY_XTYPE\n\ #define YY_XTYPE void *\n\ @@ -500,11 +575,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\ @@ -517,17 +592,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\ @@ -546,7 +624,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\ @@ -560,30 +638,68 @@ YY_LOCAL(int) yymatchDot(GREG *G)\n\ }\n\ \n\ #ifdef YY_DEBUG\n\ -YY_LOCAL(void) yyprintcontext(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\ +YY_LOCAL(void) yyerror(struct _GREG *G, char *message)\n\ +{\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\ + 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, \" at %s:%d\\n\", G->filename, G->lineno);\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\ 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\ @@ -617,10 +733,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\ @@ -639,7 +761,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\ @@ -664,13 +786,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\ @@ -704,6 +826,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\ @@ -714,12 +837,22 @@ 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\ +#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\ \n\ -#define YYACCEPT yyAccept(G, yythunkpos0)\n\ +#define YYACCEPT yyAccept(G, yythunkpos0)\n\ \n\ "; @@ -772,10 +905,23 @@ 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\ + 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\ {\n\ if (G->buf) YY_FREE(G->buf);\n\ @@ -783,13 +929,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\ @@ -815,50 +954,51 @@ 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 Error: return consumesInput(node->error.element); 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); @@ -882,13 +1022,18 @@ 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)); - fprintf(output, " %s;\n", block); + tmp = yyqq(block); + fprintf(output, " yyprintf((stderr, \"\\n {%s}\\n\"));\n", tmp); + if (tmp != block) YY_FREE(tmp); + 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 89df094..b622441 100644 --- a/greg.c +++ b/greg.c @@ -1,17 +1,14 @@ -/* A recursive-descent parser generated by greg 0.4.4 */ +/* A recursive-descent parser generated by greg 0.4.5 */ #include #include #include struct _GREG; -#define YYRULECOUNT 37 +#define YYRULECOUNT 38 # include "greg.h" -# include -# include # include -# include # include # include @@ -22,30 +19,26 @@ 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; + 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); - 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,55 +52,85 @@ 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 (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);\ + yyprintcontext(G,stderr,G->buf+G->pos);\ + fprintf(stderr, "\n");\ + } else {\ + yyprintfv((stderr, " ok %s @ \"\"\n", rule));\ + }} +# define yyprintfvokrule(rule) if (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_VERBOSE) {\ + fprintf(stderr, " fail %s", rule);\ + yyprintcontext(G,stderr,G->buf+G->pos);\ + fprintf(stderr, "\n");\ + } #else +# define yydebug 0 # define yyprintf(args) # define yyprintfv(args) # define yyprintfGcontext # define yyprintfvGcontext # define yyprintfvTcontext(text) +# define yyprintfokrule(rule) +# define yyprintfvokrule(rule) +# define yyprintfvfailrule(rule) #endif #ifndef YYSTYPE -#define YYSTYPE int +#define YYSTYPE int #endif #ifndef YY_XTYPE #define YY_XTYPE void * @@ -117,11 +140,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 +157,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 +189,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,30 +203,68 @@ YY_LOCAL(int) yymatchDot(GREG *G) } #ifdef YY_DEBUG -YY_LOCAL(void) yyprintcontext(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 +YY_LOCAL(void) yyerror(struct _GREG *G, char *message) +{ + fputs(message, stderr); + 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, " at %s:%d\n", G->filename, G->lineno); + exit(1); +} + 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));} @@ -234,10 +298,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)); @@ -256,7 +326,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 +351,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 +391,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,37 +402,48 @@ 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) { +#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 */ -#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 */ +#define YYACCEPT yyAccept(G, yythunkpos0) + +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 */ @@ -376,968 +458,1277 @@ 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")); 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))); ; + 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) { 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)); ; + } } 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) { -#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 + { + 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) { -#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) { 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) -{ 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")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + l2: + ; + yyprintfvokrule("end_of_line"); return 1; - l1:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "end_of_line")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l1: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("end_of_line"); 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; - yyprintf((stderr, " ok comment")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - + 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; + yyprintfvokrule("comment"); return 1; - l5:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "comment")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l5: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("comment"); 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")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + l10: + ; + yyprintfvokrule("space"); return 1; - l9:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "space")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l9: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("space"); 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; - } - l14:; yyprintf((stderr, " ok braces")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "braces")); + { + int yypos14= G->pos, yythunkpos14= G->thunkpos; + if (!yymatchChar(G, '{')) goto l15; - return 1; - l13:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "braces")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + l16: + { + int yypos17= G->pos, yythunkpos17= G->thunkpos; + if (!yy_braces(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 yypos18= G->pos, yythunkpos18= G->thunkpos; + if (!yymatchChar(G, '}')) goto l18; + goto l13; + l18: + G->pos= yypos18; G->thunkpos= yythunkpos18; + } + if (!yymatchDot(G)) goto l13; + } + l14: + ; + yyprintfokrule("braces"); + return 1; + l13: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("braces"); 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 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:; yyprintf((stderr, " ok range")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + l20: + ; + yyprintfokrule("range"); return 1; - l20:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "range")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l19: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("range"); 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; - } - l24:; yyprintf((stderr, " ok char")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - - return 1; - 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")); - if (!yymatchString(G, "~{")) goto l31; - yyText(G, G->begin, G->end); if (!(YY_BEGIN)) goto l31; - l32:; - { int yypos33= G->pos, yythunkpos33= G->thunkpos; if (!yy_braces(G)) goto l33; - goto l32; - l33:; G->pos= yypos33; G->thunkpos= yythunkpos33; - } yyText(G, G->begin, G->end); if (!(YY_END)) goto l31; if (!yymatchChar(G, '}')) goto l31; - if (!yy__(G)) goto l31; - yyprintf((stderr, " ok errblock")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "char")); + { + int yypos23= G->pos, yythunkpos23= G->thunkpos; + if (!yymatchChar(G, '\\')) 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; + if (!yymatchChar(G, '\\')) goto l25; + 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= 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; + goto l23; + l26: + G->pos= yypos23; G->thunkpos= yythunkpos23; + if (!yymatchChar(G, '\\')) goto l27; + 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= yypos23; G->thunkpos= yythunkpos23; + if (!yymatchChar(G, '\\')) 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; + + 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 (!yymatchChar(G, '\\')) goto l31; + goto l22; + l31: + G->pos= yypos31; G->thunkpos= yythunkpos31; + } + if (!yymatchDot(G)) goto l22; + } + l23: + ; + yyprintfokrule("char"); return 1; - l31:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "errblock")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l22: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("char"); 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 l34; - if (!yy__(G)) goto l34; - yyprintf((stderr, " ok END")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "END")); + if (!yymatchChar(G, '>')) goto l32; + if (!yy__(G)) goto l32; + yyprintfokrule("END"); return 1; - l34:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "END")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l32: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("END"); return 0; } 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; - yyprintf((stderr, " ok BEGIN")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "BEGIN")); + if (!yymatchChar(G, '<')) goto l33; + if (!yy__(G)) goto l33; + yyprintfokrule("BEGIN"); return 1; - l35:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "BEGIN")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l33: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("BEGIN"); return 0; } 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; - yyprintf((stderr, " ok DOT")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "DOT")); + if (!yymatchChar(G, '.')) goto l34; + if (!yy__(G)) goto l34; + yyprintfokrule("DOT"); return 1; - l36:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "DOT")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l34: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("DOT"); return 0; } YY_RULE(int) yy_class(GREG *G) -{ 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; - yyprintf((stderr, " ok class")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "class")); + if (!yymatchChar(G, '[')) goto l35; + yyText(G, G->begin, G->end); + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l35; + #undef yytext + #undef yyleng + } - return 1; - l37:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "class")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + l36: + { + int yypos37= G->pos, yythunkpos37= G->thunkpos; + { + 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 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 l35; + #undef yytext + #undef yyleng + } + + if (!yymatchChar(G, ']')) goto l35; + if (!yy__(G)) goto l35; + yyprintfokrule("class"); + return 1; + l35: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("class"); 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; - - } - l42:; yyprintf((stderr, " ok literal")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "literal")); + { + 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 l41; + #undef yytext + #undef yyleng + } - return 1; - l41:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "literal")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + l42: + { + int yypos43= G->pos, yythunkpos43= G->thunkpos; + { + 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 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 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 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 l39; + #undef yytext + #undef yyleng + } + + + l45: + { + int yypos46= G->pos, yythunkpos46= G->thunkpos; + { + 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 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 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 l39; + if (!yy__(G)) goto l39; + } + + l40: + ; + yyprintfokrule("literal"); + return 1; + l39: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("literal"); return 0; } 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; - yyprintf((stderr, " ok CLOSE")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "CLOSE")); + if (!yymatchChar(G, ')')) goto l48; + if (!yy__(G)) goto l48; + yyprintfokrule("CLOSE"); return 1; - l50:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "CLOSE")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l48: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("CLOSE"); return 0; } 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; - yyprintf((stderr, " ok OPEN")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "OPEN")); + if (!yymatchChar(G, '(')) goto l49; + if (!yy__(G)) goto l49; + yyprintfokrule("OPEN"); return 1; - l51:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "OPEN")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l49: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("OPEN"); return 0; } 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; - yyprintf((stderr, " ok COLON")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "COLON")); + if (!yymatchChar(G, ':')) goto l50; + if (!yy__(G)) goto l50; + yyprintfokrule("COLON"); return 1; - l52:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "COLON")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l50: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("COLON"); return 0; } 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; - yyprintf((stderr, " ok PLUS")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "PLUS")); + if (!yymatchChar(G, '+')) goto l51; + if (!yy__(G)) goto l51; + yyprintfokrule("PLUS"); return 1; - l53:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "PLUS")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l51: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("PLUS"); return 0; } 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; - yyprintf((stderr, " ok STAR")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "STAR")); + if (!yymatchChar(G, '*')) goto l52; + if (!yy__(G)) goto l52; + yyprintfokrule("STAR"); return 1; - l54:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "STAR")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l52: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("STAR"); return 0; } 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; - yyprintf((stderr, " ok QUESTION")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "QUESTION")); + if (!yymatchChar(G, '?')) goto l53; + if (!yy__(G)) goto l53; + yyprintfokrule("QUESTION"); return 1; - l55:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "QUESTION")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l53: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("QUESTION"); 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"); - - } - 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")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "primary")); + { + 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 l56; + if (!yy_identifier(G)) goto l56; + { + 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 l55; + l56: + G->pos= yypos55; G->thunkpos= yythunkpos55; + 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_3_primary, G->begin, G->end, "yy_3_primary"); + 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 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 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 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 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 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"); + } + l55: + ; + yyprintfokrule("primary"); return 1; - l56:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "primary")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l54: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("primary"); return 0; } 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; - yyprintf((stderr, " ok NOT")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "NOT")); + if (!yymatchChar(G, '!')) goto l66; + if (!yy__(G)) goto l66; + yyprintfokrule("NOT"); return 1; - l70:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "NOT")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l66: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("NOT"); 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 yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "suffix")); + if (!yy_primary(G)) goto l67; - { 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"); + l68: + { + int yypos69= G->pos, yythunkpos69= G->thunkpos; + { + 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 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 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"); + } + l70: + ; + goto l68; + l69: + G->pos= yypos69; G->thunkpos= yythunkpos69; } - l74:; goto l73; - l72:; G->pos= yypos72; G->thunkpos= yythunkpos72; - } - 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")); - + 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 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")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "action")); + if (!yymatchChar(G, '{')) goto l74; + yyText(G, G->begin, G->end); + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l74; + #undef yytext + #undef yyleng + } - return 1; - l77:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "action")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + l75: + { + 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 l74; + #undef yytext + #undef yyleng + } + + if (!yymatchChar(G, '}')) goto l74; + if (!yy__(G)) goto l74; + yyprintfokrule("action"); + return 1; + l74: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("action"); 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 l80; - if (!yy__(G)) goto l80; - yyprintf((stderr, " ok AND")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +YY_RULE(int) yy_TILDE(GREG *G) +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "TILDE")); + if (!yymatchChar(G, '~')) goto l77; + if (!yy__(G)) goto l77; + yyprintfokrule("TILDE"); return 1; - l80:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "AND")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l77: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("TILDE"); 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; - - } - l82:; yyprintf((stderr, " ok prefix")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "prefix")); + { + 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 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 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; + } + l79: + ; + yyprintfokrule("prefix"); return 1; - l81:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "prefix")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + 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")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "BAR")); if (!yymatchChar(G, '|')) goto l86; - if (!yy__(G)) goto l86; - yyprintf((stderr, " ok BAR")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - + if (!yy__(G)) goto l86; + yyprintfokrule("BAR"); return 1; - l86:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "BAR")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l86: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("BAR"); 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")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "sequence")); + if (!yy_error(G)) goto l87; + + l88: + { + 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 l88; + l89: + G->pos= yypos89; G->thunkpos= yythunkpos89; + } + yyprintfokrule("sequence"); return 1; - l87:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "sequence")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l87: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("sequence"); 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; - yyprintf((stderr, " ok SEMICOLON")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - + if (!yy__(G)) goto l90; + yyprintfokrule("SEMICOLON"); return 1; - l90:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "SEMICOLON")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l90: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("SEMICOLON"); 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")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + 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; + } + yyprintfokrule("expression"); return 1; - l91:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "expression")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l91: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("expression"); 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; - yyprintf((stderr, " ok EQUAL")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - + if (!yy__(G)) goto l94; + yyprintfokrule("EQUAL"); return 1; - l94:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "EQUAL")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l94: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("EQUAL"); 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; - yyprintf((stderr, " ok identifier")); - yyprintfGcontext; - yyprintf((stderr, "\n")); +{ + int yypos0= G->pos, yythunkpos0= G->thunkpos; + yyprintfv((stderr, "%s\n", "identifier")); + yyText(G, G->begin, G->end); + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l95; + #undef yytext + #undef yyleng + } - return 1; - l95:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "identifier")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + 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); + { + #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: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("identifier"); 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; - yyprintf((stderr, " ok RPERCENT")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - + if (!yy__(G)) goto l98; + yyprintfokrule("RPERCENT"); return 1; - l98:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "RPERCENT")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l98: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("RPERCENT"); 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")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - +{ + 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; + } + yyprintfvokrule("end_of_file"); return 1; - l99:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "end_of_file")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l99: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("end_of_file"); 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"); - yyprintf((stderr, " ok trailer")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyText(G, G->begin, G->end); + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l101; + #undef yytext + #undef yyleng + } - return 1; - l101:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "trailer")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + 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); + { + #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: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("trailer"); 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; - yyDo(G, yySet, -1, 0, "yySet"); + 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 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; + l105: + { + int yypos106= G->pos, yythunkpos106= G->thunkpos; + if (!yy_SEMICOLON(G)) goto l106; + goto l105; + l106: + G->pos= yypos106; G->thunkpos= yythunkpos106; } - 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")); - + l104: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("definition"); 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; - yyDo(G, yy_1_declaration, G->begin, G->end, "yy_1_declaration"); - yyprintf((stderr, " ok declaration")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + yyText(G, G->begin, G->end); + { + #define yytext G->text + #define yyleng G->textlen + if (!(YY_BEGIN)) goto l107; + #undef yytext + #undef yyleng + } - return 1; - l107:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "declaration")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); + 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); + { + #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; + l107: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("declaration"); 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 _")); - yyprintfGcontext; - yyprintf((stderr, "\n")); - + yyprintfvokrule("_"); 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; - } - l124:; if (!yy_end_of_file(G)) goto l116; - yyprintf((stderr, " ok grammar")); - yyprintfGcontext; - yyprintf((stderr, "\n")); + l123: + { + 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 l116; + yyprintfokrule("grammar"); return 1; - l116:; G->pos= yypos0; G->thunkpos= yythunkpos0; yyprintfv((stderr, " fail %s", "grammar")); - yyprintfvGcontext; - yyprintfv((stderr, "\n")); - + l116: + G->pos= yypos0; G->thunkpos= yythunkpos0; + yyprintfvfailrule("grammar"); return 0; } @@ -1388,10 +1779,23 @@ 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)); + memset(G, 0, sizeof(GREG)); + G->input= stdin; + G->lineno= 1; + G->filename= "-"; } + YY_PARSE(void) YY_NAME(deinit)(GREG *G) { if (G->buf) YY_FREE(G->buf); @@ -1399,13 +1803,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 +1812,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 +1838,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 +1854,6 @@ int main(int argc, char **argv) int c; output= stdout; - input= stdin; - lineNumber= 1; - fileName= ""; while (-1 != (c= getopt(argc, argv, "Vho:v"))) { @@ -1517,40 +1889,33 @@ int main(int argc, char **argv) G = yyparse_new(NULL); #ifdef YY_DEBUG - if (verboseFlag > 0) { - G->debug = DEBUG_PARSE; - if (verboseFlag > 1) - G->debug = DEBUG_PARSE + DEBUG_VERBOSE; + if (verboseFlag > 0) { yydebug = YYDEBUG_PARSE; + if (verboseFlag > 1) 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) @@ -1559,14 +1924,27 @@ 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) + if (rules) { Rule_compile_c(rules); + freeRules(); + } - if (trailer) - fprintf(output, "%s\n", trailer); + if (trailer) { + fputs(trailer, output); + fputs("\n", output); + free(trailer); + } + else + fputs(deftrailer, output); return 0; } diff --git a/greg.g b/greg.g index dc612fb..3bbb758 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-10-01 11:36:41 rurban %{ # include "greg.h" -# include -# include # include -# include # include # include @@ -34,29 +34,25 @@ Header *next; }; - FILE *input= 0; - int verboseFlag= 0; - static int lineNumber= 0; - static char *fileName= 0; 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); - - 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,17 +63,20 @@ 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)); } )* -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())); } @@ -88,10 +87,9 @@ suffix= primary (QUESTION { push(makeQuery(pop())); } | PLUS { push(makePlus (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))); } +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 | literal { push(makeString(yytext)); } | class { push(makeClass(yytext)); } @@ -99,29 +97,29 @@ 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 identifier= < [-a-zA-Z_][-a-zA-Z_0-9]* > - -literal= ['] < ( !['] char )* > ['] - +literal= ['] < ( !['] char )* > ['] - #' | ["] < ( !["] char )* > ["] - 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] | '\\' [0-7][0-7]? | !'\\' . -errblock= '~{' < braces* > '}' - action= '{' < braces* > '}' - -braces= '{' (!'}' .)* '}' +braces= '{' braces* '}' | !'}' . EQUAL= '=' - @@ -138,6 +136,7 @@ CLOSE= ')' - DOT= '.' - BEGIN= '<' - END= '>' - +TILDE= '~' - RPERCENT= '%}' - -= (space | comment)* @@ -148,31 +147,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 +173,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 +189,6 @@ int main(int argc, char **argv) int c; output= stdout; - input= stdin; - lineNumber= 1; - fileName= ""; while (-1 != (c= getopt(argc, argv, "Vho:v"))) { @@ -250,40 +224,33 @@ int main(int argc, char **argv) G = yyparse_new(NULL); #ifdef YY_DEBUG - if (verboseFlag > 0) { - G->debug = DEBUG_PARSE; - if (verboseFlag > 1) - G->debug = DEBUG_PARSE + DEBUG_VERBOSE; + if (verboseFlag > 0) { yydebug = YYDEBUG_PARSE; + if (verboseFlag > 1) 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) @@ -292,14 +259,27 @@ 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) + if (rules) { Rule_compile_c(rules); + freeRules(); + } - if (trailer) - fprintf(output, "%s\n", trailer); + if (trailer) { + fputs(trailer, output); + fputs("\n", output); + free(trailer); + } + else + fputs(deftrailer, output); return 0; } diff --git a/greg.h b/greg.h index e4a4ac5..43b2482 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,29 @@ * * 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 +#ifdef WIN32 +# undef inline +# define inline __inline +#endif -#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, Error, 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 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; }; @@ -41,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; }; @@ -53,24 +60,25 @@ 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 Error error; + 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 +89,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); @@ -94,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); @@ -112,3 +121,5 @@ 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/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..c22d625 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)) \ { \ @@ -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); 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; } 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/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/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 ") } ) diff --git a/tree.c b/tree.c index a64724d..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,11 +35,10 @@ 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; - ((struct Any *) node)->errblock= NULL; return node; } @@ -163,6 +163,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) @@ -297,7 +305,9 @@ 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; case Dot: fprintf(stream, " ."); break; case Character: fprintf(stream, " '%s'", node->character.value); break; @@ -305,6 +315,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, " ("); @@ -351,3 +362,112 @@ static void Rule_fprint(FILE *stream, Node *node) } void Rule_print(Node *node) { Rule_fprint(stderr, node); } + +void Rule_free(Node *node) +{ + switch (node->type) + { + 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: +#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; + } + Rule_free(node); + node= root; + break; + } + 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; + } + Rule_free(node); + node= root; + break; + } + case PeekFor: break; + case PeekNot: break; + case Query: break; + case Star: break; + case Plus: break; + default: + fprintf(stderr, "\nunknown node type %d\n", node->type); + return; + } + assert(node); + node->type = Freed; +#ifndef DD_CYCLE + free(node); +#endif +} + +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; + } + } +#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 +}