]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/doc/psd/15.yacc/ssb
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / doc / psd / 15.yacc / ssb
1 .\" Copyright (C) Caldera International Inc. 2001-2002.  All rights reserved.
2 .\" 
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions are
5 .\" met:
6 .\" 
7 .\" Redistributions of source code and documentation must retain the above
8 .\" copyright notice, this list of conditions and the following
9 .\" disclaimer.
10 .\" 
11 .\" Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 
15 .\" All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" 
18 .\" This product includes software developed or owned by Caldera
19 .\" International, Inc.  Neither the name of Caldera International, Inc.
20 .\" nor the names of other contributors may be used to endorse or promote
21 .\" products derived from this software without specific prior written
22 .\" permission.
23 .\" 
24 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
25 .\" INTERNATIONAL, INC.  AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
26 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 .\" DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34 .\" OR OTHERWISE) RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
35 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 .\"
37 .\"     @(#)ssb 8.1 (Berkeley) 6/8/93
38 .\"
39 .\" $FreeBSD$
40 .SH
41 Appendix B: Yacc Input Syntax
42 .PP
43 This Appendix has a description of the Yacc input syntax, as a Yacc specification.
44 Context dependencies, etc., are not considered.
45 Ironically, the Yacc input specification language
46 is most naturally specified as an LR(2) grammar; the sticky
47 part comes when an identifier is seen in a rule, immediately
48 following an action.
49 If this identifier is followed by a colon, it is the start of the
50 next rule; otherwise
51 it is a continuation of the current rule, which just happens to have
52 an action embedded in it.
53 As implemented, the lexical analyzer looks
54 ahead after seeing an identifier, and
55 decide whether the next token (skipping blanks, newlines, comments, etc.)
56 is a colon.
57 If so, it returns the token C_IDENTIFIER.
58 Otherwise, it returns IDENTIFIER.
59 Literals (quoted strings) are also returned as IDENTIFIERS,
60 but never as part of C_IDENTIFIERs.
61 .sp
62 .nf
63 .ta .6i 1.2i 1.8i 2.4i 3i 3.6i
64
65             /*  grammar  for  the  input  to  Yacc  */
66
67         /*  basic  entities  */
68 %token  IDENTIFIER      /*   includes  identifiers   and  literals  */
69 %token  C_IDENTIFIER    /*    identifier  (but  not  literal)  followed  by  colon    */
70 %token  NUMBER          /*    [0-9]+    */
71
72         /*  reserved  words:    %type  =>  TYPE,  %left  =>  LEFT,  etc.  */
73
74 %token  LEFT  RIGHT  NONASSOC  TOKEN  PREC  TYPE  START  UNION
75
76 %token  MARK    /*  the  %%  mark  */
77 %token  LCURL   /*  the  %{  mark  */
78 %token  RCURL   /*  the  %}  mark  */
79
80         /*  ascii  character  literals  stand  for  themselves  */
81
82 %start  spec
83
84 %%
85
86 spec    :       defs  MARK  rules  tail
87         ;
88
89 tail    :       MARK    {    \fIIn  this  action,  eat  up  the  rest  of  the  file\fR    }
90         |       /*  empty:  the  second  MARK  is  optional  */
91         ;
92
93 defs    :       /*  empty  */
94         |       defs  def
95         ;
96
97 def     :       START  IDENTIFIER
98         |       UNION  {  \fICopy union  definition  to  output\fR  }
99         |       LCURL  {  \fICopy  C  code  to  output  file\fR   }  RCURL
100         |       ndefs  rword  tag  nlist
101         ;
102
103 rword   :       TOKEN
104         |       LEFT
105         |       RIGHT
106         |       NONASSOC
107         |       TYPE
108         ;
109
110 tag     :       /*  empty:  union  tag  is  optional  */
111         |       \'<\'  IDENTIFIER  \'>\'
112         ;
113
114 nlist   :       nmno
115         |       nlist  nmno
116         |       nlist  \',\'  nmno
117         ;
118
119 nmno    :       IDENTIFIER              /*  NOTE:  literal  illegal  with  %type  */
120         |       IDENTIFIER  NUMBER      /*  NOTE:  illegal  with  %type  */
121         ;
122
123         /*  rules  section  */
124
125 rules   :       C_IDENTIFIER  rbody  prec
126         |       rules  rule
127         ;
128
129 rule    :       C_IDENTIFIER  rbody  prec
130         |       '|'  rbody  prec
131         ;
132
133 rbody   :       /*  empty  */
134         |       rbody  IDENTIFIER
135         |       rbody  act
136         ;
137
138 act     :       \'{\'  {  \fICopy  action,  translate  $$,  etc.\fR  }  \'}\'
139         ;
140
141 prec    :       /*  empty  */
142         |       PREC  IDENTIFIER
143         |       PREC  IDENTIFIER  act
144         |       prec  \';\'
145         ;
146 .fi
147 .bp