Annotation of 43BSDReno/share/doc/ps1/15.yacc/ssb, revision 1.1.1.1

1.1       root        1: .\"    @(#)ssb 6.1 (Berkeley) 5/8/86
                      2: .\"
                      3: .SH
                      4: Appendix B: Yacc Input Syntax
                      5: .PP
                      6: This Appendix has a description of the Yacc input syntax, as a Yacc specification.
                      7: Context dependencies, etc., are not considered.
                      8: Ironically, the Yacc input specification language
                      9: is most naturally specified as an LR(2) grammar; the sticky
                     10: part comes when an identifier is seen in a rule, immediately
                     11: following an action.
                     12: If this identifier is followed by a colon, it is the start of the
                     13: next rule; otherwise
                     14: it is a continuation of the current rule, which just happens to have
                     15: an action embedded in it.
                     16: As implemented, the lexical analyzer looks
                     17: ahead after seeing an identifier, and
                     18: decide whether the next token (skipping blanks, newlines, comments, etc.)
                     19: is a colon.
                     20: If so, it returns the token C_IDENTIFIER.
                     21: Otherwise, it returns IDENTIFIER.
                     22: Literals (quoted strings) are also returned as IDENTIFIERS,
                     23: but never as part of C_IDENTIFIERs.
                     24: .sp
                     25: .nf
                     26: .ta .6i 1.2i 1.8i 2.4i 3i 3.6i
                     27: 
                     28:             /*  grammar  for  the  input  to  Yacc  */
                     29: 
                     30:        /*  basic  entities  */
                     31: %token IDENTIFIER      /*   includes  identifiers   and  literals  */
                     32: %token C_IDENTIFIER    /*    identifier  (but  not  literal)  followed  by  colon    */
                     33: %token NUMBER          /*    [0-9]+    */
                     34: 
                     35:        /*  reserved  words:    %type  =>  TYPE,  %left  =>  LEFT,  etc.  */
                     36: 
                     37: %token LEFT  RIGHT  NONASSOC  TOKEN  PREC  TYPE  START  UNION
                     38: 
                     39: %token MARK    /*  the  %%  mark  */
                     40: %token LCURL   /*  the  %{  mark  */
                     41: %token RCURL   /*  the  %}  mark  */
                     42: 
                     43:        /*  ascii  character  literals  stand  for  themselves  */
                     44: 
                     45: %start spec
                     46: 
                     47: %%
                     48: 
                     49: spec   :       defs  MARK  rules  tail
                     50:        ;
                     51: 
                     52: tail   :       MARK    {    \fIIn  this  action,  eat  up  the  rest  of  the  file\fR    }
                     53:        |       /*  empty:  the  second  MARK  is  optional  */
                     54:        ;
                     55: 
                     56: defs   :       /*  empty  */
                     57:        |       defs  def
                     58:        ;
                     59: 
                     60: def    :       START  IDENTIFIER
                     61:        |       UNION  {  \fICopy union  definition  to  output\fR  }
                     62:        |       LCURL  {  \fICopy  C  code  to  output  file\fR   }  RCURL
                     63:        |       ndefs  rword  tag  nlist
                     64:        ;
                     65: 
                     66: rword  :       TOKEN
                     67:        |       LEFT
                     68:        |       RIGHT
                     69:        |       NONASSOC
                     70:        |       TYPE
                     71:        ;
                     72: 
                     73: tag    :       /*  empty:  union  tag  is  optional  */
                     74:        |       \'<\'  IDENTIFIER  \'>\'
                     75:        ;
                     76: 
                     77: nlist  :       nmno
                     78:        |       nlist  nmno
                     79:        |       nlist  \',\'  nmno
                     80:        ;
                     81: 
                     82: nmno   :       IDENTIFIER              /*  NOTE:  literal  illegal  with  %type  */
                     83:        |       IDENTIFIER  NUMBER      /*  NOTE:  illegal  with  %type  */
                     84:        ;
                     85: 
                     86:        /*  rules  section  */
                     87: 
                     88: rules  :       C_IDENTIFIER  rbody  prec
                     89:        |       rules  rule
                     90:        ;
                     91: 
                     92: rule   :       C_IDENTIFIER  rbody  prec
                     93:        |       '|'  rbody  prec
                     94:        ;
                     95: 
                     96: rbody  :       /*  empty  */
                     97:        |       rbody  IDENTIFIER
                     98:        |       rbody  act
                     99:        ;
                    100: 
                    101: act    :       \'{\'  {  \fICopy  action,  translate  $$,  etc.\fR  }  \'}\'
                    102:        ;
                    103: 
                    104: prec   :       /*  empty  */
                    105:        |       PREC  IDENTIFIER
                    106:        |       PREC  IDENTIFIER  act
                    107:        |       prec  \';\'
                    108:        ;
                    109: .fi
                    110: .bp

unix.superglobalmegacorp.com

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