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