home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / pascal / src / yy.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  8.5 KB  |  339 lines

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