Debian Codegraph @

debian/external_deps/fetk/maloc/src/vsh/vyacc.y

raw
1 /*
2 * ***************************************************************************
3 * MALOC = < Minimal Abstraction Layer for Object-oriented C >
4 * Copyright (C) 1994-- Michael Holst
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * rcsid="$Id: vyacc.y,v 1.8 2010/08/12 05:40:28 fetk Exp $"
21 * ***************************************************************************
22 */
23
24 /*
25 * ***************************************************************************
26 * File: vyacc.y
27 *
28 * Purpose: Class Vsh: YACC Specification
29 *
30 * Author: Michael Holst
31 * ***************************************************************************
32 */
33
34 %{
35
36 #include "vsh_p.h"
37
38 VEMBED(rcsid="$Id: vyacc.y,v 1.8 2010/08/12 05:40:28 fetk Exp $")
39
40 VPUBLIC void yyerror(const char *errmsg)
41 {
42 fprintf(stderr, "Vsh: %s at '%s'\n", errmsg, yytext);
43 if (!Vsh_isInteractive(Vsh_thee)) {
44 exit(1);
45 }
46 }
47
48 VPUBLIC void report_error(const char *format, ...)
49 {
50 fprintf(stderr,"report_error: ERROR:\n");
51 }
52
53 VPUBLIC void programming_error(const char *format, ...)
54 {
55 fprintf(stderr,"programming_error: ERROR:\n");
56 }
57
58 VPUBLIC int yywrap(void)
59 {
60 if (Vsh_thee->cinUnit == stdin) {
61 Vnm_print(1,"%s",Vsh_thee->PR_EXIT);
62 Vnm_print(1,"%s",VNEWLINE_STRING);
63 }
64 cmdKey = 2;
65 return 1;
66 }
67
68 /*
69 * Reverse the chain of structures in LIST. Output the new head
70 * of the chain. You should always assign the output value of this
71 * function to something, or you will lose the chain.
72 */
73 GENERIC_LIST *reverse_list (GENERIC_LIST *list)
74 {
75 register GENERIC_LIST *next, *prev = (GENERIC_LIST *)NULL;
76
77 while (list) {
78 next = list->next;
79 list->next = prev;
80 prev = list;
81 list = next;
82 }
83 return (prev);
84 }
85
86 WORD_LIST* make_word_list(WORD_DESC *word, WORD_LIST *link)
87 {
88 WORD_LIST *temp;
89
90 temp = (WORD_LIST *)malloc (sizeof (WORD_LIST));
91 temp->word = word;
92 temp->next = link;
93 return temp;
94 }
95
96 COMMAND *make_bare_simple_command(void)
97 {
98 COMMAND *command;
99 SIMPLE_COM *temp = (SIMPLE_COM *)malloc (sizeof (SIMPLE_COM));
100
101 temp->flags = 0;
102 /* temp->line = line_number; */
103 temp->line = 0;
104 temp->words = (WORD_LIST *)NULL;
105 temp->redirects = (REDIRECT *)NULL;
106 command = (COMMAND *)malloc (sizeof (COMMAND));
107 command->type = cm_simple;
108 command->redirects = (REDIRECT *)NULL;
109 command->flags = 0;
110 command->value.Simple = temp;
111 return command;
112 }
113
114 /*
115 * Generate a REDIRECT from SOURCE, DEST, and INSTRUCTION.
116 * INSTRUCTION is the instruction type, SOURCE is a file descriptor,
117 * and DEST is a file descriptor or a WORD_DESC*.
118 */
119 REDIRECT *make_redirection (int source,
120 enum r_instruction instruction, REDIRECTEE dest_and_filename)
121 {
122 REDIRECT *temp = (REDIRECT *)malloc (sizeof (REDIRECT));
123
124 /* First do the common cases. */
125 temp->redirector = source;
126 temp->redirectee = dest_and_filename;
127 temp->instruction = instruction;
128 temp->flags = 0;
129 temp->next = (REDIRECT *)NULL;
130
131 switch (instruction) {
132
133 case r_output_direction: /* >foo */
134 case r_output_force: /* >| foo */
135 temp->flags = O_TRUNC | O_WRONLY | O_CREAT;
136 break;
137
138 case r_input_direction: /* <foo */
139 case r_inputa_direction: /* foo & makes this. */
140 temp->flags = O_RDONLY;
141 break;
142
143 case r_appending_to: /* >>foo */
144 temp->flags = O_APPEND | O_WRONLY | O_CREAT;
145 break;
146
147 case r_deblank_reading_until: /* <<-foo */
148 case r_reading_until: /* << foo */
149 break;
150
151 case r_duplicating_input: /* 1<&2 */
152 case r_duplicating_output: /* 1>&2 */
153 case r_close_this: /* <&- */
154 case r_duplicating_input_word: /* 1<&$foo */
155 case r_duplicating_output_word: /* 1>&$foo */
156 break;
157
158 case r_err_and_out: /* command &>filename */
159 temp->flags = O_TRUNC | O_WRONLY | O_CREAT;
160 break;
161
162 case r_input_output:
163 temp->flags = O_RDWR | O_CREAT;
164 break;
165
166 default:
167 fprintf(stderr,"We seem to have a problem...\n");
168 abort ();
169 break;
170 }
171 return (temp);
172 }
173
174 /*
175 * Return a command which is the connection of the word or redirection
176 * in ELEMENT, and the command * or NULL in COMMAND.
177 */
178 COMMAND *make_simple_command (ELEMENT element, COMMAND *command) {
179 /* If we are starting from scratch, then make the initial command
180 structure. Also note that we have to fill in all the slots, since
181 malloc doesn't return zeroed space. */
182 if (!command) command = make_bare_simple_command ();
183
184 if (element.word) {
185 WORD_LIST *tw = (WORD_LIST *)malloc (sizeof (WORD_LIST));
186 tw->word = element.word;
187 tw->next = command->value.Simple->words;
188 command->value.Simple->words = tw;
189 } else {
190 REDIRECT *r = element.redirect;
191 /* Due to the way <> is implemented, there may be more than a single
192 redirection in element.redirect. We just follow the chain as far
193 as it goes, and hook onto the end. */
194 while (r->next) r = r->next;
195 r->next = command->value.Simple->redirects;
196 command->value.Simple->redirects = element.redirect;
197 }
198 return (command);
199 }
200
201 COMMAND* make_command (enum command_type type, SIMPLE_COM *pointer)
202 {
203 COMMAND *temp;
204
205 temp = (COMMAND *)malloc (sizeof (COMMAND));
206 temp->type = type;
207 temp->value.Simple = pointer;
208 temp->value.Simple->flags = 0;
209 temp->flags = 0;
210 temp->redirects = (REDIRECT *)NULL;
211 return temp;
212 }
213
214 void dispose_command (COMMAND *command);
215 void dispose_word (WORD_DESC *word);
216 void dispose_words (WORD_LIST *list);
217 void dispose_word_array (char **array);
218 void dispose_redirects (REDIRECT *list);
219
220 /* Dispose of the command structure passed. */
221 void dispose_command (COMMAND *command)
222 {
223 if (!command) return;
224
225 if (command->redirects)
226 dispose_redirects (command->redirects);
227
228 switch (command->type)
229 {
230 case cm_for:
231 {
232 register FOR_COM *c = command->value.For;
233 dispose_word (c->name);
234 dispose_words (c->map_list);
235 dispose_command (c->action);
236 free (c);
237 break;
238 }
239
240 case cm_group:
241 {
242 dispose_command (command->value.Group->command);
243 free (command->value.Group);
244 break;
245 }
246
247 case cm_case:
248 {
249 register CASE_COM *c = command->value.Case;
250 PATTERN_LIST *t, *p = c->clauses;
251
252 dispose_word (c->word);
253
254 while (p)
255 {
256 dispose_words (p->patterns);
257 dispose_command (p->action);
258 t = p;
259 p = p->next;
260 free (t);
261 }
262 free (c);
263 break;
264 }
265
266 case cm_until:
267 case cm_while:
268 {
269 register WHILE_COM *c = command->value.While;
270
271 dispose_command (c->test);
272 dispose_command (c->action);
273 free (c);
274 break;
275 }
276
277 case cm_if:
278 {
279 register IF_COM *c = command->value.If;
280 dispose_command (c->test);
281 dispose_command (c->true_case);
282 dispose_command (c->false_case);
283 free (c);
284 break;
285 }
286
287 case cm_simple:
288 {
289 register SIMPLE_COM *c = command->value.Simple;
290 dispose_words (c->words);
291 dispose_redirects (c->redirects);
292 free (c);
293 break;
294 }
295
296 case cm_connection:
297 {
298 register CONNECTION *c = command->value.Connection;
299 dispose_command (c->first);
300 dispose_command (c->second);
301 free (c);
302 break;
303 }
304
305 case cm_function_def:
306 {
307 register FUNCTION_DEF *c = command->value.Function_def;
308 dispose_word (c->name);
309 dispose_command (c->command);
310 free (c);
311 break;
312 }
313
314 default:
315 report_error ("Attempt free unknown command type `%d'.\n", command->type);
316 break;
317 }
318 free (command);
319 }
320
321 /* How to free a WORD_DESC. */
322 void dispose_word (WORD_DESC *word)
323 {
324 if (word->word)
325 free (word->word);
326 free (word);
327 }
328
329 /* How to get rid of a linked list of words. A WORD_LIST. */
330 void dispose_words (WORD_LIST *list)
331 {
332 WORD_LIST *t;
333 while (list)
334 {
335 t = list;
336 list = list->next;
337 dispose_word (t->word);
338 free (t);
339 }
340 }
341
342 /* How to dispose of an array of pointers to char. */
343 void dispose_word_array (char **array)
344 {
345 register int count;
346
347 for (count = 0; array[count]; count++)
348 free (array[count]);
349
350 free (array);
351 }
352
353 /* How to dispose of an list of redirections. A REDIRECT. */
354 void dispose_redirects (REDIRECT *list)
355 {
356 register REDIRECT *t;
357
358 while (list)
359 {
360 t = list;
361 list = list->next;
362 switch (t->instruction)
363 {
364 case r_reading_until:
365 case r_deblank_reading_until:
366 free (t->here_doc_eof);
367 /* ... */
368 case r_output_direction:
369 case r_input_direction:
370 case r_inputa_direction:
371 case r_appending_to:
372 case r_err_and_out:
373 case r_input_output:
374 case r_output_force:
375 case r_duplicating_input_word:
376 case r_duplicating_output_word:
377 dispose_word (t->redirectee.filename);
378 break;
379 }
380 free (t);
381 }
382 }
383
384 /* Reverse the word list and redirection list in the simple command
385 has just been parsed. It seems simpler to do this here the one
386 time then by any other method that I can think of. */
387 COMMAND *clean_simple_command (COMMAND *command)
388 {
389 if (command->type != cm_simple)
390 {
391 programming_error
392 ("clean_simple_command () got a command with type %d.", command->type);
393 }
394 else
395 {
396 command->value.Simple->words =
397 REVERSE_LIST (command->value.Simple->words, WORD_LIST *);
398 command->value.Simple->redirects =
399 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
400 }
401
402 return (command);
403 }
404
405 static REDIRECTEE redir;
406
407 static WORD_LIST *wordTmp;
408 static WORD_DESC *wTmp;
409 static char buf[VMAX_BUFSIZE];
410
411 %}
412
413 %union {
414 WORD_DESC *word; /* the word that we read. */
415 /* int number; */ /* number we saw */
416 WORD_LIST *word_list; /* a sequence of white-space separated words */
417 COMMAND *command; /* a complete command */
418 REDIRECT *redirect; /* redirect i/o info */
419 ELEMENT element; /* base element */
420 PATTERN_LIST *pattern; /* a case pattern */
421 }
422
423 /* Reserved words coming from yylex() */
424 %token IF THEN ELSE ELIF FI
425 %token CASE IN ESAC
426 %token FOR WHILE UNTIL DO DONE
427
428 /* Special 2-character tokens coming from yylex() */
429 %token SEMI_SEMI AND_AND OR_OR LESS_LESS GREATER_GREATER
430 %token LESS_AND GREATER_AND AND_GREATER LESS_GREATER GREATER_BAR
431
432 /* Special 3-character tokens coming from yylex() */
433 %token LESS_LESS_MINUS
434
435 /* Remaining tokens coming from yylex() */
436 %token <word> WORD ASSIGNMENT_WORD
437
438 %token IF THEN ELSE ELIF FI CASE ESAC FOR SELECT WHILE UNTIL DO DONE FUNCTION
439 %token IN BANG
440
441 /* New Non-terminal types */
442 %type <command> for_command case_command while_command until_command
443
444 /* Non-terminal types */
445 %type <command> inputunit command pipeline
446 %type <command> list list0 list1 simple_list simple_list1
447 %type <command> simple_command shell_command_1 shell_command
448 %type <command> group_command function_def if_command elif_clause subshell
449 %type <redirect> redirection redirections
450 %type <element> simple_command_element
451 %type <word_list> words pattern
452 %type <pattern> pattern_list case_clause_sequence case_clause_1 pattern_list_1
453
454 /* Start rule */
455 %start inputunit
456
457 /* Precedence (low-to-high) */
458 %left '&' ';' '\n' vsh_EOF
459 %left AND_AND OR_OR
460 %right '|'
461
462 /* The complete grammar specification */
463 %%
464
465 /*
466 * ************************************************************************
467 * start state
468 * ************************************************************************
469 */
470
471 inputunit : simple_list '\n' {
472 Vsh_trace("Yacc","inputunit::1");
473 global_command = $1;
474 if (global_command != VNULL) {
475 if (global_command->type == cm_simple) {
476 wordTmp = $1->value.Simple->words;
477 memset(buf, VNULL_SYMBOL, sizeof(buf));
478 while (wordTmp != VNULL) {
479 wTmp = wordTmp->word;
480 if (wTmp != VNULL) {
481 strcat(buf,wTmp->word);
482 wordTmp = wordTmp->next;
483 } else {
484 wordTmp = VNULL;
485 }
486 if (wordTmp != VNULL) strcat(buf," ");
487 }
488 Vnm_print(1,"Vsh: will execv: <%s>\n", buf);
489 Vsh_parseHandoff(buf);
490 Vsh_yyexecute(global_command);
491 dispose_command (global_command);
492 }
493 }
494 YYACCEPT;
495 }
496 | '\n' {
497 Vsh_trace("Yacc","inputunit::2");
498 global_command = (COMMAND*)VNULL;
499 YYACCEPT;
500 }
501 | vsh_EOF {
502 Vsh_trace("Yacc","inputunit::3");
503 global_command = (COMMAND*)VNULL;
504 cmdKey = 2;
505 YYACCEPT;
506 }
507 | error newlines {
508 Vsh_trace("Yacc","inputunit::4");
509 global_command = (COMMAND*)VNULL;
510 YYABORT;
511 }
512 ;
513
514 /*
515 * ************************************************************************
516 * sim lists and regular lists
517 * ************************************************************************
518 */
519
520 /*
521 * A simple_list is a list that contains no significant newline
522 * and no leading or trailing newline. newline are allowed
523 * only following operators, where they are not significant.
524 * This is what an inputunit consists of.
525 */
526 simple_list : simple_list1 {
527 Vsh_trace("Yacc","simple_list::1");
528 $$ = $1;
529 }
530 | simple_list1 '&' {
531 Vsh_trace("Yacc","simple_list::2");
532 $$ = $1;
533 }
534 | simple_list1 ';' {
535 Vsh_trace("Yacc","simple_list::3");
536 $$ = $1;
537 }
538 ;
539
540 simple_list1 : simple_list1 AND_AND newlines simple_list1 {
541 Vsh_trace("Yacc","simple_list1::1");
542 $$ = $1;
543 }
544 | simple_list1 OR_OR newlines simple_list1 {
545 Vsh_trace("Yacc","simple_list1::2");
546 $$ = $1;
547 }
548 | simple_list1 '&' simple_list1 {
549 Vsh_trace("Yacc","simple_list1::3");
550 $$ = $1;
551 }
552 | simple_list1 ';' simple_list1 {
553 Vsh_trace("Yacc","simple_list1::4");
554 $$ = $1;
555 }
556 | pipeline {
557 Vsh_trace("Yacc","simple_list1::5");
558 $$ = $1;
559 }
560 | '!' pipeline {
561 Vsh_trace("Yacc","simple_list1::6");
562 $$ = $2;
563 }
564 ;
565
566 pipeline : pipeline '|' newlines pipeline {
567 Vsh_trace("Yacc","pipeline::1");
568 $$ = $1;
569 }
570 | command {
571 Vsh_trace("Yacc","pipeline::2");
572 $$ = $1;
573 }
574 ;
575
576 /*
577 * A list allows leading or trailing newline and
578 * newline as operators (equivalent to semicolons).
579 * It must end with a newline or semicolon.
580 * Lists are used within commands such as if, for, while.
581 */
582 list : newlines list0 {
583 Vsh_trace("Yacc","list::1");
584 $$ = $2;
585 }
586 ;
587
588 list0 : list1 {
589 Vsh_trace("Yacc","list0::1");
590 $$ = $1;
591 }
592 | list1 '\n' newlines {
593 Vsh_trace("Yacc","list0::2");
594 $$ = $1;
595 }
596 | list1 '&' newlines {
597 Vsh_trace("Yacc","list0::3");
598 $$ = $1;
599 }
600 | list1 ';' newlines {
601 Vsh_trace("Yacc","list0::4");
602 $$ = $1;
603 }
604 ;
605
606 list1 : list1 AND_AND newlines list1 {
607 Vsh_trace("Yacc","list1::1");
608 $$ = $1;
609 }
610 | list1 OR_OR newlines list1 {
611 Vsh_trace("Yacc","list1::2");
612 $$ = $1;
613 }
614 | list1 '&' newlines list1 {
615 Vsh_trace("Yacc","list1::3");
616 $$ = $1;
617 }
618 | list1 ';' newlines list1 {
619 Vsh_trace("Yacc","list1::4");
620 $$ = $1;
621 }
622 | list1 '\n' newlines list1 {
623 Vsh_trace("Yacc","list1::5");
624 $$ = $1;
625 }
626 | pipeline {
627 Vsh_trace("Yacc","list1::6");
628 $$ = $1;
629 }
630 | '!' pipeline {
631 Vsh_trace("Yacc","list1::7");
632 $$ = $2;
633 }
634 ;
635
636 /*
637 * ************************************************************************
638 * redirection (creates MANY shift/reduce conflicts unfortunately...)
639 * ************************************************************************
640 */
641
642 redirection : '>' WORD {
643 Vsh_trace("Yacc","redirection::1");
644 redir.filename = $2;
645 $$ = make_redirection(1, r_output_direction, redir);
646 }
647 | GREATER_GREATER WORD {
648 Vsh_trace("Yacc","redirection::2");
649 redir.filename = $2;
650 $$ = make_redirection(1, r_appending_to, redir);
651 }
652
653 /*
654 : '>' WORD { Vsh_trace("Yacc","redirection"); }
655 | '<' WORD { Vsh_trace("Yacc","redirection"); }
656 | GREATER_GREATER WORD { Vsh_trace("Yacc","redirection"); }
657 | LESS_LESS WORD { Vsh_trace("Yacc","redirection"); }
658 | number '>' WORD { Vsh_trace("Yacc","redirection"); }
659 | number '<' WORD { Vsh_trace("Yacc","redirection"); }
660 | number GREATER_GREATER WORD { Vsh_trace("Yacc","redirection"); }
661 | number LESS_LESS WORD { Vsh_trace("Yacc","redirection"); }
662 | LESS_AND number { Vsh_trace("Yacc","redirection"); }
663 | number LESS_AND number { Vsh_trace("Yacc","redirection"); }
664 | GREATER_AND number { Vsh_trace("Yacc","redirection"); }
665 | number GREATER_AND number { Vsh_trace("Yacc","redirection"); }
666 | number LESS_AND WORD { Vsh_trace("Yacc","redirection"); }
667 | number GREATER_AND WORD { Vsh_trace("Yacc","redirection"); }
668 | number LESS_LESS_MINUS WORD { Vsh_trace("Yacc","redirection"); }
669 | number GREATER_AND '-' { Vsh_trace("Yacc","redirection"); }
670 | number LESS_AND '-' { Vsh_trace("Yacc","redirection"); }
671 | number LESS_GREATER WORD { Vsh_trace("Yacc","redirection"); }
672 | number GREATER_BAR WORD { Vsh_trace("Yacc","redirection"); }
673 | GREATER_GREATER WORD { Vsh_trace("Yacc","redirection"); }
674 | LESS_LESS WORD { Vsh_trace("Yacc","redirection"); }
675 | LESS_AND WORD { Vsh_trace("Yacc","redirection"); }
676 | GREATER_AND WORD { Vsh_trace("Yacc","redirection"); }
677 | LESS_LESS_MINUS WORD { Vsh_trace("Yacc","redirection"); }
678 | GREATER_AND '-' { Vsh_trace("Yacc","redirection"); }
679 | LESS_AND '-' { Vsh_trace("Yacc","redirection"); }
680 | AND_GREATER WORD { Vsh_trace("Yacc","redirection"); }
681 | LESS_GREATER WORD { Vsh_trace("Yacc","redirection"); }
682 | GREATER_BAR WORD { Vsh_trace("Yacc","redirection"); }
683 */
684
685 ;
686
687 redirections : redirection {
688 Vsh_trace("Yacc","redirections::1");
689 $$ = $1;
690 }
691 | redirections redirection {
692 Vsh_trace("Yacc","redirections::2");
693 $$ = $1;
694 }
695 ;
696
697 /*
698 * ************************************************************************
699 * sim and shell commands
700 * ************************************************************************
701 */
702
703 command : simple_command {
704 Vsh_trace("Yacc","command::1");
705 $$ = clean_simple_command($1);
706 }
707 | shell_command {
708 Vsh_trace("Yacc","command::2");
709 $$ = $1;
710 }
711 ;
712
713 simple_command : simple_command_element {
714 Vsh_trace("Yacc","simple_command::1");
715 $$ = make_simple_command($1,(COMMAND*)VNULL);
716 }
717 | simple_command simple_command_element {
718 Vsh_trace("Yacc","simple_command::2");
719 $$ = make_simple_command($2,$1);
720 }
721 ;
722
723 shell_command : shell_command_1 {
724 Vsh_trace("Yacc","shell_command::1");
725 $$ = $1;
726 }
727 | shell_command_1 redirections {
728 Vsh_trace("Yacc","shell_command::2");
729 $$ = $1;
730 }
731 ;
732
733 shell_command_1 : for_command {
734 Vsh_trace("Yacc","shell_command_1::1");
735 $$ = VNULL;
736 }
737 | case_command {
738 Vsh_trace("Yacc","shell_command_1::2");
739 $$ = VNULL;
740 }
741 | while_command {
742 Vsh_trace("Yacc","shell_command_1::3");
743 $$ = VNULL;
744 }
745 | until_command {
746 Vsh_trace("Yacc","shell_command_1::4");
747 $$ = VNULL;
748 }
749 | if_command {
750 Vsh_trace("Yacc","shell_command_1::5");
751 $$ = VNULL;
752 }
753 | subshell {
754 Vsh_trace("Yacc","shell_command_1::6");
755 $$ = VNULL;
756 }
757 | group_command {
758 Vsh_trace("Yacc","shell_command_1::7");
759 $$ = VNULL;
760 }
761 | function_def {
762 Vsh_trace("Yacc","shell_command_1::8");
763 $$ = VNULL;
764 }
765 ;
766
767 simple_command_element : WORD {
768 Vsh_trace("Yacc","simple_command_element::1");
769 $$.word = $1;
770 $$.redirect = 0;
771 }
772 | ASSIGNMENT_WORD {
773 Vsh_trace("Yacc","simple_command_element::2");
774 $$.word = $1;
775 $$.redirect = 0;
776 }
777 | redirection {
778 Vsh_trace("Yacc","simple_command_element::3");
779 $$.word = 0;
780 $$.redirect = $1;
781 }
782 ;
783
784 /*
785 * ************************************************************************
786 * subshell, group, function definition
787 * ************************************************************************
788 */
789
790 subshell : '(' list ')' {
791 Vsh_trace("Yacc","subshell::1");
792 $$ = $2;
793 }
794 ;
795
796 group_command : '{' list '}' {
797 Vsh_trace("Yacc","group_command::1");
798 $$ = $2;
799 }
800 ;
801
802 function_def : WORD '(' ')' newlines group_command {
803 Vsh_trace("Yacc","function_def::1");
804 $$ = VNULL;
805 }
806 | WORD '(' ')' newlines group_command redirections {
807 Vsh_trace("Yacc","function_def::2");
808 $$ = VNULL;
809 }
810 ;
811
812 /*
813 * ************************************************************************
814 * if command
815 * ************************************************************************
816 */
817
818 if_command : IF list THEN list FI {
819 Vsh_trace("Yacc","if_command::1");
820 $$ = VNULL;
821 }
822 | IF list THEN list ELSE list FI {
823 Vsh_trace("Yacc","if_command::2");
824 $$ = VNULL;
825 }
826 | IF list THEN list elif_clause FI {
827 Vsh_trace("Yacc","if_command::3");
828 $$ = VNULL;
829 }
830 ;
831
832 elif_clause : ELIF list THEN list {
833 Vsh_trace("Yacc","elif_clause::1");
834 $$ = VNULL;
835 }
836 | ELIF list THEN list ELSE list {
837 Vsh_trace("Yacc","elif_clause::2");
838 $$ = VNULL;
839 }
840 | ELIF list THEN list elif_clause {
841 Vsh_trace("Yacc","elif_clause::3");
842 $$ = VNULL;
843 }
844 ;
845
846 /*
847 * ************************************************************************
848 * case command
849 * ************************************************************************
850 */
851
852 case_command : CASE WORD newlines IN newlines ESAC {
853 Vsh_trace("Yacc","case_command::1");
854 $$ = VNULL;
855 }
856 | CASE WORD newlines IN case_clause_sequence newlines ESAC {
857 Vsh_trace("Yacc","case_command::2");
858 $$ = VNULL;
859 }
860 | CASE WORD newlines IN case_clause_1 ESAC {
861 Vsh_trace("Yacc","case_command::3");
862 $$ = VNULL;
863 }
864 ;
865
866 case_clause_1 : pattern_list_1 {
867 Vsh_trace("Yacc","case_clause_1::1");
868 $$ = VNULL;
869 }
870 | case_clause_sequence pattern_list_1 {
871 Vsh_trace("Yacc","case_clause_1::2");
872 $$ = VNULL;
873 }
874 ;
875
876 pattern_list_1 : newlines pattern ')' list {
877 Vsh_trace("Yacc","pattern_list_1::1");
878 $$ = VNULL;
879 }
880 | newlines pattern ')' newlines {
881 Vsh_trace("Yacc","pattern_list_1::2");
882 $$ = VNULL;
883 }
884 | newlines '(' pattern ')' list {
885 Vsh_trace("Yacc","pattern_list_1::3");
886 $$ = VNULL;
887 }
888 | newlines '(' pattern ')' newlines {
889 Vsh_trace("Yacc","pattern_list_1::4");
890 $$ = VNULL;
891 }
892 ;
893
894 case_clause_sequence : pattern_list {
895 Vsh_trace("Yacc","case_clause_sequence::1");
896 $$ = VNULL;
897 }
898 | case_clause_sequence pattern_list {
899 Vsh_trace("Yacc","case_clause_sequence::2");
900 $$ = VNULL;
901 }
902 ;
903
904 pattern_list : newlines pattern ')' list SEMI_SEMI {
905 Vsh_trace("Yacc","pattern_list::1");
906 $$ = VNULL;
907 }
908 | newlines pattern ')' newlines SEMI_SEMI {
909 Vsh_trace("Yacc","pattern_list::2");
910 $$ = VNULL;
911 }
912 | newlines '(' pattern ')' list SEMI_SEMI {
913 Vsh_trace("Yacc","pattern_list::3");
914 $$ = VNULL;
915 }
916 | newlines '(' pattern ')' newlines SEMI_SEMI {
917 Vsh_trace("Yacc","pattern_list::4");
918 $$ = VNULL;
919 }
920 ;
921
922 pattern : WORD {
923 Vsh_trace("Yacc","pattern::1");
924 $$ = VNULL;
925 }
926 | pattern '|' WORD {
927 Vsh_trace("Yacc","pattern::2");
928 $$ = VNULL;
929 }
930 ;
931
932 /*
933 * ************************************************************************
934 * for command
935 * ************************************************************************
936 */
937
938 for_command : FOR WORD newlines DO list DONE {
939 Vsh_trace("Yacc","for_command::1");
940 $$ = VNULL;
941 }
942 | FOR WORD newlines '{' list '}' {
943 Vsh_trace("Yacc","for_command::2");
944 $$ = VNULL;
945 }
946 | FOR WORD ';' newlines DO list DONE {
947 Vsh_trace("Yacc","for_command::3");
948 $$ = VNULL;
949 }
950 | FOR WORD ';' newlines '{' list '}' {
951 Vsh_trace("Yacc","for_command::4");
952 $$ = VNULL;
953 }
954 | FOR WORD newlines IN words term newlines DO list DONE {
955 Vsh_trace("Yacc","for_command::5");
956 $$ = VNULL;
957 }
958 | FOR WORD newlines IN words term newlines '{' list '}' {
959 Vsh_trace("Yacc","for_command::6");
960 $$ = VNULL;
961 }
962 ;
963
964 /*
965 * ************************************************************************
966 * while command
967 * ************************************************************************
968 */
969
970 while_command : WHILE list DO list DONE {
971 Vsh_trace("Yacc","while_command::1");
972 $$ = VNULL;
973 }
974 ;
975
976 /*
977 * ************************************************************************
978 * until command
979 * ************************************************************************
980 */
981
982 until_command : UNTIL list DO list DONE {
983 Vsh_trace("Yacc","until_command::1");
984 $$ = VNULL;
985 }
986 ;
987
988 /*
989 * ************************************************************************
990 * word, words, term, newline
991 * ************************************************************************
992 */
993
994 words : {
995 Vsh_trace("Yacc","words::1");
996 $$ = (WORD_LIST*)VNULL;
997 }
998 | words WORD {
999 Vsh_trace("Yacc","words::2");
1000 $$ = make_word_list($2,$1);
1001 }
1002 ;
1003
1004 term : '\n' {
1005 Vsh_trace("Yacc","term::1");
1006 }
1007 | ';' {
1008 Vsh_trace("Yacc","term::2");
1009 }
1010 | vsh_EOF {
1011 Vsh_trace("Yacc","term::3");
1012 }
1013 ;
1014
1015 newlines : {
1016 Vsh_trace("Yacc","newlines::1");
1017 }
1018 | newlines '\n' {
1019 Vsh_trace("Yacc","newlines::2");
1020 }
1021 ;
1022
1023 %%
1024