diff --git a/Makefile b/Makefile index 9263dd08..e5947569 100644 --- a/Makefile +++ b/Makefile @@ -174,6 +174,10 @@ core/potion.o: core/potion.c core/potion.h core/config.h core/internal.h \ core/opcodes.h core/khash.h core/table.h @${ECHO} CC $@ -O0 @${CC} -c ${CFLAGS} -O0 ${INCS} -o $@ $< +core/syntax.o: core/syntax.c core/potion.h core/config.h core/internal.h \ + core/asm.h core/ast.h tools/greg.h + @${ECHO} CC $@ + @${CC} -c ${CFLAGS} ${INCS} -Itools -o $@ $< ifneq (${FPIC},) core/callcc.${OPIC}: core/callcc.c core/potion.h core/config.h core/internal.h @${ECHO} CC $@ -O0 +frame-pointer @@ -182,6 +186,10 @@ core/potion.${OPIC}: core/potion.c core/potion.h core/config.h core/internal.h \ core/opcodes.h core/khash.h core/table.h @${ECHO} CC $@ -O0 @${CC} -c ${CFLAGS} -O0 ${FPIC} ${INCS} -o $@ $< +core/syntax.${OPIC}: core/syntax.c core/potion.h core/config.h core/internal.h \ + core/asm.h core/ast.h tools/greg.h + @${ECHO} CC $@ + @${CC} -c ${CFLAGS} ${FPIC} ${INCS} -Itools -o $@ $< endif core/potion.h: core/config.h @@ -259,7 +267,7 @@ endif ${GREG}: tools/greg.c tools/compile.c tools/tree.c @${ECHO} CC $@ - @${CC} ${GREGCFLAGS} -o $@ tools/greg.c tools/compile.c tools/tree.c -Itools + @${CC} ${GREGCFLAGS} -Itools -o $@ tools/greg.c tools/compile.c tools/tree.c bin/potion${EXE}: ${PIC_OBJ_POTION} lib/libpotion${DLL} @${ECHO} LINK $@ diff --git a/core/gc.c b/core/gc.c index d610985a..30e05050 100644 --- a/core/gc.c +++ b/core/gc.c @@ -14,6 +14,7 @@ by Basile Starynkevitch. #include "gc.h" #include "khash.h" #include "table.h" +#include "../tools/greg.h" #if defined(DEBUG) //mingw32 has struct timeval in sys/time.h @@ -133,6 +134,56 @@ static inline int NEW_BIRTH_REGION(struct PNMemory *M, void **wb, int sz) { return sz; } +void potion_gc_minor_parser(PN parser) { + if(parser == 0) + return; + + struct _GREG *G = (struct _GREG *)parser; + struct PNMemory *M = ((Potion *)G->data)->mem; + Potion *P = G->data; + + if(PN_IS_PTR(G->ss)) { + GC_MINOR_UPDATE(G->ss); + potion_mark_minor(G->data, (const struct PNObject *) G->ss); + } + if(PN_IS_PTR(G->val[0])) { + GC_MINOR_UPDATE(G->val[0]); + potion_mark_minor(G->data, (const struct PNObject *) G->val[0]); + } + int c = G->val - G->vals; + for(int i = 0; i < c; i++) { + if(PN_IS_PTR(G->vals[i])) { + GC_MINOR_UPDATE(G->vals[i]); + potion_mark_minor(G->data, (const struct PNObject *) G->vals[i]); + } + } +} + +void potion_gc_major_parser(PN parser) { + if(parser == 0) + return; + + struct _GREG *G = (struct _GREG *)parser; + struct PNMemory *M = ((Potion *)G->data)->mem; + Potion *P = G->data; + + if(PN_IS_PTR(G->ss)) { + GC_MAJOR_UPDATE(G->ss); + potion_mark_major(P, (const struct PNObject *) G->ss); + } + if(PN_IS_PTR(G->val[0])) { + GC_MAJOR_UPDATE(G->val[0]); + potion_mark_major(P, (const struct PNObject *) G->val[0]); + } + int c = G->val - G->vals; + for(int i = 0; i < c; i++) { + if(G->vals[i] != NULL && PN_IS_PTR(G->vals[i])) { + GC_MAJOR_UPDATE(G->vals[i]); + potion_mark_major(P, (const struct PNObject *) G->vals[i]); + } + } +} + /** \par Both this function and potion_gc_major embody a simple Cheney loop (also called a "two-finger collector.") @@ -161,6 +212,7 @@ static int potion_gc_minor(Potion *P, int sz) { potion_mark_stack(P, 1); GC_MINOR_STRINGS(); + potion_gc_minor_parser(P->parser); wb = (void **)M->birth_storeptr; for (storead = wb; storead < (void **)M->birth_hi; storead++) { @@ -239,6 +291,7 @@ static int potion_gc_major(Potion *P, int siz) { scanptr = 0; GC_MAJOR_STRINGS(); + potion_gc_minor_parser(P->parser); pngc_page_delete((void *)prevoldlo, (char *)prevoldhi - (char *)prevoldlo); prevoldlo = 0; diff --git a/core/potion.h b/core/potion.h index 008754eb..cc4aee50 100644 --- a/core/potion.h +++ b/core/potion.h @@ -653,7 +653,7 @@ struct Potion_State { int prec; ///< double precision //parser-only: - PN input, source; ///< parser input and output (AST) + PN input, source, parser;///< parser input and output (AST) int yypos; ///< parser buffer position PNAsm * volatile pbuf; ///< parser buffer PN line; ///< currently parsed line (for debug) diff --git a/core/syntax.y b/core/syntax.y index c77bc0f8..d9dc9277 100644 --- a/core/syntax.y +++ b/core/syntax.y @@ -387,6 +387,7 @@ PN potion_parse(Potion *P, PN code, char *filename) { P->yypos = 0; P->input = code; P->source = PN_NIL; + P->parser = (PN)G; P->pbuf = potion_asm_new(P); #ifdef YY_DEBUG yydebug = P->flags; @@ -449,6 +450,7 @@ PN potion_sig(Potion *P, char *fmt) { P->yypos = 0; P->input = potion_byte_str(P, fmt); P->source = out = PN_TUP0(); + P->parser = (PN)G; P->pbuf = NULL; #ifdef YY_DEBUG yydebug = P->flags; diff --git a/tools/compile.c b/tools/compile.c index 9d7e3596..5a0d103d 100644 --- a/tools/compile.c +++ b/tools/compile.c @@ -1,6 +1,6 @@ /* Copyright (c) 2007 by Ian Piumarta * Copyright (c) 2011 by Amos Wenger nddrylliog@gmail.com - * Copyright (c) 2013 by perl11 org + * Copyright (c) 2013,2019 by perl11 org * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -470,7 +470,7 @@ static char *header= "\ #include \n\ #include \n\ #include \n\ -struct _GREG;\n\ +#include \"greg.h\"\n\ "; static char *preamble= "\ @@ -564,12 +564,6 @@ static char *preamble= "\ # define yyprintfvokrule(rule)\n\ # define yyprintfvfailrule(rule)\n\ #endif\n\ -#ifndef YYSTYPE\n\ -#define YYSTYPE int\n\ -#endif\n\ -#ifndef YY_XTYPE\n\ -#define YY_XTYPE void *\n\ -#endif\n\ #ifndef YY_XVAR\n\ #define YY_XVAR yyxvar\n\ #endif\n\ @@ -586,35 +580,9 @@ static char *preamble= "\ #define yydata G->data\n\ #define yy G->ss\n\ \n\ -struct _yythunk; // forward declaration\n\ typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR);\n\ typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk;\n\ \n\ -typedef struct _GREG {\n\ - char *buf;\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\ - yythunk *thunks;\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\ - int valslen;\n\ - YY_XTYPE data;\n\ -#ifdef YY_DEBUG\n\ - int debug;\n\ -#endif\n\ -} GREG;\n\ \n\ YY_LOCAL(int) yyrefill(GREG *G)\n\ {\n\ @@ -925,7 +893,8 @@ YY_PARSE(void) YY_NAME(parse_free)(GREG *G)\n\ void Rule_compile_c_header(void) { - fprintf(output, "/* A recursive-descent parser generated by greg %d.%d.%d */\n", GREG_MAJOR, GREG_MINOR, GREG_LEVEL); + fprintf(output, "/* A recursive-descent parser generated by greg %d.%d.%d */\n", + GREG_MAJOR, GREG_MINOR, GREG_LEVEL); fprintf(output, "\n"); fprintf(output, "%s", header); fprintf(output, "#define YYRULECOUNT %d\n", ruleCount); diff --git a/tools/greg.c b/tools/greg.c index 390e8e7e..67b1bc0d 100644 --- a/tools/greg.c +++ b/tools/greg.c @@ -1,9 +1,8 @@ -/* A recursive-descent parser generated by greg 0.4.5 */ +/* A recursive-descent parser generated by greg 0.4.6 */ #include #include #include -struct _GREG; #define YYRULECOUNT 38 # include "greg.h" @@ -129,12 +128,6 @@ int main()\n\ # define yyprintfvokrule(rule) # define yyprintfvfailrule(rule) #endif -#ifndef YYSTYPE -#define YYSTYPE int -#endif -#ifndef YY_XTYPE -#define YY_XTYPE void * -#endif #ifndef YY_XVAR #define YY_XVAR yyxvar #endif @@ -151,35 +144,9 @@ int main()\n\ #define yydata G->data #define yy G->ss -struct _yythunk; // forward declaration typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR); typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk; -typedef struct _GREG { - char *buf; - int buflen; - int offset; - int pos; - int limit; - char *text; - int textlen; - int begin; - int end; - yythunk *thunks; - int thunkslen; - int thunkpos; - int lineno; - char *filename; - FILE *input; - YYSTYPE ss; - YYSTYPE *val; - YYSTYPE *vals; - int valslen; - YY_XTYPE data; -#ifdef YY_DEBUG - int debug; -#endif -} GREG; YY_LOCAL(int) yyrefill(GREG *G) { @@ -284,7 +251,7 @@ YY_LOCAL(int) yymatchString(GREG *G, const char *s) return 1; } -YY_LOCAL(int) yymatchClass(GREG *G, const unsigned char *bits, char *cclass) +YY_LOCAL(int) yymatchClass(GREG *G, unsigned char *bits, char *cclass) { int c; if (G->pos >= G->limit && !yyrefill(G)) return 0; @@ -799,35 +766,35 @@ YY_RULE(int) yy_char(GREG *G) { int yypos23= G->pos, yythunkpos23= G->thunkpos; if (!yymatchChar(G, '\\')) goto l24; - if (!yymatchClass(G, (const 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; + 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, (const 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, (const 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; + 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, (const unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l26; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\003\176\000\000\000\176\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-9A-Fa-f")) goto l26; goto l23; l26: G->pos= yypos23; G->thunkpos= yythunkpos23; if (!yymatchChar(G, '\\')) goto l27; - if (!yymatchClass(G, (const 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, (const 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, (const 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\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, (const unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-7")) goto l28; + if (!yymatchClass(G, (unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "0-7")) goto l28; { int yypos30= G->pos, yythunkpos30= G->thunkpos; - if (!yymatchClass(G, (const 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; + 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; @@ -950,7 +917,7 @@ YY_RULE(int) yy_literal(GREG *G) yyprintfv((stderr, "%s\n", "literal")); { int yypos40= G->pos, yythunkpos40= G->thunkpos; - if (!yymatchClass(G, (const 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 (!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 @@ -966,7 +933,7 @@ YY_RULE(int) yy_literal(GREG *G) int yypos43= G->pos, yythunkpos43= G->thunkpos; { int yypos44= G->pos, yythunkpos44= G->thunkpos; - if (!yymatchClass(G, (const unsigned char *)"\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", "'")) goto l44; + if (!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; @@ -985,12 +952,12 @@ YY_RULE(int) yy_literal(GREG *G) #undef yyleng } - if (!yymatchClass(G, (const 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 (!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, (const 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 (!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 @@ -1006,7 +973,7 @@ YY_RULE(int) yy_literal(GREG *G) int yypos46= G->pos, yythunkpos46= G->thunkpos; { int yypos47= G->pos, yythunkpos47= G->thunkpos; - if (!yymatchClass(G, (const 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; + 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; @@ -1025,7 +992,7 @@ YY_RULE(int) yy_literal(GREG *G) #undef yyleng } - if (!yymatchClass(G, (const 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 (!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; } @@ -1469,12 +1436,12 @@ YY_RULE(int) yy_identifier(GREG *G) #undef yyleng } - if (!yymatchClass(G, (const 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; + 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, (const 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; + 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; @@ -1729,18 +1696,19 @@ typedef int (*yyrule)(GREG *G); YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart) { int yyok; - if (!G->buflen) { - G->buflen= YY_BUFFER_START_SIZE; - G->buf= (char*)YY_ALLOC(G->buflen, G->data); - G->textlen= YY_BUFFER_START_SIZE; - G->text= (char*)YY_ALLOC(G->textlen, G->data); - G->thunkslen= YY_STACK_SIZE; - G->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * G->thunkslen, G->data); - G->valslen= YY_STACK_SIZE; - G->vals= (YYSTYPE*)YY_ALLOC(sizeof(YYSTYPE) * G->valslen, G->data); - G->begin= G->end= G->pos= G->limit= G->thunkpos= 0; - } - G->pos= 0; + if (!G->buflen) + { + G->buflen= YY_BUFFER_START_SIZE; + G->buf= (char*)YY_ALLOC(G->buflen, G->data); + G->textlen= YY_BUFFER_START_SIZE; + G->text= (char*)YY_ALLOC(G->textlen, G->data); + G->thunkslen= YY_STACK_SIZE; + G->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * G->thunkslen, G->data); + G->valslen= YY_STACK_SIZE; + G->vals= (YYSTYPE*)YY_ALLOC(sizeof(YYSTYPE) * G->valslen, G->data); + G->begin= G->end= G->pos= G->limit= G->thunkpos= 0; + } + G->pos = 0; G->begin= G->end= G->pos; G->thunkpos= 0; G->val= G->vals; @@ -1748,7 +1716,6 @@ YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart) if (yyok) yyDone(G); yyCommit(G); return yyok; - (void)yyrefill; (void)yymatchDot; (void)yymatchChar; diff --git a/tools/greg.h b/tools/greg.h index 43b24823..16a1cd4d 100644 --- a/tools/greg.h +++ b/tools/greg.h @@ -15,7 +15,7 @@ * * THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. * - * Last edited: 2013-04-11 11:10:34 rurban + * Last edited: 2019-02-06 12:05:37 rurban */ #include @@ -26,9 +26,11 @@ #define GREG_MAJOR 0 #define GREG_MINOR 4 -#define GREG_LEVEL 5 +#define GREG_LEVEL 6 -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; +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, @@ -38,26 +40,59 @@ enum { typedef union Node Node; #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; }; -struct Dot { NODE_COMMON; }; -struct Character { NODE_COMMON; char *value; }; -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; }; -struct PeekNot { NODE_COMMON; Node *element; }; -struct Query { NODE_COMMON; Node *element; }; -struct Star { NODE_COMMON; Node *element; }; -struct Plus { NODE_COMMON; Node *element; }; -struct Any { NODE_COMMON; }; +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; }; +struct Dot { NODE_COMMON; }; +struct Character { NODE_COMMON; char *value; }; +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; }; +struct PeekNot { NODE_COMMON; Node *element; }; +struct Query { NODE_COMMON; Node *element; }; +struct Star { NODE_COMMON; Node *element; }; +struct Plus { NODE_COMMON; Node *element; }; +struct Any { NODE_COMMON; }; #undef NODE_COMMON +#ifndef YYSTYPE +#define YYSTYPE int +#endif +#ifndef YY_XTYPE +#define YY_XTYPE void * +#endif +struct _yythunk; // forward declaration +typedef struct _GREG { + char *buf; + int buflen; + int offset; + int pos; + int limit; + char *text; + int textlen; + int begin; + int end; + struct _yythunk *thunks; + int thunkslen; + int thunkpos; + int lineno; + char *filename; + FILE *input; + YYSTYPE ss; + YYSTYPE *val; + YYSTYPE *vals; + int valslen; + YY_XTYPE data; +#ifdef YY_DEBUG + int debug; +#endif +} GREG; + union Node { NodeType type;