Wed Jun 14 13:27:22 1995 Steve Chamberlain <sac@slash.cygnus.com>
[platform/upstream/binutils.git] / binutils / defparse.y
1 {
2 /* defparse.y - parser for .def files */
3
4 /*   Copyright (C) 1995 Free Software Foundation, Inc.
5
6 This file is part of GNU Binutils.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
21
22
23 %union {
24   char *id;
25   int number;
26 char *string;
27 };
28
29 %token NAME, LIBRARY, DESCRIPTION, STACKSIZE, HEAPSIZE, CODE, DATA
30 %token SECTIONS, EXPORTS, IMPORTS, VERSION, BASE, CONSTANT
31 %token READ WRITE EXECUTE SHARED NONAME
32 %token <id> ID
33 %token <string> STRING
34 %token <number> NUMBER
35 %type  <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT attr attr_list opt_number
36 %type  <id> opt_name opt_equal_name 
37
38 %%
39
40 start: start command
41         | command
42         ;
43
44 command: 
45                 NAME opt_name opt_base { def_name ($2, $3); }
46         |       LIBRARY opt_name opt_base { def_library ($2, $3); }
47         |       EXPORTS explist 
48         |       DESCRIPTION STRING { def_description ($2);}
49         |       STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
50         |       HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
51         |       CODE attr_list { def_code ($2);}
52         |       DATA attr_list  { def_data ($2);}
53         |       SECTIONS seclist
54         |       IMPORTS implist
55         |       VERSION NUMBER { def_version ($2,0);}
56         |       VERSION NUMBER '.' NUMBER { def_version ($2,$4);}
57         ;
58
59
60 explist:
61                 explist expline
62         |       expline
63         ;
64
65 expline:
66                 ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT
67                         { def_exports ($1, $2, $3, $4, $5);}
68         ;
69 implist:        
70                 implist impline
71         |       impline
72         ;
73
74 impline:
75                 ID '=' ID '.' ID { def_import ($1,$3,$5);}
76         |       ID '.' ID        { def_import (0, $1,$3);}
77         ;
78 seclist:
79                 seclist secline
80         |       secline
81         ;
82
83 secline:
84         ID attr_list { def_section ($1,$2);}
85         ;
86
87 attr_list:
88         attr_list opt_comma attr
89         | attr
90         ;
91
92 opt_comma:
93         ','
94         | 
95         ;
96 opt_number: ',' NUMBER { $$=$2;}
97         |          { $$=-1;}
98         ;
99         
100 attr:
101                 READ { $$ = 1;}
102         |       WRITE { $$ = 2;}        
103         |       EXECUTE { $$=4;}
104         |       SHARED { $$=8;}
105         ;
106
107 opt_CONSTANT:
108                 CONSTANT {$$=1;}
109         |                {$$=0;}
110         ;
111 opt_NONAME:
112                 NONAME {$$=1;}
113         |                {$$=0;}
114         ;
115
116 opt_name: ID            { $$ =$1; }
117         |               { $$=""; }
118         ;
119
120 opt_ordinal: 
121           '@' NUMBER     { $$=$2;}
122         |                { $$=-1;}
123         ;
124
125 opt_equal_name:
126           '=' ID        { $$ = $2; }
127         |               { $$ =  0; }                     
128         ;
129
130 opt_base: BASE  '=' NUMBER      { $$= $3;}
131         |       { $$=-1;}
132         ;
133
134         
135