1 /*- 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)yy.h 8.1 (Berkeley) 06/06/93 8 */ 9 10 #include "y.tab.h" 11 #undef CBSIZE /* from paramsys/param.h */ 12 /* 13 * INPUT/OUTPUT 14 */ 15 16 /* 17 * The buffer for the input file is normally "ibuf". 18 * When files are included, however, this may be 19 * pushed down in the stack of currently active 20 * files. For this reason, the pointer ibp always 21 * references the i/o buffer of the current input file. 22 */ 23 FILE *ibuf, *ibp; 24 25 /* 26 * Line and token buffers. Charbuf is the character buffer for 27 * input lines, token the buffer for tokens returned 28 * by the scanner. CBSIZE defines the maximum line 29 * length allowed on input and is doubtless too small. 30 * The token buffer should be a local array in yylex. 31 */ 32 #ifdef ADDR16 33 #define CBSIZE 161 34 #endif ADDR16 35 #ifdef ADDR32 36 #define CBSIZE 1024 37 #endif ADDR32 38 39 char charbuf[CBSIZE], *bufp, token[CBSIZE]; 40 41 #define digit(c) (c >= '0' && c <= '9') 42 #define alph(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 43 44 /* 45 * Flag to prevent reprinting current line after 46 * an error. 47 */ 48 char yyprtd; 49 50 /* 51 * The following variables are maintained by 52 * the scanner in the file lex and used in scanning 53 * and in parsing. 54 * 55 * The variable yychar is the current scanner character. 56 * Currently, the scanner must be called as 57 * yychar = yylex() 58 * even though it should set yychar itself. 59 * Yychar has value YEOF at end of file, and negative value if 60 * there is no yychar, e.g. after a shift in the parser. 61 * 62 * The variable yycol is the current column in the line whose number 63 * is given by yyline. Yyecol and yyeline give the position for an 64 * error message to flag, usually the start of an input token. 65 * Yylval is the semantic return from the scanner. 66 * 67 * In fact all of these variables are "per token". 68 * In the usual case, only the copies in the scanner token structure 69 * 'Y' are used, and the #defines below serve to make them look 70 * like variables. 71 * 72 * For the purposes of the error recovery, however, they are copied 73 * and restored quite freely. For the error recovery also, the 74 * file name which the input line this token is on and the seek 75 * pointer of this line in its source file are saved as yyefile 76 * and yyseekp. The global variable yylinpt is the seek pointer 77 * of the current input line. 78 */ 79 int yycol; 80 int yyline; 81 int yyseqid; 82 int yysavc; 83 int yylinpt; 84 85 /* *** NOTE *** 86 * It would be much better to not have the Yyeline and Yyefile 87 * in the scanner structure and to have a mechanism for mapping 88 * seqid's to these globally. 89 */ 90 struct yytok { 91 int Yychar; 92 int Yylval; 93 int Yyecol; 94 int Yyeline; 95 int Yyseekp; 96 char *Yyefile; 97 int Yyeseqid; 98 } Y, OY; 99 100 #define yychar Y.Yychar 101 #define yylval Y.Yylval 102 #define yyecol Y.Yyecol 103 #define yyeline Y.Yyeline 104 #define yyseekp Y.Yyseekp 105 #define yyefile Y.Yyefile 106 #define yyeseqid Y.Yyeseqid 107 108 /* Semantic Stack so that y.tab.c will lint */ 109 110 union semstack 111 { 112 int i_entry; 113 struct nl *nl_entry; 114 struct tnode *tr_entry; 115 char *cptr; 116 } yyval; 117 118 /* 119 * Yyval is the semantic value returned by a reduction. 120 * It is what "$$" is expanded to by yacc. 121 */ 122 123 int *Ps; 124 125 /* 126 * N is the length of a reduction. 127 * Used externally by "lineof" to get the left and 128 * right margins for a reduction. 129 */ 130 int N; 131 /* 132 * Definitions for looking up keywords. 133 * The keyword array is called yykey, and 134 * lastkey points at the end of it. 135 */ 136 char *lastkey; 137 138 struct kwtab { 139 char *kw_str; 140 int kw_val; 141 } yykey[]; 142 143 /* 144 * ERROR RECOVERY EXTERNALS 145 */ 146 147 #define CLIMIT 40 /* see yyrecover.c */ 148 char *tokname(); 149 char *charname(); 150 151 char *classes[]; 152 153 /* 154 * Tokens which yacc doesn't define 155 */ 156 #define YEOF 0 157 #define ERROR 256 158 159 /* 160 * Limit on the number of syntax errors 161 */ 162 #define MAXSYNERR 100 163 164 /* 165 * Big costs 166 */ 167 #define HUGE 50 168 #define INFINITY 100 169 170 /* 171 * Kinds of panics 172 */ 173 #define PDECL 0 174 #define PSTAT 1 175 #define PEXPR 2 176 #define PPROG 3 177 178 #define yyresume() yyResume = 1; 179 180 char yyResume; 181 182 char dquote; 183 184 #ifndef PC 185 #ifndef OBJ 186 char errout; 187 #endif OBJ 188 #endif PC 189 190 /* 191 * Yyidwant and yyidhave are the namelist classes 192 * of identifiers associated with a identifier reduce 193 * error, set before the recovery is called. 194 * Since they may be set again during the forward move 195 * they must be saved by yyrecover, which uses them in printing 196 * error messages. 197 */ 198 int yyidhave, yyidwant; 199 200 /* 201 * The variables yy*shifts are used to prevent looping and the printing 202 * of spurious messages in the parser. Yyshifts gives the number of 203 * true input shifts since the last corrective action. YyOshifts 204 * is the value of yyshifts before it was last cleared, and is used 205 * by yyPerror in yypanic.c to suppress messages. 206 * 207 * Yytshifts counts true input shifts. It is used to prevent looping 208 * inserting unique symbols. If yytshifts == yyTshifts (local to 209 * yyrecover.c) then there has been no shift over true input since 210 * the last unique symbol insertion. We refuse, in this case, 211 * to insert more unique symbols so as to prevent looping. 212 * 213 * The recovery cannot loop because it guarantees the progress of the 214 * parse, i.e.: 215 * 216 * 1) Any insertion guarantees to shift over 2 symbols, a replacement 217 * over one symbol. 218 * 219 * 2) Unique symbol insertions are limited to one for each true 220 * symbol of input, or "safe" insertion of the keywords "end" 221 * and "until" at zero cost (safe since these are know to match 222 * stack that cannot have been generated - e.g. "begin" or "repeat") 223 * 224 * 3) We never panic more than once from a given state without 225 * shifting over input, i.e. we force the parse stack to shrink 226 * after each unsuccessful panic. 227 */ 228 int yyshifts, yyOshifts; 229 unsigned yytshifts; 230 231 #ifdef PXP 232 233 /* 234 * Identifier class definitions 235 */ 236 #define UNDEF 0 237 #define CONST 1 238 #define TYPE 2 239 #define VAR 3 240 #define ARRAY 4 241 #define PTRFILE 5 242 #define RECORD 6 243 #define FIELD 7 244 #define PROC 8 245 #define FUNC 9 246 #define FVAR 10 247 #define REF 11 248 #define PTR 12 249 #define FILET 13 250 #define SET 14 251 #define RANGE 15 252 #define LABEL 16 253 #define WITHPTR 17 254 #define SCAL 18 255 #define STR 19 256 #define PROG 20 257 #define IMPROPER 21 258 259 /* 260 * COMMENT FORMATTING DEFINITIONS 261 */ 262 263 /* 264 * Count of tokens on this input line 265 * Note that this can be off if input is not syntactically correct. 266 */ 267 int yytokcnt; 268 int yywhcnt; 269 270 /* 271 * Types of comments 272 */ 273 #define CLMARG 0 274 #define CALIGN 1 275 #define CTRAIL 2 276 #define CRMARG 3 277 #define CSRMARG 4 278 #define CNL 5 279 #define CNLBL 6 280 #define CFORM 7 281 #define CINCLUD 8 282 283 /* 284 * Comment structure 285 * Cmhp is the head of the current list of comments 286 */ 287 struct comment { 288 struct comment *cmnext; 289 int cmdelim; 290 struct commline *cml; 291 int cmjust; 292 int cmseqid; 293 } *cmhp; 294 295 /* 296 * Structure for holding a comment line 297 */ 298 struct commline { 299 char *cmtext; 300 int cmcol; /* Only used for first line of comment currently */ 301 struct commline *cml; 302 }; 303 304 struct W { 305 int Wseqid; 306 int Wcol; 307 } yyw[MAXDEPTH + 1], *yypw; 308 309 #define commform() quickcomm(CFORM) 310 #define commnl() quickcomm(CNL) 311 #define commnlbl() quickcomm(CNLBL) 312 #endif 313