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