]>
Commit | Line | Data |
---|---|---|
86d7f2db JB |
1 | /* Bytecode definition file parser. |
2 | Copyright (C) 1993 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
940d9d63 RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
86d7f2db JB |
20 | |
21 | ||
22 | %{ | |
23 | ||
24 | #include <stdio.h> | |
a2c18d49 | 25 | #include "hconfig.h" |
86d7f2db JB |
26 | #include "bi-defs.h" |
27 | ||
28 | extern char yytext[]; | |
29 | extern int yyleng; | |
30 | ||
86d7f2db JB |
31 | |
32 | /* Chain of all defs built by the parser. */ | |
33 | struct def *defs; | |
34 | int ndefs; | |
35 | ||
1f57f40b JB |
36 | static struct node *makenode (); |
37 | static struct variation *makevar (); | |
38 | static struct def *makedef (); | |
39 | ||
40 | void yyerror (); | |
86d7f2db JB |
41 | |
42 | %} | |
43 | ||
1f57f40b JB |
44 | %union |
45 | { | |
86d7f2db JB |
46 | char *string; |
47 | struct def *def; | |
48 | struct variation *variation; | |
49 | struct node *node; | |
50 | } | |
51 | ||
52 | %token <string> DEFOP STRING | |
53 | %type <string> opt_string | |
54 | %type <def> defs def | |
55 | %type <variation> variations variation | |
56 | %type <node> list items item | |
57 | ||
58 | %% | |
59 | ||
60 | top: | |
61 | defs | |
62 | { defs = $1; } | |
63 | ; | |
64 | ||
65 | defs: | |
66 | def | |
67 | | defs def | |
68 | { $2->next = $1; $$ = $2; } | |
69 | ; | |
70 | ||
71 | def: | |
72 | DEFOP '(' STRING ',' opt_string ',' '(' variations ')' ')' | |
1f57f40b | 73 | { $$ = makedef ($3, $5, $8); } |
86d7f2db JB |
74 | ; |
75 | ||
76 | variations: | |
77 | variation | |
78 | | variations ',' variation | |
79 | { $3->next = $1; $$ = $3; } | |
80 | ; | |
81 | ||
82 | variation: | |
83 | '(' opt_string ')' | |
a773f6c7 | 84 | { $$ = makevar ($2, (struct node *) NULL, (struct node *) NULL, (struct node *) NULL); } |
86d7f2db | 85 | | '(' opt_string ',' list ')' |
1f57f40b | 86 | { $$ = makevar ($2, $4, (struct node *) NULL, (struct node *) NULL); } |
86d7f2db | 87 | | '(' opt_string ',' list ',' list ')' |
1f57f40b | 88 | { $$ = makevar ($2, $4, $6, (struct node *) NULL); } |
86d7f2db | 89 | | '(' opt_string ',' list ',' list ',' list ')' |
1f57f40b | 90 | { $$ = makevar ($2, $4, $6, $8); } |
86d7f2db JB |
91 | ; |
92 | ||
93 | opt_string: | |
94 | /* empty */ { $$ = ""; } | |
95 | | STRING { $$ = $1; } | |
96 | ; | |
97 | ||
98 | list: | |
99 | '(' items ')' | |
100 | { $$ = $2; } | |
101 | | /* empty */ | |
102 | { $$ = NULL; } | |
103 | ; | |
104 | ||
105 | items: | |
106 | item | |
107 | /* Note right recursion. */ | |
108 | | item ',' items | |
109 | { $1->next = $3; $$ = $1; } | |
110 | ; | |
111 | ||
112 | item: | |
113 | STRING | |
1f57f40b | 114 | { $$ = makenode ($1); } |
86d7f2db JB |
115 | ; |
116 | ||
117 | %% | |
118 | ||
119 | static struct node * | |
1f57f40b | 120 | makenode (s) |
86d7f2db JB |
121 | char *s; |
122 | { | |
123 | struct node *n; | |
124 | ||
1f57f40b | 125 | n = (struct node *) malloc (sizeof (struct node)); |
86d7f2db JB |
126 | n->text = s; |
127 | n->next = NULL; | |
128 | return n; | |
129 | } | |
130 | ||
131 | static struct variation * | |
1f57f40b | 132 | makevar (name, inputs, outputs, literals) |
86d7f2db JB |
133 | char *name; |
134 | struct node *inputs, *outputs, *literals; | |
135 | { | |
136 | struct variation *v; | |
137 | ||
1f57f40b | 138 | v = (struct variation *) malloc (sizeof (struct variation)); |
86d7f2db JB |
139 | v->name = name; |
140 | v->code = ndefs++; | |
141 | v->inputs = inputs; | |
142 | v->outputs = outputs; | |
143 | v->literals = literals; | |
144 | v->next = NULL; | |
145 | return v; | |
146 | } | |
147 | ||
148 | static struct def * | |
1f57f40b | 149 | makedef (name, template, vars) |
86d7f2db JB |
150 | char *name, *template; |
151 | struct variation *vars; | |
152 | { | |
153 | struct def *d; | |
154 | ||
1f57f40b | 155 | d = (struct def *) malloc (sizeof (struct def)); |
86d7f2db JB |
156 | d->basename = name; |
157 | d->template = template; | |
158 | d->variations = vars; | |
159 | d->next = NULL; | |
160 | return d; | |
161 | } | |
162 | ||
163 | void | |
1f57f40b | 164 | yyerror (s) |
86d7f2db JB |
165 | char *s; |
166 | { | |
a773f6c7 | 167 | fprintf (stderr, "syntax error in input\n"); |
6026c19c | 168 | exit (FATAL_EXIT_CODE); |
86d7f2db | 169 | } |