2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * jamgram.yy - jam grammar
10 * 04/13/94 (seiwald) - added shorthand L0 for null list pointer
11 * 06/01/94 (seiwald) - new 'actions existing' does existing sources
12 * 08/23/94 (seiwald) - Support for '+=' (append to variable)
13 * 08/31/94 (seiwald) - Allow ?= as alias for "default =".
14 * 09/15/94 (seiwald) - if conditionals take only single arguments, so
15 * that 'if foo == bar' gives syntax error (use =).
16 * 02/11/95 (seiwald) - when scanning arguments to rules, only treat
17 * punctuation keywords as keywords. All arg lists
18 * are terminated with punctuation keywords.
19 * 09/11/00 (seiwald) - Support for function calls; rules return LIST *.
20 * 01/22/01 (seiwald) - replace evaluate_if() with compile_eval()
21 * 01/24/01 (seiwald) - 'while' statement
22 * 03/23/01 (seiwald) - "[ on target rule ]" support
23 * 02/27/02 (seiwald) - un-break "expr : arg in list" syntax
24 * 03/02/02 (seiwald) - rules can be invoked via variable names
25 * 03/12/02 (seiwald) - set YYMAXDEPTH for big, right-recursive rules
26 * 02/28/02 (seiwald) - merge EXEC_xxx flags in with RULE_xxx
27 * 06/21/02 (seiwald) - support for named parameters
28 * 10/22/02 (seiwald) - working return/break/continue statements
36 %left `<` `<=` `>` `>=`
50 # define YYMAXDEPTH 10000 /* for OSF and other less endowed yaccs */
52 # define F0 (LIST *(*)(PARSE *, LOL *, int *))0
53 # define P0 (PARSE *)0
56 # define pappend( l,r ) parse_make( compile_append,l,r,P0,S0,S0,0 )
57 # define pbreak( l,f ) parse_make( compile_break,l,P0,P0,S0,S0,f )
58 # define peval( c,l,r ) parse_make( compile_eval,l,r,P0,S0,S0,c )
59 # define pfor( s,l,r ) parse_make( compile_foreach,l,r,P0,s,S0,0 )
60 # define pif( l,r,t ) parse_make( compile_if,l,r,t,S0,S0,0 )
61 # define pincl( l ) parse_make( compile_include,l,P0,P0,S0,S0,0 )
62 # define plist( s ) parse_make( compile_list,P0,P0,P0,s,S0,0 )
63 # define plocal( l,r,t ) parse_make( compile_local,l,r,t,S0,S0,0 )
64 # define pnull() parse_make( compile_null,P0,P0,P0,S0,S0,0 )
65 # define pon( l,r ) parse_make( compile_on,l,r,P0,S0,S0,0 )
66 # define prule( a,p ) parse_make( compile_rule,a,p,P0,S0,S0,0 )
67 # define prules( l,r ) parse_make( compile_rules,l,r,P0,S0,S0,0 )
68 # define pset( l,r,a ) parse_make( compile_set,l,r,P0,S0,S0,a )
69 # define pset1( l,r,t,a ) parse_make( compile_settings,l,r,t,S0,S0,a )
70 # define psetc( s,l,r ) parse_make( compile_setcomp,l,r,P0,s,S0,0 )
71 # define psete( s,l,s1,f ) parse_make( compile_setexec,l,P0,P0,s,s1,f )
72 # define pswitch( l,r ) parse_make( compile_switch,l,r,P0,S0,S0,0 )
73 # define pwhile( l,r ) parse_make( compile_while,l,r,P0,S0,S0,0 )
75 # define pnode( l,r ) parse_make( F0,l,r,P0,S0,S0,0 )
76 # define psnode( s,l ) parse_make( F0,l,P0,P0,s,S0,0 )
85 { parse_save( $1.parse ); }
89 * block - zero or more rules
90 * rules - one or more rules
91 * rule - any one of jam's rules
92 * right-recursive so rules execute in order.
96 { $$.parse = pnull(); }
98 { $$.parse = $1.parse; }
102 { $$.parse = $1.parse; }
104 { $$.parse = prules( $1.parse, $2.parse ); }
105 | `local` list `;` block
106 { $$.parse = plocal( $2.parse, pnull(), $4.parse ); }
107 | `local` list `=` list `;` block
108 { $$.parse = plocal( $2.parse, $4.parse, $6.parse ); }
112 { $$.parse = $2.parse; }
114 { $$.parse = pincl( $2.parse ); }
116 { $$.parse = prule( $1.parse, $2.parse ); }
117 | arg assign list `;`
118 { $$.parse = pset( $1.parse, $3.parse, $2.number ); }
119 | arg `on` list assign list `;`
120 { $$.parse = pset1( $1.parse, $3.parse, $5.parse, $4.number ); }
122 { $$.parse = pbreak( $2.parse, JMP_BREAK ); }
123 | `continue` list `;`
124 { $$.parse = pbreak( $2.parse, JMP_CONTINUE ); }
126 { $$.parse = pbreak( $2.parse, JMP_RETURN ); }
127 | `for` ARG `in` list `{` block `}`
128 { $$.parse = pfor( $2.string, $4.parse, $6.parse ); }
129 | `switch` list `{` cases `}`
130 { $$.parse = pswitch( $2.parse, $4.parse ); }
131 | `if` expr `{` block `}`
132 { $$.parse = pif( $2.parse, $4.parse, pnull() ); }
133 | `if` expr `{` block `}` `else` rule
134 { $$.parse = pif( $2.parse, $4.parse, $7.parse ); }
135 | `while` expr `{` block `}`
136 { $$.parse = pwhile( $2.parse, $4.parse ); }
137 | `rule` ARG params `{` block `}`
138 { $$.parse = psetc( $2.string, $3.parse, $5.parse ); }
140 { $$.parse = pon( $2.parse, $3.parse ); }
141 | `actions` eflags ARG bindlist `{`
142 { yymode( SCAN_STRING ); }
144 { yymode( SCAN_NORMAL ); }
146 { $$.parse = psete( $3.string,$4.parse,$7.string,$2.number ); }
154 { $$.number = VAR_SET; }
156 { $$.number = VAR_APPEND; }
158 { $$.number = VAR_DEFAULT; }
160 { $$.number = VAR_DEFAULT; }
164 * expr - an expression for if
168 { $$.parse = peval( EXPR_EXISTS, $1.parse, pnull() ); }
170 { $$.parse = peval( EXPR_EQUALS, $1.parse, $3.parse ); }
172 { $$.parse = peval( EXPR_NOTEQ, $1.parse, $3.parse ); }
174 { $$.parse = peval( EXPR_LESS, $1.parse, $3.parse ); }
176 { $$.parse = peval( EXPR_LESSEQ, $1.parse, $3.parse ); }
178 { $$.parse = peval( EXPR_MORE, $1.parse, $3.parse ); }
180 { $$.parse = peval( EXPR_MOREEQ, $1.parse, $3.parse ); }
182 { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); }
184 { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); }
186 { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); }
188 { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); }
190 { $$.parse = peval( EXPR_IN, $1.parse, $3.parse ); }
192 { $$.parse = peval( EXPR_NOT, $2.parse, pnull() ); }
194 { $$.parse = $2.parse; }
198 * cases - action elements inside a 'switch'
199 * case - a single action element inside a 'switch'
200 * right-recursive rule so cases can be examined in order.
206 { $$.parse = pnode( $1.parse, $2.parse ); }
209 case : `case` ARG `:` block
210 { $$.parse = psnode( $2.string, $4.parse ); }
214 * params - optional parameter names to rule definition
215 * right-recursive rule so that params can be added in order.
221 { $$.parse = psnode( $1.string, $3.parse ); }
223 { $$.parse = psnode( $1.string, P0 ); }
227 * lol - list of lists
228 * right-recursive rule so that lists can be added in order.
232 { $$.parse = pnode( P0, $1.parse ); }
234 { $$.parse = pnode( $3.parse, $1.parse ); }
238 * list - zero or more args in a LIST
239 * listp - list (in puncutation only mode)
240 * arg - one ARG or function call
244 { $$.parse = $1.parse; yymode( SCAN_NORMAL ); }
248 { $$.parse = pnull(); yymode( SCAN_PUNCT ); }
250 { $$.parse = pappend( $1.parse, $2.parse ); }
254 { $$.parse = plist( $1.string ); }
255 | `[` { yymode( SCAN_NORMAL ); } func `]`
256 { $$.parse = $3.parse; }
260 * func - a function call (inside [])
261 * This needs to be split cleanly out of 'rule'
265 { $$.parse = prule( $1.parse, $2.parse ); }
267 { $$.parse = pon( $2.parse, prule( $3.parse, $4.parse ) ); }
268 | `on` arg `return` list
269 { $$.parse = pon( $2.parse, $4.parse ); }
273 * eflags - zero or more modifiers to 'executes'
274 * eflag - a single modifier to 'executes'
280 { $$.number = $1.number | $2.number; }
284 { $$.number = RULE_UPDATED; }
286 { $$.number = RULE_TOGETHER; }
288 { $$.number = RULE_IGNORE; }
290 { $$.number = RULE_QUIETLY; }
292 { $$.number = RULE_PIECEMEAL; }
294 { $$.number = RULE_EXISTING; }
296 { $$.number = atoi( $2.string ) * RULE_MAXLINE; }
301 * bindlist - list of variable to bind for an action
304 bindlist : /* empty */
305 { $$.parse = pnull(); }
307 { $$.parse = $2.parse; }