This repository has been archived by the owner on Mar 12, 2023. It is now read-only.
/
sub_gram.y
193 lines (187 loc) · 3.97 KB
/
sub_gram.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
%token ARROW WHITESPACE COLON BACKSLASH NEWLINE BACKNEW BANG WORD GEXCEPT ENDOFFILE
%{
#include "bellcore-copyright.h"
#include "mit-copyright.h"
#include "track.h"
extern FILE *yyin, *yyout;
char linebuf[2048];
char wordbuf[256];
char *wordp;
int wordcnt = 0;
Entry* e = &entries[ 0];
%}
%%
sublist : opt_space header entrylist
{
entnum = 0; /* signifies to printmsg() that parse is complete. */
}
;
header :
{
clear_ent();
entrycnt = 1;
e = clear_ent();
}
| GEXCEPT opt_space COLON except COLON opt_space
{
savestr( &e->fromfile, "GLOBAL_EXCEPTIONS");
/* cram compiled-in default exceptions onto lists:
*/
while ( wordp = next_def_except()) {
if ( file_pat( wordp))
add_list_elt( wordp, DONT_TRACK, &e->patterns);
else add_list_elt( wordp, DONT_TRACK, LIST( e->names));
}
/* XXX: global names should match both entry-children and
* should match occurences which are deep in an entry.
* it's ok to use linebuf for this,
* because we've processed linebuf's contents already.
*/
for ( wordp = TEXT( e->names.table); wordp;
wordp = TEXT( NEXT( wordp))) {
strcpy( linebuf, "*/");
strcat( linebuf, wordp);
add_list_elt( linebuf, DONT_TRACK, &e->patterns);
}
if ( e->names.table) { /* lie, to make extra-roomy global table */
e->names.shift *= 8;
list2hashtable( &e->names);
}
entrycnt++;
e = clear_ent();
}
;
entrylist :
| entrylist entry opt_space
;
entry : ARROW opt_space fromname COLON toname COLON shellcmd
{
savestr( &e->cmpfile, writeflag ? e->fromfile : e->tofile);
e->islink = 1;
entrycnt++;
e = clear_ent();
}
| fromname COLON toname COLON cmpname COLON except COLON shellcmd
{
if ( e->names.table) list2hashtable( &e->names);
entrycnt++;
e = clear_ent();
}
;
fromname: WORD opt_space
{
char *r = wordbuf;
while ( '/' == *r) r++;
savestr(&e->fromfile,r);
KEYCPY( e->sortkey, r);
e->keylen = strlen( r);
doreset();
}
;
toname : opt_space
{
char *defname;
defname = e->fromfile;
savestr( &e->tofile, defname);
doreset();
}
| opt_word
{
char *r = wordbuf;
while ( '/' == *r) r++;
savestr(&e->tofile,r);
doreset();
}
;
cmpname : opt_space
{
savestr( &e->cmpfile, writeflag ? e->fromfile : e->tofile);
doreset();
}
| opt_word
{
char *r = wordbuf;
while ( '/' == *r) r++;
savestr(&e->cmpfile,r);
doreset();
}
;
except : opt_space
| opt_space exlist opt_space
{
doreset();
}
;
exlist: exceptword
| exlist opt_space exceptword
;
exceptword: WORD
{
wordp = wordbuf; /* XXX lex returns longest match. */
wordcnt = DONT_TRACK; /* ->foo will thus come here. */
if ( ! strncmp( wordp, "->", 2)) {
wordp += 2;
wordcnt = FORCE_LINK;
}
if ( file_pat( wordp))
add_list_elt( wordp, wordcnt, &e->patterns);
else add_list_elt( wordp, wordcnt, LIST( e->names));
}
| BANG opt_space WORD
{
if ( file_pat( wordbuf))
add_list_elt( wordbuf, NORMALCASE, &e->patterns);
else add_list_elt( wordbuf, NORMALCASE, LIST( e->names));
}
| ARROW opt_space WORD
{
/* set force_links bit, add to e->names.
*/
if ( file_pat( wordbuf))
add_list_elt( wordbuf, FORCE_LINK, &e->patterns);
else add_list_elt( wordbuf, FORCE_LINK, LIST( e->names));
}
;
shellcmd: nullcmd NEWLINE
{
savestr(&e->cmdbuf,"");
doreset();
}
| nullcmd shline NEWLINE
{
savestr(&e->cmdbuf,linebuf);
doreset();
}
;
nullcmd:
| nullcmd WHITESPACE
| nullcmd BACKNEW
;
shline: black
| shline black
| shline WHITESPACE
| shline BACKNEW
;
black: WORD
| COLON
| BANG
| BACKSLASH
;
opt_word: opt_space WORD opt_space
;
opt_space:
| opt_space opt_ele
;
opt_ele : NEWLINE | WHITESPACE
;
%%
#include "lex.yy.c"
int
yyerror(s)
char *s;
{
if ( parseflag) justshow();
sprintf(errmsg,"parser error -- '%s'.\n bad element was near: %s\n",
s, wordbuf);
do_panic();
}