Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

ast_expr.c

Go to the documentation of this file.
00001 /* A Bison parser, made from ast_expr.y
00002    by GNU bison 1.35.  */
00003 
00004 #define YYBISON 1  /* Identify Bison output.  */
00005 
00006 #define yyparse ast_yyparse
00007 #define yylex ast_yylex
00008 #define yyerror ast_yyerror
00009 #define yylval ast_yylval
00010 #define yychar ast_yychar
00011 #define yydebug ast_yydebug
00012 #define yynerrs ast_yynerrs
00013 #define YYLSP_NEEDED 1
00014 
00015 # define GE 257
00016 # define LE 258
00017 # define NE 259
00018 # define TOKEN 260
00019 
00020 #line 1 "ast_expr.y"
00021 
00022 /* Written by Pace Willisson (pace@blitz.com) 
00023  * and placed in the public domain.
00024  *
00025  * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
00026  *
00027  * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
00028  */
00029 
00030 #include <sys/types.h>
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <locale.h>
00035 #include <ctype.h>
00036 #include <err.h>
00037 #include <errno.h>
00038 #include <regex.h>
00039 #include <limits.h>
00040 #include <asterisk/ast_expr.h>
00041 #include <asterisk/logger.h>
00042 
00043 #ifdef LONG_LONG_MIN
00044 #define QUAD_MIN LONG_LONG_MIN
00045 #endif
00046 #ifdef LONG_LONG_MAX
00047 #define QUAD_MAX LONG_LONG_MAX
00048 #endif
00049 
00050 #  if ! defined(QUAD_MIN)
00051 #   define QUAD_MIN     (-0x7fffffffffffffffL-1)
00052 #  endif
00053 #  if ! defined(QUAD_MAX)
00054 #   define QUAD_MAX     (0x7fffffffffffffffL)
00055 #  endif
00056 
00057 #define YYPARSE_PARAM kota
00058 #define YYLEX_PARAM kota
00059 
00060 /* #define ast_log fprintf
00061 #define LOG_WARNING stderr */
00062   
00063 enum valtype {
00064    integer, numeric_string, string
00065 } ;
00066 
00067 struct val {
00068    enum valtype type;
00069    union {
00070       char *s;
00071       quad_t i;
00072    } u;
00073 } ;
00074 
00075 struct parser_control {
00076    struct val *result;
00077    int pipa;
00078    char *arg_orig;
00079    char *argv;
00080    char *ptrptr;
00081    int firsttoken;
00082 } ;
00083 
00084 static int     chk_div __P((quad_t, quad_t));
00085 static int     chk_minus __P((quad_t, quad_t, quad_t));
00086 static int     chk_plus __P((quad_t, quad_t, quad_t));
00087 static int     chk_times __P((quad_t, quad_t, quad_t));
00088 static void    free_value __P((struct val *));
00089 static int     is_zero_or_null __P((struct val *));
00090 static int     isstring __P((struct val *));
00091 static struct val *make_integer __P((quad_t));
00092 static struct val *make_str __P((const char *));
00093 static struct val *op_and __P((struct val *, struct val *));
00094 static struct val *op_colon __P((struct val *, struct val *));
00095 static struct val *op_div __P((struct val *, struct val *));
00096 static struct val *op_eq __P((struct val *, struct val *));
00097 static struct val *op_ge __P((struct val *, struct val *));
00098 static struct val *op_gt __P((struct val *, struct val *));
00099 static struct val *op_le __P((struct val *, struct val *));
00100 static struct val *op_lt __P((struct val *, struct val *));
00101 static struct val *op_minus __P((struct val *, struct val *));
00102 static struct val *op_ne __P((struct val *, struct val *));
00103 static struct val *op_or __P((struct val *, struct val *));
00104 static struct val *op_plus __P((struct val *, struct val *));
00105 static struct val *op_rem __P((struct val *, struct val *));
00106 static struct val *op_times __P((struct val *, struct val *));
00107 static quad_t     to_integer __P((struct val *));
00108 static void    to_string __P((struct val *));
00109 
00110 /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
00111 typedef struct yyltype
00112 {
00113   int first_line;
00114   int first_column;
00115 
00116   int last_line;
00117   int last_column;
00118 } yyltype;
00119 
00120 # define YYLTYPE yyltype
00121 # define YYLTYPE_IS_TRIVIAL 1
00122 
00123 static int     ast_yyerror __P((const char *,YYLTYPE *, struct parser_control *));
00124 
00125 #define ast_yyerror(x) ast_yyerror(x,&yyloc,kota)
00126 
00127 
00128 #line 115 "ast_expr.y"
00129 #ifndef YYSTYPE
00130 typedef union
00131 {
00132    struct val *val;
00133 } yystype;
00134 # define YYSTYPE yystype
00135 # define YYSTYPE_IS_TRIVIAL 1
00136 #endif
00137 #line 120 "ast_expr.y"
00138 
00139 static int     ast_yylex __P((YYSTYPE *, YYLTYPE *, struct parser_control *));
00140 
00141 #ifndef YYLTYPE
00142 typedef struct yyltype
00143 {
00144   int first_line;
00145   int first_column;
00146 
00147   int last_line;
00148   int last_column;
00149 } yyltype;
00150 
00151 # define YYLTYPE yyltype
00152 # define YYLTYPE_IS_TRIVIAL 1
00153 #endif
00154 
00155 #ifndef YYDEBUG
00156 # define YYDEBUG 0
00157 #endif
00158 
00159 
00160 
00161 #define  YYFINAL     36
00162 #define  YYFLAG      -32768
00163 #define  YYNTBASE 20
00164 
00165 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
00166 #define YYTRANSLATE(x) ((unsigned)(x) <= 260 ? yytranslate[x] : 22)
00167 
00168 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
00169 static const char yytranslate[] =
00170 {
00171        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00172        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00173        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00174        2,     2,     2,     2,     2,     2,     2,    15,     4,     2,
00175       18,    19,    13,    11,     2,    12,     2,    14,     2,     2,
00176        2,     2,     2,     2,     2,     2,     2,     2,    16,     2,
00177        7,     5,     6,     2,     2,     2,     2,     2,     2,     2,
00178        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00179        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00180        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00181        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00182        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00183        2,     2,     2,     2,     3,     2,     2,     2,     2,     2,
00184        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00185        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00186        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00187        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00188        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00189        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00190        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00191        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00192        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00193        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00194        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00195        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00196        2,     2,     2,     2,     2,     2,     1,     8,     9,    10,
00197       17
00198 };
00199 
00200 #if YYDEBUG
00201 static const short yyprhs[] =
00202 {
00203        0,     0,     2,     4,     8,    12,    16,    20,    24,    28,
00204       32,    36,    40,    44,    48,    52,    56,    60
00205 };
00206 static const short yyrhs[] =
00207 {
00208       21,     0,    17,     0,    18,    21,    19,     0,    21,     3,
00209       21,     0,    21,     4,    21,     0,    21,     5,    21,     0,
00210       21,     6,    21,     0,    21,     7,    21,     0,    21,     8,
00211       21,     0,    21,     9,    21,     0,    21,    10,    21,     0,
00212       21,    11,    21,     0,    21,    12,    21,     0,    21,    13,
00213       21,     0,    21,    14,    21,     0,    21,    15,    21,     0,
00214       21,    16,    21,     0
00215 };
00216 
00217 #endif
00218 
00219 #if YYDEBUG
00220 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
00221 static const short yyrline[] =
00222 {
00223        0,   137,   140,   141,   142,   143,   144,   145,   146,   147,
00224      148,   149,   150,   151,   152,   153,   154,   155
00225 };
00226 #endif
00227 
00228 
00229 #if (YYDEBUG) || defined YYERROR_VERBOSE
00230 
00231 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
00232 static const char *const yytname[] =
00233 {
00234   "$", "error", "$undefined.", "'|'", "'&'", "'='", "'>'", "'<'", "GE", 
00235   "LE", "NE", "'+'", "'-'", "'*'", "'/'", "'%'", "':'", "TOKEN", "'('", 
00236   "')'", "start", "expr", 0
00237 };
00238 #endif
00239 
00240 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
00241 static const short yyr1[] =
00242 {
00243        0,    20,    21,    21,    21,    21,    21,    21,    21,    21,
00244       21,    21,    21,    21,    21,    21,    21,    21
00245 };
00246 
00247 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
00248 static const short yyr2[] =
00249 {
00250        0,     1,     1,     3,     3,     3,     3,     3,     3,     3,
00251        3,     3,     3,     3,     3,     3,     3,     3
00252 };
00253 
00254 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
00255    doesn't specify something else to do.  Zero means the default is an
00256    error. */
00257 static const short yydefact[] =
00258 {
00259        0,     2,     0,     1,     0,     0,     0,     0,     0,     0,
00260        0,     0,     0,     0,     0,     0,     0,     0,     0,     3,
00261        4,     5,     6,     7,     8,     9,    10,    11,    12,    13,
00262       14,    15,    16,    17,     0,     0,     0
00263 };
00264 
00265 static const short yydefgoto[] =
00266 {
00267       34,     3
00268 };
00269 
00270 static const short yypact[] =
00271 {
00272       64,-32768,    64,    28,    -3,    64,    64,    64,    64,    64,
00273       64,    64,    64,    64,    64,    64,    64,    64,    64,-32768,
00274       41,    53,    59,    59,    59,    59,    59,    59,    63,    63,
00275       -1,    -1,    -1,-32768,    80,    83,-32768
00276 };
00277 
00278 static const short yypgoto[] =
00279 {
00280   -32768,    12
00281 };
00282 
00283 
00284 #define  YYLAST      83
00285 
00286 
00287 static const short yytable[] =
00288 {
00289        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
00290       15,    16,    17,    18,     4,    18,    19,    20,    21,    22,
00291       23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
00292       33,     5,     6,     7,     8,     9,    10,    11,    12,    13,
00293       14,    15,    16,    17,    18,     6,     7,     8,     9,    10,
00294       11,    12,    13,    14,    15,    16,    17,    18,     7,     8,
00295        9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
00296       13,    14,    15,    16,    17,    18,    15,    16,    17,    18,
00297       35,     1,     2,    36
00298 };
00299 
00300 static const short yycheck[] =
00301 {
00302        3,     4,     5,     6,     7,     8,     9,    10,    11,    12,
00303       13,    14,    15,    16,     2,    16,    19,     5,     6,     7,
00304        8,     9,    10,    11,    12,    13,    14,    15,    16,    17,
00305       18,     3,     4,     5,     6,     7,     8,     9,    10,    11,
00306       12,    13,    14,    15,    16,     4,     5,     6,     7,     8,
00307        9,    10,    11,    12,    13,    14,    15,    16,     5,     6,
00308        7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
00309       11,    12,    13,    14,    15,    16,    13,    14,    15,    16,
00310        0,    17,    18,     0
00311 };
00312 #define YYPURE 1
00313 
00314 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
00315 #line 3 "/usr/share/bison/bison.simple"
00316 
00317 /* Skeleton output parser for bison,
00318 
00319    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
00320    Foundation, Inc.
00321 
00322    This program is free software; you can redistribute it and/or modify
00323    it under the terms of the GNU General Public License as published by
00324    the Free Software Foundation; either version 2, or (at your option)
00325    any later version.
00326 
00327    This program is distributed in the hope that it will be useful,
00328    but WITHOUT ANY WARRANTY; without even the implied warranty of
00329    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00330    GNU General Public License for more details.
00331 
00332    You should have received a copy of the GNU General Public License
00333    along with this program; if not, write to the Free Software
00334    Foundation, Inc., 59 Temple Place - Suite 330,
00335    Boston, MA 02111-1307, USA.  */
00336 
00337 /* As a special exception, when this file is copied by Bison into a
00338    Bison output file, you may use that output file without restriction.
00339    This special exception was added by the Free Software Foundation
00340    in version 1.24 of Bison.  */
00341 
00342 /* This is the parser code that is written into each bison parser when
00343    the %semantic_parser declaration is not specified in the grammar.
00344    It was written by Richard Stallman by simplifying the hairy parser
00345    used when %semantic_parser is specified.  */
00346 
00347 /* All symbols defined below should begin with yy or YY, to avoid
00348    infringing on user name space.  This should be done even for local
00349    variables, as they might otherwise be expanded by user macros.
00350    There are some unavoidable exceptions within include files to
00351    define necessary library symbols; they are noted "INFRINGES ON
00352    USER NAME SPACE" below.  */
00353 
00354 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
00355 
00356 /* The parser invokes alloca or malloc; define the necessary symbols.  */
00357 
00358 # if YYSTACK_USE_ALLOCA
00359 #  define YYSTACK_ALLOC alloca
00360 # else
00361 #  ifndef YYSTACK_USE_ALLOCA
00362 #   if defined (alloca) || defined (_ALLOCA_H)
00363 #    define YYSTACK_ALLOC alloca
00364 #   else
00365 #    ifdef __GNUC__
00366 #     define YYSTACK_ALLOC __builtin_alloca
00367 #    endif
00368 #   endif
00369 #  endif
00370 # endif
00371 
00372 # ifdef YYSTACK_ALLOC
00373    /* Pacify GCC's `empty if-body' warning. */
00374 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
00375 # else
00376 #  if defined (__STDC__) || defined (__cplusplus)
00377 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
00378 #   define YYSIZE_T size_t
00379 #  endif
00380 #  define YYSTACK_ALLOC malloc
00381 #  define YYSTACK_FREE free
00382 # endif
00383 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
00384 
00385 
00386 #if (! defined (yyoverflow) \
00387      && (! defined (__cplusplus) \
00388     || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
00389 
00390 /* A type that is properly aligned for any stack member.  */
00391 union yyalloc
00392 {
00393   short yyss;
00394   YYSTYPE yyvs;
00395 # if YYLSP_NEEDED
00396   YYLTYPE yyls;
00397 # endif
00398 };
00399 
00400 /* The size of the maximum gap between one aligned stack and the next.  */
00401 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
00402 
00403 /* The size of an array large to enough to hold all stacks, each with
00404    N elements.  */
00405 # if YYLSP_NEEDED
00406 #  define YYSTACK_BYTES(N) \
00407      ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))   \
00408       + 2 * YYSTACK_GAP_MAX)
00409 # else
00410 #  define YYSTACK_BYTES(N) \
00411      ((N) * (sizeof (short) + sizeof (YYSTYPE))          \
00412       + YYSTACK_GAP_MAX)
00413 # endif
00414 
00415 /* Copy COUNT objects from FROM to TO.  The source and destination do
00416    not overlap.  */
00417 # ifndef YYCOPY
00418 #  if 1 < __GNUC__
00419 #   define YYCOPY(To, From, Count) \
00420       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
00421 #  else
00422 #   define YYCOPY(To, From, Count)     \
00423       do             \
00424    {              \
00425      register YYSIZE_T yyi;      \
00426      for (yyi = 0; yyi < (Count); yyi++)  \
00427        (To)[yyi] = (From)[yyi];     \
00428    }              \
00429       while (0)
00430 #  endif
00431 # endif
00432 
00433 /* Relocate STACK from its old location to the new one.  The
00434    local variables YYSIZE and YYSTACKSIZE give the old and new number of
00435    elements in the stack, and YYPTR gives the new location of the
00436    stack.  Advance YYPTR to a properly aligned location for the next
00437    stack.  */
00438 # define YYSTACK_RELOCATE(Stack)             \
00439     do                           \
00440       {                          \
00441    YYSIZE_T yynewbytes;                \
00442    YYCOPY (&yyptr->Stack, Stack, yysize);          \
00443    Stack = &yyptr->Stack;                 \
00444    yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;  \
00445    yyptr += yynewbytes / sizeof (*yyptr);          \
00446       }                          \
00447     while (0)
00448 
00449 #endif
00450 
00451 
00452 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
00453 # define YYSIZE_T __SIZE_TYPE__
00454 #endif
00455 #if ! defined (YYSIZE_T) && defined (size_t)
00456 # define YYSIZE_T size_t
00457 #endif
00458 #if ! defined (YYSIZE_T)
00459 # if defined (__STDC__) || defined (__cplusplus)
00460 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
00461 #  define YYSIZE_T size_t
00462 # endif
00463 #endif
00464 #if ! defined (YYSIZE_T)
00465 # define YYSIZE_T unsigned int
00466 #endif
00467 
00468 #define yyerrok      (yyerrstatus = 0)
00469 #define yyclearin (yychar = YYEMPTY)
00470 #define YYEMPTY      -2
00471 #define YYEOF     0
00472 #define YYACCEPT  goto yyacceptlab
00473 #define YYABORT   goto yyabortlab
00474 #define YYERROR      goto yyerrlab1
00475 /* Like YYERROR except do call yyerror.  This remains here temporarily
00476    to ease the transition to the new meaning of YYERROR, for GCC.
00477    Once GCC version 2 has supplanted version 1, this can go.  */
00478 #define YYFAIL    goto yyerrlab
00479 #define YYRECOVERING()  (!!yyerrstatus)
00480 #define YYBACKUP(Token, Value)               \
00481 do                      \
00482   if (yychar == YYEMPTY && yylen == 1)          \
00483     {                      \
00484       yychar = (Token);                \
00485       yylval = (Value);                \
00486       yychar1 = YYTRANSLATE (yychar);           \
00487       YYPOPSTACK;                \
00488       goto yybackup;                \
00489     }                      \
00490   else                        \
00491     {                         \
00492       yyerror ("syntax error: cannot back up");       \
00493       YYERROR;                   \
00494     }                      \
00495 while (0)
00496 
00497 #define YYTERROR  1
00498 #define YYERRCODE 256
00499 
00500 
00501 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
00502    are run).
00503 
00504    When YYLLOC_DEFAULT is run, CURRENT is set the location of the
00505    first token.  By default, to implement support for ranges, extend
00506    its range to the last symbol.  */
00507 
00508 #ifndef YYLLOC_DEFAULT
00509 # define YYLLOC_DEFAULT(Current, Rhs, N)        \
00510    Current.last_line   = Rhs[N].last_line;   \
00511    Current.last_column = Rhs[N].last_column;
00512 #endif
00513 
00514 
00515 /* YYLEX -- calling `yylex' with the right arguments.  */
00516 
00517 #if YYPURE
00518 # if YYLSP_NEEDED
00519 #  ifdef YYLEX_PARAM
00520 #   define YYLEX     yylex (&yylval, &yylloc, YYLEX_PARAM)
00521 #  else
00522 #   define YYLEX     yylex (&yylval, &yylloc)
00523 #  endif
00524 # else /* !YYLSP_NEEDED */
00525 #  ifdef YYLEX_PARAM
00526 #   define YYLEX     yylex (&yylval, YYLEX_PARAM)
00527 #  else
00528 #   define YYLEX     yylex (&yylval)
00529 #  endif
00530 # endif /* !YYLSP_NEEDED */
00531 #else /* !YYPURE */
00532 # define YYLEX       yylex ()
00533 #endif /* !YYPURE */
00534 
00535 
00536 /* Enable debugging if requested.  */
00537 #if YYDEBUG
00538 
00539 # ifndef YYFPRINTF
00540 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
00541 #  define YYFPRINTF fprintf
00542 # endif
00543 
00544 # define YYDPRINTF(Args)         \
00545 do {                 \
00546   if (yydebug)             \
00547     YYFPRINTF Args;           \
00548 } while (0)
00549 /* Nonzero means print parse trace.  It is left uninitialized so that
00550    multiple parsers can coexist.  */
00551 int yydebug;
00552 #else /* !YYDEBUG */
00553 # define YYDPRINTF(Args)
00554 #endif /* !YYDEBUG */
00555 
00556 /* YYINITDEPTH -- initial size of the parser's stacks.  */
00557 #ifndef  YYINITDEPTH
00558 # define YYINITDEPTH 200
00559 #endif
00560 
00561 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
00562    if the built-in stack extension method is used).
00563 
00564    Do not make this value too large; the results are undefined if
00565    SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
00566    evaluated with infinite-precision integer arithmetic.  */
00567 
00568 #if YYMAXDEPTH == 0
00569 # undef YYMAXDEPTH
00570 #endif
00571 
00572 #ifndef YYMAXDEPTH
00573 # define YYMAXDEPTH 10000
00574 #endif
00575 
00576 #ifdef YYERROR_VERBOSE
00577 
00578 # ifndef yystrlen
00579 #  if defined (__GLIBC__) && defined (_STRING_H)
00580 #   define yystrlen strlen
00581 #  else
00582 /* Return the length of YYSTR.  */
00583 static YYSIZE_T
00584 #   if defined (__STDC__) || defined (__cplusplus)
00585 yystrlen (const char *yystr)
00586 #   else
00587 yystrlen (yystr)
00588      const char *yystr;
00589 #   endif
00590 {
00591   register const char *yys = yystr;
00592 
00593   while (*yys++ != '\0')
00594     continue;
00595 
00596   return yys - yystr - 1;
00597 }
00598 #  endif
00599 # endif
00600 
00601 # ifndef yystpcpy
00602 #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
00603 #   define yystpcpy stpcpy
00604 #  else
00605 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
00606    YYDEST.  */
00607 static char *
00608 #   if defined (__STDC__) || defined (__cplusplus)
00609 yystpcpy (char *yydest, const char *yysrc)
00610 #   else
00611 yystpcpy (yydest, yysrc)
00612      char *yydest;
00613      const char *yysrc;
00614 #   endif
00615 {
00616   register char *yyd = yydest;
00617   register const char *yys = yysrc;
00618 
00619   while ((*yyd++ = *yys++) != '\0')
00620     continue;
00621 
00622   return yyd - 1;
00623 }
00624 #  endif
00625 # endif
00626 #endif
00627 
00628 #line 315 "/usr/share/bison/bison.simple"
00629 
00630 
00631 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
00632    into yyparse.  The argument should have type void *.
00633    It should actually point to an object.
00634    Grammar actions can access the variable by casting it
00635    to the proper pointer type.  */
00636 
00637 #ifdef YYPARSE_PARAM
00638 # if defined (__STDC__) || defined (__cplusplus)
00639 #  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
00640 #  define YYPARSE_PARAM_DECL
00641 # else
00642 #  define YYPARSE_PARAM_ARG YYPARSE_PARAM
00643 #  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
00644 # endif
00645 #else /* !YYPARSE_PARAM */
00646 # define YYPARSE_PARAM_ARG
00647 # define YYPARSE_PARAM_DECL
00648 #endif /* !YYPARSE_PARAM */
00649 
00650 /* Prevent warning if -Wstrict-prototypes.  */
00651 #ifdef __GNUC__
00652 # ifdef YYPARSE_PARAM
00653 int yyparse (void *);
00654 # else
00655 int yyparse (void);
00656 # endif
00657 #endif
00658 
00659 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
00660    variables are global, or local to YYPARSE.  */
00661 
00662 #define YY_DECL_NON_LSP_VARIABLES         \
00663 /* The lookahead symbol.  */           \
00664 int yychar;                \
00665                      \
00666 /* The semantic value of the lookahead symbol. */  \
00667 YYSTYPE yylval;                  \
00668                      \
00669 /* Number of parse errors so far.  */        \
00670 int yynerrs;
00671 
00672 #if YYLSP_NEEDED
00673 # define YY_DECL_VARIABLES       \
00674 YY_DECL_NON_LSP_VARIABLES        \
00675                   \
00676 /* Location data for the lookahead symbol.  */  \
00677 YYLTYPE yylloc;
00678 #else
00679 # define YY_DECL_VARIABLES       \
00680 YY_DECL_NON_LSP_VARIABLES
00681 #endif
00682 
00683 
00684 /* If nonreentrant, generate the variables here. */
00685 
00686 #if !YYPURE
00687 YY_DECL_VARIABLES
00688 #endif  /* !YYPURE */
00689 
00690 int
00691 yyparse (YYPARSE_PARAM_ARG)
00692      YYPARSE_PARAM_DECL
00693 {
00694   /* If reentrant, generate the variables here. */
00695 #if YYPURE
00696   YY_DECL_VARIABLES
00697 #endif  /* !YYPURE */
00698 
00699   register int yystate;
00700   register int yyn;
00701   int yyresult;
00702   /* Number of tokens to shift before error messages enabled.  */
00703   int yyerrstatus;
00704   /* Lookahead token as an internal (translated) token number.  */
00705   int yychar1 = 0;
00706 
00707   /* Three stacks and their tools:
00708      `yyss': related to states,
00709      `yyvs': related to semantic values,
00710      `yyls': related to locations.
00711 
00712      Refer to the stacks thru separate pointers, to allow yyoverflow
00713      to reallocate them elsewhere.  */
00714 
00715   /* The state stack. */
00716   short  yyssa[YYINITDEPTH];
00717   short *yyss = yyssa;
00718   register short *yyssp;
00719 
00720   /* The semantic value stack.  */
00721   YYSTYPE yyvsa[YYINITDEPTH];
00722   YYSTYPE *yyvs = yyvsa;
00723   register YYSTYPE *yyvsp;
00724 
00725 #if YYLSP_NEEDED
00726   /* The location stack.  */
00727   YYLTYPE yylsa[YYINITDEPTH];
00728   YYLTYPE *yyls = yylsa;
00729   YYLTYPE *yylsp;
00730 #endif
00731 
00732 #if YYLSP_NEEDED
00733 # define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
00734 #else
00735 # define YYPOPSTACK   (yyvsp--, yyssp--)
00736 #endif
00737 
00738   YYSIZE_T yystacksize = YYINITDEPTH;
00739 
00740 
00741   /* The variables used to return semantic value and location from the
00742      action routines.  */
00743   YYSTYPE yyval;
00744 #if YYLSP_NEEDED
00745   YYLTYPE yyloc;
00746 #endif
00747 
00748   /* When reducing, the number of symbols on the RHS of the reduced
00749      rule. */
00750   int yylen;
00751 
00752   YYDPRINTF ((stderr, "Starting parse\n"));
00753 
00754   yystate = 0;
00755   yyerrstatus = 0;
00756   yynerrs = 0;
00757   yychar = YYEMPTY;     /* Cause a token to be read.  */
00758 
00759   /* Initialize stack pointers.
00760      Waste one element of value and location stack
00761      so that they stay on the same level as the state stack.
00762      The wasted elements are never initialized.  */
00763 
00764   yyssp = yyss;
00765   yyvsp = yyvs;
00766 #if YYLSP_NEEDED
00767   yylsp = yyls;
00768 #endif
00769   goto yysetstate;
00770 
00771 /*------------------------------------------------------------.
00772 | yynewstate -- Push a new state, which is found in yystate.  |
00773 `------------------------------------------------------------*/
00774  yynewstate:
00775   /* In all cases, when you get here, the value and location stacks
00776      have just been pushed. so pushing a state here evens the stacks.
00777      */
00778   yyssp++;
00779 
00780  yysetstate:
00781   *yyssp = yystate;
00782 
00783   if (yyssp >= yyss + yystacksize - 1)
00784     {
00785       /* Get the current used size of the three stacks, in elements.  */
00786       YYSIZE_T yysize = yyssp - yyss + 1;
00787 
00788 #ifdef yyoverflow
00789       {
00790    /* Give user a chance to reallocate the stack. Use copies of
00791       these so that the &'s don't force the real ones into
00792       memory.  */
00793    YYSTYPE *yyvs1 = yyvs;
00794    short *yyss1 = yyss;
00795 
00796    /* Each stack pointer address is followed by the size of the
00797       data in use in that stack, in bytes.  */
00798 # if YYLSP_NEEDED
00799    YYLTYPE *yyls1 = yyls;
00800    /* This used to be a conditional around just the two extra args,
00801       but that might be undefined if yyoverflow is a macro.  */
00802    yyoverflow ("parser stack overflow",
00803           &yyss1, yysize * sizeof (*yyssp),
00804           &yyvs1, yysize * sizeof (*yyvsp),
00805           &yyls1, yysize * sizeof (*yylsp),
00806           &yystacksize);
00807    yyls = yyls1;
00808 # else
00809    yyoverflow ("parser stack overflow",
00810           &yyss1, yysize * sizeof (*yyssp),
00811           &yyvs1, yysize * sizeof (*yyvsp),
00812           &yystacksize);
00813 # endif
00814    yyss = yyss1;
00815    yyvs = yyvs1;
00816       }
00817 #else /* no yyoverflow */
00818 # ifndef YYSTACK_RELOCATE
00819       goto yyoverflowlab;
00820 # else
00821       /* Extend the stack our own way.  */
00822       if (yystacksize >= YYMAXDEPTH)
00823    goto yyoverflowlab;
00824       yystacksize *= 2;
00825       if (yystacksize > YYMAXDEPTH)
00826    yystacksize = YYMAXDEPTH;
00827 
00828       {
00829    short *yyss1 = yyss;
00830    union yyalloc *yyptr =
00831      (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
00832    if (! yyptr)
00833      goto yyoverflowlab;
00834    YYSTACK_RELOCATE (yyss);
00835    YYSTACK_RELOCATE (yyvs);
00836 # if YYLSP_NEEDED
00837    YYSTACK_RELOCATE (yyls);
00838 # endif
00839 # undef YYSTACK_RELOCATE
00840    if (yyss1 != yyssa)
00841      YYSTACK_FREE (yyss1);
00842       }
00843 # endif
00844 #endif /* no yyoverflow */
00845 
00846       yyssp = yyss + yysize - 1;
00847       yyvsp = yyvs + yysize - 1;
00848 #if YYLSP_NEEDED
00849       yylsp = yyls + yysize - 1;
00850 #endif
00851 
00852       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
00853         (unsigned long int) yystacksize));
00854 
00855       if (yyssp >= yyss + yystacksize - 1)
00856    YYABORT;
00857     }
00858 
00859   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
00860 
00861   goto yybackup;
00862 
00863 
00864 /*-----------.
00865 | yybackup.  |
00866 `-----------*/
00867 yybackup:
00868 
00869 /* Do appropriate processing given the current state.  */
00870 /* Read a lookahead token if we need one and don't already have one.  */
00871 /* yyresume: */
00872 
00873   /* First try to decide what to do without reference to lookahead token.  */
00874 
00875   yyn = yypact[yystate];
00876   if (yyn == YYFLAG)
00877     goto yydefault;
00878 
00879   /* Not known => get a lookahead token if don't already have one.  */
00880 
00881   /* yychar is either YYEMPTY or YYEOF
00882      or a valid token in external form.  */
00883 
00884   if (yychar == YYEMPTY)
00885     {
00886       YYDPRINTF ((stderr, "Reading a token: "));
00887       yychar = YYLEX;
00888     }
00889 
00890   /* Convert token to internal form (in yychar1) for indexing tables with */
00891 
00892   if (yychar <= 0)      /* This means end of input. */
00893     {
00894       yychar1 = 0;
00895       yychar = YYEOF;      /* Don't call YYLEX any more */
00896 
00897       YYDPRINTF ((stderr, "Now at end of input.\n"));
00898     }
00899   else
00900     {
00901       yychar1 = YYTRANSLATE (yychar);
00902 
00903 #if YYDEBUG
00904      /* We have to keep this `#if YYDEBUG', since we use variables
00905    which are defined only if `YYDEBUG' is set.  */
00906       if (yydebug)
00907    {
00908      YYFPRINTF (stderr, "Next token is %d (%s",
00909            yychar, yytname[yychar1]);
00910      /* Give the individual parser a way to print the precise
00911         meaning of a token, for further debugging info.  */
00912 # ifdef YYPRINT
00913      YYPRINT (stderr, yychar, yylval);
00914 # endif
00915      YYFPRINTF (stderr, ")\n");
00916    }
00917 #endif
00918     }
00919 
00920   yyn += yychar1;
00921   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
00922     goto yydefault;
00923 
00924   yyn = yytable[yyn];
00925 
00926   /* yyn is what to do for this token type in this state.
00927      Negative => reduce, -yyn is rule number.
00928      Positive => shift, yyn is new state.
00929        New state is final state => don't bother to shift,
00930        just return success.
00931      0, or most negative number => error.  */
00932 
00933   if (yyn < 0)
00934     {
00935       if (yyn == YYFLAG)
00936    goto yyerrlab;
00937       yyn = -yyn;
00938       goto yyreduce;
00939     }
00940   else if (yyn == 0)
00941     goto yyerrlab;
00942 
00943   if (yyn == YYFINAL)
00944     YYACCEPT;
00945 
00946   /* Shift the lookahead token.  */
00947   YYDPRINTF ((stderr, "Shifting token %d (%s), ",
00948          yychar, yytname[yychar1]));
00949 
00950   /* Discard the token being shifted unless it is eof.  */
00951   if (yychar != YYEOF)
00952     yychar = YYEMPTY;
00953 
00954   *++yyvsp = yylval;
00955 #if YYLSP_NEEDED
00956   *++yylsp = yylloc;
00957 #endif
00958 
00959   /* Count tokens shifted since error; after three, turn off error
00960      status.  */
00961   if (yyerrstatus)
00962     yyerrstatus--;
00963 
00964   yystate = yyn;
00965   goto yynewstate;
00966 
00967 
00968 /*-----------------------------------------------------------.
00969 | yydefault -- do the default action for the current state.  |
00970 `-----------------------------------------------------------*/
00971 yydefault:
00972   yyn = yydefact[yystate];
00973   if (yyn == 0)
00974     goto yyerrlab;
00975   goto yyreduce;
00976 
00977 
00978 /*-----------------------------.
00979 | yyreduce -- Do a reduction.  |
00980 `-----------------------------*/
00981 yyreduce:
00982   /* yyn is the number of a rule to reduce with.  */
00983   yylen = yyr2[yyn];
00984 
00985   /* If YYLEN is nonzero, implement the default value of the action:
00986      `$$ = $1'.
00987 
00988      Otherwise, the following line sets YYVAL to the semantic value of
00989      the lookahead token.  This behavior is undocumented and Bison
00990      users should not rely upon it.  Assigning to YYVAL
00991      unconditionally makes the parser a bit smaller, and it avoids a
00992      GCC warning that YYVAL may be used uninitialized.  */
00993   yyval = yyvsp[1-yylen];
00994 
00995 #if YYLSP_NEEDED
00996   /* Similarly for the default location.  Let the user run additional
00997      commands if for instance locations are ranges.  */
00998   yyloc = yylsp[1-yylen];
00999   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
01000 #endif
01001 
01002 #if YYDEBUG
01003   /* We have to keep this `#if YYDEBUG', since we use variables which
01004      are defined only if `YYDEBUG' is set.  */
01005   if (yydebug)
01006     {
01007       int yyi;
01008 
01009       YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
01010        yyn, yyrline[yyn]);
01011 
01012       /* Print the symbols being reduced, and their result.  */
01013       for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
01014    YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
01015       YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
01016     }
01017 #endif
01018 
01019   switch (yyn) {
01020 
01021 case 1:
01022 #line 137 "ast_expr.y"
01023 { ((struct parser_control *)kota)->result = yyval.val; ;
01024     break;}
01025 case 3:
01026 #line 141 "ast_expr.y"
01027 { yyval.val = yyvsp[-1].val; yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01028     break;}
01029 case 4:
01030 #line 142 "ast_expr.y"
01031 { yyval.val = op_or (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01032     break;}
01033 case 5:
01034 #line 143 "ast_expr.y"
01035 { yyval.val = op_and (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01036     break;}
01037 case 6:
01038 #line 144 "ast_expr.y"
01039 { yyval.val = op_eq (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01040     break;}
01041 case 7:
01042 #line 145 "ast_expr.y"
01043 { yyval.val = op_gt (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01044     break;}
01045 case 8:
01046 #line 146 "ast_expr.y"
01047 { yyval.val = op_lt (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01048     break;}
01049 case 9:
01050 #line 147 "ast_expr.y"
01051 { yyval.val = op_ge (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01052     break;}
01053 case 10:
01054 #line 148 "ast_expr.y"
01055 { yyval.val = op_le (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01056     break;}
01057 case 11:
01058 #line 149 "ast_expr.y"
01059 { yyval.val = op_ne (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01060     break;}
01061 case 12:
01062 #line 150 "ast_expr.y"
01063 { yyval.val = op_plus (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01064     break;}
01065 case 13:
01066 #line 151 "ast_expr.y"
01067 { yyval.val = op_minus (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01068     break;}
01069 case 14:
01070 #line 152 "ast_expr.y"
01071 { yyval.val = op_times (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01072     break;}
01073 case 15:
01074 #line 153 "ast_expr.y"
01075 { yyval.val = op_div (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01076     break;}
01077 case 16:
01078 #line 154 "ast_expr.y"
01079 { yyval.val = op_rem (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01080     break;}
01081 case 17:
01082 #line 155 "ast_expr.y"
01083 { yyval.val = op_colon (yyvsp[-2].val, yyvsp[0].val); yyloc.first_column = yylsp[-2].first_column; yyloc.last_column = yylsp[0].last_column; yyloc.first_line=0; yyloc.last_line=0;;
01084     break;}
01085 }
01086 
01087 #line 705 "/usr/share/bison/bison.simple"
01088 
01089 
01090   yyvsp -= yylen;
01091   yyssp -= yylen;
01092 #if YYLSP_NEEDED
01093   yylsp -= yylen;
01094 #endif
01095 
01096 #if YYDEBUG
01097   if (yydebug)
01098     {
01099       short *yyssp1 = yyss - 1;
01100       YYFPRINTF (stderr, "state stack now");
01101       while (yyssp1 != yyssp)
01102    YYFPRINTF (stderr, " %d", *++yyssp1);
01103       YYFPRINTF (stderr, "\n");
01104     }
01105 #endif
01106 
01107   *++yyvsp = yyval;
01108 #if YYLSP_NEEDED
01109   *++yylsp = yyloc;
01110 #endif
01111 
01112   /* Now `shift' the result of the reduction.  Determine what state
01113      that goes to, based on the state we popped back to and the rule
01114      number reduced by.  */
01115 
01116   yyn = yyr1[yyn];
01117 
01118   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
01119   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
01120     yystate = yytable[yystate];
01121   else
01122     yystate = yydefgoto[yyn - YYNTBASE];
01123 
01124   goto yynewstate;
01125 
01126 
01127 /*------------------------------------.
01128 | yyerrlab -- here on detecting error |
01129 `------------------------------------*/
01130 yyerrlab:
01131   /* If not already recovering from an error, report this error.  */
01132   if (!yyerrstatus)
01133     {
01134       ++yynerrs;
01135 
01136 #ifdef YYERROR_VERBOSE
01137       yyn = yypact[yystate];
01138 
01139       if (yyn > YYFLAG && yyn < YYLAST)
01140    {
01141      YYSIZE_T yysize = 0;
01142      char *yymsg;
01143      int yyx, yycount;
01144 
01145      yycount = 0;
01146      /* Start YYX at -YYN if negative to avoid negative indexes in
01147         YYCHECK.  */
01148      for (yyx = yyn < 0 ? -yyn : 0;
01149           yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
01150        if (yycheck[yyx + yyn] == yyx)
01151          yysize += yystrlen (yytname[yyx]) + 15, yycount++;
01152      yysize += yystrlen ("parse error, unexpected ") + 1;
01153      yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
01154      yymsg = (char *) YYSTACK_ALLOC (yysize);
01155      if (yymsg != 0)
01156        {
01157          char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
01158          yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
01159 
01160          if (yycount < 5)
01161       {
01162         yycount = 0;
01163         for (yyx = yyn < 0 ? -yyn : 0;
01164              yyx < (int) (sizeof (yytname) / sizeof (char *));
01165              yyx++)
01166           if (yycheck[yyx + yyn] == yyx)
01167             {
01168          const char *yyq = ! yycount ? ", expecting " : " or ";
01169          yyp = yystpcpy (yyp, yyq);
01170          yyp = yystpcpy (yyp, yytname[yyx]);
01171          yycount++;
01172             }
01173       }
01174          yyerror (yymsg);
01175          YYSTACK_FREE (yymsg);
01176        }
01177      else
01178        yyerror ("parse error; also virtual memory exhausted");
01179    }
01180       else
01181 #endif /* defined (YYERROR_VERBOSE) */
01182    yyerror ("parse error");
01183     }
01184   goto yyerrlab1;
01185 
01186 
01187 /*--------------------------------------------------.
01188 | yyerrlab1 -- error raised explicitly by an action |
01189 `--------------------------------------------------*/
01190 yyerrlab1:
01191   if (yyerrstatus == 3)
01192     {
01193       /* If just tried and failed to reuse lookahead token after an
01194     error, discard it.  */
01195 
01196       /* return failure if at end of input */
01197       if (yychar == YYEOF)
01198    YYABORT;
01199       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
01200         yychar, yytname[yychar1]));
01201       yychar = YYEMPTY;
01202     }
01203 
01204   /* Else will try to reuse lookahead token after shifting the error
01205      token.  */
01206 
01207   yyerrstatus = 3;      /* Each real token shifted decrements this */
01208 
01209   goto yyerrhandle;
01210 
01211 
01212 /*-------------------------------------------------------------------.
01213 | yyerrdefault -- current state does not do anything special for the |
01214 | error token.                                                       |
01215 `-------------------------------------------------------------------*/
01216 yyerrdefault:
01217 #if 0
01218   /* This is wrong; only states that explicitly want error tokens
01219      should shift them.  */
01220 
01221   /* If its default is to accept any token, ok.  Otherwise pop it.  */
01222   yyn = yydefact[yystate];
01223   if (yyn)
01224     goto yydefault;
01225 #endif
01226 
01227 
01228 /*---------------------------------------------------------------.
01229 | yyerrpop -- pop the current state because it cannot handle the |
01230 | error token                                                    |
01231 `---------------------------------------------------------------*/
01232 yyerrpop:
01233   if (yyssp == yyss)
01234     YYABORT;
01235   yyvsp--;
01236   yystate = *--yyssp;
01237 #if YYLSP_NEEDED
01238   yylsp--;
01239 #endif
01240 
01241 #if YYDEBUG
01242   if (yydebug)
01243     {
01244       short *yyssp1 = yyss - 1;
01245       YYFPRINTF (stderr, "Error: state stack now");
01246       while (yyssp1 != yyssp)
01247    YYFPRINTF (stderr, " %d", *++yyssp1);
01248       YYFPRINTF (stderr, "\n");
01249     }
01250 #endif
01251 
01252 /*--------------.
01253 | yyerrhandle.  |
01254 `--------------*/
01255 yyerrhandle:
01256   yyn = yypact[yystate];
01257   if (yyn == YYFLAG)
01258     goto yyerrdefault;
01259 
01260   yyn += YYTERROR;
01261   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
01262     goto yyerrdefault;
01263 
01264   yyn = yytable[yyn];
01265   if (yyn < 0)
01266     {
01267       if (yyn == YYFLAG)
01268    goto yyerrpop;
01269       yyn = -yyn;
01270       goto yyreduce;
01271     }
01272   else if (yyn == 0)
01273     goto yyerrpop;
01274 
01275   if (yyn == YYFINAL)
01276     YYACCEPT;
01277 
01278   YYDPRINTF ((stderr, "Shifting error token, "));
01279 
01280   *++yyvsp = yylval;
01281 #if YYLSP_NEEDED
01282   *++yylsp = yylloc;
01283 #endif
01284 
01285   yystate = yyn;
01286   goto yynewstate;
01287 
01288 
01289 /*-------------------------------------.
01290 | yyacceptlab -- YYACCEPT comes here.  |
01291 `-------------------------------------*/
01292 yyacceptlab:
01293   yyresult = 0;
01294   goto yyreturn;
01295 
01296 /*-----------------------------------.
01297 | yyabortlab -- YYABORT comes here.  |
01298 `-----------------------------------*/
01299 yyabortlab:
01300   yyresult = 1;
01301   goto yyreturn;
01302 
01303 /*---------------------------------------------.
01304 | yyoverflowab -- parser overflow comes here.  |
01305 `---------------------------------------------*/
01306 yyoverflowlab:
01307   yyerror ("parser stack overflow");
01308   yyresult = 2;
01309   /* Fall through.  */
01310 
01311 yyreturn:
01312 #ifndef yyoverflow
01313   if (yyss != yyssa)
01314     YYSTACK_FREE (yyss);
01315 #endif
01316   return yyresult;
01317 }
01318 #line 159 "ast_expr.y"
01319 
01320 
01321 static struct val *
01322 make_integer (i)
01323 quad_t i;
01324 {
01325    struct val *vp;
01326 
01327    vp = (struct val *) malloc (sizeof (*vp));
01328    if (vp == NULL) {
01329       ast_log(LOG_WARNING, "malloc() failed\n");
01330       return(NULL);
01331    }
01332 
01333    vp->type = integer;
01334    vp->u.i  = i;
01335    return vp; 
01336 }
01337 
01338 static struct val *
01339 make_str (s)
01340 const char *s;
01341 {
01342    struct val *vp;
01343    size_t i;
01344    int isint;
01345 
01346    vp = (struct val *) malloc (sizeof (*vp));
01347    if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
01348       ast_log(LOG_WARNING,"malloc() failed\n");
01349       return(NULL);
01350    }
01351 
01352    for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
01353        isint && i < strlen(s);
01354        i++)
01355    {
01356       if(!isdigit(s[i]))
01357           isint = 0;
01358    }
01359 
01360    if (isint)
01361       vp->type = numeric_string;
01362    else  
01363       vp->type = string;
01364 
01365    return vp;
01366 }
01367 
01368 
01369 static void
01370 free_value (vp)
01371 struct val *vp;
01372 {  
01373    if (vp==NULL) {
01374       return;
01375    }
01376    if (vp->type == string || vp->type == numeric_string)
01377       free (vp->u.s);   
01378 }
01379 
01380 
01381 static quad_t
01382 to_integer (vp)
01383 struct val *vp;
01384 {
01385    quad_t i;
01386 
01387    if (vp == NULL) {
01388       ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
01389       return(0);
01390    }
01391 
01392    if (vp->type == integer)
01393       return 1;
01394 
01395    if (vp->type == string)
01396       return 0;
01397 
01398    /* vp->type == numeric_string, make it numeric */
01399    errno = 0;
01400    i  = strtoq(vp->u.s, (char**)NULL, 10);
01401    if (errno != 0) {
01402       free(vp->u.s);
01403       ast_log(LOG_WARNING,"overflow\n");
01404       return(0);
01405    }
01406    free (vp->u.s);
01407    vp->u.i = i;
01408    vp->type = integer;
01409    return 1;
01410 }
01411 
01412 static void
01413 to_string (vp)
01414 struct val *vp;
01415 {
01416    char *tmp;
01417 
01418    if (vp->type == string || vp->type == numeric_string)
01419       return;
01420 
01421    tmp = malloc ((size_t)25);
01422    if (tmp == NULL) {
01423       ast_log(LOG_WARNING,"malloc() failed\n");
01424       return;
01425    }
01426 
01427    sprintf (tmp, "%lld", (long long)vp->u.i);
01428    vp->type = string;
01429    vp->u.s  = tmp;
01430 }
01431 
01432 
01433 static int
01434 isstring (vp)
01435 struct val *vp;
01436 {
01437    /* only TRUE if this string is not a valid integer */
01438    return (vp->type == string);
01439 }
01440 
01441 static int
01442 ast_yylex (YYSTYPE *lvalp, YYLTYPE *yylloc, struct parser_control *karoto)
01443 {
01444    char *p=0;
01445    char *t1=0;
01446    char savep = 0;
01447    char *savepp = 0;
01448    
01449    if (karoto->firsttoken==1) {
01450       t1 = karoto->argv;
01451       karoto->firsttoken = 0;
01452    } else {
01453       t1 = karoto->ptrptr;
01454    }
01455    
01456    while(*t1 && *t1 == ' ' )  /* we can remove worries about leading/multiple spaces being present */
01457       t1++;
01458    karoto->ptrptr = t1;
01459    yylloc->first_column = t1 - karoto->argv;
01460    
01461    while( *t1 && *t1 != ' ' && *t1 != '"') /* find the next space or quote */
01462       t1++;
01463    if( *t1 == ' ' )
01464    {
01465       *t1 = 0;
01466       p = karoto->ptrptr;
01467       karoto->ptrptr = t1+1;
01468       yylloc->last_column = t1 - karoto->argv;
01469    }
01470    else if (*t1 == '"' )
01471    {
01472       /* opening quote. find the closing quote */
01473       char *t2=t1+1;
01474       while( *t2 && *t2 != '"')
01475          t2++;
01476       if( *t2 == '"' )
01477       {
01478          if( *(t2+1) == ' ' || *(t2+1) == 0 )
01479          {
01480             if( *(t2+1) )
01481             {
01482                *(t2+1) = 0;
01483                karoto->ptrptr = t2+2;
01484             }
01485             else
01486             {
01487                karoto->ptrptr = t2+1;
01488             }
01489          }
01490          else
01491          {
01492             /* hmmm. what if another token is here? */
01493             /* maybe we can insert a space? */
01494             savep = *(t2+1);
01495             savepp = t2+1;
01496             *(t2+1) = 0;
01497             karoto->ptrptr = t2+1;
01498          }
01499          p = t1;
01500       }
01501       else
01502       {
01503          /* NOT GOOD -- no closing quote! */
01504          p = t1;
01505          karoto->ptrptr = t2;
01506       }
01507       yylloc->last_column = t2 - karoto->argv;
01508    }
01509    else if( *t1 == 0 )
01510    {
01511       if( t1 != karoto->ptrptr )
01512       {
01513          /* this is the last token */
01514          p = karoto->ptrptr;
01515          karoto->ptrptr = t1;
01516       }
01517       else
01518       {
01519          /* we are done. That was quick */
01520          p = karoto->ptrptr;
01521          yylloc->last_column = t1 - karoto->argv;
01522       }
01523    }
01524    if( *p == 0 )
01525       p = 0;
01526    
01527    if (p==NULL) {
01528       return (0);
01529    }
01530 
01531 
01532    if (strlen (p) == 1) {
01533       if (strchr ("|&=<>+-*/%:()", *p))
01534          return (*p);
01535    } else if (strlen (p) == 2 && p[1] == '=') {
01536       switch (*p) {
01537       case '>': return (GE);
01538       case '<': return (LE);
01539       case '!': return (NE);
01540       }
01541    }
01542 
01543    lvalp->val = make_str (p);
01544    if( savep )
01545    {
01546       *savepp = savep; /* restore the null terminated string */
01547       savepp = 0;
01548       savep = 0;
01549    }
01550    return (TOKEN);
01551 }
01552 
01553 static int
01554 is_zero_or_null (vp)
01555 struct val *vp;
01556 {
01557    if (vp->type == integer) {
01558       return (vp->u.i == 0);
01559    } else {
01560       return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
01561    }
01562    /* NOTREACHED */
01563 }
01564 
01565 char *ast_expr (char *arg)
01566 {
01567    struct parser_control karoto;
01568 
01569    char *kota;
01570    char *pirouni;
01571    
01572    kota=strdup(arg);
01573    karoto.result = NULL;
01574    karoto.firsttoken=1;
01575    karoto.argv=kota;
01576    karoto.arg_orig = arg;
01577    /* ast_yydebug = 1; */
01578    
01579    ast_yyparse ((void *)&karoto);
01580 
01581    free(kota);
01582 
01583    if (karoto.result==NULL) {
01584       pirouni=strdup("0");
01585       return(pirouni);
01586    } else {
01587       if (karoto.result->type == integer) {
01588          pirouni=malloc(256);
01589          sprintf (pirouni,"%lld", (long long)karoto.result->u.i);
01590       }
01591       else {
01592          pirouni=strdup(karoto.result->u.s);
01593       }
01594       free(karoto.result);
01595    }
01596    return(pirouni);
01597 }
01598 
01599 #ifdef STANDALONE
01600 
01601 int main(int argc,char **argv) {
01602    char *s;
01603 
01604    s=ast_expr(argv[1]);
01605 
01606    printf("=====%s======\n",s);
01607 }
01608 
01609 #endif
01610 
01611 #undef ast_yyerror
01612 #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parser_control *karoto)
01613 
01614 static int
01615 ast_yyerror (const char *s)
01616 {  
01617    char spacebuf[8000]; /* best safe than sorry */
01618    char spacebuf2[8000]; /* best safe than sorry */
01619    int i=0;
01620    spacebuf[0] = 0;
01621    
01622    if( yylloc->first_column > 7990 ) /* if things get out of whack, why crash? */
01623       yylloc->first_column = 7990;
01624    if( yylloc->last_column > 7990 )
01625       yylloc->last_column = 7990;
01626    for(i=0;i<yylloc->first_column;i++) spacebuf[i] = ' ';
01627    for(   ;i<yylloc->last_column;i++) spacebuf[i] = '^';
01628    spacebuf[i] = 0;
01629 
01630    for(i=0;i<karoto->ptrptr-karoto->argv;i++) spacebuf2[i] = ' ';
01631    spacebuf2[i++]='^';
01632    spacebuf2[i]= 0;
01633 
01634    ast_log(LOG_WARNING,"ast_yyerror(): syntax error: %s; Input:\n%s\n%s\n%s\n",s, 
01635          karoto->arg_orig,spacebuf,spacebuf2);
01636    return(0);
01637 }
01638 
01639 
01640 static struct val *
01641 op_or (a, b)
01642 struct val *a, *b;
01643 {
01644    if (is_zero_or_null (a)) {
01645       free_value (a);
01646       return (b);
01647    } else {
01648       free_value (b);
01649       return (a);
01650    }
01651 }
01652       
01653 static struct val *
01654 op_and (a, b)
01655 struct val *a, *b;
01656 {
01657    if (is_zero_or_null (a) || is_zero_or_null (b)) {
01658       free_value (a);
01659       free_value (b);
01660       return (make_integer ((quad_t)0));
01661    } else {
01662       free_value (b);
01663       return (a);
01664    }
01665 }
01666 
01667 static struct val *
01668 op_eq (a, b)
01669 struct val *a, *b;
01670 {
01671    struct val *r; 
01672 
01673    if (isstring (a) || isstring (b)) {
01674       to_string (a);
01675       to_string (b); 
01676       r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
01677    } else {
01678       (void)to_integer(a);
01679       (void)to_integer(b);
01680       r = make_integer ((quad_t)(a->u.i == b->u.i));
01681    }
01682 
01683    free_value (a);
01684    free_value (b);
01685    return r;
01686 }
01687 
01688 static struct val *
01689 op_gt (a, b)
01690 struct val *a, *b;
01691 {
01692    struct val *r;
01693 
01694    if (isstring (a) || isstring (b)) {
01695       to_string (a);
01696       to_string (b);
01697       r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
01698    } else {
01699       (void)to_integer(a);
01700       (void)to_integer(b);
01701       r = make_integer ((quad_t)(a->u.i > b->u.i));
01702    }
01703 
01704    free_value (a);
01705    free_value (b);
01706    return r;
01707 }
01708 
01709 static struct val *
01710 op_lt (a, b)
01711 struct val *a, *b;
01712 {
01713    struct val *r;
01714 
01715    if (isstring (a) || isstring (b)) {
01716       to_string (a);
01717       to_string (b);
01718       r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
01719    } else {
01720       (void)to_integer(a);
01721       (void)to_integer(b);
01722       r = make_integer ((quad_t)(a->u.i < b->u.i));
01723    }
01724 
01725    free_value (a);
01726    free_value (b);
01727    return r;
01728 }
01729 
01730 static struct val *
01731 op_ge (a, b)
01732 struct val *a, *b;
01733 {
01734    struct val *r;
01735 
01736    if (isstring (a) || isstring (b)) {
01737       to_string (a);
01738       to_string (b);
01739       r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
01740    } else {
01741       (void)to_integer(a);
01742       (void)to_integer(b);
01743       r = make_integer ((quad_t)(a->u.i >= b->u.i));
01744    }
01745 
01746    free_value (a);
01747    free_value (b);
01748    return r;
01749 }
01750 
01751 static struct val *
01752 op_le (a, b)
01753 struct val *a, *b;
01754 {
01755    struct val *r;
01756 
01757    if (isstring (a) || isstring (b)) {
01758       to_string (a);
01759       to_string (b);
01760       r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
01761    } else {
01762       (void)to_integer(a);
01763       (void)to_integer(b);
01764       r = make_integer ((quad_t)(a->u.i <= b->u.i));
01765    }
01766 
01767    free_value (a);
01768    free_value (b);
01769    return r;
01770 }
01771 
01772 static struct val *
01773 op_ne (a, b)
01774 struct val *a, *b;
01775 {
01776    struct val *r;
01777 
01778    if (isstring (a) || isstring (b)) {
01779       to_string (a);
01780       to_string (b);
01781       r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
01782    } else {
01783       (void)to_integer(a);
01784       (void)to_integer(b);
01785       r = make_integer ((quad_t)(a->u.i != b->u.i));
01786    }
01787 
01788    free_value (a);
01789    free_value (b);
01790    return r;
01791 }
01792 
01793 static int
01794 chk_plus (a, b, r)
01795 quad_t a, b, r;
01796 {
01797    /* sum of two positive numbers must be positive */
01798    if (a > 0 && b > 0 && r <= 0)
01799       return 1;
01800    /* sum of two negative numbers must be negative */
01801    if (a < 0 && b < 0 && r >= 0)
01802       return 1;
01803    /* all other cases are OK */
01804    return 0;
01805 }
01806 
01807 static struct val *
01808 op_plus (a, b)
01809 struct val *a, *b;
01810 {
01811    struct val *r;
01812 
01813    if (!to_integer (a) || !to_integer (b)) {
01814       ast_log(LOG_WARNING,"non-numeric argument\n");
01815       free_value(a);
01816       free_value(b);
01817       return(NULL);
01818    }
01819 
01820    r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
01821    if (chk_plus (a->u.i, b->u.i, r->u.i)) {
01822       ast_log(LOG_WARNING,"overflow\n");
01823       free_value(a);
01824       free_value(b);
01825       return(NULL);
01826    }
01827    free_value (a);
01828    free_value (b);
01829    return r;
01830 }
01831 
01832 static int
01833 chk_minus (a, b, r)
01834 quad_t a, b, r;
01835 {
01836    /* special case subtraction of QUAD_MIN */
01837    if (b == QUAD_MIN) {
01838       if (a >= 0)
01839          return 1;
01840       else
01841          return 0;
01842    }
01843    /* this is allowed for b != QUAD_MIN */
01844    return chk_plus (a, -b, r);
01845 }
01846 
01847 static struct val *
01848 op_minus (a, b)
01849 struct val *a, *b;
01850 {
01851    struct val *r;
01852 
01853    if (!to_integer (a) || !to_integer (b)) {
01854       free_value(a);
01855       free_value(b);
01856       ast_log(LOG_WARNING, "non-numeric argument\n");
01857       return(NULL);
01858    }
01859 
01860    r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
01861    if (chk_minus (a->u.i, b->u.i, r->u.i)) {
01862       free_value(a);
01863       free_value(b);
01864       ast_log(LOG_WARNING, "overload\n");
01865       return(NULL);
01866    }
01867    free_value (a);
01868    free_value (b);
01869    return r;
01870 }
01871 
01872 static int
01873 chk_times (a, b, r)
01874 quad_t a, b, r;
01875 {
01876    /* special case: first operand is 0, no overflow possible */
01877    if (a == 0)
01878       return 0;
01879    /* cerify that result of division matches second operand */
01880    if (r / a != b)
01881       return 1;
01882    return 0;
01883 }
01884 
01885 static struct val *
01886 op_times (a, b)
01887 struct val *a, *b;
01888 {
01889    struct val *r;
01890 
01891    if (!to_integer (a) || !to_integer (b)) {
01892       free_value(a);
01893       free_value(b);
01894       ast_log(LOG_WARNING, "non-numeric argument\n");
01895       return(NULL);
01896    }
01897 
01898    r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
01899    if (chk_times (a->u.i, b->u.i, r->u.i)) {
01900       ast_log(LOG_WARNING, "overflow\n");
01901       free_value(a);
01902       free_value(b);
01903       return(NULL);
01904    }
01905    free_value (a);
01906    free_value (b);
01907    return (r);
01908 }
01909 
01910 static int
01911 chk_div (a, b)
01912 quad_t a, b;
01913 {
01914    /* div by zero has been taken care of before */
01915    /* only QUAD_MIN / -1 causes overflow */
01916    if (a == QUAD_MIN && b == -1)
01917       return 1;
01918    /* everything else is OK */
01919    return 0;
01920 }
01921 
01922 static struct val *
01923 op_div (a, b)
01924 struct val *a, *b;
01925 {
01926    struct val *r;
01927 
01928    if (!to_integer (a) || !to_integer (b)) {
01929       free_value(a);
01930       free_value(b);
01931       ast_log(LOG_WARNING, "non-numeric argument\n");
01932       return(NULL);
01933    }
01934 
01935    if (b->u.i == 0) {
01936       ast_log(LOG_WARNING, "division by zero\n");     
01937       free_value(a);
01938       free_value(b);
01939       return(NULL);
01940    }
01941 
01942    r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
01943    if (chk_div (a->u.i, b->u.i)) {
01944       ast_log(LOG_WARNING, "overflow\n");
01945       free_value(a);
01946       free_value(b);
01947       return(NULL);
01948    }
01949    free_value (a);
01950    free_value (b);
01951    return r;
01952 }
01953    
01954 static struct val *
01955 op_rem (a, b)
01956 struct val *a, *b;
01957 {
01958    struct val *r;
01959 
01960    if (!to_integer (a) || !to_integer (b)) {
01961       ast_log(LOG_WARNING, "non-numeric argument\n");
01962       free_value(a);
01963       free_value(b);
01964       return(NULL);
01965    }
01966 
01967    if (b->u.i == 0) {
01968       ast_log(LOG_WARNING, "div by zero\n");
01969       free_value(a);
01970       free_value(b);
01971       return(NULL);
01972    }
01973 
01974    r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
01975    /* chk_rem necessary ??? */
01976    free_value (a);
01977    free_value (b);
01978    return r;
01979 }
01980    
01981 static struct val *
01982 op_colon (a, b)
01983 struct val *a, *b;
01984 {
01985    regex_t rp;
01986    regmatch_t rm[2];
01987    char errbuf[256];
01988    int eval;
01989    struct val *v;
01990 
01991    /* coerce to both arguments to strings */
01992    to_string(a);
01993    to_string(b);
01994 
01995    /* compile regular expression */
01996    if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
01997       regerror (eval, &rp, errbuf, sizeof(errbuf));
01998       ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
01999       free_value(a);
02000       free_value(b);
02001       return(NULL);     
02002    }
02003 
02004    /* compare string against pattern */
02005    /* remember that patterns are anchored to the beginning of the line */
02006    if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
02007       if (rm[1].rm_so >= 0) {
02008          *(a->u.s + rm[1].rm_eo) = '\0';
02009          v = make_str (a->u.s + rm[1].rm_so);
02010 
02011       } else {
02012          v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
02013       }
02014    } else {
02015       if (rp.re_nsub == 0) {
02016          v = make_integer ((quad_t)0);
02017       } else {
02018          v = make_str ("");
02019       }
02020    }
02021 
02022    /* free arguments and pattern buffer */
02023    free_value (a);
02024    free_value (b);
02025    regfree (&rp);
02026 
02027    return v;
02028 }

Generated on Thu Oct 28 11:32:52 2004 for Asterisk by doxygen1.2.15