|
|
1.1 ! root 1: /* ! 2: * COCOA structure definitions ! 3: * ! 4: * This parser generator is dedicated to Reinaldo Braga. ! 5: * May he live a hundred years ! 6: */ ! 7: #include <stdio.h> ! 8: #include <sys/mdata.h> ! 9: ! 10: #define FATAL 01 /* flag for yyerror */ ! 11: #define SKIP 02 /* ditto */ ! 12: #define NLNO 04 /* no line number on error line */ ! 13: #define WARNING 010 ! 14: #define TTERM 0 /* "genre" for token */ ! 15: #define TNTERM 1 /* non terminal */ ! 16: #define TTYPE 2 /* <type> */ ! 17: #define MAXT 3 /* number of different genres */ ! 18: /* if maxterm is > 127 change LSETSIZE */ ! 19: #define LSETSIZE 20 /* chars in ws ::= MAXTERM/8 + 1 */ ! 20: ! 21: /* defaults -- can be changed with run time options */ ! 22: #define MAXPROD 175 /* maximum number of productions */ ! 23: #define MAXTERM 150 /* maximum number of different terminals */ ! 24: #define MAXNTERM 100 /* maximum number of non terminal symbols */ ! 25: #define MAXSTATE 300 /* max # of states */ ! 26: #define MAXTYPE 10 /* for the union of YYSTYPE */ ! 27: ! 28: /* compiled in sizes -- can be increased without problem */ ! 29: #define MAXPRODL 20 /* maximum number of symbols in any prodn */ ! 30: #define MAXITEM 160 /* maximum number of items in any state */ ! 31: #define MAXREDS 60 /* maximum number of reductions per state */ ! 32: ! 33: /* keyword codings */ ! 34: #define START 1 ! 35: /* %token .. %nonassoc must be contiguously coded */ ! 36: #define TOKEN 2 ! 37: #define LEFT 3 ! 38: #define RIGHT 4 ! 39: #define NONASSOC 5 ! 40: #define UNION 6 ! 41: #define PREC 7 ! 42: #define TYPE 8 ! 43: #define SEMICOLON 9 ! 44: #define VBAR 10 /* production separators */ ! 45: #define LBRAC 11 /* beginning of action */ ! 46: #define T_IDENT 12 ! 47: #define C_IDENT 13 ! 48: #define MARK 14 ! 49: #define IDENT 15 ! 50: #define COMMA 16 ! 51: #define INTEGER 17 ! 52: ! 53: /* precedence associativities */ ! 54: #define UNASSOC 0 ! 55: #define LASSOC 1 ! 56: #define RASSOC 2 ! 57: #define BASSOC 3 /* "binary" associativity - %nonassoc */ ! 58: ! 59: /* macros */ ! 60: /* character manipulation */ ! 61: ! 62: /* run of the mill manifests */ ! 63: #define UINT -1 /* "unknown" type -- integer */ ! 64: #define UNKNOWN -1 ! 65: #define SYMSIZE 32 ! 66: #define DERIV 01 /* non terminal derives the empty string */ ! 67: #define CPRES 02 /* temp flag for closure */ ! 68: #define nterm gtab[TTERM].g_ordno ! 69: #define nnonterm gtab[TNTERM].g_ordno ! 70: #define ntype gtab[TTYPE].g_ordno ! 71: #define maxterm gtab[TTERM].g_maxord ! 72: #define maxnterm gtab[TNTERM].g_maxord ! 73: #define maxtype gtab[TTYPE].g_maxord ! 74: #define maxsym (maxterm+maxnterm+maxtype) ! 75: #define NTBASE 010000 /* base number for non terminal allocation */ ! 76: #define EOFNO 0 ! 77: #define ERRNO 1 ! 78: #define bounded(v,l,name) if( v>=l ) yyerror(FATAL, bounderr, name, l) ! 79: #define MAXSYM 353 ! 80: ! 81: ! 82: ! 83: struct sym ! 84: { ! 85: char s_name[SYMSIZE]; ! 86: int s_no; /* ordinal number of symbol */ ! 87: int s_val; /* external value, for non terminal only */ ! 88: char s_prc, s_ass; /* precedence, associativity */ ! 89: int s_type; ! 90: char s_genre; /* "kind" of symbol -- terminal, nonterminal, type */ ! 91: /* remaining flags are only used for non-terminals */ ! 92: ! 93: char s_flags; /* for closure and lookahead computations */ ! 94: int s_nprods; /* number of productions having nt as lhs */ ! 95: struct prod **s_prods; ! 96: int s_nstates; /* sfor nt A, # of states with item A->. ai* */ ! 97: int *s_states; /* list */ ! 98: }; ! 99: ! 100: struct sitem ! 101: { ! 102: int i_nitems; /* number of items in set */ ! 103: int *i_items[]; ! 104: } ; ! 105: ! 106: struct state ! 107: { ! 108: int s_tgo; ! 109: struct tgo *s_tgos; ! 110: int s_ntgo; ! 111: struct ntgo *s_ntgos; ! 112: int s_nred; ! 113: struct redn *s_reds; ! 114: } ; ! 115: ! 116: struct prod ! 117: { ! 118: int p_prodno; /* index in prdptr */ ! 119: char p_prc, p_ass; /* precedence, associativity */ ! 120: int p_left; /* -(ordinal number for lhs) */ ! 121: int p_right[]; /* ordinal numbers for rhs w. -1 end marker */ ! 122: }; ! 123: /* kludgy accessing macro */ ! 124: #define i2p(leftp) ( (struct prod *) ( (char *)leftp - (int) &0->p_left) ) ! 125: ! 126: struct tgo ! 127: { ! 128: int tg_trm; /* ordinal number of terminal */ ! 129: int tg_st; ! 130: }; ! 131: ! 132: struct ntgo ! 133: { ! 134: int ng_nt; /* ordinal number of non terminal */ ! 135: int ng_st; /* index of state */ ! 136: union { /* MWC DSC */ ! 137: struct rel *reln; /* pointer to relation set */ ! 138: struct lset *look; /* pointer to lookahead set */ ! 139: } cheapo; /* they're not used at once, so... */ ! 140: }; ! 141: #define ng_rel cheapo.reln ! 142: #define ng_lset cheapo.look ! 143: ! 144: struct redn ! 145: { ! 146: struct prod *rd_prod; /* production pointer */ ! 147: struct lset *rd_lset; /* lookahead set */ ! 148: }; ! 149: ! 150: /* relation between nt transitions */ ! 151: struct rel ! 152: { ! 153: int r_count; ! 154: int r_list[]; ! 155: }; ! 156: ! 157: struct trans ! 158: { ! 159: struct ntgo *t_trans; ! 160: int t_level; ! 161: }; ! 162: ! 163: struct lset ! 164: { ! 165: union { ! 166: unsigned char u_bits[LSETSIZE]; ! 167: struct lset *u_next; ! 168: } un; ! 169: }; ! 170: #define l_bits un.u_bits ! 171: #define l_next un.u_next ! 172: ! 173: struct resv ! 174: { ! 175: char *r_name; ! 176: int r_val; ! 177: }; ! 178: ! 179: struct genre ! 180: { ! 181: int g_ordno; /* current index for table ptr */ ! 182: int g_maxord; /* limit value for g_ordno */ ! 183: int g_base; /* "base" value for s_no */ ! 184: struct sym ***g_sptr; /* pointer to table for type - MWC DSC */ ! 185: char *g_name; ! 186: }; ! 187: ! 188: typedef union ! 189: { ! 190: struct sym *sptr; ! 191: int ival; ! 192: } YYSTYPE; ! 193: ! 194: extern struct sym **symtab; /* global symbol table */ ! 195: extern struct sym **ntrmptr; /* non terminal pointers into symtab */ ! 196: extern struct sym **trmptr; /* " terminal " " */ ! 197: extern struct sym **typeptr; /* " type " " */ ! 198: extern struct state *states; ! 199: extern struct sitem **items; ! 200: extern struct prod **prdptr; ! 201: extern int yyline; ! 202: extern nerrors; ! 203: extern FILE *defin, *tabout, *actout, *listout, *optout, *fhdr; ! 204: extern int tno; ! 205: extern char *gramy; /* input file name */ ! 206: extern char *ytabc; /* y.tab.c output file */ ! 207: extern char *youtput; /* listing file */ ! 208: extern char *ytabh; /* header file for token # definers */ ! 209: extern char acttmp[], opttmp[]; ! 210: extern char *parser; ! 211: extern char bounderr[]; ! 212: extern struct sitem *nititem; ! 213: extern struct prod *nitprod; ! 214: extern verbose, yydebug; ! 215: extern pstat; ! 216: extern int nstates; ! 217: extern int nprod; ! 218: extern int maxstates; ! 219: extern int maxprod; ! 220: extern int nrrconf, nsrconf; ! 221: extern int ndupgos, ndupacts; ! 222: extern struct genre gtab[MAXT]; ! 223: extern int startsym; ! 224: extern int predlev; ! 225: extern struct resv restab[]; ! 226: ! 227: char *calloc(); ! 228: char *yalloc(); ! 229: char *ptosym(); ! 230: char *prsym(); ! 231: char *nextarg(); ! 232: struct ntgo *findnt(); ! 233: struct lset *getset();
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.