(do_lookup_versioned): Replace reloc_type parameter with noexec and noplt parameter...
[glibc.git] / intl / plural.y
blob00b6fccb4fd3d25e22630105a747507793ae282c
1 %{
2 /* Expression parsing for plural form selection.
3 Copyright (C) 2000 Free Software Foundation, Inc.
4 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library 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 GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include "gettext.h"
24 #include "gettextP.h"
26 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
27 #define YYPARSE_PARAM arg
29 %pure_parser
30 %expect 10
32 %union {
33 unsigned long int num;
34 struct expression *exp;
38 /* Prototypes for local functions. */
39 static struct expression *new_exp (enum operator op, ...);
40 static int yylex (YYSTYPE *lval, const char **pexp);
41 static void yyerror (const char *str);
44 %left '?'
45 %left '|'
46 %left '&'
47 %left '=', '!'
48 %left '+', '-'
49 %left '*', '/', '%'
50 %token <num> NUMBER
51 %type <exp> exp
55 start: exp
57 ((struct parse_args *) arg)->res = $1;
61 exp: exp '?' exp ':' exp
63 if (($$ = new_exp (qmop, $1, $3, $5, NULL)) == NULL)
64 YYABORT
66 | exp '|' exp
68 if (($$ = new_exp (lor, $1, $3, NULL)) == NULL)
69 YYABORT
71 | exp '&' exp
73 if (($$ = new_exp (land, $1, $3, NULL)) == NULL)
74 YYABORT
76 | exp '=' exp
78 if (($$ = new_exp (equal, $1, $3, NULL)) == NULL)
79 YYABORT
81 | exp '!' exp
83 if (($$ = new_exp (not_equal, $1, $3, NULL)) == NULL)
84 YYABORT
86 | exp '+' exp
88 if (($$ = new_exp (plus, $1, $3, NULL)) == NULL)
89 YYABORT
91 | exp '-' exp
93 if (($$ = new_exp (minus, $1, $3, NULL)) == NULL)
94 YYABORT
96 | exp '*' exp
98 if (($$ = new_exp (mult, $1, $3, NULL)) == NULL)
99 YYABORT
101 | exp '/' exp
103 if (($$ = new_exp (divide, $1, $3, NULL)) == NULL)
104 YYABORT
106 | exp '%' exp
108 if (($$ = new_exp (module, $1, $3, NULL)) == NULL)
109 YYABORT
111 | 'n'
113 if (($$ = new_exp (var, NULL)) == NULL)
114 YYABORT
116 | NUMBER
118 if (($$ = new_exp (num, NULL)) == NULL)
119 YYABORT;
120 $$->val.num = $1
122 | '(' exp ')'
124 $$ = $2
130 static struct expression *
131 new_exp (enum operator op, ...)
133 struct expression *newp = (struct expression *) malloc (sizeof (*newp));
134 va_list va;
135 struct expression *next;
137 va_start (va, op);
139 if (newp == NULL)
140 while ((next = va_arg (va, struct expression *)) != NULL)
141 __gettext_free_exp (next);
142 else
144 newp->operation = op;
145 next = va_arg (va, struct expression *);
146 if (next != NULL)
148 newp->val.args3.bexp = next;
149 next = va_arg (va, struct expression *);
150 if (next != NULL)
152 newp->val.args3.tbranch = next;
153 next = va_arg (va, struct expression *);
154 if (next != NULL)
155 newp->val.args3.fbranch = next;
160 va_end (va);
162 return newp;
165 void
166 internal_function
167 __gettext_free_exp (struct expression *exp)
169 if (exp == NULL)
170 return;
172 /* Handle the recursive case. */
173 switch (exp->operation)
175 case qmop:
176 __gettext_free_exp (exp->val.args3.fbranch);
177 /* FALLTHROUGH */
179 case mult:
180 case divide:
181 case module:
182 case plus:
183 case minus:
184 case equal:
185 case not_equal:
186 case land:
187 case lor:
188 __gettext_free_exp (exp->val.args2.right);
189 __gettext_free_exp (exp->val.args2.left);
190 break;
192 default:
193 break;
196 free (exp);
200 static int
201 yylex (YYSTYPE *lval, const char **pexp)
203 const char *exp = *pexp;
204 int result;
206 while (1)
208 if (exp[0] == '\\' && exp[1] == '\n')
210 exp += 2;
211 continue;
213 if (exp[0] != '\0' && exp[0] != ' ' && exp[0] != '\t')
214 break;
216 ++exp;
219 result = *exp++;
220 switch (result)
222 case '0' ... '9':
224 unsigned long int n = exp[-1] - '0';
225 while (exp[0] >= '0' && exp[0] <= '9')
227 n *= 10;
228 n += exp[0] - '0';
229 ++exp;
231 lval->num = n;
232 result = NUMBER;
234 break;
236 case '=':
237 case '!':
238 if (exp[0] == '=')
239 ++exp;
240 else
241 result = YYERRCODE;
242 break;
244 case '&':
245 case '|':
246 if (exp[0] == result)
247 ++exp;
248 else
249 result = YYERRCODE;
250 break;
252 case 'n':
253 case '*':
254 case '/':
255 case '%':
256 case '+':
257 case '-':
258 case '?':
259 case ':':
260 case '(':
261 case ')':
262 /* Nothing, just return the character. */
263 break;
265 case '\n':
266 case '\0':
267 /* Be safe and let the user call this function again. */
268 --exp;
269 result = YYEOF;
270 break;
272 default:
273 result = YYERRCODE;
274 #if YYDEBUG != 0
275 --exp;
276 #endif
277 break;
280 *pexp = exp;
282 return result;
286 static void
287 yyerror (const char *str)
289 /* Do nothing. We don't print error messages here. */