~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to ftsh/src/parser.y

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
%expect 1
 
3
 
 
4
/*
 
5
The "expect" directive indicates that this grammar has
 
6
a known ambiguity which is resolved by the default
 
7
precedence in bison.
 
8
 
 
9
The ambiguity is as follows:  A single function call can
 
10
be confused with two expressions separated by a space.
 
11
This conflict does not apear in singleton expressions,
 
12
but only in space-separated lists, used by forany and forall.
 
13
For example, "foo ( baz )" could be interpreted as a
 
14
call to function foo, or the literal expression
 
15
foo followed by baz.
 
16
 
 
17
I belive this is an acceptable ambiguity, because the
 
18
default is the common case and can be overridden when
 
19
necessary.  For example,
 
20
 
 
21
        forany x in foo(baz)
 
22
                ...
 
23
        end
 
24
 
 
25
...indicates that the function foo should be called and the
 
26
resulting list be used for the branches of the forany.
 
27
To force the expression-list interpretation, use this instead:
 
28
 
 
29
        forany x in (foo) (baz)
 
30
                ...
 
31
        end
 
32
*/
 
33
 
 
34
%token TOKEN_DELIMITER
 
35
%token TOKEN_LEFT_ARROW
 
36
%token TOKEN_DOUBLE_LEFT_ARROW
 
37
%token TOKEN_LONG_LEFT_ARROW
 
38
%token TOKEN_LONG_DOUBLE_LEFT_ARROW
 
39
%token TOKEN_RIGHT_ARROW
 
40
%token TOKEN_DOUBLE_RIGHT_ARROW
 
41
%token TOKEN_SQUIGGLY_RIGHT_ARROW
 
42
%token TOKEN_NUMBERED_SQUIGGLY_RIGHT_ARROW
 
43
%token TOKEN_DOUBLE_SQUIGGLY_RIGHT_ARROW
 
44
%token TOKEN_NUMBERED_DOUBLE_SQUIGGLY_RIGHT_ARROW
 
45
%token TOKEN_LONG_RIGHT_ARROW
 
46
%token TOKEN_LONG_DOUBLE_RIGHT_ARROW
 
47
%token TOKEN_LONG_SQUIGGLY_RIGHT_ARROW
 
48
%token TOKEN_LONG_DOUBLE_SQUIGGLY_RIGHT_ARROW
 
49
%token TOKEN_FUNCTION
 
50
%token TOKEN_ASSIGN
 
51
%token TOKEN_IF
 
52
%token TOKEN_ELSE
 
53
%token TOKEN_END
 
54
%token TOKEN_TRY
 
55
%token TOKEN_EVERY
 
56
%token TOKEN_CATCH
 
57
%token TOKEN_IN
 
58
%token TOKEN_FOR
 
59
%token TOKEN_FORANY
 
60
%token TOKEN_FORALL
 
61
%token TOKEN_TIMES
 
62
%token TOKEN_SECONDS
 
63
%token TOKEN_MINUTES
 
64
%token TOKEN_HOURS
 
65
%token TOKEN_DAYS
 
66
%token TOKEN_ATOM
 
67
%token TOKEN_SHIFT
 
68
%token TOKEN_WHILE
 
69
%token TOKEN_VAR
 
70
%token TOKEN_RETURN
 
71
%token TOKEN_COMMA
 
72
 
 
73
%token TOKEN_ADD
 
74
%token TOKEN_SUB
 
75
%token TOKEN_MUL
 
76
%token TOKEN_DIV
 
77
%token TOKEN_MOD
 
78
%token TOKEN_POW
 
79
%token TOKEN_EQ
 
80
%token TOKEN_NE
 
81
%token TOKEN_EQL
 
82
%token TOKEN_NEQL
 
83
%token TOKEN_LT
 
84
%token TOKEN_GT
 
85
%token TOKEN_LE
 
86
%token TOKEN_GE
 
87
%token TOKEN_AND
 
88
%token TOKEN_OR
 
89
%token TOKEN_QUESTION
 
90
%token TOKEN_COLON
 
91
%token TOKEN_LPAREN
 
92
%token TOKEN_RPAREN
 
93
%token TOKEN_NOT
 
94
%token TOKEN_TO
 
95
%token TOKEN_STEP
 
96
 
 
97
%token TOKEN_EXISTS
 
98
%token TOKEN_ISR
 
99
%token TOKEN_ISW
 
100
%token TOKEN_ISX
 
101
 
 
102
%token TOKEN_ISBLOCK
 
103
%token TOKEN_ISCHAR
 
104
%token TOKEN_ISDIR
 
105
%token TOKEN_ISFILE
 
106
%token TOKEN_ISLINK
 
107
%token TOKEN_ISPIPE
 
108
%token TOKEN_ISSOCK
 
109
 
 
110
%type <group> program group
 
111
%type <command> command
 
112
%type <function> function
 
113
%type <try> try try_limit
 
114
%type <try_limit> time_limit loop_limit opt_every_limit
 
115
%type <forloop> forloop
 
116
%type <whileloop> whileloop
 
117
%type <conditional> conditional
 
118
%type <shift> shift_line
 
119
%type <rtn> return_line
 
120
%type <assign> assign_line
 
121
%type <simple> simple_line simple
 
122
%type <redirect> redirect
 
123
%type <number> time_units fortype
 
124
%type <word> word wordequals
 
125
%type <expr> expr expr_list opt_expr_comma_list expr_comma_list
 
126
%type <token> TOKEN_FUNCTION TOKEN_END TOKEN_DELIMITER TOKEN_WHILE TOKEN_FOR TOKEN_IN TOKEN_IF TOKEN_ELSE TOKEN_TRY TOKEN_CATCH TOKEN_ASSIGN TOKEN_ATOM TOKEN_OR TOKEN_AND TOKEN_EQ TOKEN_NE TOKEN_EQL TOKEN_NEQL TOKEN_LT TOKEN_LE TOKEN_GT TOKEN_GE TOKEN_ADD TOKEN_SUB TOKEN_MUL TOKEN_DIV TOKEN_MOD TOKEN_NOT TOKEN_EXISTS TOKEN_ISR TOKEN_ISW TOKEN_ISX TOKEN_ISBLOCK TOKEN_ISCHAR TOKEN_ISDIR TOKEN_ISFILE TOKEN_ISLINK TOKEN_ISPIPE TOKEN_ISSOCK TOKEN_POW TOKEN_LPAREN TOKEN_RPAREN TOKEN_TO TOKEN_SHIFT TOKEN_LEFT_ARROW TOKEN_RIGHT_ARROW TOKEN_DOUBLE_RIGHT_ARROW TOKEN_NUMBERED_SQUIGGLY_RIGHT_ARROW TOKEN_NUMBERED_DOUBLE_SQUIGGLY_RIGHT_ARROW TOKEN_SQUIGGLY_RIGHT_ARROW TOKEN_LONG_LEFT_ARROW TOKEN_LONG_RIGHT_ARROW TOKEN_LONG_DOUBLE_RIGHT_ARROW TOKEN_LONG_SQUIGGLY_RIGHT_ARROW TOKEN_LONG_DOUBLE_SQUIGGLY_RIGHT_ARROW TOKEN_DOUBLE_SQUIGGLY_RIGHT_ARROW
 
127
 
 
128
%nonassoc TOKEN_TO
 
129
%nonassoc TOKEN_STEP
 
130
%left     TOKEN_OR
 
131
%left     TOKEN_AND
 
132
%nonassoc TOKEN_EQ TOKEN_NE TOKEN_EQL TOKEN_NEQL TOKEN_LT TOKEN_LE TOKEN_GT TOKEN_GE
 
133
%left     TOKEN_ADD TOKEN_SUB
 
134
%left     TOKEN_MUL TOKEN_DIV TOKEN_MOD
 
135
%right    TOKEN_NOT TOKEN_EXISTS TOKEN_ISR TOKEN_ISW TOKEN_ISX TOKEN_ISBLOCK TOKEN_ISCHAR TOKEN_ISDIR TOKEN_ISFILE TOKEN_ISLINK TOKEN_ISPIPE TOKEN_ISSOCK
 
136
%left     TOKEN_POW
 
137
%nonassoc PREC_EXPR
 
138
%nonassoc PREC_LITERAL
 
139
%nonassoc PREC_FCALL
 
140
 
 
141
%{
 
142
 
 
143
#include "ast.h"
 
144
#include "parser.h"
 
145
#include "ftsh_error.h"
 
146
#include "xmalloc.h"
 
147
 
 
148
#include <string.h>
 
149
#include <stdlib.h>
 
150
#include <stdio.h>
 
151
 
 
152
#define YYDEBUG 1
 
153
 
 
154
extern char * yytext;
 
155
extern FILE * yyin;
 
156
 
 
157
extern int yyerror( char *str );
 
158
extern int yylex();
 
159
 
 
160
static struct ast_group * parser_result=0;
 
161
 
 
162
%}
 
163
 
 
164
%%
 
165
 
 
166
program
 
167
        : group
 
168
                { parser_result = $1; }
 
169
        ;
 
170
 
 
171
group
 
172
        : command group
 
173
                { $$ = ast_group_create( $1, $2 ); }
 
174
        | command
 
175
                { $$ = ast_group_create( $1, 0 ); }
 
176
        ;
 
177
 
 
178
command
 
179
        : function
 
180
                { $$ = ast_command_create( AST_COMMAND_FUNCTION, $1 ); }
 
181
        | try
 
182
                { $$ = ast_command_create( AST_COMMAND_TRY, $1 ); }
 
183
        | forloop
 
184
                { $$ = ast_command_create( AST_COMMAND_FORLOOP, $1 ); }
 
185
        | whileloop
 
186
                { $$ = ast_command_create( AST_COMMAND_WHILELOOP, $1 ); }
 
187
        | conditional
 
188
                { $$ = ast_command_create( AST_COMMAND_CONDITIONAL, $1 ); }
 
189
        | shift_line
 
190
                { $$ = ast_command_create( AST_COMMAND_SHIFT, $1 ); }
 
191
        | assign_line
 
192
                { $$ = ast_command_create( AST_COMMAND_ASSIGN, $1 ); }
 
193
        | return_line
 
194
                { $$ = ast_command_create( AST_COMMAND_RETURN, $1 ); }
 
195
        | simple_line
 
196
                { $$ = ast_command_create( AST_COMMAND_SIMPLE, $1 ); }
 
197
        | TOKEN_DELIMITER
 
198
                { $$ = ast_command_create( AST_COMMAND_EMPTY, 0 ); }
 
199
        ;
 
200
 
 
201
function
 
202
        : TOKEN_FUNCTION word TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
203
                { $$ = ast_function_create( $1.line, $5.line, $2, $4 ); }
 
204
        ;
 
205
 
 
206
/*
 
207
Ok, this is ugly, but the only way to get around the reality of LALR(1).
 
208
*/
 
209
 
 
210
try
 
211
        : TOKEN_TRY try_limit TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
212
                {
 
213
                        $$ = $2;
 
214
                        $$->try_line=$1.line;
 
215
                        $$->catch_line=$5.line;
 
216
                        $$->end_line=$5.line;
 
217
                        $$->body=$4;
 
218
                }
 
219
        | TOKEN_TRY try_limit TOKEN_DELIMITER group TOKEN_CATCH TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
220
                {
 
221
                        $$ = $2;
 
222
                        $$->try_line=$1.line;
 
223
                        $$->catch_line=$5.line;
 
224
                        $$->end_line=$8.line;
 
225
                        $$->body=$4;
 
226
                        $$->catch_block=$7;
 
227
                }
 
228
        ;
 
229
 
 
230
try_limit
 
231
        : opt_every_limit
 
232
                { $$ = ast_try_create(0,0,0,0,0,$1,0,0); }
 
233
        | opt_conj time_limit opt_every_limit
 
234
                { $$ = ast_try_create(0,0,0,$2,0,$3,0,0); }
 
235
        | opt_conj loop_limit opt_every_limit
 
236
                { $$ = ast_try_create(0,0,0,0,$2,$3,0,0); }
 
237
        | opt_conj time_limit opt_conj loop_limit opt_every_limit
 
238
                { $$ = ast_try_create(0,0,0,$2,$4,$5,0,0); }
 
239
        | opt_conj loop_limit opt_conj time_limit opt_every_limit
 
240
                { $$ = ast_try_create(0,0,0,$4,$2,$5,0,0); }
 
241
        ;
 
242
 
 
243
opt_conj
 
244
        : TOKEN_FOR
 
245
                { }
 
246
        | TOKEN_OR
 
247
                { }
 
248
        |
 
249
                { }
 
250
        ;
 
251
 
 
252
time_limit
 
253
        : expr time_units
 
254
                { $$ = ast_try_limit_create( $1, $2 ); }
 
255
        ;
 
256
 
 
257
loop_limit
 
258
        : expr TOKEN_TIMES
 
259
                { $$ = ast_try_limit_create( $1, 0 ); }
 
260
        ;
 
261
 
 
262
opt_every_limit
 
263
        : /* nothing */
 
264
                { $$ = 0; }
 
265
        | TOKEN_EVERY expr time_units
 
266
                { $$ = ast_try_limit_create( $2, $3 ); }
 
267
        ;
 
268
        
 
269
time_units
 
270
        : TOKEN_SECONDS
 
271
                { $$ = 1; }
 
272
        | TOKEN_MINUTES
 
273
                { $$ = 60; }
 
274
        | TOKEN_HOURS
 
275
                { $$ = 60*60; }
 
276
        | TOKEN_DAYS
 
277
                { $$ = 24*60*60; }
 
278
        ;
 
279
 
 
280
forloop
 
281
        : fortype word TOKEN_IN expr_list TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
282
                { $$ = ast_forloop_create( $1, $3.line, $7.line, $2, $4, $6 ); }
 
283
        ;
 
284
 
 
285
fortype
 
286
        : TOKEN_FOR
 
287
                { $$ = AST_FOR; }
 
288
        | TOKEN_FORANY
 
289
                { $$ = AST_FORANY; }
 
290
        | TOKEN_FORALL
 
291
                { $$ = AST_FORALL; }
 
292
        ;
 
293
 
 
294
whileloop
 
295
        : TOKEN_WHILE expr TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
296
                { $$ = ast_whileloop_create( $1.line, $3.line, $5.line, $2, $4 ); }
 
297
        ;
 
298
 
 
299
conditional
 
300
        : TOKEN_IF expr TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
301
                { $$ = ast_conditional_create( $1.line, $3.line, $5.line, $5.line, $2, $4, 0 ); }
 
302
        | TOKEN_IF expr TOKEN_DELIMITER group TOKEN_ELSE TOKEN_DELIMITER group TOKEN_END TOKEN_DELIMITER
 
303
                { $$ = ast_conditional_create( $1.line, $3.line, $8.line, $8.line, $2, $4, $7 ); }
 
304
        | TOKEN_IF expr TOKEN_DELIMITER group TOKEN_ELSE conditional
 
305
                {
 
306
                        struct ast_group *g = ast_group_create( ast_command_create( AST_COMMAND_CONDITIONAL, $6 ), 0 );
 
307
                        $$ = ast_conditional_create( $1.line, $3.line, $5.line, $5.line, $2, $4, g );
 
308
                }
 
309
        ;
 
310
 
 
311
shift_line
 
312
        : TOKEN_SHIFT expr TOKEN_DELIMITER
 
313
                { $$ = ast_shift_create($1.line,$2); }
 
314
        | TOKEN_SHIFT TOKEN_DELIMITER
 
315
                { $$ = ast_shift_create($1.line,0); }
 
316
        ;
 
317
 
 
318
assign_line
 
319
        : wordequals expr TOKEN_DELIMITER
 
320
                { $$ = ast_assign_create( $3.line, $1, $2 ); }
 
321
        | wordequals TOKEN_DELIMITER
 
322
                { $$ = ast_assign_create( $2.line, $1, 0 ); }
 
323
        ;
 
324
 
 
325
return_line
 
326
        : TOKEN_RETURN expr TOKEN_DELIMITER
 
327
                { $$ = ast_return_create( $3.line, $2 ); }
 
328
        ;
 
329
 
 
330
simple_line
 
331
        : simple TOKEN_DELIMITER
 
332
                { $$ = $1; $1->line = $2.line; }
 
333
        ;
 
334
 
 
335
simple
 
336
        : simple word
 
337
                {
 
338
                        struct ast_word *w;
 
339
                        for( w=$1->words; w->next; w=w->next ) {}
 
340
                        w->next = $2;
 
341
                        $$ = $1;
 
342
                }
 
343
        | simple redirect
 
344
                {
 
345
                        struct ast_redirect *r;
 
346
                        if( $1->redirects ) {
 
347
                                for( r=$1->redirects; r->next; r=r->next ) {}
 
348
                                r->next = $2;
 
349
                        } else {
 
350
                                $1->redirects = $2;
 
351
                        }
 
352
                        $$ = $1;
 
353
                }
 
354
        | word
 
355
                { $$ = ast_simple_create( 0, $1, 0 ); }
 
356
        ;
 
357
 
 
358
redirect
 
359
        : TOKEN_LEFT_ARROW word
 
360
                { $$ = ast_redirect_create( AST_REDIRECT_FILE, $1.firstint, $2, AST_REDIRECT_INPUT ); }
 
361
        | TOKEN_RIGHT_ARROW word
 
362
                { $$ = ast_redirect_create( AST_REDIRECT_FILE, $1.firstint, $2, AST_REDIRECT_OUTPUT ); }
 
363
        | TOKEN_DOUBLE_RIGHT_ARROW word
 
364
                { $$ = ast_redirect_create( AST_REDIRECT_FILE, $1.firstint, $2, AST_REDIRECT_APPEND ); }
 
365
        | TOKEN_NUMBERED_SQUIGGLY_RIGHT_ARROW word
 
366
                { $$ = ast_redirect_create( AST_REDIRECT_FD, $1.firstint, $2, AST_REDIRECT_OUTPUT ); }
 
367
        | TOKEN_NUMBERED_DOUBLE_SQUIGGLY_RIGHT_ARROW word
 
368
                { $$ = ast_redirect_create( AST_REDIRECT_FD, $1.firstint, $2, AST_REDIRECT_APPEND ); }
 
369
        | TOKEN_SQUIGGLY_RIGHT_ARROW word
 
370
                {
 
371
                $$ = ast_redirect_create( AST_REDIRECT_FILE, 1, $2, AST_REDIRECT_OUTPUT );
 
372
                $$->next = ast_redirect_create( AST_REDIRECT_FD, 2, ast_word_create($1.line,"1"), AST_REDIRECT_APPEND );
 
373
                }
 
374
        | TOKEN_DOUBLE_SQUIGGLY_RIGHT_ARROW word
 
375
                {
 
376
                $$ = ast_redirect_create( AST_REDIRECT_FILE, 1, $2, AST_REDIRECT_APPEND );
 
377
                $$->next = ast_redirect_create( AST_REDIRECT_FD, 2, ast_word_create($1.line,"1"), AST_REDIRECT_APPEND );
 
378
                }
 
379
        | TOKEN_LONG_LEFT_ARROW word
 
380
                { $$ = ast_redirect_create( AST_REDIRECT_BUFFER, $1.firstint, $2, AST_REDIRECT_INPUT ); }
 
381
        | TOKEN_LONG_RIGHT_ARROW word
 
382
                { $$ = ast_redirect_create( AST_REDIRECT_BUFFER, $1.firstint, $2, AST_REDIRECT_OUTPUT ); }
 
383
        | TOKEN_LONG_DOUBLE_RIGHT_ARROW word
 
384
                { $$ = ast_redirect_create( AST_REDIRECT_BUFFER, $1.firstint, $2, AST_REDIRECT_APPEND ); }
 
385
        | TOKEN_LONG_SQUIGGLY_RIGHT_ARROW word
 
386
                {
 
387
                $$ = ast_redirect_create( AST_REDIRECT_BUFFER, 1, $2, AST_REDIRECT_OUTPUT );
 
388
                $$->next = ast_redirect_create( AST_REDIRECT_FD, 2, ast_word_create($1.line,"1"), AST_REDIRECT_APPEND );
 
389
                }
 
390
        | TOKEN_LONG_DOUBLE_SQUIGGLY_RIGHT_ARROW word
 
391
                {
 
392
                $$ = ast_redirect_create( AST_REDIRECT_BUFFER, 1, $2, AST_REDIRECT_APPEND );
 
393
                $$->next = ast_redirect_create( AST_REDIRECT_FD, 2, ast_word_create($1.line,"1"), AST_REDIRECT_APPEND );
 
394
                }
 
395
        ;
 
396
 
 
397
opt_expr_comma_list
 
398
        : /* nothing */
 
399
                { $$ = 0; }
 
400
        | expr_comma_list
 
401
                { $$ = $1; }
 
402
        ;
 
403
 
 
404
expr_comma_list
 
405
        : expr
 
406
                { $$ = $1; }
 
407
        | expr TOKEN_COMMA expr_comma_list
 
408
                { $$ = $1; $1->next=$3; }
 
409
        ;
 
410
 
 
411
expr_list
 
412
        : expr
 
413
                { $$ = $1; }
 
414
        | expr expr_list
 
415
                { $$ = $1; $1->next=$2; }
 
416
        ;
 
417
 
 
418
expr
 
419
        : expr TOKEN_TO expr %prec TOKEN_TO
 
420
                { $$ = expr_create($2.line,EXPR_TO,0,$1,$3,0); }
 
421
        | expr TOKEN_TO expr TOKEN_STEP expr %prec TOKEN_STEP
 
422
                { $$ = expr_create($2.line,EXPR_TO,0,$1,$3,$5); }
 
423
        | expr TOKEN_OR expr
 
424
                { $$ = expr_create($2.line,EXPR_OR,0,$1,$3,0); }
 
425
        | expr TOKEN_AND expr
 
426
                { $$ = expr_create($2.line,EXPR_AND,0,$1,$3,0); }
 
427
        | expr TOKEN_EQ expr
 
428
                { $$ = expr_create($2.line,EXPR_EQ,0,$1,$3,0); }
 
429
        | expr TOKEN_NE expr
 
430
                { $$ = expr_create($2.line,EXPR_NE,0,$1,$3,0); }
 
431
        | expr TOKEN_EQL expr
 
432
                { $$ = expr_create($2.line,EXPR_EQL,0,$1,$3,0); }
 
433
        | expr TOKEN_NEQL expr
 
434
                { $$ = expr_create($2.line,EXPR_NEQL,0,$1,$3,0); }
 
435
        | expr TOKEN_LT expr
 
436
                { $$ = expr_create($2.line,EXPR_LT,0,$1,$3,0); }
 
437
        | expr TOKEN_LE expr
 
438
                { $$ = expr_create($2.line,EXPR_LE,0,$1,$3,0); }
 
439
        | expr TOKEN_GT expr
 
440
                { $$ = expr_create($2.line,EXPR_GT,0,$1,$3,0); }
 
441
        | expr TOKEN_GE expr
 
442
                { $$ = expr_create($2.line,EXPR_GE,0,$1,$3,0); }
 
443
        | expr TOKEN_ADD expr
 
444
                { $$ = expr_create($2.line,EXPR_ADD,0,$1,$3,0); }
 
445
        | expr TOKEN_SUB expr
 
446
                { $$ = expr_create($2.line,EXPR_SUB,0,$1,$3,0); }
 
447
        | expr TOKEN_MUL expr
 
448
                { $$ = expr_create($2.line,EXPR_MUL,0,$1,$3,0); }
 
449
        | expr TOKEN_DIV expr
 
450
                { $$ = expr_create($2.line,EXPR_DIV,0,$1,$3,0); }
 
451
        | expr TOKEN_MOD expr
 
452
                { $$ = expr_create($2.line,EXPR_MOD,0,$1,$3,0); }
 
453
        | TOKEN_NOT expr
 
454
                { $$ = expr_create( $1.line, EXPR_NOT, 0, $2, 0, 0); }
 
455
        | TOKEN_EXISTS expr
 
456
                { $$ = expr_create( $1.line, EXPR_EXISTS, 0, $2, 0, 0); }
 
457
        | TOKEN_ISR expr
 
458
                { $$ = expr_create( $1.line, EXPR_ISR, 0, $2, 0, 0); }
 
459
        | TOKEN_ISW expr
 
460
                { $$ = expr_create( $1.line, EXPR_ISW, 0, $2, 0, 0); }
 
461
        | TOKEN_ISX expr
 
462
                { $$ = expr_create( $1.line, EXPR_ISX, 0, $2, 0, 0); }
 
463
        | TOKEN_ISBLOCK expr
 
464
                { $$ = expr_create( $1.line, EXPR_ISBLOCK, 0, $2, 0, 0); }
 
465
        | TOKEN_ISCHAR expr
 
466
                { $$ = expr_create( $1.line, EXPR_ISCHAR, 0, $2, 0, 0); }
 
467
        | TOKEN_ISDIR expr
 
468
                { $$ = expr_create( $1.line, EXPR_ISDIR, 0, $2, 0, 0); }
 
469
        | TOKEN_ISFILE expr
 
470
                { $$ = expr_create( $1.line, EXPR_ISFILE, 0, $2, 0, 0); }
 
471
        | TOKEN_ISLINK expr
 
472
                { $$ = expr_create( $1.line, EXPR_ISLINK, 0, $2, 0, 0); }
 
473
        | TOKEN_ISPIPE expr
 
474
                { $$ = expr_create( $1.line, EXPR_ISPIPE, 0, $2, 0, 0); }
 
475
        | TOKEN_ISSOCK expr
 
476
                { $$ = expr_create( $1.line, EXPR_ISSOCK, 0, $2, 0, 0); }
 
477
        | expr TOKEN_POW expr
 
478
                { $$ = expr_create( $2.line, EXPR_POW, 0, $1, $3, 0 ); }
 
479
        | TOKEN_LPAREN expr TOKEN_RPAREN %prec PREC_EXPR
 
480
                { $$ = expr_create($1.line,EXPR_EXPR,0,$2,0,0); }
 
481
        | word %prec PREC_LITERAL
 
482
                { $$ = expr_create($1->line,EXPR_LITERAL,$1,0,0,0); }
 
483
        | word TOKEN_LPAREN opt_expr_comma_list TOKEN_RPAREN %prec PREC_FCALL
 
484
                { $$ = expr_create($2.line,EXPR_FCALL,$1,$3,0,0); }
 
485
        ;
 
486
 
 
487
wordequals
 
488
        : TOKEN_ASSIGN
 
489
                { $$ = ast_word_create( $1.line, yytext ); }
 
490
        ;
 
491
 
 
492
word
 
493
        : TOKEN_ATOM
 
494
                { $$ = ast_word_create( $1.line, yytext ); }
 
495
        ;
 
496
 
 
497
%%
 
498
 
 
499
 
 
500
struct ast_group * parse_file( FILE *f, int do_debug )
 
501
{
 
502
        yydebug = do_debug;
 
503
        yyin = f;
 
504
        parser_result = 0;
 
505
        yyparse();
 
506
        return parser_result;
 
507
}
 
508
 
 
509
extern int current_line;
 
510
 
 
511
int yyerror( char *string )
 
512
{
 
513
        ftsh_fatal(current_line,"parse error near here",current_line);
 
514
        return 0;
 
515
}