1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
|
/* Copyright (c) 2007, 2012 by Ian Piumarta
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the 'Software'),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, provided that the above copyright notice(s) and this
* permission notice appear in all copies of the Software. Acknowledgement
* of the use of this Software in supporting documentation would be
* appreciated but is not required.
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*
* Last edited: 2012-04-29 16:09:36 by piumarta on emilia
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "version.h"
#include "tree.h"
static int yyl(void)
{
static int prev= 0;
return ++prev;
}
static void charClassSet (unsigned char bits[], int c) { bits[c >> 3] |= (1 << (c & 7)); }
static void charClassClear(unsigned char bits[], int c) { bits[c >> 3] &= ~(1 << (c & 7)); }
typedef void (*setter)(unsigned char bits[], int c);
static inline int oigit(int c) { return '0' <= c && c <= '7'; }
static int cnext(unsigned char **ccp)
{
unsigned char *cclass= *ccp;
int c= *cclass++;
if (c)
{
if ('\\' == c && *cclass)
{
switch (c= *cclass++)
{
case 'a': c= '\a'; break; /* bel */
case 'b': c= '\b'; break; /* bs */
case 'e': c= '\e'; break; /* esc */
case 'f': c= '\f'; break; /* ff */
case 'n': c= '\n'; break; /* nl */
case 'r': c= '\r'; break; /* cr */
case 't': c= '\t'; break; /* ht */
case 'v': c= '\v'; break; /* vt */
default:
if (oigit(c))
{
c -= '0';
if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0';
if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0';
}
break;
}
}
*ccp= cclass;
}
return c;
}
static char *makeCharClass(unsigned char *cclass)
{
unsigned char bits[32];
setter set;
int c, prev= -1;
static char string[256];
char *ptr;
if ('^' == *cclass)
{
memset(bits, 255, 32);
set= charClassClear;
++cclass;
}
else
{
memset(bits, 0, 32);
set= charClassSet;
}
while (*cclass)
{
if ('-' == *cclass && cclass[1] && prev >= 0)
{
++cclass;
for (c= cnext(&cclass); prev <= c; ++prev)
set(bits, prev);
prev= -1;
}
else
{
c= cnext(&cclass);
set(bits, prev= c);
}
}
ptr= string;
for (c= 0; c < 32; ++c)
ptr += sprintf(ptr, "\\%03o", bits[c]);
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= ctx->pos, yythunkpos%d= ctx->thunkpos;", n, n); }
static void restore(int n) { fprintf(output, " ctx->pos= yypos%d; ctx->thunkpos= yythunkpos%d;", n, n); }
static void Node_compile_c_ko(Node *node, int ko)
{
assert(node);
switch (node->type)
{
case Rule:
fprintf(stderr, "\ninternal error #1 (%s)\n", node->rule.name);
exit(1);
break;
case Dot:
fprintf(output, " if (!yymatchDot(ctx)) goto l%d;", ko);
break;
case Name:
fprintf(output, " if (!yy_%s(ctx)) goto l%d;", node->name.rule->rule.name, ko);
if (node->name.variable)
fprintf(output, " yyDo(ctx, yySet, %d, 0);", node->name.variable->variable.offset);
break;
case Character:
case String:
{
int len= strlen(node->string.value);
if (1 == len)
{
if ('\'' == node->string.value[0])
fprintf(output, " if (!yymatchChar(ctx, '\\'')) goto l%d;", ko);
else
fprintf(output, " if (!yymatchChar(ctx, '%s')) goto l%d;", node->string.value, ko);
}
else
if (2 == len && '\\' == node->string.value[0])
fprintf(output, " if (!yymatchChar(ctx, '%s')) goto l%d;", node->string.value, ko);
else
fprintf(output, " if (!yymatchString(ctx, \"%s\")) goto l%d;", node->string.value, ko);
}
break;
case Class:
fprintf(output, " if (!yymatchClass(ctx, (unsigned char *)\"%s\")) goto l%d;", makeCharClass(node->cclass.value), ko);
break;
case Action:
fprintf(output, " yyDo(ctx, yy%s, ctx->begin, ctx->end);", node->action.name);
break;
case Predicate:
fprintf(output, " yyText(ctx, ctx->begin, ctx->end); if (!(%s)) goto l%d;", node->action.text, ko);
break;
case Alternate:
{
int ok= yyl();
begin();
save(ok);
for (node= node->alternate.first; node; node= node->alternate.next)
if (node->alternate.next)
{
int next= yyl();
Node_compile_c_ko(node, next);
jump(ok);
label(next);
restore(ok);
}
else
Node_compile_c_ko(node, ko);
end();
label(ok);
}
break;
case Sequence:
for (node= node->sequence.first; node; node= node->sequence.next)
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();
}
break;
case PeekNot:
{
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);
}
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();
}
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();
}
break;
default:
fprintf(stderr, "\nNode_compile_c_ko: illegal node type %d\n", node->type);
exit(1);
}
}
static int countVariables(Node *node)
{
int count= 0;
while (node)
{
++count;
node= node->variable.next;
}
return count;
}
static void defineVariables(Node *node)
{
int count= 0;
while (node)
{
fprintf(output, "#define %s ctx->val[%d]\n", node->variable.name, --count);
node->variable.offset= count;
node= node->variable.next;
}
fprintf(output, "#define yy ctx->yy\n");
fprintf(output, "#define yypos ctx->pos\n");
fprintf(output, "#define yythunkpos ctx->thunkpos\n");
}
static void undefineVariables(Node *node)
{
fprintf(output, "#undef yythunkpos\n");
fprintf(output, "#undef yypos\n");
fprintf(output, "#undef yy\n");
while (node)
{
fprintf(output, "#undef %s\n", node->variable.name);
node= node->variable.next;
}
}
static void Rule_compile_c2(Node *node)
{
assert(node);
assert(Rule == node->type);
if (!node->rule.expression)
fprintf(stderr, "rule '%s' used but not defined\n", node->rule.name);
else
{
int ko= yyl(), safe;
if ((!(RuleUsed & node->rule.flags)) && (node != start))
fprintf(stderr, "rule '%s' defined but not used\n", node->rule.name);
safe= ((Query == node->rule.expression->type) || (Star == node->rule.expression->type));
fprintf(output, "\nYY_RULE(int) yy_%s(yycontext *ctx)\n{", node->rule.name);
if (!safe) save(0);
if (node->rule.variables)
fprintf(output, " yyDo(ctx, yyPush, %d, 0);", countVariables(node->rule.variables));
fprintf(output, "\n yyprintf((stderr, \"%%s\\n\", \"%s\"));", node->rule.name);
Node_compile_c_ko(node->rule.expression, ko);
fprintf(output, "\n yyprintf((stderr, \" ok %%s @ %%s\\n\", \"%s\", ctx->buf+ctx->pos));", node->rule.name);
if (node->rule.variables)
fprintf(output, " yyDo(ctx, yyPop, %d, 0);", countVariables(node->rule.variables));
fprintf(output, "\n return 1;");
if (!safe)
{
label(ko);
restore(0);
fprintf(output, "\n yyprintf((stderr, \" fail %%s @ %%s\\n\", \"%s\", ctx->buf+ctx->pos));", node->rule.name);
fprintf(output, "\n return 0;");
}
fprintf(output, "\n}");
}
if (node->rule.next)
Rule_compile_c2(node->rule.next);
}
static char *header= "\
#include <stdio.h>\n\
#include <stdlib.h>\n\
#include <string.h>\n\
";
static char *preamble= "\
#ifndef YY_LOCAL\n\
#define YY_LOCAL(T) static T\n\
#endif\n\
#ifndef YY_ACTION\n\
#define YY_ACTION(T) static T\n\
#endif\n\
#ifndef YY_RULE\n\
#define YY_RULE(T) static T\n\
#endif\n\
#ifndef YY_PARSE\n\
#define YY_PARSE(T) T\n\
#endif\n\
#ifndef YYPARSE\n\
#define YYPARSE yyparse\n\
#endif\n\
#ifndef YYPARSEFROM\n\
#define YYPARSEFROM yyparsefrom\n\
#endif\n\
#ifndef YY_INPUT\n\
#define YY_INPUT(buf, result, max_size) \\\n\
{ \\\n\
int yyc= getchar(); \\\n\
result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \\\n\
yyprintf((stderr, \"<%c>\", yyc)); \\\n\
}\n\
#endif\n\
#ifndef YY_BEGIN\n\
#define YY_BEGIN ( ctx->begin= ctx->pos, 1)\n\
#endif\n\
#ifndef YY_END\n\
#define YY_END ( ctx->end= ctx->pos, 1)\n\
#endif\n\
#ifdef YY_DEBUG\n\
# define yyprintf(args) fprintf args\n\
#else\n\
# define yyprintf(args)\n\
#endif\n\
#ifndef YYSTYPE\n\
#define YYSTYPE int\n\
#endif\n\
\n\
#ifndef YY_PART\n\
\n\
typedef struct _yycontext yycontext;\n\
typedef void (*yyaction)(yycontext *ctx, char *yytext, int yyleng);\n\
typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk;\n\
\n\
struct _yycontext {\n\
char *buf;\n\
int buflen;\n\
int pos;\n\
int limit;\n\
char *text;\n\
int textlen;\n\
int begin;\n\
int end;\n\
int textmax;\n\
yythunk *thunks;\n\
int thunkslen;\n\
int thunkpos;\n\
YYSTYPE yy;\n\
YYSTYPE *val;\n\
YYSTYPE *vals;\n\
int valslen;\n\
#ifdef YY_CTX_MEMBERS\n\
YY_CTX_MEMBERS\n\
#endif\n\
};\n\
\n\
#ifdef YY_CTX_LOCAL\n\
#define YY_CTX_PARAM_ yycontext *yyctx,\n\
#define YY_CTX_PARAM yycontext *yyctx\n\
#define YY_CTX_ARG_ yyctx,\n\
#define YY_CTX_ARG yyctx\n\
#else\n\
#define YY_CTX_PARAM_\n\
#define YY_CTX_PARAM\n\
#define YY_CTX_ARG_\n\
#define YY_CTX_ARG\n\
yycontext yyctx0;\n\
yycontext *yyctx= &yyctx0;\n\
#endif\n\
\n\
YY_LOCAL(int) yyrefill(yycontext *ctx)\n\
{\n\
int yyn;\n\
while (ctx->buflen - ctx->pos < 512)\n\
{\n\
ctx->buflen *= 2;\n\
ctx->buf= (char *)realloc(ctx->buf, ctx->buflen);\n\
}\n\
YY_INPUT((ctx->buf + ctx->pos), yyn, (ctx->buflen - ctx->pos));\n\
if (!yyn) return 0;\n\
ctx->limit += yyn;\n\
return 1;\n\
}\n\
\n\
YY_LOCAL(int) yymatchDot(yycontext *ctx)\n\
{\n\
if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0;\n\
++ctx->pos;\n\
return 1;\n\
}\n\
\n\
YY_LOCAL(int) yymatchChar(yycontext *ctx, int c)\n\
{\n\
if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0;\n\
if ((unsigned char)ctx->buf[ctx->pos] == c)\n\
{\n\
++ctx->pos;\n\
yyprintf((stderr, \" ok yymatchChar(ctx, %c) @ %s\\n\", c, ctx->buf+ctx->pos));\n\
return 1;\n\
}\n\
yyprintf((stderr, \" fail yymatchChar(ctx, %c) @ %s\\n\", c, ctx->buf+ctx->pos));\n\
return 0;\n\
}\n\
\n\
YY_LOCAL(int) yymatchString(yycontext *ctx, char *s)\n\
{\n\
int yysav= ctx->pos;\n\
while (*s)\n\
{\n\
if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0;\n\
if (ctx->buf[ctx->pos] != *s)\n\
{\n\
ctx->pos= yysav;\n\
return 0;\n\
}\n\
++s;\n\
++ctx->pos;\n\
}\n\
return 1;\n\
}\n\
\n\
YY_LOCAL(int) yymatchClass(yycontext *ctx, unsigned char *bits)\n\
{\n\
int c;\n\
if (ctx->pos >= ctx->limit && !yyrefill(ctx)) return 0;\n\
c= (unsigned char)ctx->buf[ctx->pos];\n\
if (bits[c >> 3] & (1 << (c & 7)))\n\
{\n\
++ctx->pos;\n\
yyprintf((stderr, \" ok yymatchClass @ %s\\n\", ctx->buf+ctx->pos));\n\
return 1;\n\
}\n\
yyprintf((stderr, \" fail yymatchClass @ %s\\n\", ctx->buf+ctx->pos));\n\
return 0;\n\
}\n\
\n\
YY_LOCAL(void) yyDo(yycontext *ctx, yyaction action, int begin, int end)\n\
{\n\
while (ctx->thunkpos >= ctx->thunkslen)\n\
{\n\
ctx->thunkslen *= 2;\n\
ctx->thunks= (yythunk *)realloc(ctx->thunks, sizeof(yythunk) * ctx->thunkslen);\n\
}\n\
ctx->thunks[ctx->thunkpos].begin= begin;\n\
ctx->thunks[ctx->thunkpos].end= end;\n\
ctx->thunks[ctx->thunkpos].action= action;\n\
++ctx->thunkpos;\n\
}\n\
\n\
YY_LOCAL(int) yyText(yycontext *ctx, int begin, int end)\n\
{\n\
int yyleng= end - begin;\n\
if (yyleng <= 0)\n\
yyleng= 0;\n\
else\n\
{\n\
while (ctx->textlen < (yyleng + 1))\n\
{\n\
ctx->textlen *= 2;\n\
ctx->text= (char *)realloc(ctx->text, ctx->textlen);\n\
}\n\
memcpy(ctx->text, ctx->buf + begin, yyleng);\n\
}\n\
ctx->text[yyleng]= '\\0';\n\
return yyleng;\n\
}\n\
\n\
YY_LOCAL(void) yyDone(yycontext *ctx)\n\
{\n\
int pos;\n\
for (pos= 0; pos < ctx->thunkpos; ++pos)\n\
{\n\
yythunk *thunk= &ctx->thunks[pos];\n\
int yyleng= thunk->end ? yyText(ctx, thunk->begin, thunk->end) : thunk->begin;\n\
yyprintf((stderr, \"DO [%d] %p %s\\n\", pos, thunk->action, ctx->text));\n\
thunk->action(ctx, ctx->text, yyleng);\n\
}\n\
ctx->thunkpos= 0;\n\
}\n\
\n\
YY_LOCAL(void) yyCommit(yycontext *ctx)\n\
{\n\
if ((ctx->limit -= ctx->pos))\n\
{\n\
memmove(ctx->buf, ctx->buf + ctx->pos, ctx->limit);\n\
}\n\
ctx->begin -= ctx->pos;\n\
ctx->end -= ctx->pos;\n\
ctx->pos= ctx->thunkpos= 0;\n\
}\n\
\n\
YY_LOCAL(int) yyAccept(yycontext *ctx, int tp0)\n\
{\n\
if (tp0)\n\
{\n\
fprintf(stderr, \"accept denied at %d\\n\", tp0);\n\
return 0;\n\
}\n\
else\n\
{\n\
yyDone(ctx);\n\
yyCommit(ctx);\n\
}\n\
return 1;\n\
}\n\
\n\
YY_LOCAL(void) yyPush(yycontext *ctx, char *text, int count) { ctx->val += count; }\n\
YY_LOCAL(void) yyPop(yycontext *ctx, char *text, int count) { ctx->val -= count; }\n\
YY_LOCAL(void) yySet(yycontext *ctx, char *text, int count) { ctx->val[count]= ctx->yy; }\n\
\n\
#endif /* YY_PART */\n\
\n\
#define YYACCEPT yyAccept(ctx, yythunkpos0)\n\
\n\
";
static char *footer= "\n\
\n\
#ifndef YY_PART\n\
\n\
typedef int (*yyrule)(yycontext *ctx);\n\
\n\
YY_PARSE(int) YYPARSEFROM(YY_CTX_PARAM_ yyrule yystart)\n\
{\n\
int yyok;\n\
if (!yyctx->buflen)\n\
{\n\
yyctx->buflen= 1024;\n\
yyctx->buf= (char *)malloc(yyctx->buflen);\n\
yyctx->textlen= 1024;\n\
yyctx->text= (char *)malloc(yyctx->textlen);\n\
yyctx->thunkslen= 32;\n\
yyctx->thunks= (yythunk *)malloc(sizeof(yythunk) * yyctx->thunkslen);\n\
yyctx->valslen= 32;\n\
yyctx->vals= (YYSTYPE *)malloc(sizeof(YYSTYPE) * yyctx->valslen);\n\
yyctx->begin= yyctx->end= yyctx->pos= yyctx->limit= yyctx->thunkpos= 0;\n\
}\n\
yyctx->begin= yyctx->end= yyctx->pos;\n\
yyctx->thunkpos= 0;\n\
yyctx->val= yyctx->vals;\n\
yyok= yystart(yyctx);\n\
if (yyok) yyDone(yyctx);\n\
yyCommit(yyctx);\n\
return yyok;\n\
}\n\
\n\
YY_PARSE(int) YYPARSE(YY_CTX_PARAM)\n\
{\n\
return YYPARSEFROM(YY_CTX_ARG_ yy_%s);\n\
}\n\
\n\
#endif\n\
";
void Rule_compile_c_header(void)
{
fprintf(output, "/* A recursive-descent parser generated by peg %d.%d.%d */\n", PEG_MAJOR, PEG_MINOR, PEG_LEVEL);
fprintf(output, "\n");
fprintf(output, "%s", header);
fprintf(output, "#define YYRULECOUNT %d\n", ruleCount);
}
int consumesInput(Node *node)
{
if (!node) return 0;
switch (node->type)
{
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;
}
break;
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 Alternate:
{
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;
}
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);
default:
fprintf(stderr, "\nconsumesInput: illegal node type %d\n", node->type);
exit(1);
}
return 0;
}
void Rule_compile_c(Node *node)
{
Node *n;
for (n= rules; n; n= n->rule.next)
consumesInput(n);
fprintf(output, "%s", preamble);
for (n= node; n; n= n->rule.next)
fprintf(output, "YY_RULE(int) yy_%s(yycontext *ctx); /* %d */\n", n->rule.name, n->rule.id);
fprintf(output, "\n");
for (n= actions; n; n= n->action.list)
{
fprintf(output, "YY_ACTION(void) yy%s(yycontext *ctx, char *yytext, int yyleng)\n{\n", n->action.name);
defineVariables(n->action.rule->rule.variables);
fprintf(output, " yyprintf((stderr, \"do yy%s\\n\"));\n", n->action.name);
fprintf(output, " %s;\n", n->action.text);
undefineVariables(n->action.rule->rule.variables);
fprintf(output, "}\n");
}
Rule_compile_c2(node);
fprintf(output, footer, start->rule.name);
}
|