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. */
26 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
27 #define YYPARSE_PARAM arg
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
);
57 ((struct parse_args
*) arg
)->res
= $1;
61 exp: exp
'?' exp
':' exp
63 if
(($$
= new_exp
(qmop
, $1, $3, $5, NULL
)) == NULL
)
68 if
(($$
= new_exp
(lor
, $1, $3, NULL
)) == NULL
)
73 if
(($$
= new_exp
(land
, $1, $3, NULL
)) == NULL
)
78 if
(($$
= new_exp
(equal
, $1, $3, NULL
)) == NULL
)
83 if
(($$
= new_exp
(not_equal
, $1, $3, NULL
)) == NULL
)
88 if
(($$
= new_exp
(plus
, $1, $3, NULL
)) == NULL
)
93 if
(($$
= new_exp
(minus
, $1, $3, NULL
)) == NULL
)
98 if
(($$
= new_exp
(mult
, $1, $3, NULL
)) == NULL
)
103 if
(($$
= new_exp
(divide
, $1, $3, NULL
)) == NULL
)
108 if
(($$
= new_exp
(module
, $1, $3, NULL
)) == NULL
)
113 if
(($$
= new_exp
(var
, NULL
)) == NULL
)
118 if
(($$
= new_exp
(num
, NULL
)) == NULL
)
130 static struct expression
*
131 new_exp
(enum operator op
, ...
)
133 struct expression
*newp
= (struct expression
*) malloc
(sizeof
(*newp
));
135 struct expression
*next
;
140 while
((next
= va_arg
(va
, struct expression
*)) != NULL
)
141 __gettext_free_exp
(next
);
144 newp
->operation
= op
;
145 next
= va_arg
(va
, struct expression
*);
148 newp
->val.args3.bexp
= next
;
149 next
= va_arg
(va
, struct expression
*);
152 newp
->val.args3.tbranch
= next
;
153 next
= va_arg
(va
, struct expression
*);
155 newp
->val.args3.fbranch
= next
;
167 __gettext_free_exp
(struct expression
*exp
)
172 /* Handle the recursive case. */
173 switch
(exp
->operation
)
176 __gettext_free_exp
(exp
->val.args3.fbranch
);
188 __gettext_free_exp
(exp
->val.args2.right
);
189 __gettext_free_exp
(exp
->val.args2.left
);
201 yylex (YYSTYPE *lval
, const char **pexp
)
203 const char *exp
= *pexp
;
208 if
(exp
[0] == '\\' && exp
[1] == '\n')
213 if
(exp
[0] != '\0' && exp
[0] != ' ' && exp
[0] != '\t')
224 unsigned long int n
= exp
[-1] - '0';
225 while
(exp
[0] >= '0' && exp
[0] <= '9')
246 if
(exp
[0] == result
)
262 /* Nothing, just return the character. */
267 /* Be safe and let the user call this function again. */
287 yyerror (const char *str
)
289 /* Do nothing. We don't print error messages here. */