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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [intl/] [plural.y] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
%{
%{
/* Expression parsing for plural form selection.
/* Expression parsing for plural form selection.
   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
   Written by Ulrich Drepper , 2000.
   Written by Ulrich Drepper , 2000.
   This program is free software; you can redistribute it and/or modify it
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU Library General Public License as published
   under the terms of the GNU Library General Public License as published
   by the Free Software Foundation; either version 2, or (at your option)
   by the Free Software Foundation; either version 2, or (at your option)
   any later version.
   any later version.
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   Library General Public License for more details.
   You should have received a copy of the GNU Library General Public
   You should have received a copy of the GNU Library General Public
   License along with this program; if not, write to the Free Software
   License along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
   USA.  */
   USA.  */
/* The bison generated parser uses alloca.  AIX 3 forces us to put this
/* The bison generated parser uses alloca.  AIX 3 forces us to put this
   declaration at the beginning of the file.  The declaration in bison's
   declaration at the beginning of the file.  The declaration in bison's
   skeleton file comes too late.  This must come before 
   skeleton file comes too late.  This must come before 
   because  may include arbitrary system headers.  */
   because  may include arbitrary system headers.  */
#if defined _AIX && !defined __GNUC__
#if defined _AIX && !defined __GNUC__
 #pragma alloca
 #pragma alloca
#endif
#endif
#ifdef HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
# include 
# include 
#endif
#endif
#include 
#include 
#include 
#include 
#include "plural-exp.h"
#include "plural-exp.h"
/* The main function generated by the parser is called __gettextparse,
/* The main function generated by the parser is called __gettextparse,
   but we want it to be called PLURAL_PARSE.  */
   but we want it to be called PLURAL_PARSE.  */
#ifndef _LIBC
#ifndef _LIBC
# define __gettextparse PLURAL_PARSE
# define __gettextparse PLURAL_PARSE
#endif
#endif
#define YYLEX_PARAM     &((struct parse_args *) arg)->cp
#define YYLEX_PARAM     &((struct parse_args *) arg)->cp
#define YYPARSE_PARAM   arg
#define YYPARSE_PARAM   arg
%}
%}
%pure_parser
%pure_parser
%expect 7
%expect 7
%union {
%union {
  unsigned long int num;
  unsigned long int num;
  enum operator op;
  enum operator op;
  struct expression *exp;
  struct expression *exp;
}
}
%{
%{
/* Prototypes for local functions.  */
/* Prototypes for local functions.  */
static struct expression *new_exp PARAMS ((int nargs, enum operator op,
static struct expression *new_exp PARAMS ((int nargs, enum operator op,
                                           struct expression * const *args));
                                           struct expression * const *args));
static inline struct expression *new_exp_0 PARAMS ((enum operator op));
static inline struct expression *new_exp_0 PARAMS ((enum operator op));
static inline struct expression *new_exp_1 PARAMS ((enum operator op,
static inline struct expression *new_exp_1 PARAMS ((enum operator op,
                                                   struct expression *right));
                                                   struct expression *right));
static struct expression *new_exp_2 PARAMS ((enum operator op,
static struct expression *new_exp_2 PARAMS ((enum operator op,
                                             struct expression *left,
                                             struct expression *left,
                                             struct expression *right));
                                             struct expression *right));
static inline struct expression *new_exp_3 PARAMS ((enum operator op,
static inline struct expression *new_exp_3 PARAMS ((enum operator op,
                                                   struct expression *bexp,
                                                   struct expression *bexp,
                                                   struct expression *tbranch,
                                                   struct expression *tbranch,
                                                   struct expression *fbranch));
                                                   struct expression *fbranch));
static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
static void yyerror PARAMS ((const char *str));
static void yyerror PARAMS ((const char *str));
/* Allocation of expressions.  */
/* Allocation of expressions.  */
static struct expression *
static struct expression *
new_exp (nargs, op, args)
new_exp (nargs, op, args)
     int nargs;
     int nargs;
     enum operator op;
     enum operator op;
     struct expression * const *args;
     struct expression * const *args;
{
{
  int i;
  int i;
  struct expression *newp;
  struct expression *newp;
  /* If any of the argument could not be malloc'ed, just return NULL.  */
  /* If any of the argument could not be malloc'ed, just return NULL.  */
  for (i = nargs - 1; i >= 0; i--)
  for (i = nargs - 1; i >= 0; i--)
    if (args[i] == NULL)
    if (args[i] == NULL)
      goto fail;
      goto fail;
  /* Allocate a new expression.  */
  /* Allocate a new expression.  */
  newp = (struct expression *) malloc (sizeof (*newp));
  newp = (struct expression *) malloc (sizeof (*newp));
  if (newp != NULL)
  if (newp != NULL)
    {
    {
      newp->nargs = nargs;
      newp->nargs = nargs;
      newp->operation = op;
      newp->operation = op;
      for (i = nargs - 1; i >= 0; i--)
      for (i = nargs - 1; i >= 0; i--)
        newp->val.args[i] = args[i];
        newp->val.args[i] = args[i];
      return newp;
      return newp;
    }
    }
 fail:
 fail:
  for (i = nargs - 1; i >= 0; i--)
  for (i = nargs - 1; i >= 0; i--)
    FREE_EXPRESSION (args[i]);
    FREE_EXPRESSION (args[i]);
  return NULL;
  return NULL;
}
}
static inline struct expression *
static inline struct expression *
new_exp_0 (op)
new_exp_0 (op)
     enum operator op;
     enum operator op;
{
{
  return new_exp (0, op, NULL);
  return new_exp (0, op, NULL);
}
}
static inline struct expression *
static inline struct expression *
new_exp_1 (op, right)
new_exp_1 (op, right)
     enum operator op;
     enum operator op;
     struct expression *right;
     struct expression *right;
{
{
  struct expression *args[1];
  struct expression *args[1];
  args[0] = right;
  args[0] = right;
  return new_exp (1, op, args);
  return new_exp (1, op, args);
}
}
static struct expression *
static struct expression *
new_exp_2 (op, left, right)
new_exp_2 (op, left, right)
     enum operator op;
     enum operator op;
     struct expression *left;
     struct expression *left;
     struct expression *right;
     struct expression *right;
{
{
  struct expression *args[2];
  struct expression *args[2];
  args[0] = left;
  args[0] = left;
  args[1] = right;
  args[1] = right;
  return new_exp (2, op, args);
  return new_exp (2, op, args);
}
}
static inline struct expression *
static inline struct expression *
new_exp_3 (op, bexp, tbranch, fbranch)
new_exp_3 (op, bexp, tbranch, fbranch)
     enum operator op;
     enum operator op;
     struct expression *bexp;
     struct expression *bexp;
     struct expression *tbranch;
     struct expression *tbranch;
     struct expression *fbranch;
     struct expression *fbranch;
{
{
  struct expression *args[3];
  struct expression *args[3];
  args[0] = bexp;
  args[0] = bexp;
  args[1] = tbranch;
  args[1] = tbranch;
  args[2] = fbranch;
  args[2] = fbranch;
  return new_exp (3, op, args);
  return new_exp (3, op, args);
}
}
%}
%}
/* This declares that all operators have the same associativity and the
/* This declares that all operators have the same associativity and the
   precedence order as in C.  See [Harbison, Steele: C, A Reference Manual].
   precedence order as in C.  See [Harbison, Steele: C, A Reference Manual].
   There is no unary minus and no bitwise operators.
   There is no unary minus and no bitwise operators.
   Operators with the same syntactic behaviour have been merged into a single
   Operators with the same syntactic behaviour have been merged into a single
   token, to save space in the array generated by bison.  */
   token, to save space in the array generated by bison.  */
%right '?'              /*   ?          */
%right '?'              /*   ?          */
%left '|'               /*   ||         */
%left '|'               /*   ||         */
%left '&'               /*   &&         */
%left '&'               /*   &&         */
%left EQUOP2            /*   == !=      */
%left EQUOP2            /*   == !=      */
%left CMPOP2            /*   < > <= >= */
%left CMPOP2            /*   < > <= >= */
%left ADDOP2            /*   + -        */
%left ADDOP2            /*   + -        */
%left MULOP2            /*   * / %      */
%left MULOP2            /*   * / %      */
%right '!'              /*   !          */
%right '!'              /*   !          */
%token  EQUOP2 CMPOP2 ADDOP2 MULOP2
%token  EQUOP2 CMPOP2 ADDOP2 MULOP2
%token  NUMBER
%token  NUMBER
%type  exp
%type  exp
%%
%%
start:    exp
start:    exp
          {
          {
            if ($1 == NULL)
            if ($1 == NULL)
              YYABORT;
              YYABORT;
            ((struct parse_args *) arg)->res = $1;
            ((struct parse_args *) arg)->res = $1;
          }
          }
        ;
        ;
exp:      exp '?' exp ':' exp
exp:      exp '?' exp ':' exp
          {
          {
            $$ = new_exp_3 (qmop, $1, $3, $5);
            $$ = new_exp_3 (qmop, $1, $3, $5);
          }
          }
        | exp '|' exp
        | exp '|' exp
          {
          {
            $$ = new_exp_2 (lor, $1, $3);
            $$ = new_exp_2 (lor, $1, $3);
          }
          }
        | exp '&' exp
        | exp '&' exp
          {
          {
            $$ = new_exp_2 (land, $1, $3);
            $$ = new_exp_2 (land, $1, $3);
          }
          }
        | exp EQUOP2 exp
        | exp EQUOP2 exp
          {
          {
            $$ = new_exp_2 ($2, $1, $3);
            $$ = new_exp_2 ($2, $1, $3);
          }
          }
        | exp CMPOP2 exp
        | exp CMPOP2 exp
          {
          {
            $$ = new_exp_2 ($2, $1, $3);
            $$ = new_exp_2 ($2, $1, $3);
          }
          }
        | exp ADDOP2 exp
        | exp ADDOP2 exp
          {
          {
            $$ = new_exp_2 ($2, $1, $3);
            $$ = new_exp_2 ($2, $1, $3);
          }
          }
        | exp MULOP2 exp
        | exp MULOP2 exp
          {
          {
            $$ = new_exp_2 ($2, $1, $3);
            $$ = new_exp_2 ($2, $1, $3);
          }
          }
        | '!' exp
        | '!' exp
          {
          {
            $$ = new_exp_1 (lnot, $2);
            $$ = new_exp_1 (lnot, $2);
          }
          }
        | 'n'
        | 'n'
          {
          {
            $$ = new_exp_0 (var);
            $$ = new_exp_0 (var);
          }
          }
        | NUMBER
        | NUMBER
          {
          {
            if (($$ = new_exp_0 (num)) != NULL)
            if (($$ = new_exp_0 (num)) != NULL)
              $$->val.num = $1;
              $$->val.num = $1;
          }
          }
        | '(' exp ')'
        | '(' exp ')'
          {
          {
            $$ = $2;
            $$ = $2;
          }
          }
        ;
        ;
%%
%%
void
void
internal_function
internal_function
FREE_EXPRESSION (exp)
FREE_EXPRESSION (exp)
     struct expression *exp;
     struct expression *exp;
{
{
  if (exp == NULL)
  if (exp == NULL)
    return;
    return;
  /* Handle the recursive case.  */
  /* Handle the recursive case.  */
  switch (exp->nargs)
  switch (exp->nargs)
    {
    {
    case 3:
    case 3:
      FREE_EXPRESSION (exp->val.args[2]);
      FREE_EXPRESSION (exp->val.args[2]);
      /* FALLTHROUGH */
      /* FALLTHROUGH */
    case 2:
    case 2:
      FREE_EXPRESSION (exp->val.args[1]);
      FREE_EXPRESSION (exp->val.args[1]);
      /* FALLTHROUGH */
      /* FALLTHROUGH */
    case 1:
    case 1:
      FREE_EXPRESSION (exp->val.args[0]);
      FREE_EXPRESSION (exp->val.args[0]);
      /* FALLTHROUGH */
      /* FALLTHROUGH */
    default:
    default:
      break;
      break;
    }
    }
  free (exp);
  free (exp);
}
}
static int
static int
yylex (lval, pexp)
yylex (lval, pexp)
     YYSTYPE *lval;
     YYSTYPE *lval;
     const char **pexp;
     const char **pexp;
{
{
  const char *exp = *pexp;
  const char *exp = *pexp;
  int result;
  int result;
  while (1)
  while (1)
    {
    {
      if (exp[0] == '\0')
      if (exp[0] == '\0')
        {
        {
          *pexp = exp;
          *pexp = exp;
          return YYEOF;
          return YYEOF;
        }
        }
      if (exp[0] != ' ' && exp[0] != '\t')
      if (exp[0] != ' ' && exp[0] != '\t')
        break;
        break;
      ++exp;
      ++exp;
    }
    }
  result = *exp++;
  result = *exp++;
  switch (result)
  switch (result)
    {
    {
    case '0': case '1': case '2': case '3': case '4':
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
    case '5': case '6': case '7': case '8': case '9':
      {
      {
        unsigned long int n = result - '0';
        unsigned long int n = result - '0';
        while (exp[0] >= '0' && exp[0] <= '9')
        while (exp[0] >= '0' && exp[0] <= '9')
          {
          {
            n *= 10;
            n *= 10;
            n += exp[0] - '0';
            n += exp[0] - '0';
            ++exp;
            ++exp;
          }
          }
        lval->num = n;
        lval->num = n;
        result = NUMBER;
        result = NUMBER;
      }
      }
      break;
      break;
    case '=':
    case '=':
      if (exp[0] == '=')
      if (exp[0] == '=')
        {
        {
          ++exp;
          ++exp;
          lval->op = equal;
          lval->op = equal;
          result = EQUOP2;
          result = EQUOP2;
        }
        }
      else
      else
        result = YYERRCODE;
        result = YYERRCODE;
      break;
      break;
    case '!':
    case '!':
      if (exp[0] == '=')
      if (exp[0] == '=')
        {
        {
          ++exp;
          ++exp;
          lval->op = not_equal;
          lval->op = not_equal;
          result = EQUOP2;
          result = EQUOP2;
        }
        }
      break;
      break;
    case '&':
    case '&':
    case '|':
    case '|':
      if (exp[0] == result)
      if (exp[0] == result)
        ++exp;
        ++exp;
      else
      else
        result = YYERRCODE;
        result = YYERRCODE;
      break;
      break;
    case '<':
    case '<':
      if (exp[0] == '=')
      if (exp[0] == '=')
        {
        {
          ++exp;
          ++exp;
          lval->op = less_or_equal;
          lval->op = less_or_equal;
        }
        }
      else
      else
        lval->op = less_than;
        lval->op = less_than;
      result = CMPOP2;
      result = CMPOP2;
      break;
      break;
    case '>':
    case '>':
      if (exp[0] == '=')
      if (exp[0] == '=')
        {
        {
          ++exp;
          ++exp;
          lval->op = greater_or_equal;
          lval->op = greater_or_equal;
        }
        }
      else
      else
        lval->op = greater_than;
        lval->op = greater_than;
      result = CMPOP2;
      result = CMPOP2;
      break;
      break;
    case '*':
    case '*':
      lval->op = mult;
      lval->op = mult;
      result = MULOP2;
      result = MULOP2;
      break;
      break;
    case '/':
    case '/':
      lval->op = divide;
      lval->op = divide;
      result = MULOP2;
      result = MULOP2;
      break;
      break;
    case '%':
    case '%':
      lval->op = module;
      lval->op = module;
      result = MULOP2;
      result = MULOP2;
      break;
      break;
    case '+':
    case '+':
      lval->op = plus;
      lval->op = plus;
      result = ADDOP2;
      result = ADDOP2;
      break;
      break;
    case '-':
    case '-':
      lval->op = minus;
      lval->op = minus;
      result = ADDOP2;
      result = ADDOP2;
      break;
      break;
    case 'n':
    case 'n':
    case '?':
    case '?':
    case ':':
    case ':':
    case '(':
    case '(':
    case ')':
    case ')':
      /* Nothing, just return the character.  */
      /* Nothing, just return the character.  */
      break;
      break;
    case ';':
    case ';':
    case '\n':
    case '\n':
    case '\0':
    case '\0':
      /* Be safe and let the user call this function again.  */
      /* Be safe and let the user call this function again.  */
      --exp;
      --exp;
      result = YYEOF;
      result = YYEOF;
      break;
      break;
    default:
    default:
      result = YYERRCODE;
      result = YYERRCODE;
#if YYDEBUG != 0
#if YYDEBUG != 0
      --exp;
      --exp;
#endif
#endif
      break;
      break;
    }
    }
  *pexp = exp;
  *pexp = exp;
  return result;
  return result;
}
}
static void
static void
yyerror (str)
yyerror (str)
     const char *str;
     const char *str;
{
{
  /* Do nothing.  We don't print error messages here.  */
  /* Do nothing.  We don't print error messages here.  */
}
}
 
 

powered by: WebSVN 2.1.0

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