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