windoze binary rebuilt with mingw-gcc-4.4
[k8jam.git] / jamgram.y
blobb121ea9092391997d2582f92ca511748ffcefe0d
1 %token _LANGLE_t
2 %token _LANGLE_EQUALS_t
3 %token _EQUALS_t
4 %token _RANGLE_t
5 %token _RANGLE_EQUALS_t
6 %token _BAR_t
7 %token _BARBAR_t
8 %token _SEMIC_t
9 %token _COLON_t
10 %token _BANG_t
11 %token _BANG_EQUALS_t
12 %token _QUESTION_EQUALS_t
13 %token _LPAREN_t
14 %token _RPAREN_t
15 %token _LBRACKET_t
16 %token _RBRACKET_t
17 %token _LBRACE_t
18 %token _RBRACE_t
19 %token _AMPER_t
20 %token _AMPERAMPER_t
21 %token _PLUS_EQUALS_t
22 %token ACTIONS_t
23 %token BIND_t
24 %token BREAK_t
25 %token CASE_t
26 %token CONTINUE_t
27 %token DEFAULT_t
28 %token ELSE_t
29 %token EXISTING_t
30 %token FOR_t
31 %token IF_t
32 %token IGNORE_t
33 %token IN_t
34 %token INCLUDE_t
35 %token LOCAL_t
36 %token MAXLINE_t
37 %token ON_t
38 %token PIECEMEAL_t
39 %token QUIETLY_t
40 %token RETURN_t
41 %token RULE_t
42 %token SWITCH_t
43 %token TOGETHER_t
44 %token UPDATED_t
45 %token WHILE_t
47 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
49 * This file is part of Jam - see jam.c for Copyright information.
53 * jamgram.yy - jam grammar
55 * 04/13/94 (seiwald) - added shorthand L0 for null list pointer
56 * 06/01/94 (seiwald) - new 'actions existing' does existing sources
57 * 08/23/94 (seiwald) - Support for '+=' (append to variable)
58 * 08/31/94 (seiwald) - Allow ?= as alias for "default =".
59 * 09/15/94 (seiwald) - if conditionals take only single arguments, so
60 * that 'if foo == bar' gives syntax error (use =).
61 * 02/11/95 (seiwald) - when scanning arguments to rules, only treat
62 * punctuation keywords as keywords. All arg lists
63 * are terminated with punctuation keywords.
64 * 09/11/00 (seiwald) - Support for function calls; rules return LIST *.
65 * 01/22/01 (seiwald) - replace evaluate_if() with compile_eval()
66 * 01/24/01 (seiwald) - 'while' statement
67 * 03/23/01 (seiwald) - "[ on target rule ]" support
68 * 02/27/02 (seiwald) - un-break "expr : arg in list" syntax
69 * 03/02/02 (seiwald) - rules can be invoked via variable names
70 * 03/12/02 (seiwald) - set YYMAXDEPTH for big, right-recursive rules
71 * 02/28/02 (seiwald) - merge EXEC_xxx flags in with RULE_xxx
72 * 06/21/02 (seiwald) - support for named parameters
73 * 10/22/02 (seiwald) - working return/break/continue statements
76 %token ARG STRING
78 %left _BARBAR_t _BAR_t
79 %left _AMPERAMPER_t _AMPER_t
80 %left _EQUALS_t _BANG_EQUALS_t IN_t
81 %left _LANGLE_t _LANGLE_EQUALS_t _RANGLE_t _RANGLE_EQUALS_t
82 %left _BANG_t
85 #include "jam.h"
87 #include "lists.h"
88 #include "variable.h"
89 #include "parse.h"
90 #include "scan.h"
91 #include "compile.h"
92 #include "newstr.h"
93 #include "rules.h"
95 # define YYMAXDEPTH 10000 /* for OSF and other less endowed yaccs */
97 # define F0 (LIST *(*)(PARSE *, LOL *, int *))0
98 # define P0 (PARSE *)0
99 # define S0 (char *)0
101 # define pappend( l,r ) parse_make( compile_append,l,r,P0,S0,S0,0 )
102 # define pbreak( l,f ) parse_make( compile_break,l,P0,P0,S0,S0,f )
103 # define peval( c,l,r ) parse_make( compile_eval,l,r,P0,S0,S0,c )
104 # define pfor( s,l,r ) parse_make( compile_foreach,l,r,P0,s,S0,0 )
105 # define pif( l,r,t ) parse_make( compile_if,l,r,t,S0,S0,0 )
106 # define pincl( l ) parse_make( compile_include,l,P0,P0,S0,S0,0 )
107 # define plist( s ) parse_make( compile_list,P0,P0,P0,s,S0,0 )
108 # define plocal( l,r,t ) parse_make( compile_local,l,r,t,S0,S0,0 )
109 # define pnull() parse_make( compile_null,P0,P0,P0,S0,S0,0 )
110 # define pon( l,r ) parse_make( compile_on,l,r,P0,S0,S0,0 )
111 # define prule( a,p ) parse_make( compile_rule,a,p,P0,S0,S0,0 )
112 # define prules( l,r ) parse_make( compile_rules,l,r,P0,S0,S0,0 )
113 # define pset( l,r,a ) parse_make( compile_set,l,r,P0,S0,S0,a )
114 # define pset1( l,r,t,a ) parse_make( compile_settings,l,r,t,S0,S0,a )
115 # define psetc( s,l,r ) parse_make( compile_setcomp,l,r,P0,s,S0,0 )
116 # define psete( s,l,s1,f ) parse_make( compile_setexec,l,P0,P0,s,s1,f )
117 # define pswitch( l,r ) parse_make( compile_switch,l,r,P0,S0,S0,0 )
118 # define pwhile( l,r ) parse_make( compile_while,l,r,P0,S0,S0,0 )
120 # define pnode( l,r ) parse_make( F0,l,r,P0,S0,S0,0 )
121 # define psnode( s,l ) parse_make( F0,l,P0,P0,s,S0,0 )
127 run : /* empty */
128 /* do nothing */
129 | rules
130 { parse_save( $1.parse ); }
134 * block - zero or more rules
135 * rules - one or more rules
136 * rule - any one of jam's rules
137 * right-recursive so rules execute in order.
140 block : /* empty */
141 { $$.parse = pnull(); }
142 | rules
143 { $$.parse = $1.parse; }
146 rules : rule
147 { $$.parse = $1.parse; }
148 | rule rules
149 { $$.parse = prules( $1.parse, $2.parse ); }
150 | LOCAL_t list _SEMIC_t block
151 { $$.parse = plocal( $2.parse, pnull(), $4.parse ); }
152 | LOCAL_t list _EQUALS_t list _SEMIC_t block
153 { $$.parse = plocal( $2.parse, $4.parse, $6.parse ); }
156 rule : _LBRACE_t block _RBRACE_t
157 { $$.parse = $2.parse; }
158 | INCLUDE_t list _SEMIC_t
159 { $$.parse = pincl( $2.parse ); }
160 | arg lol _SEMIC_t
161 { $$.parse = prule( $1.parse, $2.parse ); }
162 | arg assign list _SEMIC_t
163 { $$.parse = pset( $1.parse, $3.parse, $2.number ); }
164 | arg ON_t list assign list _SEMIC_t
165 { $$.parse = pset1( $1.parse, $3.parse, $5.parse, $4.number ); }
166 | BREAK_t list _SEMIC_t
167 { $$.parse = pbreak( $2.parse, JMP_BREAK ); }
168 | CONTINUE_t list _SEMIC_t
169 { $$.parse = pbreak( $2.parse, JMP_CONTINUE ); }
170 | RETURN_t list _SEMIC_t
171 { $$.parse = pbreak( $2.parse, JMP_RETURN ); }
172 | FOR_t ARG IN_t list _LBRACE_t block _RBRACE_t
173 { $$.parse = pfor( $2.string, $4.parse, $6.parse ); }
174 | SWITCH_t list _LBRACE_t cases _RBRACE_t
175 { $$.parse = pswitch( $2.parse, $4.parse ); }
176 | IF_t expr _LBRACE_t block _RBRACE_t
177 { $$.parse = pif( $2.parse, $4.parse, pnull() ); }
178 | IF_t expr _LBRACE_t block _RBRACE_t ELSE_t rule
179 { $$.parse = pif( $2.parse, $4.parse, $7.parse ); }
180 | WHILE_t expr _LBRACE_t block _RBRACE_t
181 { $$.parse = pwhile( $2.parse, $4.parse ); }
182 | RULE_t ARG params _LBRACE_t block _RBRACE_t
183 { $$.parse = psetc( $2.string, $3.parse, $5.parse ); }
184 | ON_t arg rule
185 { $$.parse = pon( $2.parse, $3.parse ); }
186 | ACTIONS_t eflags ARG bindlist _LBRACE_t
187 { yymode( SCAN_STRING ); }
188 STRING
189 { yymode( SCAN_NORMAL ); }
190 _RBRACE_t
191 { $$.parse = psete( $3.string,$4.parse,$7.string,$2.number ); }
195 * assign - = or +=
198 assign : _EQUALS_t
199 { $$.number = VAR_SET; }
200 | _PLUS_EQUALS_t
201 { $$.number = VAR_APPEND; }
202 | _QUESTION_EQUALS_t
203 { $$.number = VAR_DEFAULT; }
204 | DEFAULT_t _EQUALS_t
205 { $$.number = VAR_DEFAULT; }
209 * expr - an expression for if
212 expr : arg
213 { $$.parse = peval( EXPR_EXISTS, $1.parse, pnull() ); }
214 | expr _EQUALS_t expr
215 { $$.parse = peval( EXPR_EQUALS, $1.parse, $3.parse ); }
216 | expr _BANG_EQUALS_t expr
217 { $$.parse = peval( EXPR_NOTEQ, $1.parse, $3.parse ); }
218 | expr _LANGLE_t expr
219 { $$.parse = peval( EXPR_LESS, $1.parse, $3.parse ); }
220 | expr _LANGLE_EQUALS_t expr
221 { $$.parse = peval( EXPR_LESSEQ, $1.parse, $3.parse ); }
222 | expr _RANGLE_t expr
223 { $$.parse = peval( EXPR_MORE, $1.parse, $3.parse ); }
224 | expr _RANGLE_EQUALS_t expr
225 { $$.parse = peval( EXPR_MOREEQ, $1.parse, $3.parse ); }
226 | expr _AMPER_t expr
227 { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); }
228 | expr _AMPERAMPER_t expr
229 { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); }
230 | expr _BAR_t expr
231 { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); }
232 | expr _BARBAR_t expr
233 { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); }
234 | arg IN_t list
235 { $$.parse = peval( EXPR_IN, $1.parse, $3.parse ); }
236 | _BANG_t expr
237 { $$.parse = peval( EXPR_NOT, $2.parse, pnull() ); }
238 | _LPAREN_t expr _RPAREN_t
239 { $$.parse = $2.parse; }
243 * cases - action elements inside a 'switch'
244 * case - a single action element inside a 'switch'
245 * right-recursive rule so cases can be examined in order.
248 cases : /* empty */
249 { $$.parse = P0; }
250 | case cases
251 { $$.parse = pnode( $1.parse, $2.parse ); }
254 case : CASE_t ARG _COLON_t block
255 { $$.parse = psnode( $2.string, $4.parse ); }
259 * params - optional parameter names to rule definition
260 * right-recursive rule so that params can be added in order.
263 params : /* empty */
264 { $$.parse = P0; }
265 | ARG _COLON_t params
266 { $$.parse = psnode( $1.string, $3.parse ); }
267 | ARG
268 { $$.parse = psnode( $1.string, P0 ); }
272 * lol - list of lists
273 * right-recursive rule so that lists can be added in order.
276 lol : list
277 { $$.parse = pnode( P0, $1.parse ); }
278 | list _COLON_t lol
279 { $$.parse = pnode( $3.parse, $1.parse ); }
283 * list - zero or more args in a LIST
284 * listp - list (in puncutation only mode)
285 * arg - one ARG or function call
288 list : listp
289 { $$.parse = $1.parse; yymode( SCAN_NORMAL ); }
292 listp : /* empty */
293 { $$.parse = pnull(); yymode( SCAN_PUNCT ); }
294 | listp arg
295 { $$.parse = pappend( $1.parse, $2.parse ); }
298 arg : ARG
299 { $$.parse = plist( $1.string ); }
300 | _LBRACKET_t { yymode( SCAN_NORMAL ); } func _RBRACKET_t
301 { $$.parse = $3.parse; }
305 * func - a function call (inside [])
306 * This needs to be split cleanly out of 'rule'
309 func : arg lol
310 { $$.parse = prule( $1.parse, $2.parse ); }
311 | ON_t arg arg lol
312 { $$.parse = pon( $2.parse, prule( $3.parse, $4.parse ) ); }
313 | ON_t arg RETURN_t list
314 { $$.parse = pon( $2.parse, $4.parse ); }
318 * eflags - zero or more modifiers to 'executes'
319 * eflag - a single modifier to 'executes'
322 eflags : /* empty */
323 { $$.number = 0; }
324 | eflags eflag
325 { $$.number = $1.number | $2.number; }
328 eflag : UPDATED_t
329 { $$.number = RULE_UPDATED; }
330 | TOGETHER_t
331 { $$.number = RULE_TOGETHER; }
332 | IGNORE_t
333 { $$.number = RULE_IGNORE; }
334 | QUIETLY_t
335 { $$.number = RULE_QUIETLY; }
336 | PIECEMEAL_t
337 { $$.number = RULE_PIECEMEAL; }
338 | EXISTING_t
339 { $$.number = RULE_EXISTING; }
340 | MAXLINE_t ARG
341 { $$.number = atoi( $2.string ) * RULE_MAXLINE; }
346 * bindlist - list of variable to bind for an action
349 bindlist : /* empty */
350 { $$.parse = pnull(); }
351 | BIND_t list
352 { $$.parse = $2.parse; }