1 | %token _BANG_t |
---|
2 | %token _BANG_EQUALS_t |
---|
3 | %token _AMPER_t |
---|
4 | %token _AMPERAMPER_t |
---|
5 | %token _LPAREN_t |
---|
6 | %token _RPAREN_t |
---|
7 | %token _PLUS_EQUALS_t |
---|
8 | %token _COLON_t |
---|
9 | %token _SEMIC_t |
---|
10 | %token _LANGLE_t |
---|
11 | %token _LANGLE_EQUALS_t |
---|
12 | %token _EQUALS_t |
---|
13 | %token _RANGLE_t |
---|
14 | %token _RANGLE_EQUALS_t |
---|
15 | %token _QUESTION_EQUALS_t |
---|
16 | %token _LBRACKET_t |
---|
17 | %token _RBRACKET_t |
---|
18 | %token ACTIONS_t |
---|
19 | %token BIND_t |
---|
20 | %token CASE_t |
---|
21 | %token CLASS_t |
---|
22 | %token DEFAULT_t |
---|
23 | %token ELSE_t |
---|
24 | %token EXISTING_t |
---|
25 | %token FOR_t |
---|
26 | %token IF_t |
---|
27 | %token IGNORE_t |
---|
28 | %token IN_t |
---|
29 | %token INCLUDE_t |
---|
30 | %token LOCAL_t |
---|
31 | %token MODULE_t |
---|
32 | %token ON_t |
---|
33 | %token PIECEMEAL_t |
---|
34 | %token QUIETLY_t |
---|
35 | %token RETURN_t |
---|
36 | %token RULE_t |
---|
37 | %token SWITCH_t |
---|
38 | %token TOGETHER_t |
---|
39 | %token UPDATED_t |
---|
40 | %token WHILE_t |
---|
41 | %token _LBRACE_t |
---|
42 | %token _BAR_t |
---|
43 | %token _BARBAR_t |
---|
44 | %token _RBRACE_t |
---|
45 | /* |
---|
46 | * Copyright 1993, 2000 Christopher Seiwald. |
---|
47 | * |
---|
48 | * This file is part of Jam - see jam.c for Copyright information. |
---|
49 | */ |
---|
50 | |
---|
51 | /* This file is ALSO: |
---|
52 | * Copyright 2001-2004 David Abrahams. |
---|
53 | * Distributed under the Boost Software License, Version 1.0. |
---|
54 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
---|
55 | */ |
---|
56 | |
---|
57 | /* |
---|
58 | * jamgram.yy - jam grammar |
---|
59 | * |
---|
60 | * 04/13/94 (seiwald) - added shorthand L0 for null list pointer |
---|
61 | * 06/01/94 (seiwald) - new 'actions existing' does existing sources |
---|
62 | * 08/23/94 (seiwald) - Support for '+=' (append to variable) |
---|
63 | * 08/31/94 (seiwald) - Allow ?= as alias for "default =". |
---|
64 | * 09/15/94 (seiwald) - if conditionals take only single arguments, so |
---|
65 | * that 'if foo == bar' gives syntax error (use =). |
---|
66 | * 02/11/95 (seiwald) - when scanning arguments to rules, only treat |
---|
67 | * punctuation keywords as keywords. All arg lists |
---|
68 | * are terminated with punctuation keywords. |
---|
69 | * |
---|
70 | * 09/11/00 (seiwald) - Support for function calls: |
---|
71 | * |
---|
72 | * Rules now return lists (LIST *), rather than void. |
---|
73 | * |
---|
74 | * New "[ rule ]" syntax evals rule into a LIST. |
---|
75 | * |
---|
76 | * Lists are now generated by compile_list() and |
---|
77 | * compile_append(), and any other rule that indirectly |
---|
78 | * makes a list, rather than being built directly here, |
---|
79 | * so that lists values can contain rule evaluations. |
---|
80 | * |
---|
81 | * New 'return' rule sets the return value, though |
---|
82 | * other statements also may have return values. |
---|
83 | * |
---|
84 | * 'run' production split from 'block' production so |
---|
85 | * that empty blocks can be handled separately. |
---|
86 | */ |
---|
87 | |
---|
88 | %token ARG STRING |
---|
89 | |
---|
90 | %left _BARBAR_t _BAR_t |
---|
91 | %left _AMPERAMPER_t _AMPER_t |
---|
92 | %left _EQUALS_t _BANG_EQUALS_t IN_t |
---|
93 | %left _LANGLE_t _LANGLE_EQUALS_t _RANGLE_t _RANGLE_EQUALS_t |
---|
94 | %left _BANG_t |
---|
95 | |
---|
96 | %{ |
---|
97 | #include "jam.h" |
---|
98 | |
---|
99 | #include "lists.h" |
---|
100 | #include "parse.h" |
---|
101 | #include "scan.h" |
---|
102 | #include "compile.h" |
---|
103 | #include "newstr.h" |
---|
104 | #include "rules.h" |
---|
105 | |
---|
106 | # define YYMAXDEPTH 10000 /* for OSF and other less endowed yaccs */ |
---|
107 | |
---|
108 | # define F0 (LIST *(*)(PARSE *, FRAME *))0 |
---|
109 | # define P0 (PARSE *)0 |
---|
110 | # define S0 (char *)0 |
---|
111 | |
---|
112 | # define pappend( l,r ) parse_make( compile_append,l,r,P0,S0,S0,0 ) |
---|
113 | # define peval( c,l,r ) parse_make( compile_eval,l,r,P0,S0,S0,c ) |
---|
114 | # define pfor( s,l,r,x ) parse_make( compile_foreach,l,r,P0,s,S0,x ) |
---|
115 | # define pif( l,r,t ) parse_make( compile_if,l,r,t,S0,S0,0 ) |
---|
116 | # define pincl( l ) parse_make( compile_include,l,P0,P0,S0,S0,0 ) |
---|
117 | # define plist( s ) parse_make( compile_list,P0,P0,P0,s,S0,0 ) |
---|
118 | # define plocal( l,r,t ) parse_make( compile_local,l,r,t,S0,S0,0 ) |
---|
119 | # define pmodule( l,r ) parse_make( compile_module,l,r,P0,S0,S0,0 ) |
---|
120 | # define pclass( l,r ) parse_make( compile_class,l,r,P0,S0,S0,0 ) |
---|
121 | # define pnull() parse_make( compile_null,P0,P0,P0,S0,S0,0 ) |
---|
122 | # define pon( l,r ) parse_make( compile_on,l,r,P0,S0,S0,0 ) |
---|
123 | # define prule( s,p ) parse_make( compile_rule,p,P0,P0,s,S0,0 ) |
---|
124 | # define prules( l,r ) parse_make( compile_rules,l,r,P0,S0,S0,0 ) |
---|
125 | # define pset( l,r,a ) parse_make( compile_set,l,r,P0,S0,S0,a ) |
---|
126 | # define pset1( l,r,t,a ) parse_make( compile_settings,l,r,t,S0,S0,a ) |
---|
127 | # define psetc( s,p,a,l ) parse_make( compile_setcomp,p,a,P0,s,S0,l ) |
---|
128 | # define psete( s,l,s1,f ) parse_make( compile_setexec,l,P0,P0,s,s1,f ) |
---|
129 | # define pswitch( l,r ) parse_make( compile_switch,l,r,P0,S0,S0,0 ) |
---|
130 | # define pwhile( l,r ) parse_make( compile_while,l,r,P0,S0,S0,0 ) |
---|
131 | |
---|
132 | # define pnode( l,r ) parse_make( F0,l,r,P0,S0,S0,0 ) |
---|
133 | # define psnode( s,l ) parse_make( F0,l,P0,P0,s,S0,0 ) |
---|
134 | |
---|
135 | %} |
---|
136 | |
---|
137 | %% |
---|
138 | |
---|
139 | run : /* empty */ |
---|
140 | /* do nothing */ |
---|
141 | | rules |
---|
142 | { parse_save( $1.parse ); } |
---|
143 | ; |
---|
144 | |
---|
145 | /* |
---|
146 | * block - zero or more rules |
---|
147 | * rules - one or more rules |
---|
148 | * rule - any one of jam's rules |
---|
149 | * right-recursive so rules execute in order. |
---|
150 | */ |
---|
151 | |
---|
152 | block : null |
---|
153 | { $$.parse = $1.parse; } |
---|
154 | | rules |
---|
155 | { $$.parse = $1.parse; } |
---|
156 | ; |
---|
157 | |
---|
158 | rules : rule |
---|
159 | { $$.parse = $1.parse; } |
---|
160 | | rule rules |
---|
161 | { $$.parse = prules( $1.parse, $2.parse ); } |
---|
162 | | LOCAL_t list assign_list_opt _SEMIC_t block |
---|
163 | { $$.parse = plocal( $2.parse, $3.parse, $5.parse ); } |
---|
164 | ; |
---|
165 | |
---|
166 | null : /* empty */ |
---|
167 | { $$.parse = pnull(); } |
---|
168 | ; |
---|
169 | |
---|
170 | assign_list_opt : _EQUALS_t list |
---|
171 | { $$.parse = $2.parse; $$.number = ASSIGN_SET; } |
---|
172 | | null |
---|
173 | { $$.parse = $1.parse; $$.number = ASSIGN_APPEND; } |
---|
174 | ; |
---|
175 | |
---|
176 | arglist_opt : _LPAREN_t lol _RPAREN_t |
---|
177 | { $$.parse = $2.parse; } |
---|
178 | | |
---|
179 | { $$.parse = P0; } |
---|
180 | ; |
---|
181 | |
---|
182 | local_opt : LOCAL_t |
---|
183 | { $$.number = 1; } |
---|
184 | | /* empty */ |
---|
185 | { $$.number = 0; } |
---|
186 | ; |
---|
187 | |
---|
188 | rule : _LBRACE_t block _RBRACE_t |
---|
189 | { $$.parse = $2.parse; } |
---|
190 | | INCLUDE_t list _SEMIC_t |
---|
191 | { $$.parse = pincl( $2.parse ); } |
---|
192 | | ARG lol _SEMIC_t |
---|
193 | { $$.parse = prule( $1.string, $2.parse ); } |
---|
194 | | arg assign list _SEMIC_t |
---|
195 | { $$.parse = pset( $1.parse, $3.parse, $2.number ); } |
---|
196 | | arg ON_t list assign list _SEMIC_t |
---|
197 | { $$.parse = pset1( $1.parse, $3.parse, $5.parse, $4.number ); } |
---|
198 | | RETURN_t list _SEMIC_t |
---|
199 | { $$.parse = $2.parse; } |
---|
200 | | FOR_t local_opt ARG IN_t list _LBRACE_t block _RBRACE_t |
---|
201 | { $$.parse = pfor( $3.string, $5.parse, $7.parse, $2.number ); } |
---|
202 | | SWITCH_t list _LBRACE_t cases _RBRACE_t |
---|
203 | { $$.parse = pswitch( $2.parse, $4.parse ); } |
---|
204 | | IF_t expr _LBRACE_t block _RBRACE_t |
---|
205 | { $$.parse = pif( $2.parse, $4.parse, pnull() ); } |
---|
206 | | MODULE_t list _LBRACE_t block _RBRACE_t |
---|
207 | { $$.parse = pmodule( $2.parse, $4.parse ); } |
---|
208 | | CLASS_t lol _LBRACE_t block _RBRACE_t |
---|
209 | { $$.parse = pclass( $2.parse, $4.parse ); } |
---|
210 | | WHILE_t expr _LBRACE_t block _RBRACE_t |
---|
211 | { $$.parse = pwhile( $2.parse, $4.parse ); } |
---|
212 | | IF_t expr _LBRACE_t block _RBRACE_t ELSE_t rule |
---|
213 | { $$.parse = pif( $2.parse, $4.parse, $7.parse ); } |
---|
214 | | local_opt RULE_t ARG arglist_opt rule |
---|
215 | { $$.parse = psetc( $3.string, $5.parse, $4.parse, $1.number ); } |
---|
216 | | ON_t arg rule |
---|
217 | { $$.parse = pon( $2.parse, $3.parse ); } |
---|
218 | | ACTIONS_t eflags ARG bindlist _LBRACE_t |
---|
219 | { yymode( SCAN_STRING ); } |
---|
220 | STRING |
---|
221 | { yymode( SCAN_NORMAL ); } |
---|
222 | _RBRACE_t |
---|
223 | { $$.parse = psete( $3.string,$4.parse,$7.string,$2.number ); } |
---|
224 | ; |
---|
225 | |
---|
226 | /* |
---|
227 | * assign - = or += |
---|
228 | */ |
---|
229 | |
---|
230 | assign : _EQUALS_t |
---|
231 | { $$.number = ASSIGN_SET; } |
---|
232 | | _PLUS_EQUALS_t |
---|
233 | { $$.number = ASSIGN_APPEND; } |
---|
234 | | _QUESTION_EQUALS_t |
---|
235 | { $$.number = ASSIGN_DEFAULT; } |
---|
236 | | DEFAULT_t _EQUALS_t |
---|
237 | { $$.number = ASSIGN_DEFAULT; } |
---|
238 | ; |
---|
239 | |
---|
240 | /* |
---|
241 | * expr - an expression for if |
---|
242 | */ |
---|
243 | expr : arg |
---|
244 | { $$.parse = peval( EXPR_EXISTS, $1.parse, pnull() ); } |
---|
245 | | expr _EQUALS_t expr |
---|
246 | { $$.parse = peval( EXPR_EQUALS, $1.parse, $3.parse ); } |
---|
247 | | expr _BANG_EQUALS_t expr |
---|
248 | { $$.parse = peval( EXPR_NOTEQ, $1.parse, $3.parse ); } |
---|
249 | | expr _LANGLE_t expr |
---|
250 | { $$.parse = peval( EXPR_LESS, $1.parse, $3.parse ); } |
---|
251 | | expr _LANGLE_EQUALS_t expr |
---|
252 | { $$.parse = peval( EXPR_LESSEQ, $1.parse, $3.parse ); } |
---|
253 | | expr _RANGLE_t expr |
---|
254 | { $$.parse = peval( EXPR_MORE, $1.parse, $3.parse ); } |
---|
255 | | expr _RANGLE_EQUALS_t expr |
---|
256 | { $$.parse = peval( EXPR_MOREEQ, $1.parse, $3.parse ); } |
---|
257 | | expr _AMPER_t expr |
---|
258 | { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); } |
---|
259 | | expr _AMPERAMPER_t expr |
---|
260 | { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); } |
---|
261 | | expr _BAR_t expr |
---|
262 | { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); } |
---|
263 | | expr _BARBAR_t expr |
---|
264 | { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); } |
---|
265 | | arg IN_t list |
---|
266 | { $$.parse = peval( EXPR_IN, $1.parse, $3.parse ); } |
---|
267 | | _BANG_t expr |
---|
268 | { $$.parse = peval( EXPR_NOT, $2.parse, pnull() ); } |
---|
269 | | _LPAREN_t expr _RPAREN_t |
---|
270 | { $$.parse = $2.parse; } |
---|
271 | ; |
---|
272 | |
---|
273 | |
---|
274 | /* |
---|
275 | * cases - action elements inside a 'switch' |
---|
276 | * case - a single action element inside a 'switch' |
---|
277 | * right-recursive rule so cases can be examined in order. |
---|
278 | */ |
---|
279 | |
---|
280 | cases : /* empty */ |
---|
281 | { $$.parse = P0; } |
---|
282 | | case cases |
---|
283 | { $$.parse = pnode( $1.parse, $2.parse ); } |
---|
284 | ; |
---|
285 | |
---|
286 | case : CASE_t ARG _COLON_t block |
---|
287 | { $$.parse = psnode( $2.string, $4.parse ); } |
---|
288 | ; |
---|
289 | |
---|
290 | /* |
---|
291 | * lol - list of lists |
---|
292 | * right-recursive rule so that lists can be added in order. |
---|
293 | */ |
---|
294 | |
---|
295 | lol : list |
---|
296 | { $$.parse = pnode( P0, $1.parse ); } |
---|
297 | | list _COLON_t lol |
---|
298 | { $$.parse = pnode( $3.parse, $1.parse ); } |
---|
299 | ; |
---|
300 | |
---|
301 | /* |
---|
302 | * list - zero or more args in a LIST |
---|
303 | * listp - list (in puncutation only mode) |
---|
304 | * arg - one ARG or function call |
---|
305 | */ |
---|
306 | |
---|
307 | list : listp |
---|
308 | { $$.parse = $1.parse; yymode( SCAN_NORMAL ); } |
---|
309 | ; |
---|
310 | |
---|
311 | listp : /* empty */ |
---|
312 | { $$.parse = pnull(); yymode( SCAN_PUNCT ); } |
---|
313 | | listp arg |
---|
314 | { $$.parse = pappend( $1.parse, $2.parse ); } |
---|
315 | ; |
---|
316 | |
---|
317 | arg : ARG |
---|
318 | { $$.parse = plist( $1.string ); } |
---|
319 | | _LBRACKET_t { yymode( SCAN_NORMAL ); } func _RBRACKET_t |
---|
320 | { $$.parse = $3.parse; } |
---|
321 | ; |
---|
322 | |
---|
323 | /* |
---|
324 | * func - a function call (inside []) |
---|
325 | * This needs to be split cleanly out of 'rule' |
---|
326 | */ |
---|
327 | |
---|
328 | func : arg lol |
---|
329 | { $$.parse = prule( $1.string, $2.parse ); } |
---|
330 | | ON_t arg arg lol |
---|
331 | { $$.parse = pon( $2.parse, prule( $3.string, $4.parse ) ); } |
---|
332 | | ON_t arg RETURN_t list |
---|
333 | { $$.parse = pon( $2.parse, $4.parse ); } |
---|
334 | ; |
---|
335 | |
---|
336 | |
---|
337 | /* |
---|
338 | * eflags - zero or more modifiers to 'executes' |
---|
339 | * eflag - a single modifier to 'executes' |
---|
340 | */ |
---|
341 | |
---|
342 | eflags : /* empty */ |
---|
343 | { $$.number = 0; } |
---|
344 | | eflags eflag |
---|
345 | { $$.number = $1.number | $2.number; } |
---|
346 | ; |
---|
347 | |
---|
348 | eflag : UPDATED_t |
---|
349 | { $$.number = EXEC_UPDATED; } |
---|
350 | | TOGETHER_t |
---|
351 | { $$.number = EXEC_TOGETHER; } |
---|
352 | | IGNORE_t |
---|
353 | { $$.number = EXEC_IGNORE; } |
---|
354 | | QUIETLY_t |
---|
355 | { $$.number = EXEC_QUIETLY; } |
---|
356 | | PIECEMEAL_t |
---|
357 | { $$.number = EXEC_PIECEMEAL; } |
---|
358 | | EXISTING_t |
---|
359 | { $$.number = EXEC_EXISTING; } |
---|
360 | ; |
---|
361 | |
---|
362 | |
---|
363 | /* |
---|
364 | * bindlist - list of variable to bind for an action |
---|
365 | */ |
---|
366 | |
---|
367 | bindlist : /* empty */ |
---|
368 | { $$.parse = pnull(); } |
---|
369 | | BIND_t list |
---|
370 | { $$.parse = $2.parse; } |
---|
371 | ; |
---|
372 | |
---|
373 | |
---|