2 /* Expression parsing for plural form selection.
3 Copyright (C) 2000, 2001 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. */
30 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
31 #define YYPARSE_PARAM arg
37 unsigned long int num
;
38 struct expression
*exp
;
42 /* Prototypes for local functions. */
43 static struct expression
*new_exp
(enum operator op
, int n
, ...
);
44 static int yylex (YYSTYPE *lval
, const char **pexp
);
45 static void yyerror (const char *str
);
61 ((struct parse_args
*) arg
)->res
= $1;
65 exp: exp
'?' exp
':' exp
67 if
(($$
= new_exp
(qmop
, 3, $1, $3, $5)) == NULL
)
72 if
(($$
= new_exp
(lor
, 2, $1, $3)) == NULL
)
77 if
(($$
= new_exp
(land
, 2, $1, $3)) == NULL
)
82 if
(($$
= new_exp
(equal
, 2, $1, $3)) == NULL
)
87 if
(($$
= new_exp
(not_equal
, 2, $1, $3)) == NULL
)
92 if
(($$
= new_exp
(plus
, 2, $1, $3)) == NULL
)
97 if
(($$
= new_exp
(minus
, 2, $1, $3)) == NULL
)
102 if
(($$
= new_exp
(mult
, 2, $1, $3)) == NULL
)
107 if
(($$
= new_exp
(divide
, 2, $1, $3)) == NULL
)
112 if
(($$
= new_exp
(module
, 2, $1, $3)) == NULL
)
117 if
(($$
= new_exp
(var
, 0)) == NULL
)
122 if
(($$
= new_exp
(num
, 0)) == NULL
)
134 static struct expression
*
135 new_exp
(enum operator op
, int n
, ...
)
137 struct expression
*newp
= (struct expression
*) calloc
(1, sizeof
(*newp
));
144 __gettext_free_exp
(va_arg
(va
, struct expression
*));
147 newp
->operation
= op
;
150 newp
->val.args3.bexp
= va_arg
(va
, struct expression
*);
151 newp
->val.args3.tbranch
= va_arg
(va
, struct expression
*);
154 newp
->val.args3.fbranch
= va_arg
(va
, struct expression
*);
156 if
(newp
->val.args3.bexp
== NULL
157 || newp
->val.args3.tbranch
== NULL
158 ||
(n
> 2 && newp
->val.args3.fbranch
== NULL
))
160 __gettext_free_exp
(newp
);
173 __gettext_free_exp
(struct expression
*exp
)
178 /* Handle the recursive case. */
179 switch
(exp
->operation
)
182 __gettext_free_exp
(exp
->val.args3.fbranch
);
194 __gettext_free_exp
(exp
->val.args2.right
);
195 __gettext_free_exp
(exp
->val.args2.left
);
207 yylex (YYSTYPE *lval
, const char **pexp
)
209 const char *exp
= *pexp
;
214 if
(exp
[0] == '\\' && exp
[1] == '\n')
226 if
(exp
[0] != ' ' && exp
[0] != '\t')
235 case
'0': case
'1': case
'2': case
'3': case
'4':
236 case
'5': case
'6': case
'7': case
'8': case
'9':
238 unsigned long int n
= result
- '0';
239 while
(exp
[0] >= '0' && exp
[0] <= '9')
260 if
(exp
[0] == result
)
276 /* Nothing, just return the character. */
282 /* Be safe and let the user call this function again. */
302 yyerror (const char *str
)
304 /* Do nothing. We don't print error messages here. */