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

Generated on Sun Apr 18 23:33:47 2004 for Asterisk by doxygen 1.3.6-20040222