Annotation of lucent/sys/src/cmd/rc/syn.y, revision 1.1.1.1

1.1       root        1: %term FOR IN WHILE IF NOT TWIDDLE BANG SUBSHELL SWITCH FN
                      2: %term WORD REDIR DUP PIPE SUB
                      3: %term SIMPLE ARGLIST WORDS BRACE PAREN PCMD PIPEFD /* not used in syntax */
                      4: /* operator priorities -- lowest first */
                      5: %left IF WHILE FOR SWITCH ')' NOT
                      6: %left ANDAND OROR
                      7: %left BANG SUBSHELL
                      8: %left PIPE
                      9: %left '^'
                     10: %right '$' COUNT '"'
                     11: %left SUB
                     12: %{
                     13: #include "rc.h"
                     14: #include "fns.h"
                     15: %}
                     16: %union{
                     17:        struct tree *tree;
                     18: };
                     19: %type<tree> line paren brace body cmdsa cmdsan assign epilog redir
                     20: %type<tree> cmd simple first word comword keyword words
                     21: %type<tree> NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN
                     22: %type<tree> WORD REDIR DUP PIPE
                     23: %%
                     24: rc:                            { return 1;}
                     25: |      line '\n'               {return !compile($1);}
                     26: line:  cmd
                     27: |      cmdsa line              {$$=tree2(';', $1, $2);}
                     28: body:  cmd
                     29: |      cmdsan body             {$$=tree2(';', $1, $2);}
                     30: cmdsa: cmd ';'
                     31: |      cmd '&'                 {$$=tree1('&', $1);}
                     32: cmdsan:        cmdsa
                     33: |      cmd '\n'
                     34: brace: '{' body '}'            {$$=tree1(BRACE, $2);}
                     35: paren: '(' body ')'            {$$=tree1(PCMD, $2);}
                     36: assign:        first '=' word          {$$=tree2('=', $1, $3);}
                     37: epilog:                                {$$=0;}
                     38: |      redir epilog            {$$=mung2($1, $1->child[0], $2);}
                     39: redir: REDIR word              {$$=mung1($1, $1->rtype==HERE?heredoc($2):$2);}
                     40: |      DUP
                     41: cmd:                           {$$=0;}
                     42: |      brace epilog            {$$=epimung($1, $2);}
                     43: |      IF paren {skipnl();} cmd
                     44:                                {$$=mung2($1, $2, $4);}
                     45: |      IF NOT {skipnl();} cmd  {$$=mung1($2, $4);}
                     46: |      FOR '(' word IN words ')' {skipnl();} cmd
                     47:                                {$$=mung3($1, $3, tree1(PAREN, $5), $8);}
                     48: |      FOR '(' word ')' {skipnl();} cmd
                     49:                                {$$=mung3($1, $3, (struct tree *)0, $6);}
                     50: |      WHILE paren {skipnl();} cmd
                     51:                                {$$=mung2($1, $2, $4);}
                     52: |      SWITCH word {skipnl();} brace
                     53:                                {$$=tree2(SWITCH, $2, $4);}
                     54: |      simple                  {$$=simplemung($1);}
                     55: |      TWIDDLE word words      {$$=mung2($1, $2, $3);}
                     56: |      cmd ANDAND cmd          {$$=tree2(ANDAND, $1, $3);}
                     57: |      cmd OROR cmd            {$$=tree2(OROR, $1, $3);}
                     58: |      cmd PIPE cmd            {$$=mung2($2, $1, $3);}
                     59: |      redir cmd  %prec BANG   {$$=mung2($1, $1->child[0], $2);}
                     60: |      assign cmd %prec BANG   {$$=mung3($1, $1->child[0], $1->child[1], $2);}
                     61: |      BANG cmd                {$$=mung1($1, $2);}
                     62: |      SUBSHELL cmd            {$$=mung1($1, $2);}
                     63: |      FN words brace          {$$=tree2(FN, $2, $3);}
                     64: |      FN words                {$$=tree1(FN, $2);}
                     65: simple:        first
                     66: |      simple word             {$$=tree2(ARGLIST, $1, $2);}
                     67: |      simple redir            {$$=tree2(ARGLIST, $1, $2);}
                     68: first: comword 
                     69: |      first '^' word          {$$=tree2('^', $1, $3);}
                     70: word:  keyword                 {$1->type=WORD;}
                     71: |      comword
                     72: |      word '^' word           {$$=tree2('^', $1, $3);}
                     73: comword: '$' word              {$$=tree1('$', $2);}
                     74: |      '$' word SUB words ')'  {$$=tree2(SUB, $2, $4);}
                     75: |      '"' word                {$$=tree1('"', $2);}
                     76: |      COUNT word              {$$=tree1(COUNT, $2);}
                     77: |      WORD
                     78: |      '`' brace               {$$=tree1('`', $2);}
                     79: |      '(' words ')'           {$$=tree1(PAREN, $2);}
                     80: |      REDIR brace             {$$=mung1($1, $2); $$->type=PIPEFD;}
                     81: keyword: FOR|IN|WHILE|IF|NOT|TWIDDLE|BANG|SUBSHELL|SWITCH|FN
                     82: words:                         {$$=0;}
                     83: |      words word              {$$=tree2(WORDS, $1, $2);}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.