Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

lburg.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  nonterm
struct  rule
struct  term
struct  tree

Typedefs

typedef nontermNonterm
typedef ruleRule
typedef termTerm
typedef treeTree

Enumerations

enum  Kind { TERM = 1, NONTERM }

Functions

void * alloc (int nbytes)
Nonterm nonterm (char *id)
Rule rule (char *id, Tree pattern, char *template, char *code)
Term term (char *id, int esn)
Tree tree (char *op, Tree left, Tree right)
void yyerror (char *fmt,...)
int yyparse (void)
void yywarn (char *fmt,...)

Variables

int errcnt
FILEinfp
FILEoutfp


Typedef Documentation

typedef struct nonterm* Nonterm
 

Definition at line 19 of file lburg.h.

Referenced by ckreach(), computents(), emitclosure(), emitcost(), emitdefs(), emitlabel(), emitrecalc(), emitrule(), emitstruct(), main(), nonterm(), reach(), and rule().

typedef struct rule* Rule
 

Definition at line 8 of file lburg.h.

Referenced by ckreach(), emitcase(), emitclosure(), emitkids(), emitnts(), emitrecord(), emitrule(), emitstring(), print(), and rule().

typedef struct term* Term
 

Definition at line 9 of file lburg.h.

Referenced by computekids(), emitcase(), emitlabel(), emitrecalc(), emittest(), print(), rule(), term(), and tree().

typedef struct tree* Tree
 

Definition at line 33 of file lburg.h.

Referenced by addrtree(), bbcall(), bbexit(), bbincr(), computekids(), computents(), conditional(), condtree(), constexpr(), cvtconst(), dcllocal(), definept(), emitcost(), emittest(), foldcond(), forstmt(), genconst(), initializer(), initvalue(), intexpr(), listnodes(), localaddr(), nodeid(), print(), printdag(), printdag1(), printnode(), printtree(), printtree1(), reach(), retcode(), root(), root1(), rule(), simplify(), statement(), swcode(), swstmt(), texpr(), tracefinis(), tracereturn(), tracevalue(), tree(), walk(), and whilestmt().


Enumeration Type Documentation

enum Kind
 

Enumeration values:
TERM 
NONTERM 

Definition at line 7 of file lburg.h.

00007 { TERM=1, NONTERM } Kind;


Function Documentation

void* alloc int  nbytes  ) 
 

Definition at line 106 of file lburg.c.

References calloc(), exit(), block::link, memlist, p, and yyerror().

Referenced by append(), compose(), concat(), emitkids(), emitnts(), install(), rule(), string(), stringf(), strsave(), tree(), and yylex().

00106                         {
00107     struct block *p = calloc(1, sizeof *p + nbytes);
00108 
00109     if (p == NULL) {
00110         yyerror("out of memory\n");
00111         exit(1);
00112     }
00113     p->link = memlist;
00114     memlist = p;
00115     return p + 1;
00116 }

Here is the call graph for this function:

Nonterm nonterm char *  id  ) 
 

Definition at line 170 of file lburg.c.

References assert, install(), nonterm::kind, nonterm::link, lookup(), Nonterm, nonterm::number, p, q, start, and yyerror().

Referenced by rule(), tree(), and yyparse().

00170                           {
00171     Nonterm p = lookup(id), *q = &nts;
00172 
00173     if (p && p->kind == NONTERM)
00174         return p;
00175     if (p && p->kind == TERM)
00176         yyerror("`%s' is a terminal\n", id);
00177     p = install(id);
00178     p->kind = NONTERM;
00179     p->number = ++ntnumber;
00180     if (p->number == 1)
00181         start = p;
00182     while (*q && (*q)->number < p->number)
00183         q = &(*q)->link;
00184     assert(*q == 0 || (*q)->number != p->number);
00185     p->link = *q;
00186     *q = p;
00187     return p;
00188 }

Here is the call graph for this function:

Rule rule char *  id,
Tree  pattern,
char *  template,
char *  code
 

Definition at line 244 of file lburg.c.

References alloc(), nonterm::chain, code, term::kind, tree::left, nonterm::lhscount, rule::link, rule::next, Nonterm, nonterm(), NULL, tree::op, p, pattern, q, r, tree::right, Rule, term::rules, stringf(), strtol(), Term, Tree, and yyerror().

Referenced by yyparse().

00244                                                               {
00245     Rule r = alloc(sizeof *r), *q;
00246     Term p = pattern->op;
00247     char *end;
00248 
00249     r->lhs = nonterm(id);
00250     r->packed = ++r->lhs->lhscount;
00251     for (q = &r->lhs->rules; *q; q = &(*q)->decode)
00252         ;
00253     *q = r;
00254     r->pattern = pattern;
00255     r->ern = ++nrules;
00256     r->template = template;
00257     r->code = code;
00258     r->cost = strtol(code, &end, 10);
00259     if (*end) {
00260         r->cost = -1;
00261         r->code = stringf("(%s)", code);
00262     }
00263     if (p->kind == TERM) {
00264         for (q = &p->rules; *q; q = &(*q)->next)
00265             ;
00266         *q = r;
00267     } else if (pattern->left == NULL && pattern->right == NULL) {
00268         Nonterm p = pattern->op;
00269         r->chain = p->chain;
00270             p->chain = r;
00271         if (r->cost == -1)
00272             yyerror("illegal nonconstant cost `%s'\n", code);
00273     }
00274     for (q = &rules; *q; q = &(*q)->link)
00275         ;
00276     r->link = *q;
00277     *q = r;
00278     return r;
00279 }

Here is the call graph for this function:

Term term char *  id,
int  esn
 

Definition at line 191 of file lburg.c.

References term::arity, term::esn, install(), term::kind, term::link, lookup(), term::name, p, q, Term, and yyerror().

Referenced by tree(), and yyparse().

00191                              {
00192     Term p = lookup(id), *q = &terms;
00193 
00194     if (p)
00195         yyerror("redefinition of terminal `%s'\n", id);
00196     else
00197         p = install(id);
00198     p->kind = TERM;
00199     p->esn = esn;
00200     p->arity = -1;
00201     while (*q && (*q)->esn < p->esn)
00202         q = &(*q)->link;
00203     if (*q && (*q)->esn == p->esn)
00204         yyerror("duplicate external symbol number `%s=%d'\n",
00205             p->name, p->esn);
00206     p->link = *q;
00207     *q = p;
00208     return p;
00209 }

Here is the call graph for this function:

Tree tree char *  op,
Tree  left,
Tree  right
 

Definition at line 212 of file lburg.c.

References alloc(), term::arity, term::kind, lookup(), NONTERM, nonterm(), tree::nterms, NULL, p, right, t, TERM, term(), Term, Tree, and yyerror().

00212                                            {
00213     Tree t = alloc(sizeof *t);
00214     Term p = lookup(id);
00215     int arity = 0;
00216 
00217     if (left && right)
00218         arity = 2;
00219     else if (left)
00220         arity = 1;
00221     if (p == NULL && arity > 0) {
00222         yyerror("undefined terminal `%s'\n", id);
00223         p = term(id, -1);
00224     } else if (p == NULL && arity == 0)
00225         p = (Term)nonterm(id);
00226     else if (p && p->kind == NONTERM && arity > 0) {
00227         yyerror("`%s' is a nonterminal\n", id);
00228         p = term(id, -1);
00229     }
00230     if (p->kind == TERM && p->arity == -1)
00231         p->arity = arity;
00232     if (p->kind == TERM && arity != p->arity)
00233         yyerror("inconsistent arity for terminal `%s'\n", id);
00234     t->op = p;
00235     t->nterms = p->kind == TERM;
00236     if ((t->left = left) != NULL)
00237         t->nterms += left->nterms;
00238     if ((t->right = right) != NULL)
00239         t->nterms += right->nterms;
00240     return t;
00241 }

Here is the call graph for this function:

void yyerror char *  fmt,
  ...
 

Definition at line 297 of file gram.c.

References errcnt, fprintf(), stderr, strlen(), va_end, va_list, va_start, vfprintf(), and yylineno.

00297                              {
00298     va_list ap;
00299 
00300     va_start(ap, fmt);
00301     if (yylineno > 0)
00302         fprintf(stderr, "line %d: ", yylineno);
00303     vfprintf(stderr, fmt, ap);
00304     if (fmt[strlen(fmt)-1] != '\n')
00305          fprintf(stderr, "\n");
00306     errcnt++;
00307     va_end(ap);
00308 }

Here is the call graph for this function:

int yyparse void   ) 
 

Definition at line 415 of file gram.c.

References getenv(), n, nonterm(), nonterm::number, printf(), rule(), YYSTYPE::string, string(), term(), tree(), YYSTYPE::tree, yyact, yychar, yycheck, yychk, YYCONST, yydebug, yydef, yydefred, yydgoto, yyerrflag, yyerror(), YYFINAL, yyfree, yygindex, yygrow(), YYLAST, yylen, yylex(), yylhs, yylineno, yynerrs, yypact, yypgo, yyr1, yyr2, yyrindex, yysindex, yyss, yystacksize, YYSTACKSIZE, yytable, yytext, yyv, yyval, and yyvs.

00416 {
00417     register int yym, yyn, yystate;
00418     register YYSTYPE *yyvsp;
00419     register short *yyssp;
00420     short *yysse;
00421 #if YYDEBUG
00422     register YYCONST char *yys;
00423 
00424     if (yys = getenv("YYDEBUG"))
00425     {
00426         yyn = *yys;
00427         if (yyn >= '0' && yyn <= '9')
00428             yydebug = yyn - '0';
00429     }
00430 #endif
00431 
00432     yynerrs = 0;
00433     yyerrflag = 0;
00434     yychar = (-1);
00435 
00436     if (yyss == 0)
00437     {
00438         yyss = (short *) yymalloc (YYSTACKSIZE * sizeof (short));
00439         if (yyss == 0)
00440           goto yyabort;
00441         yyvs = (YYSTYPE *) yymalloc (YYSTACKSIZE * sizeof (YYSTYPE));
00442         if (yyvs == 0)
00443         {
00444             yyfree (yyss);
00445             goto yyabort;
00446         }
00447         yystacksize = YYSTACKSIZE;
00448     }
00449     yysse = yyss + yystacksize - 1;
00450     yyssp = yyss;
00451     yyvsp = yyvs;
00452     *yyssp = yystate = 0;
00453     goto yyloop;
00454 
00455 yypush_lex:
00456     yyval = yylval;
00457     yystate = yytable[yyn];
00458 yypush:
00459     if (yyssp >= yysse)
00460     {
00461         int depth = yyssp - yyss;
00462         if (yygrow() != 0)
00463              goto yyoverflow;
00464         yysse = yyss + yystacksize -1;
00465         yyssp = depth + yyss;
00466         yyvsp = depth + yyvs;
00467     }
00468     *++yyssp = yystate;
00469     *++yyvsp = yyval;
00470 
00471 yyloop:
00472     if (yyn = yydefred[yystate]) goto yyreduce;
00473     yyn = yysindex[yystate];
00474     if (yychar < 0)
00475     {
00476         if ((yychar = yylex()) < 0) yychar = 0;
00477 #if YYDEBUG
00478         if (yydebug)
00479         {
00480             yys = 0;
00481             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
00482             if (!yys) yys = "illegal-symbol";
00483             printf("yydebug: state %d, reading %d (%s)\n", yystate,
00484                     yychar, yys);
00485         }
00486 #endif
00487     }
00488     if (yyn != 0
00489         && ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
00490         && yycheck[yyn] == yychar)
00491     {
00492 #if YYDEBUG
00493         if (yydebug)
00494             printf("yydebug: state %d, shifting to state %d\n",
00495                     yystate, yytable[yyn]);
00496 #endif
00497         if (yyerrflag > 0)  --yyerrflag;
00498         yychar = (-1);
00499         goto yypush_lex;
00500     }
00501     yyn = yyrindex[yystate];
00502     if (yyn != 0
00503         && ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
00504         && yycheck[yyn] == yychar)
00505     {
00506         yyn = yytable[yyn];
00507         goto yyreduce;
00508     }
00509     if (yyerrflag) goto yyinrecovery;
00510 #ifdef lint
00511     goto yynewerror;
00512 #endif
00513 yynewerror:
00514     yyerror("syntax error");
00515 #ifdef lint
00516     goto yyerrlab;
00517 #endif
00518 yyerrlab:
00519     ++yynerrs;
00520 yyinrecovery:
00521     if (yyerrflag < 3)
00522     {
00523         yyerrflag = 3;
00524         for (;;)
00525         {
00526             yyn = yysindex[*yyssp];
00527             if (yyn != 0
00528                 && ((yyn += YYERRCODE), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
00529                 && yycheck[yyn] == YYERRCODE)
00530             {
00531 #if YYDEBUG
00532                 if (yydebug)
00533                     printf("yydebug: state %d, error recovery shifting\
00534  to state %d\n", *yyssp, yytable[yyn]);
00535 #endif
00536                 goto yypush_lex;
00537             }
00538             else
00539             {
00540 #if YYDEBUG
00541                 if (yydebug)
00542                     printf("yydebug: error recovery discarding state %d\n",
00543                             *yyssp);
00544 #endif
00545                 if (yyssp <= yyss) goto yyabort;
00546                 --yyssp;
00547                 --yyvsp;
00548             }
00549         }
00550     }
00551     else
00552     {
00553         if (yychar == 0) goto yyabort;
00554 #if YYDEBUG
00555         if (yydebug)
00556         {
00557             yys = 0;
00558             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
00559             if (!yys) yys = "illegal-symbol";
00560             printf("yydebug: state %d, error recovery discards token %d (%s)\n",
00561                     yystate, yychar, yys);
00562         }
00563 #endif
00564         yychar = (-1);
00565         goto yyloop;
00566     }
00567 yyreduce:
00568 #if YYDEBUG
00569     if (yydebug)
00570         printf("yydebug: state %d, reducing by rule %d (%s)\n",
00571                 yystate, yyn, yyrule[yyn]);
00572 #endif
00573     yym = yylen[yyn];
00574     yyval = yyvsp[1-yym];
00575     switch (yyn)
00576     {
00577 case 1:
00578 #line 22 "lburg/gram.y"
00579 { yylineno = 0; }
00580 break;
00581 case 2:
00582 #line 23 "lburg/gram.y"
00583 { yylineno = 0; }
00584 break;
00585 case 6:
00586 #line 31 "lburg/gram.y"
00587 {
00588         if (nonterm(yyvsp[-1].string)->number != 1)
00589             yyerror("redeclaration of the start symbol\n");
00590         }
00591 break;
00592 case 8:
00593 #line 36 "lburg/gram.y"
00594 { yyerrok; }
00595 break;
00596 case 10:
00597 #line 40 "lburg/gram.y"
00598 { term(yyvsp[-2].string, yyvsp[0].n); }
00599 break;
00600 case 12:
00601 #line 44 "lburg/gram.y"
00602 { rule(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-2].string, yyvsp[-1].string); }
00603 break;
00604 case 14:
00605 #line 46 "lburg/gram.y"
00606 { yyerrok; }
00607 break;
00608 case 15:
00609 #line 49 "lburg/gram.y"
00610 { nonterm(yyval.string = yyvsp[0].string); }
00611 break;
00612 case 16:
00613 #line 52 "lburg/gram.y"
00614 { yyval.tree = tree(yyvsp[0].string,  0,  0); }
00615 break;
00616 case 17:
00617 #line 53 "lburg/gram.y"
00618 { yyval.tree = tree(yyvsp[-3].string, yyvsp[-1].tree,  0); }
00619 break;
00620 case 18:
00621 #line 54 "lburg/gram.y"
00622 { yyval.tree = tree(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-1].tree); }
00623 break;
00624 case 19:
00625 #line 57 "lburg/gram.y"
00626 { if (*yyvsp[0].string == 0) yyval.string = "0"; }
00627 break;
00628 #line 630 "y.tab.c"
00629     }
00630     yyssp -= yym;
00631     yyvsp -= yym;
00632     yym = yylhs[yyn];
00633     yystate = *yyssp;
00634     if (yystate == 0 && yym == 0)
00635     {
00636 #if YYDEBUG
00637         if (yydebug)
00638             printf("yydebug: after reduction, shifting from state 0 to\
00639  state %d\n", YYFINAL);
00640 #endif
00641         yystate = YYFINAL;
00642         *++yyssp = YYFINAL;
00643         *++yyvsp = yyval;
00644         if (yychar < 0)
00645         {
00646             if ((yychar = yylex()) < 0) yychar = 0;
00647 #if YYDEBUG
00648             if (yydebug)
00649             {
00650                 yys = 0;
00651                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
00652                 if (!yys) yys = "illegal-symbol";
00653                 printf("yydebug: state %d, reading %d (%s)\n",
00654                         YYFINAL, yychar, yys);
00655             }
00656 #endif
00657         }
00658         if (yychar == 0) goto yyaccept;
00659         goto yyloop;
00660     }
00661     yyn = yygindex[yym];
00662      if (yyn != 0
00663         && ((yyn += yystate), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
00664         && yycheck[yyn] == yystate)
00665         yystate = yytable[yyn];
00666     else
00667         yystate = yydgoto[yym];
00668 #if YYDEBUG
00669     if (yydebug)
00670         printf("yydebug: after reduction, shifting from state %d \
00671 to state %d\n", *yyssp, yystate);
00672 #endif
00673     goto yypush;
00674 yyoverflow:
00675     yyerror("yacc stack overflow");
00676 yyabort:
00677     return (1);
00678 yyaccept:
00679     return (0);
00680 }

Here is the call graph for this function:

void yywarn char *  fmt,
  ...
 

Definition at line 392 of file gram.c.

References fprintf(), stderr, va_list, va_start, vfprintf(), and yylineno.

Referenced by get().

00392                             {
00393     va_list ap;
00394 
00395     va_start(ap, fmt);
00396     if (yylineno > 0)
00397         fprintf(stderr, "line %d: ", yylineno);
00398     fprintf(stderr, "warning: ");
00399     vfprintf(stderr, fmt, ap);
00400 }

Here is the call graph for this function:


Variable Documentation

int errcnt
 

Definition at line 264 of file gram.c.

FILE* infp
 

Definition at line 265 of file gram.c.

Referenced by get(), and main().

FILE* outfp
 

Definition at line 266 of file gram.c.

Referenced by get(), main(), and print().


Generated on Thu Aug 25 15:49:28 2005 for Quake III Arena by  doxygen 1.3.9.1