1: # include <sccs.h>
2:
3: SCCSID(@(#)parser.c 8.1 12/31/84)
4:
5:
6: # define MAXDEPTH 150
7:
8: /*
9: ** PARSER FOR YACC OUTPUT
10: **
11: ** This is the same as the yacc parser found in the UNIX system
12: ** library "/lib/liby.a". There have been two kinds of
13: ** modifications. 1) The coding style has been altered to conform
14: ** to the INGRES standard. 2) The changes marked by comments.
15: */
16:
17: extern int yyval; /* defined in the table file */
18: extern int yylval; /* defined in the table file */
19: extern int *yypv; /* defined in the table file */
20:
21:
22: /* -------- the next line is an INGRES customization -------- */
23: int yypflag 1; /* zero for no actions performed */
24: int yydebug 0; /* 1 for debugging */
25: int yyv[MAXDEPTH]; /* where the values are stored */
26: int yystate 0; /* current parser state */
27: int yychar -1; /* current input token number */
28: int yynerrs 0; /* number of errors */
29: int yyerrflag 0; /* error recovery flag */
30:
31:
32: yyparse()
33: {
34: extern int yygo[], yypgo[], yyr1[], yyr2[], yyact[], yypact[];
35: /* INGRES customization to make 'ps', 'p', and 'n' register variables */
36: int s[MAXDEPTH];
37: register int *ps, *p;
38: register int n;
39: int ac;
40:
41: yystate = 0;
42: yychar = -1;
43: yynerrs = 0;
44: yyerrflag = 0;
45: ps = &s[0] - 1;
46: yypv = &yyv[0] - 1;
47:
48: stack: /* put a state and value onto the stack */
49: if (yydebug)
50: printf("state %d value %d char %d\n", yystate, yyval, yychar);
51: *++ps = yystate;
52: *++yypv = yyval;
53:
54: newstate: /* set ap to point to the parsing actions for the new state */
55:
56: p = &yyact[yypact[yystate + 1]];
57:
58: actn: /* get the next action, and perform it */
59: n = (ac = *p++) & 07777; /* n is the "address" of the action */
60:
61: switch (ac >> 12) /* switch on operation */
62: {
63:
64: case 1: /* skip on test */
65: if (yychar < 0)
66: {
67: yychar = yylex();
68: if (yydebug)
69: printf( "character %d read\n", yychar );
70: }
71: /* ---------- the next two lines are an INGRES customization ---------- */
72: if (yychar < 0)
73: return(1);
74: if (n != yychar)
75: p++;
76: goto actn; /* get next action */
77:
78: case 2: /* shift */
79: yystate = n;
80: yyval = yylval;
81: yychar = -1;
82: if (yyerrflag)
83: yyerrflag--;
84: goto stack; /* stack new state */
85:
86: case 3: /* reduce */
87: if (yydebug)
88: printf("reduce %d\n", n);
89: ps =- yyr2[n];
90: yypv =- yyr2[n];
91: yyval = yypv[1];
92: /* -------- the next 2 lines are an INGRES customization -------- */
93: if (yypflag && yyactr(n))
94: goto abort;
95: /* consult goto table to find next state */
96: for (p = &yygo[yypgo[yyr1[n]]]; *p != *ps && *p >= 0; p =+ 2) ;
97: yystate = p[1];
98: goto stack; /* stack new state and value */
99:
100: case 4: /* accept */
101: return(0);
102:
103: case 0: /* error ... attempt to resume parsing */
104: switch (yyerrflag)
105: {
106:
107: case 0: /* brand new error */
108: /* ----------the next 2 lines are an INGRES customization ---------- */
109: /* syntax error */
110: yyerror("syntax error");
111: yynerrs++;
112:
113: case 1:
114: case 2: /* incompletely recovered error ... try again */
115: yyerrflag = 3;
116:
117: /* find a state where "error" is a legal shift action */
118: while (ps >= s)
119: {
120: /* search ps actions */
121: for (p = &yyact[yypact[*ps + 1]]; (*p >> 12) == 1; p =+ 2)
122: if (*p == 4352)
123: goto found;
124:
125: /* the current ps has no shift onn "error", pop stack */
126:
127: if (yydebug)
128: printf("err recov pops state %d, uncovers %d\n", ps[0], ps[-1]);
129: ps--;
130: yypv--;
131: }
132:
133: /* there is no state on the stack with an error shift ... abort */
134:
135: abort:
136: return(1);
137:
138: found: /* we have a state with a shift on "error", resume parsing */
139: yystate = p[1] & 07777;
140: goto stack;
141:
142: case 3: /* no shift yet; clobber input char */
143: if (yydebug)
144: printf("err recov discards char %d\n", yychar);
145:
146: /* don't discard EOF; quit */
147: if (yychar == 0)
148: goto abort;
149: yychar = -1;
150: goto newstate; /* try again in the same state */
151:
152: }
153: }
154: }
Defined functions
Defined variables
yychar
defined in line
27; used 12 times
yyv
defined in line
25; used 1 times
Defined macros