148117Sbostic /*- 2*62221Sbostic * Copyright (c) 1980, 1993 3*62221Sbostic * The Regents of the University of California. All rights reserved. 422256Sdist * 548117Sbostic * %sccs.include.redist.c% 648117Sbostic * 7*62221Sbostic * @(#)yy.h 8.1 (Berkeley) 06/06/93 822256Sdist */ 9742Speter 10742Speter #include "y.tab.h" 1123622Smckusick #undef CBSIZE /* from paramsys/param.h */ 12742Speter /* 13742Speter * INPUT/OUTPUT 14742Speter */ 15742Speter 16742Speter /* 17742Speter * The buffer for the input file is normally "ibuf". 18742Speter * When files are included, however, this may be 19742Speter * pushed down in the stack of currently active 20742Speter * files. For this reason, the pointer ibp always 21742Speter * references the i/o buffer of the current input file. 22742Speter */ 23742Speter FILE *ibuf, *ibp; 24742Speter 25742Speter /* 26742Speter * Line and token buffers. Charbuf is the character buffer for 27742Speter * input lines, token the buffer for tokens returned 28742Speter * by the scanner. CBSIZE defines the maximum line 29742Speter * length allowed on input and is doubtless too small. 30742Speter * The token buffer should be a local array in yylex. 31742Speter */ 3212395Speter #ifdef ADDR16 33742Speter #define CBSIZE 161 3412395Speter #endif ADDR16 3512395Speter #ifdef ADDR32 3612395Speter #define CBSIZE 1024 3712395Speter #endif ADDR32 38742Speter 39742Speter char charbuf[CBSIZE], *bufp, token[CBSIZE]; 40742Speter 41742Speter #define digit(c) (c >= '0' && c <= '9') 42742Speter #define alph(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 43742Speter 44742Speter /* 45742Speter * Flag to prevent reprinting current line after 46742Speter * an error. 47742Speter */ 48742Speter char yyprtd; 49742Speter 50742Speter /* 51742Speter * The following variables are maintained by 52742Speter * the scanner in the file lex and used in scanning 53742Speter * and in parsing. 54742Speter * 55742Speter * The variable yychar is the current scanner character. 56742Speter * Currently, the scanner must be called as 57742Speter * yychar = yylex() 58742Speter * even though it should set yychar itself. 59742Speter * Yychar has value YEOF at end of file, and negative value if 60742Speter * there is no yychar, e.g. after a shift in the parser. 61742Speter * 62742Speter * The variable yycol is the current column in the line whose number 63742Speter * is given by yyline. Yyecol and yyeline give the position for an 64742Speter * error message to flag, usually the start of an input token. 65742Speter * Yylval is the semantic return from the scanner. 66742Speter * 67742Speter * In fact all of these variables are "per token". 68742Speter * In the usual case, only the copies in the scanner token structure 69742Speter * 'Y' are used, and the #defines below serve to make them look 70742Speter * like variables. 71742Speter * 72742Speter * For the purposes of the error recovery, however, they are copied 73742Speter * and restored quite freely. For the error recovery also, the 74742Speter * file name which the input line this token is on and the seek 75742Speter * pointer of this line in its source file are saved as yyefile 76742Speter * and yyseekp. The global variable yylinpt is the seek pointer 77742Speter * of the current input line. 78742Speter */ 79742Speter int yycol; 80742Speter int yyline; 81742Speter int yyseqid; 82742Speter int yysavc; 83742Speter int yylinpt; 84742Speter 85742Speter /* *** NOTE *** 86742Speter * It would be much better to not have the Yyeline and Yyefile 87742Speter * in the scanner structure and to have a mechanism for mapping 88742Speter * seqid's to these globally. 89742Speter */ 90742Speter struct yytok { 91742Speter int Yychar; 92742Speter int Yylval; 93742Speter int Yyecol; 94742Speter int Yyeline; 95742Speter int Yyseekp; 96742Speter char *Yyefile; 97742Speter int Yyeseqid; 98742Speter } Y, OY; 99742Speter 100742Speter #define yychar Y.Yychar 101742Speter #define yylval Y.Yylval 102742Speter #define yyecol Y.Yyecol 103742Speter #define yyeline Y.Yyeline 104742Speter #define yyseekp Y.Yyseekp 105742Speter #define yyefile Y.Yyefile 106742Speter #define yyeseqid Y.Yyeseqid 107742Speter 10814751Sthien /* Semantic Stack so that y.tab.c will lint */ 10914751Sthien 11014751Sthien union semstack 11114751Sthien { 11214751Sthien int i_entry; 11314751Sthien struct nl *nl_entry; 11414751Sthien struct tnode *tr_entry; 11514751Sthien char *cptr; 11614751Sthien } yyval; 11714751Sthien 118742Speter /* 119742Speter * Yyval is the semantic value returned by a reduction. 120742Speter * It is what "$$" is expanded to by yacc. 121742Speter */ 122742Speter 12314751Sthien int *Ps; 12414751Sthien 125742Speter /* 126742Speter * N is the length of a reduction. 127742Speter * Used externally by "lineof" to get the left and 128742Speter * right margins for a reduction. 129742Speter */ 130742Speter int N; 131742Speter /* 132742Speter * Definitions for looking up keywords. 133742Speter * The keyword array is called yykey, and 134742Speter * lastkey points at the end of it. 135742Speter */ 136742Speter char *lastkey; 137742Speter 138742Speter struct kwtab { 139742Speter char *kw_str; 140742Speter int kw_val; 141742Speter } yykey[]; 142742Speter 143742Speter /* 144742Speter * ERROR RECOVERY EXTERNALS 145742Speter */ 146742Speter 147742Speter #define CLIMIT 40 /* see yyrecover.c */ 148742Speter char *tokname(); 149742Speter char *charname(); 150742Speter 151742Speter char *classes[]; 152742Speter 153742Speter /* 154742Speter * Tokens which yacc doesn't define 155742Speter */ 156742Speter #define YEOF 0 157742Speter #define ERROR 256 158742Speter 159742Speter /* 160742Speter * Limit on the number of syntax errors 161742Speter */ 162742Speter #define MAXSYNERR 100 163742Speter 164742Speter /* 165742Speter * Big costs 166742Speter */ 167742Speter #define HUGE 50 168742Speter #define INFINITY 100 169742Speter 170742Speter /* 171742Speter * Kinds of panics 172742Speter */ 173742Speter #define PDECL 0 174742Speter #define PSTAT 1 175742Speter #define PEXPR 2 176742Speter #define PPROG 3 177742Speter 178742Speter #define yyresume() yyResume = 1; 179742Speter 180742Speter char yyResume; 181742Speter 182742Speter char dquote; 183742Speter 18414751Sthien #ifndef PC 18514751Sthien #ifndef OBJ 186742Speter char errout; 18714751Sthien #endif OBJ 18814751Sthien #endif PC 189742Speter 190742Speter /* 191742Speter * Yyidwant and yyidhave are the namelist classes 192742Speter * of identifiers associated with a identifier reduce 193742Speter * error, set before the recovery is called. 194742Speter * Since they may be set again during the forward move 195742Speter * they must be saved by yyrecover, which uses them in printing 196742Speter * error messages. 197742Speter */ 198742Speter int yyidhave, yyidwant; 199742Speter 200742Speter /* 201742Speter * The variables yy*shifts are used to prevent looping and the printing 202742Speter * of spurious messages in the parser. Yyshifts gives the number of 203742Speter * true input shifts since the last corrective action. YyOshifts 204742Speter * is the value of yyshifts before it was last cleared, and is used 205742Speter * by yyPerror in yypanic.c to suppress messages. 206742Speter * 207742Speter * Yytshifts counts true input shifts. It is used to prevent looping 208742Speter * inserting unique symbols. If yytshifts == yyTshifts (local to 209742Speter * yyrecover.c) then there has been no shift over true input since 210742Speter * the last unique symbol insertion. We refuse, in this case, 211742Speter * to insert more unique symbols so as to prevent looping. 212742Speter * 213742Speter * The recovery cannot loop because it guarantees the progress of the 214742Speter * parse, i.e.: 215742Speter * 216742Speter * 1) Any insertion guarantees to shift over 2 symbols, a replacement 217742Speter * over one symbol. 218742Speter * 219742Speter * 2) Unique symbol insertions are limited to one for each true 220742Speter * symbol of input, or "safe" insertion of the keywords "end" 221742Speter * and "until" at zero cost (safe since these are know to match 222742Speter * stack that cannot have been generated - e.g. "begin" or "repeat") 223742Speter * 224742Speter * 3) We never panic more than once from a given state without 225742Speter * shifting over input, i.e. we force the parse stack to shrink 226742Speter * after each unsuccessful panic. 227742Speter */ 228742Speter int yyshifts, yyOshifts; 229742Speter unsigned yytshifts; 230742Speter 231742Speter #ifdef PXP 232742Speter 233742Speter /* 234742Speter * Identifier class definitions 235742Speter */ 236742Speter #define UNDEF 0 237742Speter #define CONST 1 238742Speter #define TYPE 2 239742Speter #define VAR 3 240742Speter #define ARRAY 4 241742Speter #define PTRFILE 5 242742Speter #define RECORD 6 243742Speter #define FIELD 7 244742Speter #define PROC 8 245742Speter #define FUNC 9 246742Speter #define FVAR 10 247742Speter #define REF 11 248742Speter #define PTR 12 249742Speter #define FILET 13 250742Speter #define SET 14 251742Speter #define RANGE 15 252742Speter #define LABEL 16 253742Speter #define WITHPTR 17 254742Speter #define SCAL 18 255742Speter #define STR 19 256742Speter #define PROG 20 257742Speter #define IMPROPER 21 258742Speter 259742Speter /* 260742Speter * COMMENT FORMATTING DEFINITIONS 261742Speter */ 262742Speter 263742Speter /* 264742Speter * Count of tokens on this input line 265742Speter * Note that this can be off if input is not syntactically correct. 266742Speter */ 267742Speter int yytokcnt; 268742Speter int yywhcnt; 269742Speter 270742Speter /* 271742Speter * Types of comments 272742Speter */ 273742Speter #define CLMARG 0 274742Speter #define CALIGN 1 275742Speter #define CTRAIL 2 276742Speter #define CRMARG 3 277742Speter #define CSRMARG 4 278742Speter #define CNL 5 279742Speter #define CNLBL 6 280742Speter #define CFORM 7 281742Speter #define CINCLUD 8 282742Speter 283742Speter /* 284742Speter * Comment structure 285742Speter * Cmhp is the head of the current list of comments 286742Speter */ 287742Speter struct comment { 288742Speter struct comment *cmnext; 289742Speter int cmdelim; 290742Speter struct commline *cml; 291742Speter int cmjust; 292742Speter int cmseqid; 293742Speter } *cmhp; 294742Speter 295742Speter /* 296742Speter * Structure for holding a comment line 297742Speter */ 298742Speter struct commline { 299742Speter char *cmtext; 300742Speter int cmcol; /* Only used for first line of comment currently */ 301742Speter struct commline *cml; 302742Speter }; 303742Speter 304742Speter struct W { 305742Speter int Wseqid; 306742Speter int Wcol; 307742Speter } yyw[MAXDEPTH + 1], *yypw; 308742Speter 309742Speter #define commform() quickcomm(CFORM) 310742Speter #define commnl() quickcomm(CNL) 311742Speter #define commnlbl() quickcomm(CNLBL) 312742Speter #endif 313