OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [intl/] [plural.y] - Blame information for rev 258

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
%{
2
/* Expression parsing for plural form selection.
3
   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4
   This file is part of the GNU C Library.
5
   Written by Ulrich Drepper , 2000.
6
 
7
   The GNU C Library is free software; you can redistribute it and/or
8
   modify it under the terms of the GNU Lesser General Public
9
   License as published by the Free Software Foundation; either
10
   version 2.1 of the License, or (at your option) any later version.
11
 
12
   The GNU C Library is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
   Lesser General Public License for more details.
16
 
17
   You should have received a copy of the GNU Lesser General Public
18
   License along with the GNU C Library; if not, write to the Free
19
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
   02111-1307 USA.  */
21
 
22
#ifdef HAVE_CONFIG_H
23
# include 
24
#endif
25
 
26
#include 
27
#include "gettextP.h"
28
 
29
/* Names for the libintl functions are a problem.  They must not clash
30
   with existing names and they should follow ANSI C.  But this source
31
   code is also used in GNU C Library where the names have a __
32
   prefix.  So we have to make a difference here.  */
33
#ifdef _LIBC
34
# define FREE_EXPRESSION __gettext_free_exp
35
#else
36
# define FREE_EXPRESSION gettext_free_exp__
37
# define __gettextparse gettextparse__
38
#endif
39
 
40
#define YYLEX_PARAM     &((struct parse_args *) arg)->cp
41
#define YYPARSE_PARAM   arg
42
%}
43
%pure_parser
44
%expect 7
45
 
46
%union {
47
  unsigned long int num;
48
  enum operator op;
49
  struct expression *exp;
50
}
51
 
52
%{
53
/* Prototypes for local functions.  */
54
static struct expression *new_exp PARAMS ((int nargs, enum operator op,
55
                                           struct expression * const *args));
56
static inline struct expression *new_exp_0 PARAMS ((enum operator op));
57
static inline struct expression *new_exp_1 PARAMS ((enum operator op,
58
                                                   struct expression *right));
59
static struct expression *new_exp_2 PARAMS ((enum operator op,
60
                                             struct expression *left,
61
                                             struct expression *right));
62
static inline struct expression *new_exp_3 PARAMS ((enum operator op,
63
                                                   struct expression *bexp,
64
                                                   struct expression *tbranch,
65
                                                   struct expression *fbranch));
66
static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
67
static void yyerror PARAMS ((const char *str));
68
 
69
/* Allocation of expressions.  */
70
 
71
static struct expression *
72
new_exp (nargs, op, args)
73
     int nargs;
74
     enum operator op;
75
     struct expression * const *args;
76
{
77
  int i;
78
  struct expression *newp;
79
 
80
  /* If any of the argument could not be malloc'ed, just return NULL.  */
81
  for (i = nargs - 1; i >= 0; i--)
82
    if (args[i] == NULL)
83
      goto fail;
84
 
85
  /* Allocate a new expression.  */
86
  newp = (struct expression *) malloc (sizeof (*newp));
87
  if (newp != NULL)
88
    {
89
      newp->nargs = nargs;
90
      newp->operation = op;
91
      for (i = nargs - 1; i >= 0; i--)
92
        newp->val.args[i] = args[i];
93
      return newp;
94
    }
95
 
96
 fail:
97
  for (i = nargs - 1; i >= 0; i--)
98
    FREE_EXPRESSION (args[i]);
99
 
100
  return NULL;
101
}
102
 
103
static inline struct expression *
104
new_exp_0 (op)
105
     enum operator op;
106
{
107
  return new_exp (0, op, NULL);
108
}
109
 
110
static inline struct expression *
111
new_exp_1 (op, right)
112
     enum operator op;
113
     struct expression *right;
114
{
115
  struct expression *args[1];
116
 
117
  args[0] = right;
118
  return new_exp (1, op, args);
119
}
120
 
121
static struct expression *
122
new_exp_2 (op, left, right)
123
     enum operator op;
124
     struct expression *left;
125
     struct expression *right;
126
{
127
  struct expression *args[2];
128
 
129
  args[0] = left;
130
  args[1] = right;
131
  return new_exp (2, op, args);
132
}
133
 
134
static inline struct expression *
135
new_exp_3 (op, bexp, tbranch, fbranch)
136
     enum operator op;
137
     struct expression *bexp;
138
     struct expression *tbranch;
139
     struct expression *fbranch;
140
{
141
  struct expression *args[3];
142
 
143
  args[0] = bexp;
144
  args[1] = tbranch;
145
  args[2] = fbranch;
146
  return new_exp (3, op, args);
147
}
148
 
149
%}
150
 
151
/* This declares that all operators have the same associativity and the
152
   precedence order as in C.  See [Harbison, Steele: C, A Reference Manual].
153
   There is no unary minus and no bitwise operators.
154
   Operators with the same syntactic behaviour have been merged into a single
155
   token, to save space in the array generated by bison.  */
156
%right '?'              /*   ?          */
157
%left '|'               /*   ||         */
158
%left '&'               /*   &&         */
159
%left EQUOP2            /*   == !=      */
160
%left CMPOP2            /*   < > <= >= */
161
%left ADDOP2            /*   + -        */
162
%left MULOP2            /*   * / %      */
163
%right '!'              /*   !          */
164
 
165
%token  EQUOP2 CMPOP2 ADDOP2 MULOP2
166
%token  NUMBER
167
%type  exp
168
 
169
%%
170
 
171
start:    exp
172
          {
173
            if ($1 == NULL)
174
              YYABORT;
175
            ((struct parse_args *) arg)->res = $1;
176
          }
177
        ;
178
 
179
exp:      exp '?' exp ':' exp
180
          {
181
            $$ = new_exp_3 (qmop, $1, $3, $5);
182
          }
183
        | exp '|' exp
184
          {
185
            $$ = new_exp_2 (lor, $1, $3);
186
          }
187
        | exp '&' exp
188
          {
189
            $$ = new_exp_2 (land, $1, $3);
190
          }
191
        | exp EQUOP2 exp
192
          {
193
            $$ = new_exp_2 ($2, $1, $3);
194
          }
195
        | exp CMPOP2 exp
196
          {
197
            $$ = new_exp_2 ($2, $1, $3);
198
          }
199
        | exp ADDOP2 exp
200
          {
201
            $$ = new_exp_2 ($2, $1, $3);
202
          }
203
        | exp MULOP2 exp
204
          {
205
            $$ = new_exp_2 ($2, $1, $3);
206
          }
207
        | '!' exp
208
          {
209
            $$ = new_exp_1 (lnot, $2);
210
          }
211
        | 'n'
212
          {
213
            $$ = new_exp_0 (var);
214
          }
215
        | NUMBER
216
          {
217
            if (($$ = new_exp_0 (num)) != NULL)
218
              $$->val.num = $1;
219
          }
220
        | '(' exp ')'
221
          {
222
            $$ = $2;
223
          }
224
        ;
225
 
226
%%
227
 
228
void
229
internal_function
230
FREE_EXPRESSION (exp)
231
     struct expression *exp;
232
{
233
  if (exp == NULL)
234
    return;
235
 
236
  /* Handle the recursive case.  */
237
  switch (exp->nargs)
238
    {
239
    case 3:
240
      FREE_EXPRESSION (exp->val.args[2]);
241
      /* FALLTHROUGH */
242
    case 2:
243
      FREE_EXPRESSION (exp->val.args[1]);
244
      /* FALLTHROUGH */
245
    case 1:
246
      FREE_EXPRESSION (exp->val.args[0]);
247
      /* FALLTHROUGH */
248
    default:
249
      break;
250
    }
251
 
252
  free (exp);
253
}
254
 
255
 
256
static int
257
yylex (lval, pexp)
258
     YYSTYPE *lval;
259
     const char **pexp;
260
{
261
  const char *exp = *pexp;
262
  int result;
263
 
264
  while (1)
265
    {
266
      if (exp[0] == '\0')
267
        {
268
          *pexp = exp;
269
          return YYEOF;
270
        }
271
 
272
      if (exp[0] != ' ' && exp[0] != '\t')
273
        break;
274
 
275
      ++exp;
276
    }
277
 
278
  result = *exp++;
279
  switch (result)
280
    {
281
    case '0': case '1': case '2': case '3': case '4':
282
    case '5': case '6': case '7': case '8': case '9':
283
      {
284
        unsigned long int n = result - '0';
285
        while (exp[0] >= '0' && exp[0] <= '9')
286
          {
287
            n *= 10;
288
            n += exp[0] - '0';
289
            ++exp;
290
          }
291
        lval->num = n;
292
        result = NUMBER;
293
      }
294
      break;
295
 
296
    case '=':
297
      if (exp[0] == '=')
298
        {
299
          ++exp;
300
          lval->op = equal;
301
          result = EQUOP2;
302
        }
303
      else
304
        result = YYERRCODE;
305
      break;
306
 
307
    case '!':
308
      if (exp[0] == '=')
309
        {
310
          ++exp;
311
          lval->op = not_equal;
312
          result = EQUOP2;
313
        }
314
      break;
315
 
316
    case '&':
317
    case '|':
318
      if (exp[0] == result)
319
        ++exp;
320
      else
321
        result = YYERRCODE;
322
      break;
323
 
324
    case '<':
325
      if (exp[0] == '=')
326
        {
327
          ++exp;
328
          lval->op = less_or_equal;
329
        }
330
      else
331
        lval->op = less_than;
332
      result = CMPOP2;
333
      break;
334
 
335
    case '>':
336
      if (exp[0] == '=')
337
        {
338
          ++exp;
339
          lval->op = greater_or_equal;
340
        }
341
      else
342
        lval->op = greater_than;
343
      result = CMPOP2;
344
      break;
345
 
346
    case '*':
347
      lval->op = mult;
348
      result = MULOP2;
349
      break;
350
 
351
    case '/':
352
      lval->op = divide;
353
      result = MULOP2;
354
      break;
355
 
356
    case '%':
357
      lval->op = module;
358
      result = MULOP2;
359
      break;
360
 
361
    case '+':
362
      lval->op = plus;
363
      result = ADDOP2;
364
      break;
365
 
366
    case '-':
367
      lval->op = minus;
368
      result = ADDOP2;
369
      break;
370
 
371
    case 'n':
372
    case '?':
373
    case ':':
374
    case '(':
375
    case ')':
376
      /* Nothing, just return the character.  */
377
      break;
378
 
379
    case ';':
380
    case '\n':
381
    case '\0':
382
      /* Be safe and let the user call this function again.  */
383
      --exp;
384
      result = YYEOF;
385
      break;
386
 
387
    default:
388
      result = YYERRCODE;
389
#if YYDEBUG != 0
390
      --exp;
391
#endif
392
      break;
393
    }
394
 
395
  *pexp = exp;
396
 
397
  return result;
398
}
399
 
400
 
401
static void
402
yyerror (str)
403
     const char *str;
404
{
405
  /* Do nothing.  We don't print error messages here.  */
406
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.