aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/syntax.y
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/rc/syntax.y')
-rw-r--r--sys/cmd/rc/syntax.y42
1 files changed, 24 insertions, 18 deletions
diff --git a/sys/cmd/rc/syntax.y b/sys/cmd/rc/syntax.y
index 6334819..cb4a174 100644
--- a/sys/cmd/rc/syntax.y
+++ b/sys/cmd/rc/syntax.y
@@ -1,6 +1,6 @@
%token Tword Twords Tif Telse Tbang Tsubshell
-%token Targs Tindex
-%token Tbasic Tparen Tblock
+%token Toror Tandand There Tredir Tpipe Tdup
+%token Tbasic Tparen Tblock Targs Tindex
%define parse.error verbose
@@ -12,20 +12,21 @@
%}
/* operator precendence: lowest first */
-%left Twhile Telse
-%left '\n'
-%left Tbang Tsubshell
+%left Twhile Telse
+%left '\n'
+%left Tbang Tsubshell
+%left Tpipe;
%right '$' Tcount Tflat
-%right Tindex
+%left Tindex
/* semantic types */
%union{
struct Tree *tree;
}
-%type<tree> line cmds cmdsln body paren block ifbody assign;
-%type<tree> cmd basic executable nonkeyword keyword word words wordsnl atom arg args;
-%type<tree> Tbang Tsubshell Tindex;
-%type<tree> Tword Tif Telse;
+%type<tree> line cmds cmdsln body paren block ifbody assign epilog redir;
+%type<tree> cmd basic executable nonkeyword keyword word words wordsnl atom;
+%type<tree> Tbang Tsubshell Tif Telse;
+%type<tree> Tword Tredir Tpipe;
/* grammar */
@@ -65,10 +66,20 @@ ifbody:
assign:
executable '=' word { $$ = maketree2('=', $1, $3); }
+redir:
+ Tdup
+| Tredir word { $$ = hangchild1($1, $2, 0); }
+
+epilog:
+/* empty */ { $$ = nil; }
+| redir epilog { $$ = hangchild1($1, $2, 1); }
+
cmd:
/* empty */ %prec Twhile { $$ = nil; }
| basic { $$ = maketree1(Tbasic, $1); }
-| block
+| block epilog { $$ = hangepilog($1, $2); }
+| cmd Tpipe nl cmd { $$ = hangchild2($2, $1, 0, $4, 1); }
+| redir cmd %prec Tbang { $$ = hangchild1($1, $2, 1); }
| assign cmd %prec Tbang { $$ = hangchild1($1, $2, 2); }
| Tif paren nl ifbody { $$ = hangchild1($2, $1, 0); }
| Tbang cmd { $$ = maketree1(Tbang, $2); }
@@ -76,13 +87,8 @@ cmd:
basic:
executable
-| basic word { $$ = maketree2(Targs, $1, $2); }
-
-arg: word
-
-args:
- arg
-| args arg { $$ = maketree2(Targs, $1, $2); }
+| basic word { $$ = maketree2(Targs, $1, $2); }
+| basic redir { $$ = maketree2(Targs, $1, $2); }
atom:
nonkeyword