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