fol.cpp

00001 /* A Bison parser, made by GNU Bison 2.3.  */
00002 
00003 /* Skeleton implementation for Bison GLR parsers in C
00004 
00005    Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.  */
00021 
00022 /* As a special exception, you may create a larger work that contains
00023    part or all of the Bison parser skeleton and distribute that work
00024    under terms of your choice, so long as that work isn't itself a
00025    parser generator using the skeleton or a modified version thereof
00026    as a parser skeleton.  Alternatively, if you modify or redistribute
00027    the parser skeleton itself, you may (at your option) remove this
00028    special exception, which will cause the skeleton and the resulting
00029    Bison output files to be licensed under the GNU General Public
00030    License without this special exception.
00031 
00032    This special exception was added by the Free Software Foundation in
00033    version 2.2 of Bison.  */
00034 
00035 /* C GLR parser skeleton written by Paul Hilfinger.  */
00036 
00037 /* Identify Bison output.  */
00038 #define YYBISON 1
00039 
00040 /* Bison version.  */
00041 #define YYBISON_VERSION "2.3"
00042 
00043 /* Skeleton name.  */
00044 #define YYSKELETON_NAME "glr.c"
00045 
00046 /* Pure parsers.  */
00047 #define YYPURE 0
00048 
00049 /* Using locations.  */
00050 #define YYLSP_NEEDED 0
00051 
00052 
00053 
00054 
00055 
00056 
00057 /* Tokens.  */
00058 #ifndef YYTOKENTYPE
00059 # define YYTOKENTYPE
00060    /* Put the tokens into the symbol table, so that GDB and other debuggers
00061       know about them.  */
00062    enum yytokentype {
00063      ZZ_NUM = 258,
00064      ZZ_DOTDOTDOT = 259,
00065      ZZ_STRING = 260,
00066      ZZ_INCLUDE = 261,
00067      ZZ_PREDICATE = 262,
00068      ZZ_FUNCTION = 263,
00069      ZZ_CONSTANT = 264,
00070      ZZ_VARIABLE = 265,
00071      ZZ_TYPE = 266,
00072      ZZ_FORALL = 267,
00073      ZZ_EXIST = 268,
00074      ZZ_EQUIV = 269,
00075      ZZ_IMPLY = 270
00076    };
00077 #endif
00078 
00079 
00080 /* Copy the first part of user declarations.  */
00081 #line 67 "../src/parser/fol.y"
00082 
00083 #define YYSTYPE int
00084 #define YYDEBUG 1
00085 
00086 #include "fol.h"
00087 #include "follex.cpp"
00088 
00089   // 0: no output; 1,2: increasing order of verbosity
00090 int folDbg = 0;
00091 //int folDbg = 1;
00092 //int folDbg = 2;
00093 
00094 
00095 
00096 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
00097 typedef int YYSTYPE;
00098 # define YYSTYPE_IS_DECLARED 1
00099 # define YYSTYPE_IS_TRIVIAL 1
00100 #endif
00101 
00102 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
00103 typedef struct YYLTYPE
00104 {
00105 
00106   char yydummy;
00107 
00108 } YYLTYPE;
00109 # define YYLTYPE_IS_DECLARED 1
00110 # define YYLTYPE_IS_TRIVIAL 1
00111 #endif
00112 
00113 
00114 /* Enabling traces.  */
00115 #ifndef YYDEBUG
00116 # define YYDEBUG 0
00117 #endif
00118 
00119 /* Enabling verbose error messages.  */
00120 #ifdef YYERROR_VERBOSE
00121 # undef YYERROR_VERBOSE
00122 # define YYERROR_VERBOSE 1
00123 #else
00124 # define YYERROR_VERBOSE 1
00125 #endif
00126 
00127 /* Enabling the token table.  */
00128 #ifndef YYTOKEN_TABLE
00129 # define YYTOKEN_TABLE 0
00130 #endif
00131 
00132 /* Default (constant) value used for initialization for null
00133    right-hand sides.  Unlike the standard yacc.c template,
00134    here we set the default value of $$ to a zeroed-out value.
00135    Since the default value is undefined, this behavior is
00136    technically correct.  */
00137 static YYSTYPE yyval_default;
00138 
00139 /* Copy the second part of user declarations.  */
00140 
00141 
00142 /* Line 234 of glr.c.  */
00143 #line 144 "fol.cpp"
00144 
00145 #include <stdio.h>
00146 #include <stdlib.h>
00147 #include <string.h>
00148 #include <stdarg.h>
00149 
00150 #ifndef YY_
00151 # if YYENABLE_NLS
00152 #  if ENABLE_NLS
00153 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
00154 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
00155 #  endif
00156 # endif
00157 # ifndef YY_
00158 #  define YY_(msgid) msgid
00159 # endif
00160 #endif
00161 
00162 /* Suppress unused-variable warnings by "using" E.  */
00163 #if ! defined lint || defined __GNUC__
00164 # define YYUSE(e) ((void) (e))
00165 #else
00166 # define YYUSE(e) /* empty */
00167 #endif
00168 
00169 /* Identity function, used to suppress warnings about constant conditions.  */
00170 #ifndef lint
00171 # define YYID(n) (n)
00172 #else
00173 #if (defined __STDC__ || defined __C99__FUNC__ \
00174      || defined __cplusplus || defined _MSC_VER)
00175 static int
00176 YYID (int i)
00177 #else
00178 static int
00179 YYID (i)
00180     int i;
00181 #endif
00182 {
00183   return i;
00184 }
00185 #endif
00186 
00187 #ifndef YYFREE
00188 # define YYFREE free
00189 #endif
00190 #ifndef YYMALLOC
00191 # define YYMALLOC malloc
00192 #endif
00193 #ifndef YYREALLOC
00194 # define YYREALLOC realloc
00195 #endif
00196 
00197 #define YYSIZEMAX ((size_t) -1)
00198 
00199 #ifdef __cplusplus
00200    typedef bool yybool;
00201 #else
00202    typedef unsigned char yybool;
00203 #endif
00204 #define yytrue 1
00205 #define yyfalse 0
00206 
00207 #ifndef YYSETJMP
00208 # include <setjmp.h>
00209 # define YYJMP_BUF jmp_buf
00210 # define YYSETJMP(env) setjmp (env)
00211 # define YYLONGJMP(env, val) longjmp (env, val)
00212 #endif
00213 
00214 /*-----------------.
00215 | GCC extensions.  |
00216 `-----------------*/
00217 
00218 #ifndef __attribute__
00219 /* This feature is available in gcc versions 2.5 and later.  */
00220 # if (! defined __GNUC__ || __GNUC__ < 2 \
00221       || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
00222 #  define __attribute__(Spec) /* empty */
00223 # endif
00224 #endif
00225 
00226 
00227 #ifdef __cplusplus
00228 # define YYOPTIONAL_LOC(Name) /* empty */
00229 #else
00230 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
00231 #endif
00232 
00233 #ifndef YYASSERT
00234 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
00235 #endif
00236 
00237 /* YYFINAL -- State number of the termination state.  */
00238 #define YYFINAL  2
00239 /* YYLAST -- Last index in YYTABLE.  */
00240 #define YYLAST   210
00241 
00242 /* YYNTOKENS -- Number of terminals.  */
00243 #define YYNTOKENS  40
00244 /* YYNNTS -- Number of nonterminals.  */
00245 #define YYNNTS  91
00246 /* YYNRULES -- Number of rules.  */
00247 #define YYNRULES  165
00248 /* YYNRULES -- Number of states.  */
00249 #define YYNSTATES  226
00250 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule.  */
00251 #define YYMAXRHS 10
00252 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
00253    accessed by $0, $-1, etc., in any rule.  */
00254 #define YYMAXLEFT 0
00255 
00256 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X.  */
00257 #define YYUNDEFTOK  2
00258 #define YYMAXUTOK   270
00259 
00260 #define YYTRANSLATE(YYX)                                                \
00261   ((YYX <= 0) ? YYEOF :                                                 \
00262    (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
00263 
00264 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
00265 static const unsigned char yytranslate[] =
00266 {
00267        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00268       24,     2,     2,    27,     2,     2,     2,     2,     2,     2,
00269        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00270        2,     2,     2,    20,     2,     2,     2,    23,     2,     2,
00271       32,    33,    21,    13,    31,    12,    26,    22,     2,    39,
00272        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00273       38,    28,    37,    34,    25,     2,     2,     2,     2,     2,
00274        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00275        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00276        2,    35,     2,    36,    19,     2,     2,     2,     2,     2,
00277        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00278        2,     2,     2,     2,     2,     2,     2,     2,    18,     2,
00279        2,     2,     2,    29,     2,    30,     2,     2,     2,     2,
00280        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00281        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00282        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00283        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00284        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00285        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00286        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00287        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00288        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00289        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00290        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00291        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00292        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
00293        5,     6,     7,     8,     9,    10,    11,    14,    15,    16,
00294       17
00295 };
00296 
00297 #if YYDEBUG
00298 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
00299    YYRHS.  */
00300 static const unsigned short int yyprhs[] =
00301 {
00302        0,     0,     3,     4,     8,    11,    14,    18,    22,    26,
00303       30,    35,    39,    43,    44,    45,    46,    55,    57,    60,
00304       61,    63,    65,    67,    68,    70,    72,    76,    78,    80,
00305       81,    88,    90,    92,    93,    94,    99,   101,   103,   105,
00306      106,   108,   112,   115,   118,   119,   120,   121,   132,   136,
00307      138,   139,   144,   146,   148,   149,   150,   151,   159,   161,
00308      162,   163,   164,   173,   175,   177,   178,   183,   184,   189,
00309      191,   193,   194,   198,   199,   203,   204,   206,   207,   209,
00310      211,   212,   216,   217,   218,   223,   224,   225,   226,   236,
00311      238,   242,   244,   246,   248,   250,   252,   254,   256,   258,
00312      259,   261,   262,   267,   268,   273,   274,   277,   278,   283,
00313      284,   290,   291,   297,   298,   304,   305,   311,   312,   313,
00314      314,   321,   322,   326,   328,   330,   331,   332,   338,   340,
00315      342,   343,   348,   349,   350,   356,   357,   358,   363,   365,
00316      367,   370,   373,   375,   378,   379,   381,   382,   387,   389,
00317      391,   393,   395,   397,   400,   402,   403,   404,   411,   412,
00318      417,   419,   421,   423,   425,   427
00319 };
00320 
00321 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
00322 static const short int yyrhs[] =
00323 {
00324       41,     0,    -1,    -1,    41,     1,    24,    -1,    41,    47,
00325       -1,    41,    49,    -1,    41,    51,    47,    -1,    41,    58,
00326       47,    -1,    41,    66,    47,    -1,    41,    70,    47,    -1,
00327       41,    45,    83,    84,    -1,    41,    45,    88,    -1,    41,
00328       45,    47,    -1,    -1,    -1,    -1,    41,    42,    95,    43,
00329       96,    46,    44,    47,    -1,    25,    -1,    45,    25,    -1,
00330       -1,    26,    -1,    24,    -1,    27,    -1,    -1,    24,    -1,
00331       27,    -1,     6,     5,    50,    -1,    24,    -1,    27,    -1,
00332       -1,    53,    28,    29,    52,    54,    30,    -1,    10,    -1,
00333       11,    -1,    -1,    -1,    54,    57,    55,    56,    -1,    10,
00334       -1,     5,    -1,     9,    -1,    -1,    31,    -1,    24,    31,
00335       24,    -1,    24,    31,    -1,    31,    24,    -1,    -1,    -1,
00336       -1,    53,    28,    29,    59,     3,    60,    31,    61,    62,
00337       30,    -1,     4,    31,     3,    -1,    63,    -1,    -1,    63,
00338       31,    64,    65,    -1,    65,    -1,     3,    -1,    -1,    -1,
00339       -1,    10,    67,    32,    68,    75,    69,    33,    -1,    10,
00340       -1,    -1,    -1,    -1,    74,    71,    10,    72,    32,    73,
00341       75,    33,    -1,    11,    -1,    10,    -1,    -1,    75,    31,
00342       76,    78,    -1,    -1,    75,    31,    77,    80,    -1,    78,
00343       -1,    80,    -1,    -1,    11,    79,    82,    -1,    -1,    10,
00344       81,    82,    -1,    -1,    20,    -1,    -1,    20,    -1,    34,
00345       -1,    -1,     7,    85,    86,    -1,    -1,    -1,    32,    87,
00346       92,    33,    -1,    -1,    -1,    -1,    94,    28,    89,     8,
00347       90,    32,    91,    92,    33,    -1,    93,    -1,    92,    57,
00348       93,    -1,     9,    -1,     5,    -1,     3,    -1,    10,    -1,
00349        9,    -1,     5,    -1,     3,    -1,    10,    -1,    -1,     3,
00350       -1,    -1,    35,    97,    96,    36,    -1,    -1,    32,    98,
00351       96,    33,    -1,    -1,    99,   114,    -1,    -1,    96,    21,
00352      100,   130,    -1,    -1,    96,    17,   101,    48,    96,    -1,
00353       -1,    96,    16,   102,    48,    96,    -1,    -1,    96,    18,
00354      103,    48,    96,    -1,    -1,    96,    19,   104,    48,    96,
00355       -1,    -1,    -1,    -1,   105,   109,   106,   110,   107,    96,
00356       -1,    -1,    20,   108,    96,    -1,    14,    -1,    15,    -1,
00357       -1,    -1,   111,   113,    31,   112,   110,    -1,   113,    -1,
00358       10,    -1,    -1,   121,     7,   115,   118,    -1,    -1,    -1,
00359      116,   124,   120,   117,   124,    -1,    -1,    -1,    32,   119,
00360      122,    33,    -1,    37,    -1,    38,    -1,    37,    28,    -1,
00361       38,    28,    -1,    28,    -1,    20,    28,    -1,    -1,    21,
00362       -1,    -1,   122,    31,   123,   124,    -1,   124,    -1,     9,
00363       -1,     5,    -1,     3,    -1,    10,    -1,    13,    10,    -1,
00364      125,    -1,    -1,    -1,     8,   126,    32,   127,   122,    33,
00365       -1,    -1,   124,   129,   128,   124,    -1,    13,    -1,    12,
00366       -1,    21,    -1,    22,    -1,    23,    -1,    39,    -1
00367 };
00368 
00369 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
00370 static const unsigned short int yyrline[] =
00371 {
00372        0,   114,   114,   116,   127,   128,   129,   130,   131,   132,
00373      133,   135,   137,   141,   146,   151,   140,   197,   198,   201,
00374      204,   214,   216,   219,   222,   224,   230,   290,   292,   303,
00375      301,   321,   334,   349,   354,   353,   365,   365,   365,   370,
00376      373,   375,   382,   388,   399,   405,   420,   397,   431,   456,
00377      467,   465,   474,   477,   502,   514,   515,   501,   529,   566,
00378      589,   614,   565,   643,   643,   649,   648,   653,   652,   655,
00379      656,   661,   660,   673,   672,   689,   691,   708,   711,   717,
00380      729,   728,   775,   783,   782,   799,   805,   850,   797,   895,
00381      903,   913,   914,   920,   929,   937,   946,   958,   967,   982,
00382      985,  1000,   999,  1018,  1017,  1032,  1032,  1036,  1035,  1050,
00383     1049,  1062,  1061,  1074,  1073,  1085,  1084,  1096,  1098,  1104,
00384     1096,  1115,  1114,  1130,  1138,  1151,  1153,  1151,  1160,  1164,
00385     1191,  1190,  1223,  1242,  1223,  1408,  1425,  1424,  1584,  1598,
00386     1612,  1629,  1646,  1659,  1682,  1684,  1701,  1699,  1710,  1738,
00387     1748,  1760,  1775,  1781,  1792,  1989,  2025,  1988,  2109,  2108,
00388     2193,  2202,  2211,  2220,  2229,  2240
00389 };
00390 #endif
00391 
00392 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
00393 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
00394    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
00395 static const char *const yytname[] =
00396 {
00397   "$end", "error", "$undefined", "ZZ_NUM", "ZZ_DOTDOTDOT", "ZZ_STRING",
00398   "ZZ_INCLUDE", "ZZ_PREDICATE", "ZZ_FUNCTION", "ZZ_CONSTANT",
00399   "ZZ_VARIABLE", "ZZ_TYPE", "'-'", "'+'", "ZZ_FORALL", "ZZ_EXIST",
00400   "ZZ_EQUIV", "ZZ_IMPLY", "'v'", "'^'", "'!'", "'*'", "'/'", "'%'",
00401   "'\\n'", "'@'", "'.'", "'\\r'", "'='", "'{'", "'}'", "','", "'('", "')'",
00402   "'?'", "'['", "']'", "'>'", "'<'", "'1'", "$accept", "input", "@1", "@2",
00403   "@3", "at", "fullstop", "newline", "optnewline", "include", "nnewline",
00404   "type_declaration", "@4", "is_variable_type", "constant_declarations",
00405   "@5", "variable_or_string_or_constant", "constant_sep",
00406   "numeric_type_declaration", "@6", "@7", "@8", "numeric_types",
00407   "single_numeric_types", "@9", "single_numeric_type",
00408   "predicate_declaration", "@10", "@11", "@12", "function_declaration",
00409   "@13", "@14", "@15", "function_return_type", "types", "@16", "@17",
00410   "type_code", "@18", "variable_code", "@19", "exist_unique", "pd_not_qs",
00411   "predicate_definition", "@20", "nothing_or_constants", "@21",
00412   "function_definition", "@22", "@23", "@24", "constants_in_groundings",
00413   "is_constant_string_num_variable", "function_return_constant", "weight",
00414   "sentence", "@25", "@26", "@27", "@28", "@29", "@30", "@31", "@32",
00415   "@33", "@34", "@35", "@36", "quantifier", "variables", "@37", "@38",
00416   "quant_variable", "atomic_sentence", "@39", "@40", "@41",
00417   "nothing_or_terms", "@42", "internal_predicate_sign", "asterisk",
00418   "terms", "@43", "term", "function_term", "@44", "@45", "@46",
00419   "internal_function_sign", "numeric_term", 0
00420 };
00421 #endif
00422 
00423 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
00424 static const unsigned char yyr1[] =
00425 {
00426        0,    40,    41,    41,    41,    41,    41,    41,    41,    41,
00427       41,    41,    41,    42,    43,    44,    41,    45,    45,    46,
00428       46,    47,    47,    48,    48,    48,    49,    50,    50,    52,
00429       51,    53,    53,    54,    55,    54,    56,    56,    56,    57,
00430       57,    57,    57,    57,    59,    60,    61,    58,    62,    62,
00431       64,    63,    63,    65,    67,    68,    69,    66,    66,    71,
00432       72,    73,    70,    74,    74,    76,    75,    77,    75,    75,
00433       75,    79,    78,    81,    80,    82,    82,    83,    83,    83,
00434       85,    84,    86,    87,    86,    89,    90,    91,    88,    92,
00435       92,    93,    93,    93,    93,    94,    94,    94,    94,    95,
00436       95,    97,    96,    98,    96,    99,    96,   100,    96,   101,
00437       96,   102,    96,   103,    96,   104,    96,   105,   106,   107,
00438       96,   108,    96,   109,   109,   111,   112,   110,   110,   113,
00439      115,   114,   116,   117,   114,   118,   119,   118,   120,   120,
00440      120,   120,   120,   120,   121,   121,   123,   122,   122,   124,
00441      124,   124,   124,   124,   124,   126,   127,   125,   128,   125,
00442      129,   129,   129,   129,   129,   130
00443 };
00444 
00445 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
00446 static const unsigned char yyr2[] =
00447 {
00448        0,     2,     0,     3,     2,     2,     3,     3,     3,     3,
00449        4,     3,     3,     0,     0,     0,     8,     1,     2,     0,
00450        1,     1,     1,     0,     1,     1,     3,     1,     1,     0,
00451        6,     1,     1,     0,     0,     4,     1,     1,     1,     0,
00452        1,     3,     2,     2,     0,     0,     0,    10,     3,     1,
00453        0,     4,     1,     1,     0,     0,     0,     7,     1,     0,
00454        0,     0,     8,     1,     1,     0,     4,     0,     4,     1,
00455        1,     0,     3,     0,     3,     0,     1,     0,     1,     1,
00456        0,     3,     0,     0,     4,     0,     0,     0,     9,     1,
00457        3,     1,     1,     1,     1,     1,     1,     1,     1,     0,
00458        1,     0,     4,     0,     4,     0,     2,     0,     4,     0,
00459        5,     0,     5,     0,     5,     0,     5,     0,     0,     0,
00460        6,     0,     3,     1,     1,     0,     0,     5,     1,     1,
00461        0,     4,     0,     0,     5,     0,     0,     4,     1,     1,
00462        2,     2,     1,     2,     0,     1,     0,     4,     1,     1,
00463        1,     1,     1,     2,     1,     0,     0,     6,     0,     4,
00464        1,     1,     1,     1,     1,     1
00465 };
00466 
00467 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none).  */
00468 static const unsigned char yydprec[] =
00469 {
00470        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00471        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00472        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00473        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00474        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00475        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00476        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00477        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00478        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00479        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00480        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00481        1,     0,     1,     0,     1,     0,     1,     0,     0,     0,
00482        2,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00483        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00484        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00485        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00486        0,     0,     0,     0,     0,     0
00487 };
00488 
00489 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM.  */
00490 static const unsigned char yymerger[] =
00491 {
00492        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00493        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00494        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00495        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00496        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00497        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00498        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00499        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00500        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00501        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00502        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00503        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00504        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00505        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00506        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00507        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00508        0,     0,     0,     0,     0,     0
00509 };
00510 
00511 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
00512    doesn't specify something else to do.  Zero means the default is an
00513    error.  */
00514 static const unsigned char yydefact[] =
00515 {
00516        2,     0,     1,     0,     0,    58,    32,    21,    17,    22,
00517       99,    77,     4,     5,     0,     0,     0,     0,     0,    59,
00518        3,     0,     0,   100,    14,    97,    96,    95,    98,    78,
00519       18,    79,    12,     0,    11,     0,     6,     0,     7,     8,
00520        9,     0,    27,    28,    26,    55,   105,    80,    10,    85,
00521       29,    60,     0,   121,   103,   101,    19,   132,     0,    82,
00522        0,    33,     0,     0,    73,    71,    56,    69,    70,   105,
00523      105,   105,   111,   109,   113,   115,   107,    20,    15,   145,
00524      106,     0,     0,   123,   124,   118,    83,    81,    86,    39,
00525       45,    61,    75,    75,    65,     0,   122,     0,     0,    23,
00526       23,    23,    23,     0,     0,   151,   150,   155,   149,   152,
00527        0,     0,   154,   130,     0,     0,     0,     0,    30,    40,
00528       34,     0,     0,    76,    74,    72,     0,     0,    57,   104,
00529      102,    24,    25,   105,   105,   105,   105,   165,   108,    16,
00530        0,   153,   161,   160,     0,   162,   163,   164,   142,   138,
00531      139,   133,   158,   135,   129,   119,     0,   128,    93,    92,
00532       91,    94,    39,    89,    87,    42,    43,     0,    46,     0,
00533       66,    68,   112,   110,   114,   116,   156,   143,   140,   141,
00534        0,     0,   136,   131,   105,     0,    84,     0,     0,    41,
00535       37,    38,    36,    35,     0,    62,     0,   134,   159,     0,
00536      120,   126,    90,    39,    53,     0,     0,    49,    52,     0,
00537      148,     0,     0,    88,     0,    47,    50,   146,   157,   137,
00538      127,    48,     0,     0,    51,   147
00539 };
00540 
00541 /* YYPDEFGOTO[NTERM-NUM].  */
00542 static const short int yydefgoto[] =
00543 {
00544       -1,     1,    10,    46,   104,    11,    78,    12,   133,    13,
00545       44,    14,    61,    15,    89,   167,   193,   187,    16,    62,
00546      121,   194,   206,   207,   222,   208,    17,    22,    52,    95,
00547       18,    41,    63,   122,    19,    66,   126,   127,    67,    93,
00548       68,    92,   124,    33,    48,    59,    87,   115,    34,    60,
00549      116,   188,   162,   163,    35,    24,    56,    71,    70,    57,
00550      103,   100,    99,   101,   102,    58,   114,   184,    69,    85,
00551      155,   156,   212,   157,    80,   153,    81,   180,   183,   199,
00552      151,    82,   209,   223,   210,   112,   140,   196,   181,   152,
00553      138
00554 };
00555 
00556 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
00557    STATE-NUM.  */
00558 #define YYPACT_NINF -82
00559 static const short int yypact[] =
00560 {
00561      -82,    12,   -82,    17,    75,    14,    79,   -82,   -82,   -82,
00562       82,    25,   -82,   -82,    24,    66,    24,    24,    24,   -82,
00563      -82,    50,    97,   -82,   -82,   -82,   -82,   -82,   -82,   -82,
00564      -82,   -82,   -82,   100,   -82,    86,   -82,   109,   -82,   -82,
00565      -82,   146,   -82,   -82,   -82,   -82,    56,   -82,   -82,   -82,
00566      138,   -82,    62,   -82,   -82,   -82,    94,    22,   135,   129,
00567      160,   -82,   166,   139,   -82,   -82,   141,   -82,   -82,    56,
00568       56,    56,   -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,
00569      -82,   118,   167,   -82,   -82,   -82,   -82,   -82,   -82,   106,
00570      -82,   -82,   150,   150,   165,   140,   155,    65,    39,    63,
00571       63,    63,    63,   143,    24,   -82,   -82,   -82,   -82,   -82,
00572      168,    41,   -82,   -82,   169,   130,   145,   149,   -82,   157,
00573      -82,   152,    62,   -82,   -82,   -82,   173,   175,   -82,   -82,
00574      -82,   -82,   -82,    56,    56,    56,    56,   -82,   -82,   -82,
00575      154,   -82,   -82,   -82,   159,   -82,   -82,   -82,   -82,   161,
00576      162,   -82,   -82,   156,   -82,   -82,   181,   -82,   -82,   -82,
00577      -82,   -82,     7,   -82,   -82,   170,   -82,   142,   -82,   -17,
00578      -82,   -82,   136,   -13,   103,   155,   -82,   -82,   -82,   -82,
00579      118,   118,   -82,   -82,    56,   164,   -82,   130,   130,   -82,
00580      -82,   -82,   -82,   -82,   163,   -82,   118,    80,    83,   118,
00581      127,   -82,   -82,   101,   -82,   171,   174,   172,   -82,   131,
00582       96,   132,   182,   -82,   190,   -82,   -82,   -82,   -82,   -82,
00583      -82,   -82,   193,   118,   -82,    96
00584 };
00585 
00586 /* YYPGOTO[NTERM-NUM].  */
00587 static const signed char yypgoto[] =
00588 {
00589      -82,   -82,   -82,   -82,   -82,   -82,   -82,    -7,    58,   -82,
00590      -82,   -82,   -82,   -82,   -82,   -82,   -82,   108,   -82,   -82,
00591      -82,   -82,   -82,   -82,   -82,   -24,   -82,   -82,   -82,   -82,
00592      -82,   -82,   -82,   -82,   -82,    77,   -82,   -82,    74,   -82,
00593       78,   -82,   113,   -82,   -82,   -82,   -82,   -82,   -82,   -82,
00594      -82,   -82,    13,    20,   -82,   -82,   -68,   -82,   -82,   -82,
00595      -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,
00596       -4,   -82,   -82,    53,   -82,   -82,   -82,   -82,   -82,   -82,
00597      -82,   -82,    11,   -82,   -81,   -82,   -82,   -82,   -82,   -82,
00598      -82
00599 };
00600 
00601 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
00602    positive, shift that token.  If negative, reduce the rule which
00603    number is the opposite.  If zero, do what YYDEFACT says.
00604    If YYTABLE_NINF, parse error.  */
00605 #define YYTABLE_NINF -145
00606 static const short int yytable[] =
00607 {
00608      111,    96,    97,    98,    32,    74,    75,    36,    76,    38,
00609       39,    40,     2,     3,    94,   -13,   195,   -13,     4,   -13,
00610      -13,   -13,     5,     6,   -64,   -13,   -13,   -13,    25,  -144,
00611       26,   117,   -13,   -13,    27,    28,     7,     8,   119,     9,
00612      186,    20,   -31,    79,   -13,    29,   -54,   -13,     7,     7,
00613       30,     9,     9,   142,   143,    72,    73,    74,    75,    31,
00614       76,   144,   145,   146,   147,   172,   173,   174,   175,   148,
00615     -117,  -117,    64,    65,    42,   130,    53,    43,   149,   150,
00616       21,    72,    73,    74,    75,    23,    76,   131,    54,   -63,
00617      132,    55,   142,   143,    37,   142,   143,   139,   129,   197,
00618      198,   145,   146,   147,   145,   146,   147,    47,   142,   143,
00619       72,    73,    74,    75,    49,    76,   200,   145,   146,   147,
00620       77,   105,    75,   106,    76,   117,   107,   108,   109,    45,
00621      117,   110,   119,   158,   213,   159,   118,   119,    50,   160,
00622      161,   -44,   225,    72,    73,    74,    75,   190,    76,    83,
00623       84,   191,   192,    73,    74,    75,    51,    76,   134,   135,
00624      136,    86,   217,   217,   218,   219,   204,   205,    88,    90,
00625      123,    91,    94,   128,   113,   -67,    76,   164,   141,   154,
00626      165,   166,   137,   168,    65,    64,   176,   177,   182,   178,
00627      179,   154,   154,   221,   189,   201,   204,   120,   224,   169,
00628      170,   203,   214,   216,   215,   171,   125,   202,   220,   185,
00629      211
00630 };
00631 
00632 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
00633    list of conflicting reductions corresponding to action entry for
00634    state STATE-NUM in yytable.  0 means no conflicts.  The list in
00635    yyconfl is terminated by a rule number of 0.  */
00636 static const unsigned char yyconflp[] =
00637 {
00638        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00639        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00640        0,     0,     1,     0,     0,     0,     0,     0,     0,     0,
00641        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00642        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00643        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00644        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00645        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00646        0,     0,     0,     0,     0,     3,     0,     0,     0,     0,
00647        0,     0,     0,     0,     0,    11,    13,     0,     0,     0,
00648        0,     9,     0,     0,    15,    17,    19,     0,     0,     0,
00649        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00650        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00651        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00652        0,     0,     0,    21,    23,    25,    27,     0,    29,     0,
00653        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00654        0,     5,     0,     0,     0,     0,     0,     0,     0,     0,
00655        0,     0,     0,     0,     0,     0,     0,     0,     0,     7,
00656        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00657        0,     0,    31,     0,     0,     0,     0,     0,     0,     0,
00658        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
00659        0
00660 };
00661 
00662 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
00663    0, pointed into by YYCONFLP.  */
00664 static const short int yyconfl[] =
00665 {
00666        0,    13,     0,    99,     0,    82,     0,   125,     0,   134,
00667        0,   159,     0,   159,     0,   159,     0,   159,     0,   159,
00668        0,   120,     0,   120,     0,   120,     0,   120,     0,   120,
00669        0,   125,     0
00670 };
00671 
00672 static const unsigned char yycheck[] =
00673 {
00674       81,    69,    70,    71,    11,    18,    19,    14,    21,    16,
00675       17,    18,     0,     1,    31,     3,    33,     5,     6,     7,
00676        8,     9,    10,    11,    10,    13,    14,    15,     3,     7,
00677        5,    24,    20,    21,     9,    10,    24,    25,    31,    27,
00678       33,    24,    28,    21,    32,    20,    32,    35,    24,    24,
00679       25,    27,    27,    12,    13,    16,    17,    18,    19,    34,
00680       21,    20,    21,    22,    23,   133,   134,   135,   136,    28,
00681       14,    15,    10,    11,    24,    36,    20,    27,    37,    38,
00682        5,    16,    17,    18,    19,     3,    21,    24,    32,    10,
00683       27,    35,    12,    13,    28,    12,    13,   104,    33,   180,
00684      181,    21,    22,    23,    21,    22,    23,     7,    12,    13,
00685       16,    17,    18,    19,    28,    21,   184,    21,    22,    23,
00686       26,     3,    19,     5,    21,    24,     8,     9,    10,    32,
00687       24,    13,    31,     3,    33,     5,    30,    31,    29,     9,
00688       10,     3,   223,    16,    17,    18,    19,     5,    21,    14,
00689       15,     9,    10,    17,    18,    19,    10,    21,   100,   101,
00690      102,    32,    31,    31,    33,    33,     3,     4,     8,     3,
00691       20,    32,    31,    33,     7,    10,    21,    32,    10,    10,
00692       31,    24,    39,    31,    11,    10,    32,    28,    32,    28,
00693       28,    10,    10,     3,    24,    31,     3,    89,   222,   122,
00694      126,   188,    31,    31,    30,   127,    93,   187,   212,   156,
00695      199
00696 };
00697 
00698 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
00699    symbol of state STATE-NUM.  */
00700 static const unsigned char yystos[] =
00701 {
00702        0,    41,     0,     1,     6,    10,    11,    24,    25,    27,
00703       42,    45,    47,    49,    51,    53,    58,    66,    70,    74,
00704       24,     5,    67,     3,    95,     3,     5,     9,    10,    20,
00705       25,    34,    47,    83,    88,    94,    47,    28,    47,    47,
00706       47,    71,    24,    27,    50,    32,    43,     7,    84,    28,
00707       29,    10,    68,    20,    32,    35,    96,    99,   105,    85,
00708       89,    52,    59,    72,    10,    11,    75,    78,    80,   108,
00709       98,    97,    16,    17,    18,    19,    21,    26,    46,    21,
00710      114,   116,   121,    14,    15,   109,    32,    86,     8,    54,
00711        3,    32,    81,    79,    31,    69,    96,    96,    96,   102,
00712      101,   103,   104,   100,    44,     3,     5,     8,     9,    10,
00713       13,   124,   125,     7,   106,    87,    90,    24,    30,    31,
00714       57,    60,    73,    20,    82,    82,    76,    77,    33,    33,
00715       36,    24,    27,    48,    48,    48,    48,    39,   130,    47,
00716      126,    10,    12,    13,    20,    21,    22,    23,    28,    37,
00717       38,   120,   129,   115,    10,   110,   111,   113,     3,     5,
00718        9,    10,    92,    93,    32,    31,    24,    55,    31,    75,
00719       78,    80,    96,    96,    96,    96,    32,    28,    28,    28,
00720      117,   128,    32,   118,   107,   113,    33,    57,    91,    24,
00721        5,     9,    10,    56,    61,    33,   127,   124,   124,   119,
00722       96,    31,    93,    92,     3,     4,    62,    63,    65,   122,
00723      124,   122,   112,    33,    31,    30,    31,    31,    33,    33,
00724      110,     3,    64,   123,    65,   124
00725 };
00726 
00727 
00728 /* Prevent warning if -Wmissing-prototypes.  */
00729 int yyparse (void);
00730 
00731 /* Error token number */
00732 #define YYTERROR 1
00733 
00734 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
00735    If N is 0, then set CURRENT to the empty location which ends
00736    the previous symbol: RHS[0] (always defined).  */
00737 
00738 
00739 #ifndef YYLLOC_DEFAULT
00740 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
00741 #endif
00742 
00743 
00744 #ifndef YY_LOCATION_PRINT
00745 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
00746 #endif
00747 
00748 
00749 /* YYLEX -- calling `yylex' with the right arguments.  */
00750 #define YYLEX yylex ()
00751 
00752 YYSTYPE yylval;
00753 
00754 YYLTYPE yylloc;
00755 
00756 int yynerrs;
00757 int yychar;
00758 
00759 static const int YYEOF = 0;
00760 static const int YYEMPTY = -2;
00761 
00762 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
00763 
00764 #define YYCHK(YYE)                                                           \
00765    do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; }       \
00766    while (YYID (0))
00767 
00768 #if YYDEBUG
00769 
00770 # ifndef YYFPRINTF
00771 #  define YYFPRINTF fprintf
00772 # endif
00773 
00774 # define YYDPRINTF(Args)                        \
00775 do {                                            \
00776   if (yydebug)                                  \
00777     YYFPRINTF Args;                             \
00778 } while (YYID (0))
00779 
00780 
00781 /*--------------------------------.
00782 | Print this symbol on YYOUTPUT.  |
00783 `--------------------------------*/
00784 
00785 /*ARGSUSED*/
00786 static void
00787 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
00788 {
00789   if (!yyvaluep)
00790     return;
00791 # ifdef YYPRINT
00792   if (yytype < YYNTOKENS)
00793     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
00794 # else
00795   YYUSE (yyoutput);
00796 # endif
00797   switch (yytype)
00798     {
00799       default:
00800         break;
00801     }
00802 }
00803 
00804 
00805 /*--------------------------------.
00806 | Print this symbol on YYOUTPUT.  |
00807 `--------------------------------*/
00808 
00809 static void
00810 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
00811 {
00812   if (yytype < YYNTOKENS)
00813     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
00814   else
00815     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
00816 
00817   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
00818   YYFPRINTF (yyoutput, ")");
00819 }
00820 
00821 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                      \
00822 do {                                                                        \
00823   if (yydebug)                                                              \
00824     {                                                                       \
00825       YYFPRINTF (stderr, "%s ", Title);                                     \
00826       yy_symbol_print (stderr, Type,                                        \
00827                        Value);  \
00828       YYFPRINTF (stderr, "\n");                                             \
00829     }                                                                       \
00830 } while (YYID (0))
00831 
00832 /* Nonzero means print parse trace.  It is left uninitialized so that
00833    multiple parsers can coexist.  */
00834 int yydebug;
00835 
00836 #else /* !YYDEBUG */
00837 
00838 # define YYDPRINTF(Args)
00839 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
00840 
00841 #endif /* !YYDEBUG */
00842 
00843 /* YYINITDEPTH -- initial size of the parser's stacks.  */
00844 #ifndef YYINITDEPTH
00845 # define YYINITDEPTH 200
00846 #endif
00847 
00848 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
00849    if the built-in stack extension method is used).
00850 
00851    Do not make this value too large; the results are undefined if
00852    SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
00853    evaluated with infinite-precision integer arithmetic.  */
00854 
00855 #ifndef YYMAXDEPTH
00856 # define YYMAXDEPTH 10000
00857 #endif
00858 
00859 /* Minimum number of free items on the stack allowed after an
00860    allocation.  This is to allow allocation and initialization
00861    to be completed by functions that call yyexpandGLRStack before the
00862    stack is expanded, thus insuring that all necessary pointers get
00863    properly redirected to new data.  */
00864 #define YYHEADROOM 2
00865 
00866 #ifndef YYSTACKEXPANDABLE
00867 # if (! defined __cplusplus \
00868       || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
00869 #  define YYSTACKEXPANDABLE 1
00870 # else
00871 #  define YYSTACKEXPANDABLE 0
00872 # endif
00873 #endif
00874 
00875 #if YYSTACKEXPANDABLE
00876 # define YY_RESERVE_GLRSTACK(Yystack)                   \
00877   do {                                                  \
00878     if (Yystack->yyspaceLeft < YYHEADROOM)              \
00879       yyexpandGLRStack (Yystack);                       \
00880   } while (YYID (0))
00881 #else
00882 # define YY_RESERVE_GLRSTACK(Yystack)                   \
00883   do {                                                  \
00884     if (Yystack->yyspaceLeft < YYHEADROOM)              \
00885       yyMemoryExhausted (Yystack);                      \
00886   } while (YYID (0))
00887 #endif
00888 
00889 
00890 #if YYERROR_VERBOSE
00891 
00892 # ifndef yystpcpy
00893 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
00894 #   define yystpcpy stpcpy
00895 #  else
00896 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
00897    YYDEST.  */
00898 static char *
00899 yystpcpy (char *yydest, const char *yysrc)
00900 {
00901   char *yyd = yydest;
00902   const char *yys = yysrc;
00903 
00904   while ((*yyd++ = *yys++) != '\0')
00905     continue;
00906 
00907   return yyd - 1;
00908 }
00909 #  endif
00910 # endif
00911 
00912 # ifndef yytnamerr
00913 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
00914    quotes and backslashes, so that it's suitable for yyerror.  The
00915    heuristic is that double-quoting is unnecessary unless the string
00916    contains an apostrophe, a comma, or backslash (other than
00917    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
00918    null, do not copy; instead, return the length of what the result
00919    would have been.  */
00920 static size_t
00921 yytnamerr (char *yyres, const char *yystr)
00922 {
00923   if (*yystr == '"')
00924     {
00925       size_t yyn = 0;
00926       char const *yyp = yystr;
00927 
00928       for (;;)
00929         switch (*++yyp)
00930           {
00931           case '\'':
00932           case ',':
00933             goto do_not_strip_quotes;
00934 
00935           case '\\':
00936             if (*++yyp != '\\')
00937               goto do_not_strip_quotes;
00938             /* Fall through.  */
00939           default:
00940             if (yyres)
00941               yyres[yyn] = *yyp;
00942             yyn++;
00943             break;
00944 
00945           case '"':
00946             if (yyres)
00947               yyres[yyn] = '\0';
00948             return yyn;
00949           }
00950     do_not_strip_quotes: ;
00951     }
00952 
00953   if (! yyres)
00954     return strlen (yystr);
00955 
00956   return yystpcpy (yyres, yystr) - yyres;
00957 }
00958 # endif
00959 
00960 #endif /* !YYERROR_VERBOSE */
00961 
00963 typedef int yyStateNum;
00964 
00966 typedef int yyRuleNum;
00967 
00969 typedef short int yySymbol;
00970 
00972 typedef short int yyItemNum;
00973 
00974 typedef struct yyGLRState yyGLRState;
00975 typedef struct yyGLRStateSet yyGLRStateSet;
00976 typedef struct yySemanticOption yySemanticOption;
00977 typedef union yyGLRStackItem yyGLRStackItem;
00978 typedef struct yyGLRStack yyGLRStack;
00979 
00980 struct yyGLRState {
00982   yybool yyisState;
00985   yybool yyresolved;
00987   yyStateNum yylrState;
00989   yyGLRState* yypred;
00991   size_t yyposn;
00992   union {
00996     yySemanticOption* yyfirstVal;
00998     YYSTYPE yysval;
00999   } yysemantics;
01001   YYLTYPE yyloc;
01002 };
01003 
01004 struct yyGLRStateSet {
01005   yyGLRState** yystates;
01010   yybool* yylookaheadNeeds;
01011   size_t yysize, yycapacity;
01012 };
01013 
01014 struct yySemanticOption {
01016   yybool yyisState;
01018   yyRuleNum yyrule;
01020   yyGLRState* yystate;
01022   int yyrawchar;
01023   YYSTYPE yyval;
01024   YYLTYPE yyloc;
01027   yySemanticOption* yynext;
01028 };
01029 
01032 union yyGLRStackItem {
01033   yyGLRState yystate;
01034   yySemanticOption yyoption;
01035 };
01036 
01037 struct yyGLRStack {
01038   int yyerrState;
01039 
01040 
01041   YYJMP_BUF yyexception_buffer;
01042   yyGLRStackItem* yyitems;
01043   yyGLRStackItem* yynextFree;
01044   size_t yyspaceLeft;
01045   yyGLRState* yysplitPoint;
01046   yyGLRState* yylastDeleted;
01047   yyGLRStateSet yytops;
01048 };
01049 
01050 #if YYSTACKEXPANDABLE
01051 static void yyexpandGLRStack (yyGLRStack* yystackp);
01052 #endif
01053 
01054 static void yyFail (yyGLRStack* yystackp, const char* yymsg)
01055   __attribute__ ((__noreturn__));
01056 static void
01057 yyFail (yyGLRStack* yystackp, const char* yymsg)
01058 {
01059   if (yymsg != NULL)
01060     yyerror (yymsg);
01061   YYLONGJMP (yystackp->yyexception_buffer, 1);
01062 }
01063 
01064 static void yyMemoryExhausted (yyGLRStack* yystackp)
01065   __attribute__ ((__noreturn__));
01066 static void
01067 yyMemoryExhausted (yyGLRStack* yystackp)
01068 {
01069   YYLONGJMP (yystackp->yyexception_buffer, 2);
01070 }
01071 
01072 #if YYDEBUG || YYERROR_VERBOSE
01073 
01074 static inline const char*
01075 yytokenName (yySymbol yytoken)
01076 {
01077   if (yytoken == YYEMPTY)
01078     return "";
01079 
01080   if (yytoken < 0) { char* buf = new char[1]; buf[0]='\0'; return buf; } return yytname[yytoken];
01081 }
01082 #endif
01083 
01087 static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
01088 static void
01089 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
01090 {
01091   yyGLRState* s;
01092   int i;
01093   s = yyvsp[yylow0].yystate.yypred;
01094   for (i = yylow0-1; i >= yylow1; i -= 1)
01095     {
01096       YYASSERT (s->yyresolved);
01097       yyvsp[i].yystate.yyresolved = yytrue;
01098       yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
01099       yyvsp[i].yystate.yyloc = s->yyloc;
01100       s = yyvsp[i].yystate.yypred = s->yypred;
01101     }
01102 }
01103 
01104 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1.  Otherwise, fill in
01105  * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
01106  * For convenience, always return YYLOW1.  */
01107 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
01108      __attribute__ ((__unused__));
01109 static inline int
01110 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
01111 {
01112   if (!yynormal && yylow1 < *yylow)
01113     {
01114       yyfillin (yyvsp, *yylow, yylow1);
01115       *yylow = yylow1;
01116     }
01117   return yylow1;
01118 }
01119 
01125 /*ARGSUSED*/ static YYRESULTTAG
01126 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
01127               YYSTYPE* yyvalp,
01128               YYLTYPE* YYOPTIONAL_LOC (yylocp),
01129               yyGLRStack* yystackp
01130               )
01131 {
01132   yybool yynormal __attribute__ ((__unused__)) =
01133     (yystackp->yysplitPoint == NULL);
01134   int yylow;
01135 # undef yyerrok
01136 # define yyerrok (yystackp->yyerrState = 0)
01137 # undef YYACCEPT
01138 # define YYACCEPT return yyaccept
01139 # undef YYABORT
01140 # define YYABORT return yyabort
01141 # undef YYERROR
01142 # define YYERROR return yyerrok, yyerr
01143 # undef YYRECOVERING
01144 # define YYRECOVERING() (yystackp->yyerrState != 0)
01145 # undef yyclearin
01146 # define yyclearin (yychar = YYEMPTY)
01147 # undef YYFILL
01148 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
01149 # undef YYBACKUP
01150 # define YYBACKUP(Token, Value)                                              \
01151   return yyerror (YY_("parse error: cannot back up")),     \
01152          yyerrok, yyerr
01153 
01154   yylow = 1;
01155   if (yyrhslen == 0)
01156     *yyvalp = yyval_default;
01157   else
01158     *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
01159   YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
01160 
01161   switch (yyn)
01162     {
01163         case 2:
01164 #line 114 "../src/parser/fol.y"
01165     { if (folDbg >= 2) printf("input: empty\n"); ;}
01166     break;
01167 
01168   case 3:
01169 #line 117 "../src/parser/fol.y"
01170     { 
01171     yyerrok; // tell Bison not to suppress any errors
01172     const char* tok; 
01173     while (true)
01174     {
01175       tok = zztokenList.removeLast();
01176       if (strcmp(tok,"\n")==0) { delete tok; break; }
01177       delete tok;
01178     }
01179   ;}
01180     break;
01181 
01182   case 13:
01183 #line 141 "../src/parser/fol.y"
01184     { 
01185     if (folDbg >= 2) printf("input: weight\n"); 
01186     zzreset();
01187   ;}
01188     break;
01189 
01190   case 14:
01191 #line 146 "../src/parser/fol.y"
01192     {  
01193     if (folDbg >= 2) printf("input: sentence\n");
01194       // the states should be reset because a parse error may have occurred
01195   ;}
01196     break;
01197 
01198   case 15:
01199 #line 151 "../src/parser/fol.y"
01200     {
01201     ListObj* formula;
01202     zzassert(zzoldNewVarList.size()==0,"expected zzoldNewVarList.size()==0");
01203     zzassert(zzformulaListObjs.size()==1,"expected zzformulaListObjs.size()=1");
01204         formula = zzformulaListObjs.top(); zzformulaListObjs.pop();
01205 
01206         zzdetermineEqPredTypes(formula);//set the any unknown type of '=' predicates
01207     zzeqPredList.clear();
01208         zzdetermineIntPredTypes(formula);//set the any unknown type of internal predicates
01209     zzintPredList.clear();
01210         zzdetermineIntFuncTypes(formula);//set the any unknown type of internal functions
01211     zzintFuncList.clear();
01212     zzsetPlusVarTypeId();// set typeIds of variables with pluses before them
01213     zzcheckVarNameToIdMap();
01214     
01215     if (zzhasFullStop && zzwt != NULL)
01216     {
01217       zzerr("A weight must not be specified for a formula that is "
01218             "terminated with a period (i.e. the formula is hard).");
01219       delete zzwt; zzwt = NULL;
01220     }
01221         
01222       // at this point we are sure we are dealing with a formula
01223 
01224       //if there are errors, we can keep this formula for further processing
01225     if (zznumErrors == 0)
01226     {
01227         //defer converting the formula to CNF until we have read all the
01228         //.db files and are sure that we know all the constants to ground
01229         //formula's clauses
01230       ZZFormulaInfo* epfi 
01231         = new ZZFormulaInfo(formula, zzformulaStr, zzfdnumPreds, zzwt, 
01232                             zzdefaultWt, zzdomain, zzmln, zzvarNameToIdMap, 
01233                             zzplusVarMap, zznumAsterisk,
01234                             zzhasFullStop, zzreadHardClauseWts, 
01235                             zzmustHaveWtOrFullStop, zzinIndivisible);
01236       zzformulaInfos.append(epfi); 
01237     }
01238 
01239     if (zzwt) { delete zzwt; zzwt = NULL; }
01240   ;}
01241     break;
01242 
01243   case 17:
01244 #line 197 "../src/parser/fol.y"
01245     { zzconsumeToken(zztokenList,"@"); ;}
01246     break;
01247 
01248   case 18:
01249 #line 198 "../src/parser/fol.y"
01250     { zzconsumeToken(zztokenList,"@"); ;}
01251     break;
01252 
01253   case 20:
01254 #line 205 "../src/parser/fol.y"
01255     { 
01256   if (folDbg >= 1) printf(".\n"); zzconsumeToken(zztokenList,"."); 
01257   zzassert(!zzhasFullStop, "expecting no full stop");
01258   zzhasFullStop = true;
01259   zzformulaStr.append(".");
01260 ;}
01261     break;
01262 
01263   case 21:
01264 #line 214 "../src/parser/fol.y"
01265     { if (folDbg >= 1) printf("\\n\n"); zzconsumeToken(zztokenList,"\n"); ;}
01266     break;
01267 
01268   case 22:
01269 #line 216 "../src/parser/fol.y"
01270     { if (folDbg >= 1) printf("\\r\n"); zzconsumeToken(zztokenList,"\r"); ;}
01271     break;
01272 
01273   case 24:
01274 #line 222 "../src/parser/fol.y"
01275     { if (folDbg >= 1) printf("\\n\n"); zzconsumeToken(zztokenList,"\n"); ;}
01276     break;
01277 
01278   case 25:
01279 #line 224 "../src/parser/fol.y"
01280     { if (folDbg >= 1) printf("\\r\n"); zzconsumeToken(zztokenList,"\r"); ;}
01281     break;
01282 
01283   case 26:
01284 #line 231 "../src/parser/fol.y"
01285     {
01286   const char* inc = zztokenList.removeLast();
01287   const char* str = zztokenList.removeLast();
01288   const char* nl = zztokenList.removeLast();
01289   zzassert(strcmp(inc,"#include")==0,"expecting #include keyword");
01290 
01291   if (folDbg >= 1) printf("#include %s ", str);
01292 
01293   string s(str);
01294   if (s.length() == 0)
01295   {
01296     zzerr("empty string used with #include");
01297     delete [] inc;
01298     delete [] str;
01299     delete [] nl;
01300     break;
01301   }
01302 
01303   zzassert(s.at(0) == '"' && s.at(s.length()-1) == '"', "no enclosing \"");
01304   s = s.substr(1, s.length()-2);
01305   int len = s.length();
01306 
01307   // if it is a .cpp file, then we are dealing with linked-in functions and predicates
01308   if (s.at(len-4)=='.' && s.at(len-3)=='c' && s.at(len-2)=='p' &&
01309           s.at(len-1)=='p')
01310   {
01311     zzcompileFunctions(str);
01312     zzusingLinkedPredicates = true;    
01313     zzusingLinkedFunctions = true;    
01314     break;
01315   }
01316 
01317   FILE* newin = fopen(s.c_str(), "r" );
01318   if (newin)
01319   {
01320     zzinStack.push(ZZFileState(yyin, string(zzinFileName), zznumCharRead, 
01321                                zzline, zzcolumn)); 
01322     ungetc('\n', newin); // pretend that file begins with a newline
01323     zzline = 1;
01324     zzcolumn = -1;
01325     zzline--;
01326     zzinFileName = str;
01327     yyrestart(newin); 
01328     zznumCharRead = 0;
01329 
01330       // if it is a .db file containing ground predicates
01331     if ((s.at(len-3)=='.' && s.at(len-2)=='d' && s.at(len-1)=='b'))
01332       zzparseGroundPred = true;
01333   } 
01334   else
01335     zzerr("Failed to open file %s.", str);
01336   
01337   delete [] inc;
01338   delete [] str;
01339   delete [] nl;
01340 ;}
01341     break;
01342 
01343   case 27:
01344 #line 290 "../src/parser/fol.y"
01345     { if (folDbg >= 1) printf("\\n\n"); ;}
01346     break;
01347 
01348   case 28:
01349 #line 292 "../src/parser/fol.y"
01350     { if (folDbg >= 1) printf("\\r\n"); ;}
01351     break;
01352 
01353   case 29:
01354 #line 303 "../src/parser/fol.y"
01355     { 
01356   zzconsumeToken(zztokenList,"=");
01357   zzconsumeToken(zztokenList,"{");
01358   if (folDbg >= 1) printf("= { "); 
01359   if (folDbg >= 2) printf("type_declarations: constant_declarations\n");
01360 ;}
01361     break;
01362 
01363   case 30:
01364 #line 311 "../src/parser/fol.y"
01365     {
01366   if (folDbg >= 1) printf("} ");           
01367   zzconsumeToken(zztokenList, "}");
01368   delete [] zztypeName;
01369   zztypeName = NULL;
01370 ;}
01371     break;
01372 
01373   case 31:
01374 #line 322 "../src/parser/fol.y"
01375     {
01376   const char* idf = zztokenList.removeLast();
01377   if (folDbg >= 1) printf("type t_%s ", idf);
01378   zzassert(!zzdomain->isType(idf), "expecting type to be undefined");
01379   int id = zzaddTypeToDomain(zzdomain, idf);
01380   zzassert(id >= 0,"expecting id >= 0");
01381   zzassert(zztypeName==NULL,"expecting zztypeName==NULL");
01382   zztypeName = new char[strlen(idf)+1];
01383   strcpy(zztypeName, idf);
01384   delete [] idf;
01385 ;}
01386     break;
01387 
01388   case 32:
01389 #line 335 "../src/parser/fol.y"
01390     {
01391   const char* idf = zztokenList.removeLast();
01392   if (folDbg >= 1) printf("type t_%s ", idf);
01393   zzassert(zzdomain->isType(idf),"expecting type to be defined");
01394   //zzwarn("Type %s has been declared before.",idf);
01395   zzassert(zztypeName==NULL,"expecting zztypeName==NULL");
01396   zztypeName = new char[strlen(idf)+1];
01397   strcpy(zztypeName, idf);
01398   delete [] idf;
01399 ;}
01400     break;
01401 
01402   case 34:
01403 #line 354 "../src/parser/fol.y"
01404     { if (folDbg >= 2) printf("constant_declarations: ZZ_VARIABLE\n"); ;}
01405     break;
01406 
01407   case 35:
01408 #line 356 "../src/parser/fol.y"
01409     {
01410     const char* vsc = zztokenList.removeLast();
01411     if (folDbg >= 1) printf("cd_%s ", vsc);
01412     zzaddConstantToDomain(vsc, zztypeName);
01413     delete [] vsc;
01414   ;}
01415     break;
01416 
01417   case 40:
01418 #line 373 "../src/parser/fol.y"
01419     { zzconsumeToken(zztokenList, ","); ;}
01420     break;
01421 
01422   case 41:
01423 #line 376 "../src/parser/fol.y"
01424     { 
01425     zzconsumeToken(zztokenList,"\n");
01426     zzconsumeToken(zztokenList,",");
01427     zzconsumeToken(zztokenList,"\n");
01428   ;}
01429     break;
01430 
01431   case 42:
01432 #line 383 "../src/parser/fol.y"
01433     { 
01434     zzconsumeToken(zztokenList,"\n");
01435     zzconsumeToken(zztokenList,",");
01436   ;}
01437     break;
01438 
01439   case 43:
01440 #line 389 "../src/parser/fol.y"
01441     { 
01442     zzconsumeToken(zztokenList,",");
01443     zzconsumeToken(zztokenList,"\n");
01444   ;}
01445     break;
01446 
01447   case 44:
01448 #line 399 "../src/parser/fol.y"
01449     {
01450   if (folDbg >= 2) printf("numeric_type_declarations: \n");
01451   zzconsumeToken(zztokenList,"=");
01452   zzconsumeToken(zztokenList,"{");  
01453 ;}
01454     break;
01455 
01456   case 45:
01457 #line 405 "../src/parser/fol.y"
01458     {
01459   const char* numStr = zztokenList.removeLast();
01460   if (folDbg >= 1) printf(" %s ", numStr);
01461   
01462   double d = atof(numStr);
01463   zzinitialNumDeclaration = int(d);
01464   if (d != zzinitialNumDeclaration) zzerr("constant %s must be an integer", numStr);
01465 
01466   char constStr[100];
01467   zzcreateIntConstant(constStr, zztypeName, zzinitialNumDeclaration);
01468   zzaddConstantToDomain(constStr, zztypeName);
01469 
01470   delete [] numStr;
01471 ;}
01472     break;
01473 
01474   case 46:
01475 #line 420 "../src/parser/fol.y"
01476     {
01477   zzconsumeToken(zztokenList, ",");
01478 ;}
01479     break;
01480 
01481   case 47:
01482 #line 425 "../src/parser/fol.y"
01483     {
01484   zzconsumeToken(zztokenList, "}");
01485 ;}
01486     break;
01487 
01488   case 48:
01489 #line 432 "../src/parser/fol.y"
01490     {
01491   //const char* numStr1 = zztokenList.removeLast();
01492   zzconsumeToken(zztokenList, "...");
01493   zzconsumeToken(zztokenList, ",");
01494   const char* numStr2 = zztokenList.removeLast();
01495   if (folDbg >= 1) printf("= ... , %s } ", numStr2);
01496   
01497   double d2 = atof(numStr2);
01498   int i2 = int(d2);
01499   if (d2 != i2) zzerr("constant %s must be an integer", numStr2);
01500   if (zzinitialNumDeclaration > i2)
01501     zzerr("first constant cannot be larger than last constant %s", numStr2);
01502 
01503   for (int i = zzinitialNumDeclaration + 1; i <= i2; i++)
01504   {
01505     char constStr[100];
01506     zzcreateIntConstant(constStr, zztypeName, i);
01507     zzaddConstantToDomain(constStr, zztypeName);
01508   }
01509 
01510   delete [] numStr2; delete [] zztypeName;
01511   zztypeName = NULL;
01512 ;}
01513     break;
01514 
01515   case 49:
01516 #line 457 "../src/parser/fol.y"
01517     {
01518   delete [] zztypeName;
01519   zztypeName = NULL;
01520 ;}
01521     break;
01522 
01523   case 50:
01524 #line 467 "../src/parser/fol.y"
01525     {  
01526     zzconsumeToken(zztokenList, ",");
01527     if (folDbg >= 1) printf(", "); 
01528     if (folDbg >= 2) printf("single_numeric_types: single_numeric_type\n"); 
01529   ;}
01530     break;
01531 
01532   case 53:
01533 #line 478 "../src/parser/fol.y"
01534     {
01535   const char* numStr = zztokenList.removeLast();
01536   if (folDbg >= 1) printf(" %s ", numStr);
01537   
01538   double d = atof(numStr);
01539   int i = int(d);
01540   if (d != i) zzerr("constant %s must be an integer", numStr);
01541 
01542   char constStr[100];
01543   zzcreateIntConstant(constStr, zztypeName, i);
01544   zzaddConstantToDomain(constStr, zztypeName);
01545 
01546   delete [] numStr;
01547 ;}
01548     break;
01549 
01550   case 54:
01551 #line 502 "../src/parser/fol.y"
01552     {
01553   const char* predName = zztokenList.removeLast();
01554 
01555   if (folDbg >= 1) printf("ZZ_PREDICATE pc_%s ", predName);  
01556     //predicate has not been declared a function
01557   zzassert(zzdomain->getFunctionId(predName) < 0, 
01558            "not expecting pred name to be declared as a function name");
01559   zzassert(zzpredTemplate==NULL,"expecting zzpredTemplate==NULL");
01560   zzpredTemplate = new PredicateTemplate();
01561   zzpredTemplate->setName(predName);
01562   delete [] predName;
01563 ;}
01564     break;
01565 
01566   case 55:
01567 #line 514 "../src/parser/fol.y"
01568     { if (folDbg >= 1) printf("( "); zzconsumeToken(zztokenList,"("); ;}
01569     break;
01570 
01571   case 56:
01572 #line 515 "../src/parser/fol.y"
01573     { if (folDbg >= 2) printf("predicate_declaration: types\n"); ;}
01574     break;
01575 
01576   case 57:
01577 #line 517 "../src/parser/fol.y"
01578     {  
01579   if (folDbg >= 1) printf(") "); 
01580 
01581   zzconsumeToken(zztokenList,")");
01582 
01583   zzassert(zzpredTemplate, "not expecting zzpredTemplate==NULL");
01584   int id = zzdomain->addPredicateTemplate(zzpredTemplate);
01585   zzassert(id >= 0, "expecting pred template id >= 0");
01586   zzpredTemplate->setId(id);
01587   zzpredTemplate = NULL;
01588 ;}
01589     break;
01590 
01591   case 58:
01592 #line 530 "../src/parser/fol.y"
01593     {
01594   const char* predName = zztokenList.removeLast();
01595 
01596   if (folDbg >= 1) printf("ZZ_PREDICATE pc_%s ", predName);  
01597     //predicate has not been declared a function
01598   zzassert(zzdomain->getFunctionId(predName) < 0, 
01599            "not expecting pred name to be declared as a function name");
01600   zzassert(zzpredTemplate==NULL,"expecting zzpredTemplate==NULL");
01601   zzpredTemplate = new PredicateTemplate();
01602   zzpredTemplate->setName(predName);
01603   delete [] predName;
01604 
01605         // Declare this predicate to have type "AlchemyPropositionalType"
01606   const char* varName = Domain::PROPOSITIONAL_TYPE;
01607   if (folDbg >= 1) printf("t_%s ", varName);
01608   if (!zzdomain->isType(varName))
01609   {
01610     int id = zzaddTypeToDomain(zzdomain, varName);
01611     zzassert(id >= 0, "expecting var id >= 0");
01612   }
01613   zzaddType(varName, zzpredTemplate, NULL, false, zzdomain);
01614 
01615   zzassert(zzpredTemplate, "not expecting zzpredTemplate==NULL");
01616   int templateId = zzdomain->addPredicateTemplate(zzpredTemplate);
01617   zzassert(templateId >= 0, "expecting pred template id >= 0");
01618   zzpredTemplate->setId(templateId);
01619   zzpredTemplate = NULL;
01620 ;}
01621     break;
01622 
01623   case 59:
01624 #line 566 "../src/parser/fol.y"
01625     { 
01626   const char* retTypeName = zztokenList.removeLast();
01627   if (folDbg >= 1) printf("ZZ_FUNCTION t_%s ", retTypeName); 
01628   if (folDbg >= 2) printf("function_declaration: ZZ_VARIABLE\n"); 
01629 
01630   if (!zzdomain->isType(retTypeName))
01631   {
01632     int id = zzaddTypeToDomain(zzdomain, retTypeName);
01633     zzassert(id >= 0, "expecting retTypeName's id >= 0");
01634   }
01635 
01636   zzassert(zzfuncTemplate==NULL, "expecting zzfuncTemplate==NULL");
01637   zzfuncTemplate = new FunctionTemplate();
01638   zzfuncTemplate->setRetTypeName(retTypeName,zzdomain);
01639 
01640   // We are creating a new predicate as well
01641   zzassert(zzpredTemplate==NULL,"expecting zzpredTemplate==NULL");
01642   zzpredTemplate = new PredicateTemplate();
01643   zzaddType(retTypeName, zzpredTemplate, NULL, false, zzdomain);
01644 
01645   delete [] retTypeName;
01646 ;}
01647     break;
01648 
01649   case 60:
01650 #line 589 "../src/parser/fol.y"
01651     {
01652   const char* funcName = zztokenList.removeLast();
01653 
01654   if (folDbg >= 1) printf("fc_%s ", funcName); 
01655   zzassert(zzdomain->getPredicateId(funcName) < 0, 
01656            "not expecting func name to be declared as pred name");
01657   zzfuncTemplate->setName(funcName);
01658 
01659   // Predicate name is PredicateTemplate::ZZ_RETURN_PREFIX + function name
01660   char* predName;
01661   predName = (char *)malloc((strlen(PredicateTemplate::ZZ_RETURN_PREFIX) +
01662                                                         strlen(funcName) + 1)*sizeof(char));
01663   strcpy(predName, PredicateTemplate::ZZ_RETURN_PREFIX);
01664   strcat(predName, funcName);
01665         
01666   // Check that predicate has not been declared a function
01667   zzassert(zzdomain->getFunctionId(predName) < 0, 
01668            "not expecting pred name to be declared as a function name");
01669   zzassert(zzpredTemplate,"expecting zzpredTemplate!=NULL");
01670   zzpredTemplate->setName(predName);
01671 
01672   free(predName);
01673   delete [] funcName;
01674 ;}
01675     break;
01676 
01677   case 61:
01678 #line 614 "../src/parser/fol.y"
01679     {
01680   zzconsumeToken(zztokenList,"(");
01681   if (folDbg >= 1) printf("( "); 
01682   if (folDbg >= 2) printf("function_declaration: types\n"); 
01683 ;}
01684     break;
01685 
01686   case 62:
01687 #line 620 "../src/parser/fol.y"
01688     {  
01689   zzconsumeToken(zztokenList,")");
01690   if (folDbg >= 1) printf(") "); 
01691   zzassert(zzfuncTemplate, "expecting zzfuncTemplate != NULL");
01692   int id = zzdomain->addFunctionTemplate(zzfuncTemplate);
01693   zzassert(id >= 0, "expecting function template's id >= 0");
01694   zzfuncTemplate->setId(id);
01695   zzfuncTemplate = NULL;
01696 
01697   zzassert(zzpredTemplate, "not expecting zzpredTemplate==NULL");
01698   // Predicate could already be there
01699   if (!zzdomain->isPredicate(zzpredTemplate->getName()))
01700   {
01701     int predId = zzdomain->addPredicateTemplate(zzpredTemplate);
01702     zzassert(predId >= 0, "expecting pred template id >= 0");
01703     zzpredTemplate->setId(predId);
01704   }
01705   zzpredTemplate = NULL;
01706 
01707 ;}
01708     break;
01709 
01710   case 65:
01711 #line 649 "../src/parser/fol.y"
01712     { if (folDbg >= 1) printf(", "); zzconsumeToken(zztokenList,","); ;}
01713     break;
01714 
01715   case 67:
01716 #line 653 "../src/parser/fol.y"
01717     { if (folDbg >= 1) printf(", "); zzconsumeToken(zztokenList,","); ;}
01718     break;
01719 
01720   case 71:
01721 #line 661 "../src/parser/fol.y"
01722     {  
01723   const char* ttype = zztokenList.removeLast();
01724   if (folDbg >= 1) printf("t_%s ", ttype);
01725   zzaddType(ttype, zzpredTemplate, NULL, false, zzdomain);
01726   // If we are in a function definition, then add the type to the function too
01727   if (zzfuncTemplate)
01728         zzaddType(ttype, NULL, zzfuncTemplate, false, zzdomain);
01729   delete [] ttype;
01730 ;}
01731     break;
01732 
01733   case 73:
01734 #line 673 "../src/parser/fol.y"
01735     {
01736   const char* varName = zztokenList.removeLast();
01737   if (folDbg >= 1) printf("t_%s ", varName);
01738   zzassert(!zzdomain->isType(varName), "expecting varName to be not a type");
01739   int id = zzaddTypeToDomain(zzdomain, varName);
01740   zzassert(id >= 0, "expecting var id >= 0");
01741   zzaddType(varName, zzpredTemplate, NULL, false, zzdomain);
01742   // If we are in a function definition, then add the type to the function too
01743   if (zzfuncTemplate)
01744         zzaddType(varName, NULL, zzfuncTemplate, false, zzdomain);
01745   delete [] varName;
01746 ;}
01747     break;
01748 
01749   case 75:
01750 #line 689 "../src/parser/fol.y"
01751     {
01752   ;}
01753     break;
01754 
01755   case 76:
01756 #line 692 "../src/parser/fol.y"
01757     {
01758     zzconsumeToken(zztokenList, "!");
01759     if (folDbg >= 1) printf("! "); 
01760     if (zzfuncTemplate)
01761       zzerr("'!' cannot be used in a function declaration.");
01762     zzassert(zzpredTemplate, "'!' used outside a predicate declaration.");
01763 
01764     int termIdx = zzpredTemplate->getNumTerms()-1;
01765     zzpredTemplate->addUniqueVarIndex(termIdx);
01766   ;}
01767     break;
01768 
01769   case 77:
01770 #line 708 "../src/parser/fol.y"
01771     { 
01772     zztrueFalseUnknown = 't';
01773   ;}
01774     break;
01775 
01776   case 78:
01777 #line 712 "../src/parser/fol.y"
01778     { 
01779     zzconsumeToken(zztokenList,"!"); 
01780     if (folDbg >= 1) printf("! "); 
01781     zztrueFalseUnknown = 'f';
01782   ;}
01783     break;
01784 
01785   case 79:
01786 #line 718 "../src/parser/fol.y"
01787     { 
01788     zzconsumeToken(zztokenList,"?"); 
01789     if (folDbg >= 1) printf("? "); 
01790     zztrueFalseUnknown = 'u';
01791   ;}
01792     break;
01793 
01794   case 80:
01795 #line 729 "../src/parser/fol.y"
01796     {
01797   const char* predName = zztokenList.removeLast();
01798   if (folDbg >= 1) printf("pd_%s ", predName); 
01799   
01800   zzcreatePred(zzpred, predName);
01801   if (zztrueFalseUnknown == 't')      zzpred->setTruthValue(TRUE);
01802   else if (zztrueFalseUnknown == 'f') zzpred->setTruthValue(FALSE);
01803   else if (zztrueFalseUnknown == 'u') zzpred->setTruthValue(UNKNOWN);
01804   else { zzassert(false, "expecting t,f,u"); }
01805 
01806   delete [] predName;
01807 ;}
01808     break;
01809 
01810   case 81:
01811 #line 742 "../src/parser/fol.y"
01812     {  
01813   zzcheckPredNumTerm(zzpred);
01814   int predId = zzpred->getId();
01815   hash_map<int,PredicateHashArray*>::iterator it;
01816   if ((it=zzpredIdToGndPredMap.find(predId)) == zzpredIdToGndPredMap.end())
01817     zzpredIdToGndPredMap[predId] = new PredicateHashArray;
01818   
01819   PredicateHashArray* pha = zzpredIdToGndPredMap[predId];
01820   if (pha->append(zzpred) < 0)
01821   {
01822     int a = pha->find(zzpred);
01823     zzassert(a >= 0, "expecting ground predicate to be found");
01824     string origTvStr = (*pha)[a]->getTruthValueAsStr();
01825     (*pha)[a]->setTruthValue(zzpred->getTruthValue());
01826     string newTvStr = (*pha)[a]->getTruthValueAsStr();
01827 
01828     if (zzwarnDuplicates)
01829     {
01830       ostringstream oss;
01831       oss << "Duplicate ground predicate "; zzpred->print(oss, zzdomain); 
01832       oss << " found. ";
01833       if (origTvStr.compare(newTvStr) != 0)
01834         oss << "Changed its truthValue from " << origTvStr << " to " <<newTvStr 
01835             << endl;
01836       zzwarn(oss.str().c_str());
01837     }
01838     delete zzpred;
01839   }
01840   zzpred = NULL;
01841 ;}
01842     break;
01843 
01844   case 82:
01845 #line 775 "../src/parser/fol.y"
01846     {
01847   // Add the one constant for propositional case
01848   const char* constName = Domain::PROPOSITIONAL_CONSTANT;
01849   if (folDbg >= 1) printf("cg_%s ", constName);
01850   zzaddConstantToPredFunc(constName);
01851 ;}
01852     break;
01853 
01854   case 83:
01855 #line 783 "../src/parser/fol.y"
01856     { 
01857   zzconsumeToken(zztokenList,"("); 
01858   if (folDbg >= 1) printf("( "); 
01859   if (folDbg >= 2) printf("predicate_definition: constants_in_groundings\n");
01860 ;}
01861     break;
01862 
01863   case 84:
01864 #line 789 "../src/parser/fol.y"
01865     { 
01866   zzconsumeToken(zztokenList,")"); 
01867   if (folDbg >= 1) printf(")\n"); 
01868 ;}
01869     break;
01870 
01871   case 85:
01872 #line 799 "../src/parser/fol.y"
01873     { 
01874   zzconsumeToken(zztokenList,"="); 
01875   if (folDbg >= 1) printf("= "); 
01876   if (folDbg >= 2) printf("function_definition: constants_in_groundings\n");
01877 ;}
01878     break;
01879 
01880   case 86:
01881 #line 805 "../src/parser/fol.y"
01882     {
01883   // Predicate name is PredicateTemplate::ZZ_RETURN_PREFIX + function name
01884   const char* funcName = zztokenList.removeLast();
01885   char* predName;
01886   predName = (char *)malloc((strlen(PredicateTemplate::ZZ_RETURN_PREFIX) +
01887                                                         strlen(funcName) + 1)*sizeof(char));
01888   strcpy(predName, PredicateTemplate::ZZ_RETURN_PREFIX);
01889   strcat(predName, funcName);
01890 
01891   if (folDbg >= 1) printf("pd_%s ", predName); 
01892   
01893   zzcreatePred(zzpred, predName);
01894   zzpred->setTruthValue(TRUE);
01895 
01896   char constName[100];
01897   char* constString;
01898   if (zztmpReturnNum)
01899   {
01900         zzcreateAndCheckNumConstant(zztmpReturnConstant, zzfunc, zzpred, zzdomain, constName);
01901     if (constName == NULL)
01902     {
01903       constString = (char *)malloc((strlen(zztmpReturnConstant) + 1)*sizeof(char));
01904       strcpy(constString, zztmpReturnConstant);
01905     } else
01906     {
01907           constString = (char *)malloc((strlen(constName) + 1)*sizeof(char));
01908       strcpy(constString, constName);
01909     }
01910   }
01911   else
01912   {
01913     constString = (char *)malloc((strlen(zztmpReturnConstant) + 1)*sizeof(char));  
01914         strcpy(constString, zztmpReturnConstant);
01915   }
01916 
01917   //Add return constant parsed earlier
01918   zzaddConstantToPredFunc(constString);
01919 
01920   zztmpReturnNum = false;
01921   free(zztmpReturnConstant);
01922   delete [] funcName;
01923   free(predName);
01924   free(constString);
01925 ;}
01926     break;
01927 
01928   case 87:
01929 #line 850 "../src/parser/fol.y"
01930     { 
01931   zzconsumeToken(zztokenList,"("); 
01932   if (folDbg >= 1) printf("( "); 
01933   if (folDbg >= 2) printf("function_definition: constants_in_groundings\n");
01934 ;}
01935     break;
01936 
01937   case 88:
01938 #line 856 "../src/parser/fol.y"
01939     { 
01940   zzconsumeToken(zztokenList,")"); 
01941   if (folDbg >= 1) printf(")\n"); 
01942   
01943   zzcheckPredNumTerm(zzpred);
01944   int predId = zzpred->getId();
01945   hash_map<int,PredicateHashArray*>::iterator it;
01946   if ((it=zzpredIdToGndPredMap.find(predId)) == zzpredIdToGndPredMap.end())
01947     zzpredIdToGndPredMap[predId] = new PredicateHashArray;
01948   
01949   PredicateHashArray* pha = zzpredIdToGndPredMap[predId];
01950   if (pha->append(zzpred) < 0)
01951   {
01952     int a = pha->find(zzpred);
01953     zzassert(a >= 0, "expecting ground predicate to be found");
01954     string origTvStr = (*pha)[a]->getTruthValueAsStr();
01955     (*pha)[a]->setTruthValue(zzpred->getTruthValue());
01956     string newTvStr = (*pha)[a]->getTruthValueAsStr();
01957 
01958     if (zzwarnDuplicates)
01959     {
01960       ostringstream oss;
01961       oss << "Duplicate ground predicate "; zzpred->print(oss, zzdomain); 
01962       oss << " found. ";
01963       if (origTvStr.compare(newTvStr) != 0)
01964         oss << "Changed its truthValue from " << origTvStr << " to " <<newTvStr 
01965             << endl;
01966       zzwarn(oss.str().c_str());
01967     }
01968     //delete zzpred;
01969   }
01970 
01971   // Insert FALSE for all other return values
01972 
01973   zzpred = NULL;
01974 ;}
01975     break;
01976 
01977   case 89:
01978 #line 896 "../src/parser/fol.y"
01979     {     
01980     const char* constName = zztokenList.removeLast();
01981     if (folDbg >= 1) printf("cg_%s ", constName);
01982     zzaddConstantToPredFunc(constName);
01983     delete [] constName;
01984   ;}
01985     break;
01986 
01987   case 90:
01988 #line 904 "../src/parser/fol.y"
01989     {     
01990     const char* constName = zztokenList.removeLast();
01991     if (folDbg >= 1) printf("cg_%s ", constName);
01992     zzaddConstantToPredFunc(constName);
01993     delete [] constName;
01994   ;}
01995     break;
01996 
01997   case 92:
01998 #line 915 "../src/parser/fol.y"
01999     {
02000     if (zzconstantMustBeDeclared)
02001       zzerr("Constant %s must be declared before it is used.",
02002             zztokenList.back());
02003   ;}
02004     break;
02005 
02006   case 93:
02007 #line 921 "../src/parser/fol.y"
02008     {
02009     const char* intStr = zztokenList.removeLast();
02010     char constName[100];
02011     zzcreateAndCheckNumConstant(intStr, zzfunc, zzpred, zzdomain, constName);
02012     if (constName == NULL) zztokenList.addLast(intStr);
02013     else                   zztokenList.addLast(constName);
02014     delete [] intStr;
02015   ;}
02016     break;
02017 
02018   case 94:
02019 #line 930 "../src/parser/fol.y"
02020     {
02021     if (zzconstantMustBeDeclared)
02022       zzerr("Constant %s must be declared before it is used",
02023             zztokenList.back());
02024   ;}
02025     break;
02026 
02027   case 95:
02028 #line 938 "../src/parser/fol.y"
02029     {
02030     const char* tmp = zztokenList.removeLast();
02031         zztmpReturnConstant = (char *)malloc((strlen(tmp) + 1)*sizeof(char));
02032         strcpy(zztmpReturnConstant, tmp);
02033         zztmpReturnNum = false;
02034         delete []tmp;
02035         if (folDbg >= 1) printf("ic_%s ", zztmpReturnConstant); 
02036   ;}
02037     break;
02038 
02039   case 96:
02040 #line 947 "../src/parser/fol.y"
02041     {
02042     if (zzconstantMustBeDeclared)
02043       zzerr("Constant %s must be declared before it is used.",
02044             zztokenList.back());
02045     const char* tmp = zztokenList.removeLast();
02046         zztmpReturnConstant = (char *)malloc((strlen(tmp) + 1)*sizeof(char));
02047         strcpy(zztmpReturnConstant, tmp);
02048         zztmpReturnNum = false;
02049         delete []tmp;
02050         if (folDbg >= 1) printf("ic_%s ", zztmpReturnConstant);
02051   ;}
02052     break;
02053 
02054   case 97:
02055 #line 959 "../src/parser/fol.y"
02056     {
02057         const char* tmp = zztokenList.removeLast();
02058         zztmpReturnConstant = (char *)malloc((strlen(tmp) + 1)*sizeof(char));
02059         strcpy(zztmpReturnConstant, tmp);
02060         zztmpReturnNum = true;
02061         delete []tmp;
02062         if (folDbg >= 1) printf("icnum_%s ", zztmpReturnConstant); 
02063   ;}
02064     break;
02065 
02066   case 98:
02067 #line 968 "../src/parser/fol.y"
02068     {
02069     if (zzconstantMustBeDeclared)
02070       zzerr("Constant %s must be declared before it is used",
02071             zztokenList.back());
02072     const char* tmp = zztokenList.removeLast();
02073         zztmpReturnConstant = (char *)malloc((strlen(tmp) + 1)*sizeof(char));
02074         strcpy(zztmpReturnConstant, tmp);
02075         zztmpReturnNum = false;
02076         delete []tmp;
02077         if (folDbg >= 1) printf("ic_%s ", zztmpReturnConstant);
02078   ;}
02079     break;
02080 
02081   case 100:
02082 #line 986 "../src/parser/fol.y"
02083     {
02084     const char* wt = zztokenList.removeLast();
02085     if (folDbg >= 1) printf("n_%f ", atof(wt));
02086     if (zzwt) delete zzwt;
02087     zzwt = new double(atof(wt));
02088     delete [] wt;
02089   ;}
02090     break;
02091 
02092   case 101:
02093 #line 1000 "../src/parser/fol.y"
02094     { 
02095       // Square Brackets
02096     zzconsumeToken(zztokenList,"["); 
02097     if (folDbg >= 1) printf("[ "); 
02098     if (folDbg >= 2) printf("sentence: '[' sentence\n");
02099     zzformulaStr.append("[");
02100     zzinIndivisible = true;
02101   ;}
02102     break;
02103 
02104   case 102:
02105 #line 1010 "../src/parser/fol.y"
02106     { 
02107     zzconsumeToken(zztokenList,"]"); 
02108     if (folDbg >= 1) printf("] "); 
02109     zzformulaStr.append("]");
02110     //zzinIndivisible = false;
02111   ;}
02112     break;
02113 
02114   case 103:
02115 #line 1018 "../src/parser/fol.y"
02116     { 
02117     zzconsumeToken(zztokenList,"("); 
02118     if (folDbg >= 1) printf("( "); 
02119     if (folDbg >= 2) printf("sentence: '(' sentence\n");
02120     zzformulaStr.append("(");
02121   ;}
02122     break;
02123 
02124   case 104:
02125 #line 1026 "../src/parser/fol.y"
02126     { 
02127     zzconsumeToken(zztokenList,")"); 
02128     if (folDbg >= 1) printf(") "); 
02129     zzformulaStr.append(")");
02130   ;}
02131     break;
02132 
02133   case 105:
02134 #line 1032 "../src/parser/fol.y"
02135     { if (folDbg >= 2) printf("sentence: atomic_sentence\n"); ;}
02136     break;
02137 
02138   case 107:
02139 #line 1036 "../src/parser/fol.y"
02140     {
02141     // Indicator
02142     if (folDbg >= 2) printf("sentence: indicator function\n");
02143     zzconsumeToken(zztokenList,"*"); 
02144     if (folDbg >= 1) printf("* "); 
02145     zzformulaStr.append(" * ");
02146   ;}
02147     break;
02148 
02149   case 108:
02150 #line 1044 "../src/parser/fol.y"
02151     {
02152         // real-valued
02153     if (folDbg >= 2) printf("sentence: numeric term\n");
02154   ;}
02155     break;
02156 
02157   case 109:
02158 #line 1050 "../src/parser/fol.y"
02159     {
02160     const char* imp = zztokenList.removeLast(); 
02161     if (folDbg >= 1) printf("=> ");
02162     zzformulaStr.append(" => ");
02163     delete [] imp;
02164   ;}
02165     break;
02166 
02167   case 110:
02168 #line 1058 "../src/parser/fol.y"
02169     { zzcreateListObjFromTopTwo(zzformulaListObjs, "=>"); ;}
02170     break;
02171 
02172   case 111:
02173 #line 1062 "../src/parser/fol.y"
02174     { 
02175     const char* eq = zztokenList.removeLast(); 
02176     if (folDbg >= 1) printf("<=> ");
02177     zzformulaStr.append(" <=> ");
02178     delete [] eq;  
02179   ;}
02180     break;
02181 
02182   case 112:
02183 #line 1070 "../src/parser/fol.y"
02184     { zzcreateListObjFromTopTwo(zzformulaListObjs, "<=>"); ;}
02185     break;
02186 
02187   case 113:
02188 #line 1074 "../src/parser/fol.y"
02189     { 
02190     zzconsumeToken(zztokenList,"v"); 
02191     if (folDbg >= 1) printf("v "); 
02192     zzformulaStr.append(" v ");
02193   ;}
02194     break;
02195 
02196   case 114:
02197 #line 1081 "../src/parser/fol.y"
02198     { zzcreateListObjFromTopTwo(zzformulaListObjs, "v"); ;}
02199     break;
02200 
02201   case 115:
02202 #line 1085 "../src/parser/fol.y"
02203     { 
02204     zzconsumeToken(zztokenList,"^"); 
02205     if (folDbg >= 1) printf("^ "); 
02206     zzformulaStr.append(" ^ ");
02207   ;}
02208     break;
02209 
02210   case 116:
02211 #line 1092 "../src/parser/fol.y"
02212     { zzcreateListObjFromTopTwo(zzformulaListObjs, "^"); ;}
02213     break;
02214 
02215   case 117:
02216 #line 1096 "../src/parser/fol.y"
02217     { if (folDbg >= 2) printf("sentence: quantifier\n"); ;}
02218     break;
02219 
02220   case 118:
02221 #line 1098 "../src/parser/fol.y"
02222     { 
02223     if (folDbg >= 2) printf("sentence: variables\n"); 
02224     zzformulaListObjs.push(new ListObj);
02225     pair<StringToStringMap*,int> pr(new StringToStringMap,zzscopeCounter++);
02226     zzoldNewVarList.push_front(pr);
02227   ;}
02228     break;
02229 
02230   case 119:
02231 #line 1104 "../src/parser/fol.y"
02232     { if (folDbg >= 2) printf("sentence: sentence\n"); ;}
02233     break;
02234 
02235   case 120:
02236 #line 1106 "../src/parser/fol.y"
02237     { 
02238     zzcreateListObjFromTopThree(zzformulaListObjs);
02239     pair<StringToStringMap*, int> pr = zzoldNewVarList.front();
02240     zzoldNewVarList.pop_front();
02241     delete pr.first;
02242   ;}
02243     break;
02244 
02245   case 121:
02246 #line 1115 "../src/parser/fol.y"
02247     { 
02248     zzassert(!zzisNegated,"expecting !zzisNegated");
02249     zzisNegated = true;
02250 
02251     zzconsumeToken(zztokenList,"!");
02252     if (folDbg >= 1) printf("! "); 
02253     if (folDbg >= 2) printf("sentence: sentence\n");
02254     zzformulaStr.append("!");
02255   ;}
02256     break;
02257 
02258   case 122:
02259 #line 1125 "../src/parser/fol.y"
02260     { zzcreateListObjFromTop(zzformulaListObjs, "!"); ;}
02261     break;
02262 
02263   case 123:
02264 #line 1131 "../src/parser/fol.y"
02265     { 
02266     const char* fa = zztokenList.removeLast();
02267     if (folDbg >= 1) printf("FORALL ");
02268     zzformulaListObjs.push(new ListObj("FORALL"));
02269     zzformulaStr.append("FORALL ");
02270     delete [] fa;
02271   ;}
02272     break;
02273 
02274   case 124:
02275 #line 1139 "../src/parser/fol.y"
02276     { 
02277     const char* ex = zztokenList.removeLast();
02278     if (folDbg >= 1) printf("EXIST "); 
02279     zzformulaListObjs.push(new ListObj("EXIST"));
02280     zzformulaStr.append("EXIST ");
02281     delete [] ex;
02282   ;}
02283     break;
02284 
02285   case 125:
02286 #line 1151 "../src/parser/fol.y"
02287     { if (folDbg >= 2) printf("variables: variables\n"); ;}
02288     break;
02289 
02290   case 126:
02291 #line 1153 "../src/parser/fol.y"
02292     {  
02293     zzconsumeToken(zztokenList,",");
02294     if (folDbg >= 1) printf(", "); 
02295     zzformulaStr.append(",");
02296   ;}
02297     break;
02298 
02299   case 128:
02300 #line 1160 "../src/parser/fol.y"
02301     { zzformulaStr.append(" "); ;}
02302     break;
02303 
02304   case 129:
02305 #line 1165 "../src/parser/fol.y"
02306     {
02307   const char* varName = zztokenList.removeLast();  
02308   if (folDbg >= 1) printf("v_%s ", varName); 
02309 
02310   //if (isupper(varName[0])) 
02311   if (zzisConstant(varName)) 
02312   {
02313     zzerr("Variable %s must be begin with a lowercase character.", varName);
02314     ((char*)varName)[0] = tolower(varName[0]);
02315   }
02316 
02317   int scopeNum = zzoldNewVarList.front().second;
02318   string newVarName = zzappend(varName,scopeNum);
02319 
02320   StringToStringMap* oldNewVarMap = zzoldNewVarList.front().first;
02321   (*oldNewVarMap)[varName]=newVarName;
02322   zzvarNameToIdMap[newVarName] = ZZVarIdType(--zzvarCounter, zzanyTypeId);
02323   zzformulaListObjs.top()->append(newVarName.c_str());
02324   zzformulaStr.append(varName); //use the old var name in the orig string
02325   delete [] varName;
02326 ;}
02327     break;
02328 
02329   case 130:
02330 #line 1191 "../src/parser/fol.y"
02331     {
02332     const char* predName = zztokenList.removeLast();
02333     if (folDbg >= 1) printf("p_%s ", predName); 
02334 
02335     zzfdnumPreds++;
02336     ListObj* predlo = new ListObj;
02337 
02338         if (PredicateTemplate::isInternalPredicateTemplateName(predName))
02339         {
02340           //zzinfixPredName is misused here to store internal pred. name
02341           zzinfixPredName = (char *)malloc((strlen(predName)
02342                                                                         + 1)*sizeof(char));
02343           strcpy(zzinfixPredName, predName);
02344           const PredicateTemplate* t = zzdomain->getEmptyPredicateTemplate();
02345       zzassert(zzpred == NULL,"expecting zzpred==NULL");
02346       zzpred = new Predicate(t);
02347       predlo->append(PredicateTemplate::EMPTY_NAME);
02348         }
02349         else
02350         {
02351       zzcreatePred(zzpred, predName);
02352       predlo->append(predName);
02353         }
02354         
02355     zzformulaStr.append(predName);
02356     if(zzisNegated)  { zzpred->setSense(false); zzisNegated = false; }
02357     zzpredFuncListObjs.push(predlo);
02358     delete [] predName;
02359   ;}
02360     break;
02361 
02362   case 132:
02363 #line 1223 "../src/parser/fol.y"
02364     {
02365     ++zzfdnumPreds;
02366     //zzfdisEqualPred = true;
02367     //const PredicateTemplate* t = zzdomain->getEqualPredicateTemplate();
02368     const PredicateTemplate* t = zzdomain->getEmptyPredicateTemplate();
02369 
02370     zzassert(zzpred == NULL, "expecting zzpred==NULL");
02371     zzpred = new Predicate(t);
02372 
02373     ListObj* predlo = new ListObj;
02374     //predlo->append(PredicateTemplate::EQUAL_NAME);
02375     predlo->append(PredicateTemplate::EMPTY_NAME);
02376     zzpredFuncListObjs.push(predlo);
02377     if (zzisNegated)  { zzpred->setSense(false); zzisNegated = false; }
02378 
02379     if (folDbg >= 2) printf("atomic_sentence (left): term\n"); 
02380   ;}
02381     break;
02382 
02383   case 133:
02384 #line 1242 "../src/parser/fol.y"
02385     {
02386         ListObj* predlo = zzpredFuncListObjs.top();
02387     predlo->replace(PredicateTemplate::EMPTY_NAME, zzinfixPredName);
02388     
02389           // If type known from LHS, then set the pred types accordingly
02390     int lTypeId = zzgetTypeId(zzpred->getTerm(0), (*predlo)[1]->getStr());
02391     if (lTypeId > 0)
02392     {
02393       if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02394       {
02395         zzsetEqPredTypeName(lTypeId);
02396       }
02397       else
02398           {
02399             zzsetInternalPredTypeName(zzinfixPredName, lTypeId);
02400           }
02401     }
02402   ;}
02403     break;
02404 
02405   case 134:
02406 #line 1261 "../src/parser/fol.y"
02407     {  
02408     ListObj* predlo = zzpredFuncListObjs.top();
02409     //predlo->replace(PredicateTemplate::EMPTY_NAME, zzinfixPredName);
02410 
02411         // types are possibly unknown
02412         // If '=' predicate then types are possibly unknown
02413         //if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0) {
02414       int lTypeId = zzgetTypeId(zzpred->getTerm(0), (*predlo)[1]->getStr());
02415       int rTypeId = zzgetTypeId(zzpred->getTerm(1), (*predlo)[2]->getStr());
02416 
02417       if (lTypeId > 0 && rTypeId > 0) //if both types are known
02418       {
02419         if (lTypeId != rTypeId)
02420           zzerr("The types on the left and right of '=' must match.");
02421         if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02422         {
02423               zzsetEqPredTypeName(lTypeId);
02424             }
02425             else
02426             {
02427               zzsetInternalPredTypeName(zzinfixPredName, lTypeId);
02428             }
02429       }
02430       else  // if only one type is known
02431       if ( (lTypeId<=0 && rTypeId>0) || (lTypeId>0 && rTypeId<=0) )
02432       {
02433         int knownTypeId = (lTypeId>0) ? lTypeId : rTypeId;
02434         if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02435         {
02436           zzsetEqPredTypeName(knownTypeId);
02437         }
02438         else
02439             {
02440               zzsetInternalPredTypeName(zzinfixPredName, knownTypeId);
02441             }
02442         const char* lvarName = (*predlo)[1]->getStr();
02443         const char* rvarName = (*predlo)[2]->getStr();
02444         const char* unknownVarName = (lTypeId>0) ?  rvarName : lvarName;
02445         zzvarNameToIdMap[unknownVarName].typeId_ = knownTypeId;
02446       }
02447       else // if both types are unknown
02448       {
02449           //both sides must be variables
02450         const char* lvarName = (*predlo)[1]->getStr();
02451         const char* rvarName = (*predlo)[2]->getStr();
02452         lTypeId = zzgetVarTypeId(lvarName);
02453         rTypeId = zzgetVarTypeId(rvarName);
02454         
02455         if (lTypeId > 0 && rTypeId > 0) //if both types are known
02456         {
02457           if (lTypeId != rTypeId)
02458             zzerr("The types of %s and %s on the left and right of "
02459                    "'=' must match.", lvarName, rvarName);
02460           if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02461           {
02462                 zzsetEqPredTypeName(lTypeId);
02463           }
02464           else
02465               {
02466                 zzsetInternalPredTypeName(zzinfixPredName, lTypeId);
02467               }
02468         }
02469         else  // if only one type is known
02470         if ( (lTypeId <= 0 && rTypeId > 0) || (lTypeId > 0 && rTypeId <= 0) )
02471         {
02472           int knownTypeId = (lTypeId > 0) ? lTypeId : rTypeId;
02473           if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME) == 0)
02474           {
02475                 zzsetEqPredTypeName(knownTypeId);
02476           }
02477           else
02478               {
02479                 zzsetInternalPredTypeName(zzinfixPredName, knownTypeId);
02480               }
02481           const char* unknowVarName = (lTypeId>0) ?  rvarName : lvarName;
02482           zzvarNameToIdMap[unknowVarName].typeId_ = knownTypeId;
02483         }
02484         else
02485         {      
02486                   if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02487           {
02488                 string unknownEqName = zzappend(PredicateTemplate::EQUAL_NAME, 
02489                                             zzeqTypeCounter++);
02490                 zzeqPredList.push_back(ZZUnknownEqPredInfo(unknownEqName,lvarName,
02491                                                        rvarName));
02492                 predlo->replace(PredicateTemplate::EQUAL_NAME, unknownEqName.c_str());
02493           }
02494           else
02495           {
02496                 string unknownIntPredName =
02497                   zzappendWithUnderscore(zzinfixPredName, zzintPredTypeCounter++);
02498                 zzintPredList.push_back(ZZUnknownIntPredInfo(unknownIntPredName, lvarName,
02499                                                          rvarName));
02500                 predlo->replace(zzinfixPredName, unknownIntPredName.c_str());
02501           }
02502         }
02503       }
02504         //}
02505         //else // Infix predicate other than '='
02506         //{
02507           //Only left term could be unknown
02508           //const char* leftTerm = (*predlo)[1]->getStr();
02509         //}
02510 
02511     zzassert(zzpredFuncListObjs.size()==1,
02512              "expecting zzpredFuncListObjs.size()==1");
02513     ListObj* topPredlo = zzpredFuncListObjs.top();
02514     zzpredFuncListObjs.pop();
02515     zzformulaListObjs.push(topPredlo);
02516       // This allows for the '!=' operator
02517     if (zzisNegated)
02518     {
02519       zzcreateListObjFromTop(zzformulaListObjs, "!");
02520       zzisNegated = false;
02521     }
02522     
02523         delete zzpred;
02524         zzpred = NULL;
02525         
02526         // If we have replaced a function inside the predicate
02527         // then we have to add the conjunction
02528         while (!zzfuncConjStack.empty())
02529         {
02530           // create the second part of the conjunction
02531           //zzformulaStr.append(" ^ ");
02532                 
02533       ListObj* topPredlo = zzfuncConjStack.top();
02534           zzfuncConjStack.pop();
02535       //zzformulaListObjs.push(topPredlo);
02536           //zzcreateListObjFromTopTwo(zzformulaListObjs, "^");
02537           zzformulaListObjs.push(topPredlo);
02538           zzcreateListObjFromTopTwo(zzformulaListObjs, "v");
02539         } //while (!zzfuncConjStack.empty())
02540 
02541         if (!zzfuncConjStr.empty())
02542         {
02543           zzformulaStr.append(zzfuncConjStr);
02544           zzfuncConjStr.clear();
02545         }
02546         zzfunc = NULL;
02547         free(zzinfixPredName);
02548     zzinfixPredName = NULL;
02549   ;}
02550     break;
02551 
02552   case 135:
02553 #line 1408 "../src/parser/fol.y"
02554     {
02555         // Add the one constant for propositional case
02556     const char* constName = Domain::PROPOSITIONAL_CONSTANT;
02557     if (folDbg >= 1) printf("c2_%s ", constName); 
02558     zztermIsConstant(constName, constName, false);
02559 
02560     zzcheckPredNumTerm(zzpred);
02561     delete zzpred;
02562     zzpred = NULL;
02563     zzassert(zzpredFuncListObjs.size()==1,
02564              "expecting zzpredFuncListObjs.size()==1");
02565     ListObj* predlo = zzpredFuncListObjs.top();
02566     zzpredFuncListObjs.pop();
02567     zzformulaListObjs.push(predlo);
02568   ;}
02569     break;
02570 
02571   case 136:
02572 #line 1425 "../src/parser/fol.y"
02573     {  
02574     zzconsumeToken(zztokenList, "(");
02575     if (folDbg >= 1) printf("( "); 
02576     if (folDbg >= 2) printf("atomic_sentence: terms\n"); 
02577     zzformulaStr.append("(");
02578   ;}
02579     break;
02580 
02581   case 137:
02582 #line 1433 "../src/parser/fol.y"
02583     {  
02584     zzconsumeToken(zztokenList, ")");
02585     if (folDbg >= 1) printf(") "); 
02586 
02587           //If an internal pred., then need to determine type
02588           //zzinfixPredName is misused here to store internal pred. name
02589         if (zzinfixPredName)
02590         {
02591           ListObj* predlo = zzpredFuncListObjs.top();
02592       predlo->replace(PredicateTemplate::EMPTY_NAME, zzinfixPredName);
02593                 // types are possibly unknown
02594                 // If '=' predicate then types are possibly unknown
02595                 //if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0) {
02596       int lTypeId = zzgetTypeId(zzpred->getTerm(0), (*predlo)[1]->getStr());
02597       int rTypeId = zzgetTypeId(zzpred->getTerm(1), (*predlo)[2]->getStr());
02598 
02599       if (lTypeId > 0 && rTypeId > 0) //if both types are known
02600       {
02601         if (lTypeId != rTypeId)
02602           zzerr("The types on the left and right of '=' must match.");
02603         if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02604         {
02605               zzsetEqPredTypeName(lTypeId);
02606             }
02607             else
02608             {
02609               zzsetInternalPredTypeName(zzinfixPredName, lTypeId);
02610             }
02611       }
02612       else  // if only one type is known
02613       if ( (lTypeId<=0 && rTypeId>0) || (lTypeId>0 && rTypeId<=0) )
02614       {
02615         int knownTypeId = (lTypeId>0) ? lTypeId : rTypeId;
02616         if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02617         {
02618           zzsetEqPredTypeName(knownTypeId);
02619         }
02620         else
02621             {
02622               zzsetInternalPredTypeName(zzinfixPredName, knownTypeId);
02623             }
02624         const char* lvarName = (*predlo)[1]->getStr();
02625         const char* rvarName = (*predlo)[2]->getStr();
02626         const char* unknownVarName = (lTypeId>0) ?  rvarName : lvarName;
02627         zzvarNameToIdMap[unknownVarName].typeId_ = knownTypeId;
02628       }
02629       else // if both types are unknown
02630       {
02631           //both sides must be variables
02632         const char* lvarName = (*predlo)[1]->getStr();
02633         const char* rvarName = (*predlo)[2]->getStr();
02634         lTypeId = zzgetVarTypeId(lvarName);
02635         rTypeId = zzgetVarTypeId(rvarName);
02636         
02637         if (lTypeId > 0 && rTypeId > 0) //if both types are known
02638         {
02639           if (lTypeId != rTypeId)
02640             zzerr("The types of %s and %s on the left and right of "
02641                    "'=' must match.", lvarName, rvarName);
02642           if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02643           {
02644                 zzsetEqPredTypeName(lTypeId);
02645           }
02646           else
02647               {
02648                 zzsetInternalPredTypeName(zzinfixPredName, lTypeId);
02649               }
02650         }
02651         else  // if only one type is known
02652         if ( (lTypeId<=0 && rTypeId>0) || (lTypeId>0 && rTypeId<=0) )
02653         {
02654           int knownTypeId = (lTypeId>0) ? lTypeId : rTypeId;
02655           if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02656           {
02657                 zzsetEqPredTypeName(knownTypeId);
02658           }
02659           else
02660               {
02661                 zzsetInternalPredTypeName(zzinfixPredName, knownTypeId);
02662               }
02663           const char* unknowVarName = (lTypeId>0) ?  rvarName : lvarName;
02664           zzvarNameToIdMap[unknowVarName].typeId_ = knownTypeId;
02665         }
02666         else
02667         {      
02668                   if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02669           {
02670                 string unknownEqName = zzappend(PredicateTemplate::EQUAL_NAME, 
02671                                             zzeqTypeCounter++);
02672                 zzeqPredList.push_back(ZZUnknownEqPredInfo(unknownEqName,lvarName,
02673                                                        rvarName));
02674                 predlo->replace(PredicateTemplate::EQUAL_NAME, unknownEqName.c_str());
02675           }
02676           else
02677           {
02678                 string unknownIntPredName =
02679                   zzappendWithUnderscore(zzinfixPredName, zzintPredTypeCounter++);
02680                 zzintPredList.push_back(ZZUnknownIntPredInfo(unknownIntPredName, lvarName,
02681                                                          rvarName));
02682                 predlo->replace(zzinfixPredName, unknownIntPredName.c_str());
02683           }
02684         }
02685       }
02686           free(zzinfixPredName);
02687       zzinfixPredName = NULL;
02688         }
02689 
02690     zzcheckPredNumTerm(zzpred);
02691     delete zzpred;
02692     zzpred = NULL;
02693     zzassert(zzpredFuncListObjs.size()==1,
02694              "expecting zzpredFuncListObjs.size()==1");
02695     ListObj* predlo = zzpredFuncListObjs.top();
02696     zzpredFuncListObjs.pop();
02697 
02698     if (zzisAsterisk)
02699     {
02700       zzisAsterisk = false;
02701       ListObj* lo = new ListObj;
02702       lo->append("*"); lo->append(predlo);
02703       zzformulaListObjs.push(lo);
02704     }
02705     else
02706       zzformulaListObjs.push(predlo);
02707 
02708     zzformulaStr.append(")");
02709 
02710         // If we have replaced a function inside the predicate
02711         // then we have to add the conjunction
02712         while (!zzfuncConjStack.empty())
02713         {
02714                 // create the second part of the conjunction
02715                 //zzformulaStr.append(" ^ ");
02716       ListObj* topPredlo = zzfuncConjStack.top();
02717       zzfuncConjStack.pop();
02718       //zzformulaListObjs.push(topPredlo);
02719       //zzcreateListObjFromTopTwo(zzformulaListObjs, "^");
02720       zzformulaListObjs.push(topPredlo);
02721       zzcreateListObjFromTopTwo(zzformulaListObjs, "v");
02722         } //while (!zzfuncConjStack.empty())
02723 
02724         if (!zzfuncConjStr.empty())
02725         {
02726       zzformulaStr.append(zzfuncConjStr);
02727       zzfuncConjStr.clear();
02728         }
02729         zzfunc = NULL;
02730   ;}
02731     break;
02732 
02733   case 138:
02734 #line 1585 "../src/parser/fol.y"
02735     {
02736         zzconsumeToken(zztokenList, ">");
02737     if (folDbg >= 1) printf("> "); 
02738     if (folDbg >= 2) printf("atomic_sentence (right): term\n"); 
02739     zzformulaStr.append(" > ");
02740     zzinfixPredName = (char *)malloc((strlen(PredicateTemplate::GT_NAME)
02741                                                                   + 1)*sizeof(char));
02742         strcpy(zzinfixPredName, PredicateTemplate::GT_NAME);
02743         //zzcreateInternalPredTemplate(zzinfixPredName);
02744     //const PredicateTemplate* t = zzdomain->getPredicateTemplate(zzinfixPredName);
02745         //zzpred->setTemplate((PredicateTemplate*)t);
02746   ;}
02747     break;
02748 
02749   case 139:
02750 #line 1599 "../src/parser/fol.y"
02751     {
02752         zzconsumeToken(zztokenList, "<");
02753     if (folDbg >= 1) printf("< "); 
02754     if (folDbg >= 2) printf("atomic_sentence (right): term\n"); 
02755     zzformulaStr.append(" < "); 
02756     zzinfixPredName = (char *)malloc((strlen(PredicateTemplate::LT_NAME)
02757                                                                   + 1)*sizeof(char));
02758         strcpy(zzinfixPredName, PredicateTemplate::LT_NAME);
02759         //zzcreateInternalPredTemplate(zzinfixPredName);
02760     //const PredicateTemplate* t = zzdomain->getPredicateTemplate(zzinfixPredName);
02761         //zzpred->setTemplate((PredicateTemplate*)t);
02762   ;}
02763     break;
02764 
02765   case 140:
02766 #line 1613 "../src/parser/fol.y"
02767     {
02768         zzconsumeToken(zztokenList, ">");
02769     if (folDbg >= 1) printf(">");
02770     zzformulaStr.append(" >");
02771     zzconsumeToken(zztokenList, "=");
02772     if (folDbg >= 1) printf("= "); 
02773     if (folDbg >= 2) printf("atomic_sentence (right): term\n"); 
02774     zzformulaStr.append("= ");
02775     zzinfixPredName = (char *)malloc((strlen(PredicateTemplate::GTEQ_NAME)
02776                                                                   + 1)*sizeof(char));
02777         strcpy(zzinfixPredName, PredicateTemplate::GTEQ_NAME);
02778         //zzcreateInternalPredTemplate(zzinfixPredName);
02779         //const PredicateTemplate* t = zzdomain->getPredicateTemplate(zzinfixPredName);
02780         //zzpred->setTemplate((PredicateTemplate*)t);
02781   ;}
02782     break;
02783 
02784   case 141:
02785 #line 1630 "../src/parser/fol.y"
02786     {
02787         zzconsumeToken(zztokenList, "<");
02788     if (folDbg >= 1) printf("<");
02789     zzformulaStr.append(" <");
02790     zzconsumeToken(zztokenList, "=");
02791     if (folDbg >= 1) printf("= "); 
02792     if (folDbg >= 2) printf("atomic_sentence (right): term\n"); 
02793     zzformulaStr.append("= ");
02794     zzinfixPredName = (char *)malloc((strlen(PredicateTemplate::LTEQ_NAME)
02795                                                                   + 1)*sizeof(char));
02796         strcpy(zzinfixPredName, PredicateTemplate::LTEQ_NAME);
02797         //zzcreateInternalPredTemplate(zzinfixPredName);
02798     //const PredicateTemplate* t = zzdomain->getPredicateTemplate(zzinfixPredName);
02799         //zzpred->setTemplate((PredicateTemplate*)t);
02800   ;}
02801     break;
02802 
02803   case 142:
02804 #line 1647 "../src/parser/fol.y"
02805     {
02806         zzconsumeToken(zztokenList, "=");
02807     if (folDbg >= 1) printf("= "); 
02808     if (folDbg >= 2) printf("atomic_sentence (right): term\n"); 
02809     zzformulaStr.append(" = ");
02810     zzinfixPredName = (char *)malloc((strlen(PredicateTemplate::EQUAL_NAME)
02811                                                                   + 1)*sizeof(char));
02812         strcpy(zzinfixPredName, PredicateTemplate::EQUAL_NAME);
02813     const PredicateTemplate* t = zzdomain->getEqualPredicateTemplate();
02814         zzpred->setTemplate((PredicateTemplate*)t);
02815   ;}
02816     break;
02817 
02818   case 143:
02819 #line 1660 "../src/parser/fol.y"
02820     {
02821         zzconsumeToken(zztokenList, "!");
02822         zzconsumeToken(zztokenList, "=");
02823     if (folDbg >= 1) printf("!= "); 
02824     if (folDbg >= 2) printf("atomic_sentence (right): term\n"); 
02825     zzformulaStr.append(" != ");
02826     zzinfixPredName = (char *)malloc((strlen(PredicateTemplate::EQUAL_NAME)
02827                                                                   + 1)*sizeof(char));
02828         strcpy(zzinfixPredName, PredicateTemplate::EQUAL_NAME);
02829     const PredicateTemplate* t = zzdomain->getEqualPredicateTemplate();
02830         zzpred->setTemplate((PredicateTemplate*)t);
02831           // Theoretically, we could have "!(a1 != a2)" which would be "a1 = a2"
02832     if (zzpred->getSense())
02833     {
02834       zzpred->setSense(false);
02835       zzisNegated = true;
02836     }
02837     else { zzpred->setSense(true); }
02838   ;}
02839     break;
02840 
02841   case 145:
02842 #line 1685 "../src/parser/fol.y"
02843     { 
02844     zzconsumeToken(zztokenList, "*");
02845     if (folDbg >= 1) printf("* "); 
02846     if (zzisNegated) zzerr("'!' and '*' cannot be used at the same time");
02847     zznumAsterisk++;
02848     zzassert(!zzisAsterisk,"expecting !zzisAsterisk");
02849     zzisAsterisk = true;
02850     zzformulaStr.append("*");
02851   ;}
02852     break;
02853 
02854   case 146:
02855 #line 1701 "../src/parser/fol.y"
02856     {  
02857     zzconsumeToken(zztokenList, ",");
02858     if (folDbg >= 1) printf(", "); 
02859     if (folDbg >= 2) printf("terms: term\n"); 
02860     // While parsing function, we do not want to append anything to the formula
02861     if (zzfunc == NULL) zzformulaStr.append(",");
02862   ;}
02863     break;
02864 
02865   case 148:
02866 #line 1711 "../src/parser/fol.y"
02867     {
02868         // After the first term in an internal pred., check if we can determine type
02869         if (zzpred && zzpred->isEmptyPred() &&
02870                 zzpred->getNumTerms() == 1 && zzinfixPredName)
02871         {
02872       ListObj* predlo = zzpredFuncListObjs.top();
02873       predlo->replace(PredicateTemplate::EMPTY_NAME, zzinfixPredName);
02874     
02875                 // If type known from term, then set the pred types accordingly
02876           int lTypeId = zzgetTypeId(zzpred->getTerm(0), (*predlo)[1]->getStr());
02877       if (lTypeId>0)
02878       {
02879         if (strcmp(zzinfixPredName, PredicateTemplate::EQUAL_NAME)==0)
02880         {
02881           zzsetEqPredTypeName(lTypeId);
02882         }
02883         else
02884                 {
02885               zzsetInternalPredTypeName(zzinfixPredName, lTypeId);
02886                 }
02887       }
02888         }
02889   ;}
02890     break;
02891 
02892   case 149:
02893 #line 1739 "../src/parser/fol.y"
02894     {
02895     const char* constName = zztokenList.removeLast();
02896     if (folDbg >= 1) printf("c2_%s ", constName); 
02897     zztermIsConstant(constName, constName, true);
02898     if (zzfunc) zzfdfuncConstants.append(string(constName));
02899     else        zzfdconstName = constName;
02900     delete [] constName;
02901   ;}
02902     break;
02903 
02904   case 150:
02905 #line 1749 "../src/parser/fol.y"
02906     {
02907     const char* constName = zztokenList.removeLast();
02908     if (folDbg >= 1) printf("c2_%s ", constName); 
02909       if (zzconstantMustBeDeclared)
02910         zzerr("Constant %s must be declared before it is used", constName);
02911     zztermIsConstant(constName, constName, true);
02912     if (zzfunc) zzfdfuncConstants.append(string(constName));
02913     else        zzfdconstName = constName;
02914     delete [] constName;
02915   ;}
02916     break;
02917 
02918   case 151:
02919 #line 1761 "../src/parser/fol.y"
02920     {
02921     const char* intStr = zztokenList.removeLast();
02922     if (folDbg >= 1) printf("c3_%s ", intStr);
02923 
02924     char constName[100];
02925     zzcreateAndCheckNumConstant(intStr, zzfunc, zzpred, zzdomain, constName);
02926     if (constName == NULL) { break; delete [] intStr; }
02927 
02928     zztermIsConstant(constName, intStr, true);
02929     if (zzfunc) zzfdfuncConstants.append(string(constName));
02930     else        zzfdconstName = constName;
02931     delete [] intStr;
02932   ;}
02933     break;
02934 
02935   case 152:
02936 #line 1776 "../src/parser/fol.y"
02937     {
02938     zztermIsVariable(folDbg);
02939     if (zzisPlus) zzisPlus = false;
02940   ;}
02941     break;
02942 
02943   case 153:
02944 #line 1782 "../src/parser/fol.y"
02945     {
02946     zzconsumeToken(zztokenList, "+");
02947     if (folDbg >= 1) printf("+ "); 
02948     zzassert(!zzisPlus,"expecting !zzisPlus");
02949     zzisPlus = true;
02950     zzformulaStr.append("+");
02951     zztermIsVariable(folDbg);
02952     if (zzisPlus) zzisPlus = false;
02953   ;}
02954     break;
02955 
02956   case 154:
02957 #line 1793 "../src/parser/fol.y"
02958     {
02959     zzassert(zzfunc != NULL,"expecting zzfunc != NULL");
02960     zzcheckFuncNumTerm(zzfunc);
02961     zzassert(zzpred != NULL, "expecting zzpred != NULL");
02962 
02963       // replace function
02964          
02965           // Append Term funcVar<zzfuncVarCounter> to predicate where
02966       // function appears and set flag to add conjunction
02967 
02968       // 1. Make new variable
02969     char* varName;
02970     string newVarName;
02971     
02972       // Check if function mapping already occurs in formula
02973     ZZFuncToFuncVarMap::iterator mit;
02974     if ((mit = zzfuncToFuncVarMap.find(zzfunc)) != zzfuncToFuncVarMap.end())
02975     {
02976       newVarName = (*mit).second;
02977       varName = (char *)malloc((strlen(newVarName.c_str()) + 1) * sizeof(char));
02978       strcpy(varName, newVarName.c_str());
02979     }
02980     else
02981     {
02982       char funcVarCounterString[10];
02983       int funcVarCounterLength =
02984         sprintf(funcVarCounterString, "%d", zzfuncVarCounter);
02985       varName = (char *)malloc((strlen(ZZ_FUNCVAR_PREFIX) +
02986                                                                 funcVarCounterLength + 1)*sizeof(char));
02987       strcpy(varName, ZZ_FUNCVAR_PREFIX);
02988       strcat(varName, funcVarCounterString);
02989       ++zzfdnumVars;
02990       ++zzfuncVarCounter;
02991       newVarName = zzgetNewVarName(varName);
02992       
02993       Function* func = new Function(*zzfunc);
02994       zzfuncToFuncVarMap[func] = newVarName;
02995     }
02996 
02997         bool rightNumTerms = true;
02998         bool rightType = true;
02999         int exp, unexp;
03000 
03001       // 2. Create new predicate
03002       // Predicate name is PredicateTemplate::ZZ_RETURN_PREFIX + function name
03003         char* predName;
03004         predName = (char *)malloc((strlen(PredicateTemplate::ZZ_RETURN_PREFIX) +
03005                                                    strlen(zzfunc->getName()) + 1)*sizeof(char));
03006         strcpy(predName, PredicateTemplate::ZZ_RETURN_PREFIX);
03007         strcat(predName, zzfunc->getName());
03008         
03009         // Only insert predicate declaration, if not yet declared
03010         if (zzdomain->getPredicateId(predName) < 0)
03011         {
03012       zzassert(zzpredTemplate==NULL,"expecting zzpredTemplate==NULL");
03013       zzpredTemplate = new PredicateTemplate();
03014       zzpredTemplate->setName(predName);
03015                         
03016       // Register the types
03017       // First parameter is the return type
03018           const char* ttype = zzfunc->getRetTypeName();
03019           zzaddType(ttype, zzpredTemplate, NULL, false, zzdomain);
03020 
03021           // Register the parameter types
03022           for (int i = 0; i < zzfunc->getNumTerms(); i++)
03023           {
03024                 const char* ttype = zzfunc->getTermTypeAsStr(i);
03025                 zzaddType(ttype, zzpredTemplate, NULL, false, zzdomain);
03026           }
03027         
03028           zzassert(zzpredTemplate, "not expecting zzpredTemplate==NULL");
03029           int id = zzdomain->addPredicateTemplate(zzpredTemplate);
03030           zzassert(id >= 0, "expecting pred template id >= 0");
03031           zzpredTemplate->setId(id);
03032           zzpredTemplate = NULL;
03033         }
03034 
03035         Predicate* prevPred = zzpred;
03036         zzpred = NULL;
03037     zzfdnumPreds++;
03038         zzcreatePred(zzpred, predName);
03039     
03040     ListObj* predlo = new ListObj;
03041     predlo->append(predName);
03042                 
03043         // Put predicate list object in stack to be used in conjunction later
03044     zzfuncConjStack.push(predlo);
03045     //zzfuncConjStr.append(" ^ ");
03046     zzfuncConjStr.append(" v !");
03047     zzfuncConjStr.append(predName);
03048         zzfuncConjStr.append("(");
03049     zzputVariableInPred(varName, folDbg);
03050     zzfuncConjStack.top()->append(varName);
03051     zzfuncConjStr.append(varName);
03052         
03053         // Information about the terms is in zzfunc
03054         for (int i = 0; i < zzfunc->getNumTerms(); i++)
03055         {
03056           zzfuncConjStr.append(", ");
03057           Term* term = new Term(*zzfunc->getTerm(i));
03058           zzpred->appendTerm(term);
03059 
03060           const char* name;
03061           if (term->getType() == Term::VARIABLE)
03062           {
03063                 name = (*zzpredFuncListObjs.top())[i+1]->getStr();
03064           }
03065           else if (term->getType() == Term::CONSTANT)
03066           {
03067                 name = zzdomain->getConstantName(term->getId());
03068           }
03069           zzpredFuncListObjs.top()->append(name);
03070           zzfuncConjStack.top()->append(name);
03071           zzfuncConjStr.append(name);
03072         }
03073         zzfuncConjStr.append(")");
03074     zzcreateListObjFromTop(zzfuncConjStack, "!");
03075     
03076     // 4. Append new variable to function in stack or to predicate
03077     if (!zzfuncStack.empty())
03078     {
03079           Function* prevFunc = zzfuncStack.top(); 
03080           zzfuncStack.pop();
03081     
03082       // check that we have not exceeded the number of terms
03083       if ((unexp = prevFunc->getNumTerms()) ==
03084           (exp = prevFunc->getTemplate()->getNumTerms()))
03085       {
03086         rightNumTerms = false;
03087         zzerr("Wrong number of terms for function %s. "
03088                   "Expected %d but given %d", prevFunc->getName(), exp, unexp+1);
03089       }
03090       
03091       int varId = -1;      
03092       if (rightNumTerms)
03093       {
03094         // check that the variable is of the right type
03095         int typeId = prevFunc->getTermTypeAsInt(prevFunc->getNumTerms());
03096         rightType = zzcheckRightTypeAndGetVarId(typeId, newVarName.c_str(),
03097                                                     varId);
03098       }
03099 
03100       if (rightNumTerms && rightType)
03101       {
03102         prevFunc->appendTerm(new Term(varId, (void*)prevFunc, false));
03103         zzpredFuncListObjs.pop();
03104         zzpredFuncListObjs.top()->append(newVarName.c_str());
03105       }
03106                   
03107       zzfunc = prevFunc;
03108     }
03109         else // function stack is empty, so append to predicate
03110     {
03111       // check that we have not exceeded the number of terms
03112       if ((unexp = prevPred->getNumTerms()) ==
03113           (exp = prevPred->getTemplate()->getNumTerms()))
03114       {
03115         rightNumTerms = false;
03116         zzerr("Wrong number of terms for predicate %s. "
03117               "Expected %d but given %d", prevPred->getName(), exp, unexp+1);
03118       }
03119         
03120       int varId = -1;
03121       if (rightNumTerms)
03122       {
03123           // check that the variable is of the right type
03124         int typeId = prevPred->getTermTypeAsInt(prevPred->getNumTerms());
03125         rightType = zzcheckRightTypeAndGetVarId(typeId, newVarName.c_str(),
03126                                                                                     varId);
03127       }
03128       
03129           if (rightNumTerms && rightType)
03130           {
03131                 prevPred->appendTerm(new Term(varId, (void*)prevPred, true));
03132 
03133                 // Pop the function from the stack
03134                 zzoldFuncLo = zzpredFuncListObjs.top();
03135                 zzpredFuncListObjs.pop();
03136                 zzpredFuncListObjs.top()->append(newVarName.c_str());
03137                 zzformulaStr.append(varName);
03138       }
03139           zzfunc = NULL;
03140                 
03141     }
03142     free(varName);
03143         free(predName);
03144         //zzformulaStr.append(")");
03145 
03146     delete zzpred;
03147         zzpred = prevPred;
03148   ;}
03149     break;
03150 
03151   case 155:
03152 #line 1989 "../src/parser/fol.y"
03153     {
03154     const char* funcName = zztokenList.removeLast();
03155     if (folDbg >= 1) printf("f_%s ", funcName);
03156     if (zzfunc != NULL) { zzfuncStack.push(zzfunc); zzfunc = NULL; }
03157     ++zzfdnumFuncs;
03158     zzfdfuncName = funcName;
03159 
03160     ListObj* funclo = new ListObj;
03161 
03162           // Check if internal function
03163         if (FunctionTemplate::isInternalFunctionTemplateName(funcName))
03164         {
03165           zzinfixFuncName = (char *)malloc((strlen(funcName)
03166                                                                         + 1)*sizeof(char));
03167           strcpy(zzinfixFuncName, funcName);
03168           const FunctionTemplate* t;
03169           if (FunctionTemplate::isInternalFunctionUnaryTemplateName(funcName))
03170                 t = zzdomain->getEmptyFunctionUnaryTemplate();
03171           else
03172                 t = zzdomain->getEmptyFunctionBinaryTemplate();
03173       zzassert(zzfunc == NULL,"expecting zzfunc==NULL");
03174       zzfunc = new Function(t);
03175       funclo->append(FunctionTemplate::EMPTY_FTEMPLATE_NAME);
03176         }
03177         else
03178         {
03179           zzcreateFunc(zzfunc, funcName); 
03180           funclo->append(funcName);
03181         }
03182         
03183     zzpredFuncListObjs.push(funclo);
03184     //zzformulaStr.append(funcName);
03185 
03186     delete [] funcName;
03187   ;}
03188     break;
03189 
03190   case 156:
03191 #line 2025 "../src/parser/fol.y"
03192     {
03193     zzconsumeToken(zztokenList, "(");
03194     if (folDbg >= 1) printf("( "); 
03195     if (folDbg >= 2) printf("term: terms\n");
03196   ;}
03197     break;
03198 
03199   case 157:
03200 #line 2031 "../src/parser/fol.y"
03201     {
03202           //If an internal func., then need to determine type
03203         if (zzinfixFuncName)
03204         {
03205           ListObj* funclo = zzpredFuncListObjs.top();
03206       funclo->replace(FunctionTemplate::EMPTY_FTEMPLATE_NAME, zzinfixFuncName);
03207           const FunctionTemplate* t =
03208             zzgetGenericInternalFunctionTemplate(zzinfixFuncName);
03209                 // If in a pred. (not LHS of infix pred.), then we know the return type
03210           if (zzpred)
03211           {
03212                 ((FunctionTemplate*)t)->setRetTypeId(
03213                         zzpred->getTermTypeAsInt(zzpred->getNumTerms()), zzdomain);
03214       }
03215           zzfunc->setTemplate((FunctionTemplate*)t);
03216 
03217                 // types are possibly unknown
03218           bool unknownTypes = false;
03219                 
03220                 // First element is return type
03221           Array<int> typeIds(zzfunc->getNumTerms() + 1);
03222           typeIds.append(zzfunc->getRetTypeId());
03223           if (typeIds[0] <= 0) unknownTypes = true;
03224                 
03225                 // Then term types
03226           for (int i = 1; i <= zzfunc->getNumTerms(); i++)
03227           {
03228                 typeIds.append(zzgetTypeId(zzfunc->getTerm(i-1), (*funclo)[i]->getStr()));
03229                 if (typeIds[i] <= 0) unknownTypes = true;
03230           }
03231 
03232                 // If all types are known
03233           if (!unknownTypes)
03234           {
03235                 zzsetInternalFuncTypeName(zzinfixFuncName, typeIds);
03236           }
03237       else // Not all types are known, delay processing
03238       {
03239         Array<string> varNames(typeIds.size());
03240         
03241         char* varName;
03242         char funcVarCounterString[10];
03243         int funcVarCounterLength =
03244                 sprintf(funcVarCounterString, "%d", zzfuncVarCounter);
03245         varName = (char *)malloc((strlen(ZZ_FUNCVAR_PREFIX) +
03246                                                                   funcVarCounterLength + 1)*sizeof(char));
03247                 strcpy(varName, ZZ_FUNCVAR_PREFIX);
03248                 strcat(varName, funcVarCounterString);
03249             string newVarName = zzgetNewVarName(varName);
03250         
03251         varNames.append(newVarName);
03252         
03253         for (int i = 1; i < typeIds.size(); i++)
03254           varNames[i] = (*funclo)[i]->getStr();
03255 
03256                 // Predicate name is PredicateTemplate::ZZ_RETURN_PREFIX + function name
03257                 char* predName;
03258                 predName = (char *)malloc((strlen(PredicateTemplate::ZZ_RETURN_PREFIX) +
03259                                                    strlen(zzfunc->getName()) + 1)*sizeof(char));
03260                 strcpy(predName, PredicateTemplate::ZZ_RETURN_PREFIX);
03261                 strcat(predName, zzinfixFuncName);
03262         
03263         string unknownIntFuncName =
03264                   zzappendWithUnderscore(predName, zzintFuncTypeCounter++);
03265         zzintFuncList.push_back(ZZUnknownIntFuncInfo(unknownIntFuncName, varNames));
03266         //funclo->replace(zzinfixFuncName, unknownIntFuncName.c_str());
03267                 free(predName);
03268                 free(varName);
03269       }
03270           free(zzinfixFuncName);
03271       zzinfixFuncName = NULL;
03272         }
03273         
03274     zzconsumeToken(zztokenList, ")");
03275     if (folDbg >= 1) printf(") ");
03276   ;}
03277     break;
03278 
03279   case 158:
03280 #line 2109 "../src/parser/fol.y"
03281     {
03282       // Create a function corresponding to the infix sign
03283     if (zzfunc != NULL) { zzfuncStack.push(zzfunc); zzfunc = NULL; }
03284     ++zzfdnumFuncs;
03285     zzfdfuncName = zzinfixFuncName;
03286         const FunctionTemplate* t =
03287       zzgetGenericInternalFunctionTemplate(zzinfixFuncName);
03288         zzfunc = new Function(t);
03289           // If in a pred. (not LHS of infix pred.), then we know the return type
03290       // It's the type of the previous variable (getNumTerms() - 1)
03291         if (zzpred)
03292       ((FunctionTemplate*)t)->setRetTypeId(
03293         zzpred->getTermTypeAsInt(zzpred->getNumTerms() - 1), zzdomain);
03294 
03295     ListObj* funclo = new ListObj;
03296     funclo->append(zzfdfuncName.c_str());
03297     zzpredFuncListObjs.push(funclo);
03298 
03299       // The first term was added to the previous pred / func
03300       // So this needs to be switched to the infix function
03301     moveTermToInfixFunction();
03302   ;}
03303     break;
03304 
03305   case 159:
03306 #line 2132 "../src/parser/fol.y"
03307     {
03308     ListObj* funclo = zzpredFuncListObjs.top();
03309 
03310           // types are possibly unknown
03311     bool unknownTypes = false;
03312         
03313       // First element is return type
03314     Array<int> typeIds(zzfunc->getNumTerms() + 1);
03315     typeIds.append(zzfunc->getRetTypeId());
03316     if (typeIds[0] <= 0) unknownTypes = true;
03317                 
03318       // Then term types
03319         for (int i = 1; i <= zzfunc->getNumTerms(); i++)
03320         {
03321       typeIds.append(zzgetTypeId(zzfunc->getTerm(i-1), (*funclo)[i]->getStr()));
03322       if (typeIds[i] <= 0) unknownTypes = true;
03323         }
03324 
03325           // If all types are known
03326         if (!unknownTypes)
03327         {
03328           zzsetInternalFuncTypeName(zzinfixFuncName, typeIds);
03329         }
03330     else // Not all types are known, delay processing
03331     {
03332       Array<string> varNames(typeIds.size());
03333         
03334       char* varName;
03335       char funcVarCounterString[10];
03336       int funcVarCounterLength =
03337                 sprintf(funcVarCounterString, "%d", zzfuncVarCounter);
03338       varName = (char *)malloc((strlen(ZZ_FUNCVAR_PREFIX) +
03339                                                                 funcVarCounterLength + 1)*sizeof(char));
03340           strcpy(varName, ZZ_FUNCVAR_PREFIX);
03341           strcat(varName, funcVarCounterString);
03342           string newVarName = zzgetNewVarName(varName);
03343         
03344       varNames.append(newVarName);
03345         
03346       for (int i = 1; i < typeIds.size(); i++)
03347         varNames[i] = (*funclo)[i]->getStr();
03348                 // Predicate name is PredicateTemplate::ZZ_RETURN_PREFIX + function name
03349       char* predName;
03350       predName = (char *)malloc((strlen(PredicateTemplate::ZZ_RETURN_PREFIX) +
03351                                                      strlen(zzfunc->getName()) + 1)*sizeof(char));
03352       strcpy(predName, PredicateTemplate::ZZ_RETURN_PREFIX);
03353       strcat(predName, zzinfixFuncName);
03354         
03355       string unknownIntFuncName =
03356         zzappendWithUnderscore(predName, zzintFuncTypeCounter++);
03357       zzintFuncList.push_back(ZZUnknownIntFuncInfo(unknownIntFuncName, varNames));
03358         //funclo->replace(zzinfixFuncName, unknownIntFuncName.c_str());
03359       free(predName);
03360       free(varName);
03361     }
03362     free(zzinfixFuncName);
03363     zzinfixFuncName = NULL;
03364   ;}
03365     break;
03366 
03367   case 160:
03368 #line 2194 "../src/parser/fol.y"
03369     {
03370     zzconsumeToken(zztokenList, "+");
03371     if (folDbg >= 1) printf("+ "); 
03372     zzinfixFuncName = (char *)malloc((strlen(PredicateTemplate::PLUS_NAME)
03373                                                                   + 1)*sizeof(char));
03374         strcpy(zzinfixFuncName, PredicateTemplate::PLUS_NAME);
03375   ;}
03376     break;
03377 
03378   case 161:
03379 #line 2203 "../src/parser/fol.y"
03380     {
03381         zzconsumeToken(zztokenList, "-");
03382     if (folDbg >= 1) printf("- "); 
03383     zzinfixFuncName = (char *)malloc((strlen(PredicateTemplate::MINUS_NAME)
03384                                       + 1)*sizeof(char));
03385     strcpy(zzinfixFuncName, PredicateTemplate::MINUS_NAME);
03386   ;}
03387     break;
03388 
03389   case 162:
03390 #line 2212 "../src/parser/fol.y"
03391     {
03392         zzconsumeToken(zztokenList, "*");
03393     if (folDbg >= 1) printf("* ");
03394     zzinfixFuncName = (char *)malloc((strlen(PredicateTemplate::TIMES_NAME)
03395                                                                   + 1)*sizeof(char));
03396         strcpy(zzinfixFuncName, PredicateTemplate::TIMES_NAME);
03397   ;}
03398     break;
03399 
03400   case 163:
03401 #line 2221 "../src/parser/fol.y"
03402     {
03403         zzconsumeToken(zztokenList, "/");
03404     if (folDbg >= 1) printf("/ ");
03405     zzinfixFuncName = (char *)malloc((strlen(PredicateTemplate::DIVIDEDBY_NAME)
03406                                                                   + 1)*sizeof(char));
03407         strcpy(zzinfixFuncName, PredicateTemplate::DIVIDEDBY_NAME);
03408   ;}
03409     break;
03410 
03411   case 164:
03412 #line 2230 "../src/parser/fol.y"
03413     {
03414         zzconsumeToken(zztokenList, "%");
03415     if (folDbg >= 1) printf("%% ");
03416     zzinfixFuncName = (char *)malloc((strlen(PredicateTemplate::MOD_NAME)
03417                                                                   + 1)*sizeof(char));
03418         strcpy(zzinfixFuncName, PredicateTemplate::MOD_NAME);
03419   ;}
03420     break;
03421 
03422   case 165:
03423 #line 2241 "../src/parser/fol.y"
03424     {
03425     
03426   ;}
03427     break;
03428 
03429 
03430 /* Line 930 of glr.c.  */
03431 #line 3432 "fol.cpp"
03432       default: break;
03433     }
03434 
03435   return yyok;
03436 # undef yyerrok
03437 # undef YYABORT
03438 # undef YYACCEPT
03439 # undef YYERROR
03440 # undef YYBACKUP
03441 # undef yyclearin
03442 # undef YYRECOVERING
03443 }
03444 
03445 
03446 /*ARGSUSED*/ static void
03447 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
03448 {
03449   YYUSE (yy0);
03450   YYUSE (yy1);
03451 
03452   switch (yyn)
03453     {
03454       
03455       default: break;
03456     }
03457 }
03458 
03459                               /* Bison grammar-table manipulation.  */
03460 
03461 /*-----------------------------------------------.
03462 | Release the memory associated to this symbol.  |
03463 `-----------------------------------------------*/
03464 
03465 /*ARGSUSED*/
03466 static void
03467 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
03468 {
03469   YYUSE (yyvaluep);
03470 
03471   if (!yymsg)
03472     yymsg = "Deleting";
03473   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
03474 
03475   switch (yytype)
03476     {
03477 
03478       default:
03479         break;
03480     }
03481 }
03482 
03484 static inline int
03485 yyrhsLength (yyRuleNum yyrule)
03486 {
03487   return yyr2[yyrule];
03488 }
03489 
03490 static void
03491 yydestroyGLRState (char const *yymsg, yyGLRState *yys)
03492 {
03493   if (yys->yyresolved)
03494     yydestruct (yymsg, yystos[yys->yylrState],
03495                 &yys->yysemantics.yysval);
03496   else
03497     {
03498 #if YYDEBUG
03499       if (yydebug)
03500         {
03501           if (yys->yysemantics.yyfirstVal)
03502             YYFPRINTF (stderr, "%s unresolved ", yymsg);
03503           else
03504             YYFPRINTF (stderr, "%s incomplete ", yymsg);
03505           yy_symbol_print (stderr, yystos[yys->yylrState],
03506                            NULL);
03507           YYFPRINTF (stderr, "\n");
03508         }
03509 #endif
03510 
03511       if (yys->yysemantics.yyfirstVal)
03512         {
03513           yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
03514           yyGLRState *yyrh;
03515           int yyn;
03516           for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
03517                yyn > 0;
03518                yyrh = yyrh->yypred, yyn -= 1)
03519             yydestroyGLRState (yymsg, yyrh);
03520         }
03521     }
03522 }
03523 
03525 static inline yySymbol
03526 yylhsNonterm (yyRuleNum yyrule)
03527 {
03528   return yyr1[yyrule];
03529 }
03530 
03531 #define yyis_pact_ninf(yystate) \
03532   ((yystate) == YYPACT_NINF)
03533 
03536 static inline yybool
03537 yyisDefaultedState (yyStateNum yystate)
03538 {
03539   return yyis_pact_ninf (yypact[yystate]);
03540 }
03541 
03543 static inline yyRuleNum
03544 yydefaultAction (yyStateNum yystate)
03545 {
03546   return yydefact[yystate];
03547 }
03548 
03549 #define yyis_table_ninf(yytable_value) \
03550   YYID (0)
03551 
03560 static inline void
03561 yygetLRActions (yyStateNum yystate, int yytoken,
03562                 int* yyaction, const short int** yyconflicts)
03563 {
03564   int yyindex = yypact[yystate] + yytoken;
03565   if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
03566     {
03567       *yyaction = -yydefact[yystate];
03568       *yyconflicts = yyconfl;
03569     }
03570   else if (! yyis_table_ninf (yytable[yyindex]))
03571     {
03572       *yyaction = yytable[yyindex];
03573       *yyconflicts = yyconfl + yyconflp[yyindex];
03574     }
03575   else
03576     {
03577       *yyaction = 0;
03578       *yyconflicts = yyconfl + yyconflp[yyindex];
03579     }
03580 }
03581 
03582 static inline yyStateNum
03583 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
03584 {
03585   int yyr;
03586   yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
03587   if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
03588     return yytable[yyr];
03589   else
03590     return yydefgoto[yylhs - YYNTOKENS];
03591 }
03592 
03593 static inline yybool
03594 yyisShiftAction (int yyaction)
03595 {
03596   return 0 < yyaction;
03597 }
03598 
03599 static inline yybool
03600 yyisErrorAction (int yyaction)
03601 {
03602   return yyaction == 0;
03603 }
03604 
03605                                 /* GLRStates */
03606 
03611 static inline yyGLRStackItem*
03612 yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
03613 {
03614   yyGLRStackItem* yynewItem = yystackp->yynextFree;
03615   yystackp->yyspaceLeft -= 1;
03616   yystackp->yynextFree += 1;
03617   yynewItem->yystate.yyisState = yyisState;
03618   return yynewItem;
03619 }
03620 
03625 static void
03626 yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
03627                      yyGLRState* rhs, yyRuleNum yyrule)
03628 {
03629   yySemanticOption* yynewOption =
03630     &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
03631   yynewOption->yystate = rhs;
03632   yynewOption->yyrule = yyrule;
03633   if (yystackp->yytops.yylookaheadNeeds[yyk])
03634     {
03635       yynewOption->yyrawchar = yychar;
03636       yynewOption->yyval = yylval;
03637       yynewOption->yyloc = yylloc;
03638     }
03639   else
03640     yynewOption->yyrawchar = YYEMPTY;
03641   yynewOption->yynext = yystate->yysemantics.yyfirstVal;
03642   yystate->yysemantics.yyfirstVal = yynewOption;
03643 
03644   YY_RESERVE_GLRSTACK (yystackp);
03645 }
03646 
03647                                 /* GLRStacks */
03648 
03650 static yybool
03651 yyinitStateSet (yyGLRStateSet* yyset)
03652 {
03653   yyset->yysize = 1;
03654   yyset->yycapacity = 16;
03655   yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
03656   if (! yyset->yystates)
03657     return yyfalse;
03658   yyset->yystates[0] = NULL;
03659   yyset->yylookaheadNeeds =
03660     (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
03661   if (! yyset->yylookaheadNeeds)
03662     {
03663       YYFREE (yyset->yystates);
03664       return yyfalse;
03665     }
03666   return yytrue;
03667 }
03668 
03669 static void yyfreeStateSet (yyGLRStateSet* yyset)
03670 {
03671   YYFREE (yyset->yystates);
03672   YYFREE (yyset->yylookaheadNeeds);
03673 }
03674 
03677 static yybool
03678 yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
03679 {
03680   yystackp->yyerrState = 0;
03681   yynerrs = 0;
03682   yystackp->yyspaceLeft = yysize;
03683   yystackp->yyitems =
03684     (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
03685   if (!yystackp->yyitems)
03686     return yyfalse;
03687   yystackp->yynextFree = yystackp->yyitems;
03688   yystackp->yysplitPoint = NULL;
03689   yystackp->yylastDeleted = NULL;
03690   return yyinitStateSet (&yystackp->yytops);
03691 }
03692 
03693 
03694 #if YYSTACKEXPANDABLE
03695 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
03696   &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
03697 
03703 static void
03704 yyexpandGLRStack (yyGLRStack* yystackp)
03705 {
03706   yyGLRStackItem* yynewItems;
03707   yyGLRStackItem* yyp0, *yyp1;
03708   size_t yysize, yynewSize;
03709   size_t yyn;
03710   yysize = yystackp->yynextFree - yystackp->yyitems;
03711   if (YYMAXDEPTH - YYHEADROOM < yysize)
03712     yyMemoryExhausted (yystackp);
03713   yynewSize = 2*yysize;
03714   if (YYMAXDEPTH < yynewSize)
03715     yynewSize = YYMAXDEPTH;
03716   yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
03717   if (! yynewItems)
03718     yyMemoryExhausted (yystackp);
03719   for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
03720        0 < yyn;
03721        yyn -= 1, yyp0 += 1, yyp1 += 1)
03722     {
03723       *yyp1 = *yyp0;
03724       if (*(yybool *) yyp0)
03725         {
03726           yyGLRState* yys0 = &yyp0->yystate;
03727           yyGLRState* yys1 = &yyp1->yystate;
03728           if (yys0->yypred != NULL)
03729             yys1->yypred =
03730               YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
03731           if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
03732             yys1->yysemantics.yyfirstVal =
03733               YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
03734         }
03735       else
03736         {
03737           yySemanticOption* yyv0 = &yyp0->yyoption;
03738           yySemanticOption* yyv1 = &yyp1->yyoption;
03739           if (yyv0->yystate != NULL)
03740             yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
03741           if (yyv0->yynext != NULL)
03742             yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
03743         }
03744     }
03745   if (yystackp->yysplitPoint != NULL)
03746     yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
03747                                  yystackp->yysplitPoint, yystate);
03748 
03749   for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
03750     if (yystackp->yytops.yystates[yyn] != NULL)
03751       yystackp->yytops.yystates[yyn] =
03752         YYRELOC (yystackp->yyitems, yynewItems,
03753                  yystackp->yytops.yystates[yyn], yystate);
03754   YYFREE (yystackp->yyitems);
03755   yystackp->yyitems = yynewItems;
03756   yystackp->yynextFree = yynewItems + yysize;
03757   yystackp->yyspaceLeft = yynewSize - yysize;
03758 }
03759 #endif
03760 
03761 static void
03762 yyfreeGLRStack (yyGLRStack* yystackp)
03763 {
03764   YYFREE (yystackp->yyitems);
03765   yyfreeStateSet (&yystackp->yytops);
03766 }
03767 
03771 static inline void
03772 yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
03773 {
03774   if (yystackp->yysplitPoint != NULL && yystackp->yysplitPoint > yys)
03775     yystackp->yysplitPoint = yys;
03776 }
03777 
03779 static inline void
03780 yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
03781 {
03782   if (yystackp->yytops.yystates[yyk] != NULL)
03783     yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
03784   yystackp->yytops.yystates[yyk] = NULL;
03785 }
03786 
03790 static void
03791 yyundeleteLastStack (yyGLRStack* yystackp)
03792 {
03793   if (yystackp->yylastDeleted == NULL || yystackp->yytops.yysize != 0)
03794     return;
03795   yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
03796   yystackp->yytops.yysize = 1;
03797   YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
03798   yystackp->yylastDeleted = NULL;
03799 }
03800 
03801 static inline void
03802 yyremoveDeletes (yyGLRStack* yystackp)
03803 {
03804   size_t yyi, yyj;
03805   yyi = yyj = 0;
03806   while (yyj < yystackp->yytops.yysize)
03807     {
03808       if (yystackp->yytops.yystates[yyi] == NULL)
03809         {
03810           if (yyi == yyj)
03811             {
03812               YYDPRINTF ((stderr, "Removing dead stacks.\n"));
03813             }
03814           yystackp->yytops.yysize -= 1;
03815         }
03816       else
03817         {
03818           yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
03819           /* In the current implementation, it's unnecessary to copy
03820              yystackp->yytops.yylookaheadNeeds[yyi] since, after
03821              yyremoveDeletes returns, the parser immediately either enters
03822              deterministic operation or shifts a token.  However, it doesn't
03823              hurt, and the code might evolve to need it.  */
03824           yystackp->yytops.yylookaheadNeeds[yyj] =
03825             yystackp->yytops.yylookaheadNeeds[yyi];
03826           if (yyj != yyi)
03827             {
03828               YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
03829                           (unsigned long int) yyi, (unsigned long int) yyj));
03830             }
03831           yyj += 1;
03832         }
03833       yyi += 1;
03834     }
03835 }
03836 
03839 static inline void
03840 yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
03841             size_t yyposn,
03842             YYSTYPE* yyvalp, YYLTYPE* yylocp)
03843 {
03844   yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
03845 
03846   yynewState->yylrState = yylrState;
03847   yynewState->yyposn = yyposn;
03848   yynewState->yyresolved = yytrue;
03849   yynewState->yypred = yystackp->yytops.yystates[yyk];
03850   yynewState->yysemantics.yysval = *yyvalp;
03851   yynewState->yyloc = *yylocp;
03852   yystackp->yytops.yystates[yyk] = yynewState;
03853 
03854   YY_RESERVE_GLRSTACK (yystackp);
03855 }
03856 
03860 static inline void
03861 yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
03862                  size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
03863 {
03864   yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
03865 
03866   yynewState->yylrState = yylrState;
03867   yynewState->yyposn = yyposn;
03868   yynewState->yyresolved = yyfalse;
03869   yynewState->yypred = yystackp->yytops.yystates[yyk];
03870   yynewState->yysemantics.yyfirstVal = NULL;
03871   yystackp->yytops.yystates[yyk] = yynewState;
03872 
03873   /* Invokes YY_RESERVE_GLRSTACK.  */
03874   yyaddDeferredAction (yystackp, yyk, yynewState, rhs, yyrule);
03875 }
03876 
03883 static inline YYRESULTTAG
03884 yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
03885             YYSTYPE* yyvalp, YYLTYPE* yylocp)
03886 {
03887   int yynrhs = yyrhsLength (yyrule);
03888 
03889   if (yystackp->yysplitPoint == NULL)
03890     {
03891       /* Standard special case: single stack.  */
03892       yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
03893       YYASSERT (yyk == 0);
03894       yystackp->yynextFree -= yynrhs;
03895       yystackp->yyspaceLeft += yynrhs;
03896       yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
03897       return yyuserAction (yyrule, yynrhs, rhs,
03898                            yyvalp, yylocp, yystackp);
03899     }
03900   else
03901     {
03902       /* At present, doAction is never called in nondeterministic
03903        * mode, so this branch is never taken.  It is here in
03904        * anticipation of a future feature that will allow immediate
03905        * evaluation of selected actions in nondeterministic mode.  */
03906       int yyi;
03907       yyGLRState* yys;
03908       yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
03909       yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
03910         = yystackp->yytops.yystates[yyk];
03911       for (yyi = 0; yyi < yynrhs; yyi += 1)
03912         {
03913           yys = yys->yypred;
03914           YYASSERT (yys);
03915         }
03916       yyupdateSplit (yystackp, yys);
03917       yystackp->yytops.yystates[yyk] = yys;
03918       return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
03919                            yyvalp, yylocp, yystackp);
03920     }
03921 }
03922 
03923 #if !YYDEBUG
03924 # define YY_REDUCE_PRINT(Args)
03925 #else
03926 # define YY_REDUCE_PRINT(Args)          \
03927 do {                                    \
03928   if (yydebug)                          \
03929     yy_reduce_print Args;               \
03930 } while (YYID (0))
03931 
03932 /*----------------------------------------------------------.
03933 | Report that the RULE is going to be reduced on stack #K.  |
03934 `----------------------------------------------------------*/
03935 
03936 /*ARGSUSED*/ static inline void
03937 yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
03938                  YYSTYPE* yyvalp, YYLTYPE* yylocp)
03939 {
03940   int yynrhs = yyrhsLength (yyrule);
03941   yybool yynormal __attribute__ ((__unused__)) =
03942     (yystackp->yysplitPoint == NULL);
03943   yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
03944   int yylow = 1;
03945   int yyi;
03946   YYUSE (yyvalp);
03947   YYUSE (yylocp);
03948   YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
03949              (unsigned long int) yyk, yyrule - 1,
03950              (unsigned long int) yyrline[yyrule]);
03951   /* The symbols being reduced.  */
03952   for (yyi = 0; yyi < yynrhs; yyi++)
03953     {
03954       fprintf (stderr, "   $%d = ", yyi + 1);
03955       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
03956                        &(((yyGLRStackItem const *)yyvsp)[YYFILL ((yyi + 1) - (yynrhs))].yystate.yysemantics.yysval)
03957                                        );
03958       fprintf (stderr, "\n");
03959     }
03960 }
03961 #endif
03962 
03974 static inline YYRESULTTAG
03975 yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
03976              yybool yyforceEval)
03977 {
03978   size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
03979 
03980   if (yyforceEval || yystackp->yysplitPoint == NULL)
03981     {
03982       YYSTYPE yysval;
03983       YYLTYPE yyloc;
03984 
03985       YY_REDUCE_PRINT ((yystackp, yyk, yyrule, &yysval, &yyloc));
03986       YYCHK (yydoAction (yystackp, yyk, yyrule, &yysval,
03987                          &yyloc));
03988       YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
03989       yyglrShift (yystackp, yyk,
03990                   yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
03991                                  yylhsNonterm (yyrule)),
03992                   yyposn, &yysval, &yyloc);
03993     }
03994   else
03995     {
03996       size_t yyi;
03997       int yyn;
03998       yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
03999       yyStateNum yynewLRState;
04000 
04001       for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
04002            0 < yyn; yyn -= 1)
04003         {
04004           yys = yys->yypred;
04005           YYASSERT (yys);
04006         }
04007       yyupdateSplit (yystackp, yys);
04008       yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
04009       YYDPRINTF ((stderr,
04010                   "Reduced stack %lu by rule #%d; action deferred.  Now in state %d.\n",
04011                   (unsigned long int) yyk, yyrule - 1, yynewLRState));
04012       for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
04013         if (yyi != yyk && yystackp->yytops.yystates[yyi] != NULL)
04014           {
04015             yyGLRState* yyp, *yysplit = yystackp->yysplitPoint;
04016             yyp = yystackp->yytops.yystates[yyi];
04017             while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
04018               {
04019                 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
04020                   {
04021                     yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
04022                     yymarkStackDeleted (yystackp, yyk);
04023                     YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
04024                                 (unsigned long int) yyk,
04025                                 (unsigned long int) yyi));
04026                     return yyok;
04027                   }
04028                 yyp = yyp->yypred;
04029               }
04030           }
04031       yystackp->yytops.yystates[yyk] = yys;
04032       yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
04033     }
04034   return yyok;
04035 }
04036 
04037 static size_t
04038 yysplitStack (yyGLRStack* yystackp, size_t yyk)
04039 {
04040   if (yystackp->yysplitPoint == NULL)
04041     {
04042       YYASSERT (yyk == 0);
04043       yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
04044     }
04045   if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
04046     {
04047       yyGLRState** yynewStates;
04048       yybool* yynewLookaheadNeeds;
04049 
04050       yynewStates = NULL;
04051 
04052       if (yystackp->yytops.yycapacity
04053           > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
04054         yyMemoryExhausted (yystackp);
04055       yystackp->yytops.yycapacity *= 2;
04056 
04057       yynewStates =
04058         (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
04059                                   (yystackp->yytops.yycapacity
04060                                    * sizeof yynewStates[0]));
04061       if (yynewStates == NULL)
04062         yyMemoryExhausted (yystackp);
04063       yystackp->yytops.yystates = yynewStates;
04064 
04065       yynewLookaheadNeeds =
04066         (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
04067                              (yystackp->yytops.yycapacity
04068                               * sizeof yynewLookaheadNeeds[0]));
04069       if (yynewLookaheadNeeds == NULL)
04070         yyMemoryExhausted (yystackp);
04071       yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
04072     }
04073   yystackp->yytops.yystates[yystackp->yytops.yysize]
04074     = yystackp->yytops.yystates[yyk];
04075   yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
04076     = yystackp->yytops.yylookaheadNeeds[yyk];
04077   yystackp->yytops.yysize += 1;
04078   return yystackp->yytops.yysize-1;
04079 }
04080 
04084 static yybool
04085 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
04086 {
04087   if (yyy0->yyrule == yyy1->yyrule)
04088     {
04089       yyGLRState *yys0, *yys1;
04090       int yyn;
04091       for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
04092            yyn = yyrhsLength (yyy0->yyrule);
04093            yyn > 0;
04094            yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
04095         if (yys0->yyposn != yys1->yyposn)
04096           return yyfalse;
04097       return yytrue;
04098     }
04099   else
04100     return yyfalse;
04101 }
04102 
04105 static void
04106 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
04107 {
04108   yyGLRState *yys0, *yys1;
04109   int yyn;
04110   for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
04111        yyn = yyrhsLength (yyy0->yyrule);
04112        yyn > 0;
04113        yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
04114     {
04115       if (yys0 == yys1)
04116         break;
04117       else if (yys0->yyresolved)
04118         {
04119           yys1->yyresolved = yytrue;
04120           yys1->yysemantics.yysval = yys0->yysemantics.yysval;
04121         }
04122       else if (yys1->yyresolved)
04123         {
04124           yys0->yyresolved = yytrue;
04125           yys0->yysemantics.yysval = yys1->yysemantics.yysval;
04126         }
04127       else
04128         {
04129           yySemanticOption** yyz0p;
04130           yySemanticOption* yyz1;
04131           yyz0p = &yys0->yysemantics.yyfirstVal;
04132           yyz1 = yys1->yysemantics.yyfirstVal;
04133           while (YYID (yytrue))
04134             {
04135               if (yyz1 == *yyz0p || yyz1 == NULL)
04136                 break;
04137               else if (*yyz0p == NULL)
04138                 {
04139                   *yyz0p = yyz1;
04140                   break;
04141                 }
04142               else if (*yyz0p < yyz1)
04143                 {
04144                   yySemanticOption* yyz = *yyz0p;
04145                   *yyz0p = yyz1;
04146                   yyz1 = yyz1->yynext;
04147                   (*yyz0p)->yynext = yyz;
04148                 }
04149               yyz0p = &(*yyz0p)->yynext;
04150             }
04151           yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
04152         }
04153     }
04154 }
04155 
04159 static int
04160 yypreference (yySemanticOption* y0, yySemanticOption* y1)
04161 {
04162   yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
04163   int p0 = yydprec[r0], p1 = yydprec[r1];
04164 
04165   if (p0 == p1)
04166     {
04167       if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
04168         return 0;
04169       else
04170         return 1;
04171     }
04172   if (p0 == 0 || p1 == 0)
04173     return 0;
04174   if (p0 < p1)
04175     return 3;
04176   if (p1 < p0)
04177     return 2;
04178   return 0;
04179 }
04180 
04181 static YYRESULTTAG yyresolveValue (yyGLRState* yys,
04182                                    yyGLRStack* yystackp);
04183 
04184 
04190 static YYRESULTTAG
04191 yyresolveStates (yyGLRState* yys, int yyn,
04192                  yyGLRStack* yystackp)
04193 {
04194   if (0 < yyn)
04195     {
04196       YYASSERT (yys->yypred);
04197       YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp));
04198       if (! yys->yyresolved)
04199         YYCHK (yyresolveValue (yys, yystackp));
04200     }
04201   return yyok;
04202 }
04203 
04208 static YYRESULTTAG
04209 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
04210                  YYSTYPE* yyvalp, YYLTYPE* yylocp)
04211 {
04212   yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
04213   int yynrhs;
04214   int yychar_current;
04215   YYSTYPE yylval_current;
04216   YYLTYPE yylloc_current;
04217   YYRESULTTAG yyflag;
04218 
04219   yynrhs = yyrhsLength (yyopt->yyrule);
04220   yyflag = yyresolveStates (yyopt->yystate, yynrhs, yystackp);
04221   if (yyflag != yyok)
04222     {
04223       yyGLRState *yys;
04224       for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
04225         yydestroyGLRState ("Cleanup: popping", yys);
04226       return yyflag;
04227     }
04228 
04229   yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;
04230   yychar_current = yychar;
04231   yylval_current = yylval;
04232   yylloc_current = yylloc;
04233   yychar = yyopt->yyrawchar;
04234   yylval = yyopt->yyval;
04235   yylloc = yyopt->yyloc;
04236   yyflag = yyuserAction (yyopt->yyrule, yynrhs,
04237                            yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
04238                            yyvalp, yylocp, yystackp);
04239   yychar = yychar_current;
04240   yylval = yylval_current;
04241   yylloc = yylloc_current;
04242   return yyflag;
04243 }
04244 
04245 #if YYDEBUG
04246 static void
04247 yyreportTree (yySemanticOption* yyx, int yyindent)
04248 {
04249   int yynrhs = yyrhsLength (yyx->yyrule);
04250   int yyi;
04251   yyGLRState* yys;
04252   yyGLRState* yystates[1 + YYMAXRHS];
04253   yyGLRState yyleftmost_state;
04254 
04255   for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
04256     yystates[yyi] = yys;
04257   if (yys == NULL)
04258     {
04259       yyleftmost_state.yyposn = 0;
04260       yystates[0] = &yyleftmost_state;
04261     }
04262   else
04263     yystates[0] = yys;
04264 
04265   if (yyx->yystate->yyposn < yys->yyposn + 1)
04266     YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
04267                yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
04268                yyx->yyrule - 1);
04269   else
04270     YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
04271                yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
04272                yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
04273                (unsigned long int) yyx->yystate->yyposn);
04274   for (yyi = 1; yyi <= yynrhs; yyi += 1)
04275     {
04276       if (yystates[yyi]->yyresolved)
04277         {
04278           if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
04279             YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
04280                        yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
04281           else
04282             YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
04283                        yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
04284                        (unsigned long int) (yystates[yyi - 1]->yyposn + 1),
04285                        (unsigned long int) yystates[yyi]->yyposn);
04286         }
04287       else
04288         yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
04289     }
04290 }
04291 #endif
04292 
04293 /*ARGSUSED*/ static YYRESULTTAG
04294 yyreportAmbiguity (yySemanticOption* yyx0,
04295                    yySemanticOption* yyx1)
04296 {
04297   YYUSE (yyx0);
04298   YYUSE (yyx1);
04299 
04300 #if YYDEBUG
04301   YYFPRINTF (stderr, "Ambiguity detected.\n");
04302   YYFPRINTF (stderr, "Option 1,\n");
04303   yyreportTree (yyx0, 2);
04304   YYFPRINTF (stderr, "\nOption 2,\n");
04305   yyreportTree (yyx1, 2);
04306   YYFPRINTF (stderr, "\n");
04307 #endif
04308 
04309   yyerror (YY_("syntax is ambiguous"));
04310   return yyabort;
04311 }
04312 
04316 static void
04317 yyresolveLocations (yyGLRState* yys1, int yyn1,
04318                     yyGLRStack *yystackp)
04319 {
04320   if (0 < yyn1)
04321     {
04322       yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp);
04323       if (!yys1->yyresolved)
04324         {
04325           yySemanticOption *yyoption;
04326           yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
04327           int yynrhs;
04328           int yychar_current;
04329           YYSTYPE yylval_current;
04330           YYLTYPE yylloc_current;
04331           yyoption = yys1->yysemantics.yyfirstVal;
04332           YYASSERT (yyoption != NULL);
04333           yynrhs = yyrhsLength (yyoption->yyrule);
04334           if (yynrhs > 0)
04335             {
04336               yyGLRState *yys;
04337               int yyn;
04338               yyresolveLocations (yyoption->yystate, yynrhs,
04339                                   yystackp);
04340               for (yys = yyoption->yystate, yyn = yynrhs;
04341                    yyn > 0;
04342                    yys = yys->yypred, yyn -= 1)
04343                 yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
04344             }
04345           else
04346             {
04347               /* Both yyresolveAction and yyresolveLocations traverse the GSS
04348                  in reverse rightmost order.  It is only necessary to invoke
04349                  yyresolveLocations on a subforest for which yyresolveAction
04350                  would have been invoked next had an ambiguity not been
04351                  detected.  Thus the location of the previous state (but not
04352                  necessarily the previous state itself) is guaranteed to be
04353                  resolved already.  */
04354               yyGLRState *yyprevious = yyoption->yystate;
04355               yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
04356             }
04357           yychar_current = yychar;
04358           yylval_current = yylval;
04359           yylloc_current = yylloc;
04360           yychar = yyoption->yyrawchar;
04361           yylval = yyoption->yyval;
04362           yylloc = yyoption->yyloc;
04363           YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
04364           yychar = yychar_current;
04365           yylval = yylval_current;
04366           yylloc = yylloc_current;
04367         }
04368     }
04369 }
04370 
04377 static YYRESULTTAG
04378 yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp)
04379 {
04380   yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
04381   yySemanticOption* yybest;
04382   yySemanticOption** yypp;
04383   yybool yymerge;
04384   YYSTYPE yysval;
04385   YYRESULTTAG yyflag;
04386   YYLTYPE *yylocp = &yys->yyloc;
04387 
04388   yybest = yyoptionList;
04389   yymerge = yyfalse;
04390   for (yypp = &yyoptionList->yynext; *yypp != NULL; )
04391     {
04392       yySemanticOption* yyp = *yypp;
04393 
04394       if (yyidenticalOptions (yybest, yyp))
04395         {
04396           yymergeOptionSets (yybest, yyp);
04397           *yypp = yyp->yynext;
04398         }
04399       else
04400         {
04401           switch (yypreference (yybest, yyp))
04402             {
04403             case 0:
04404               yyresolveLocations (yys, 1, yystackp);
04405               return yyreportAmbiguity (yybest, yyp);
04406               break;
04407             case 1:
04408               yymerge = yytrue;
04409               break;
04410             case 2:
04411               break;
04412             case 3:
04413               yybest = yyp;
04414               yymerge = yyfalse;
04415               break;
04416             default:
04417               /* This cannot happen so it is not worth a YYASSERT (yyfalse),
04418                  but some compilers complain if the default case is
04419                  omitted.  */
04420               break;
04421             }
04422           yypp = &yyp->yynext;
04423         }
04424     }
04425 
04426   if (yymerge)
04427     {
04428       yySemanticOption* yyp;
04429       int yyprec = yydprec[yybest->yyrule];
04430       yyflag = yyresolveAction (yybest, yystackp, &yysval,
04431                                 yylocp);
04432       if (yyflag == yyok)
04433         for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
04434           {
04435             if (yyprec == yydprec[yyp->yyrule])
04436               {
04437                 YYSTYPE yysval_other;
04438                 YYLTYPE yydummy;
04439                 yyflag = yyresolveAction (yyp, yystackp, &yysval_other,
04440                                           &yydummy);
04441                 if (yyflag != yyok)
04442                   {
04443                     yydestruct ("Cleanup: discarding incompletely merged value for",
04444                                 yystos[yys->yylrState],
04445                                 &yysval);
04446                     break;
04447                   }
04448                 yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
04449               }
04450           }
04451     }
04452   else
04453     yyflag = yyresolveAction (yybest, yystackp, &yysval, yylocp);
04454 
04455   if (yyflag == yyok)
04456     {
04457       yys->yyresolved = yytrue;
04458       yys->yysemantics.yysval = yysval;
04459     }
04460   else
04461     yys->yysemantics.yyfirstVal = NULL;
04462   return yyflag;
04463 }
04464 
04465 static YYRESULTTAG
04466 yyresolveStack (yyGLRStack* yystackp)
04467 {
04468   if (yystackp->yysplitPoint != NULL)
04469     {
04470       yyGLRState* yys;
04471       int yyn;
04472 
04473       for (yyn = 0, yys = yystackp->yytops.yystates[0];
04474            yys != yystackp->yysplitPoint;
04475            yys = yys->yypred, yyn += 1)
04476         continue;
04477       YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
04478                              ));
04479     }
04480   return yyok;
04481 }
04482 
04483 static void
04484 yycompressStack (yyGLRStack* yystackp)
04485 {
04486   yyGLRState* yyp, *yyq, *yyr;
04487 
04488   if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == NULL)
04489     return;
04490 
04491   for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
04492        yyp != yystackp->yysplitPoint;
04493        yyr = yyp, yyp = yyq, yyq = yyp->yypred)
04494     yyp->yypred = yyr;
04495 
04496   yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
04497   yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
04498   yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
04499   yystackp->yysplitPoint = NULL;
04500   yystackp->yylastDeleted = NULL;
04501 
04502   while (yyr != NULL)
04503     {
04504       yystackp->yynextFree->yystate = *yyr;
04505       yyr = yyr->yypred;
04506       yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
04507       yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
04508       yystackp->yynextFree += 1;
04509       yystackp->yyspaceLeft -= 1;
04510     }
04511 }
04512 
04513 static YYRESULTTAG
04514 yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
04515                    size_t yyposn)
04516 {
04517   int yyaction;
04518   const short int* yyconflicts;
04519   yyRuleNum yyrule;
04520 
04521   while (yystackp->yytops.yystates[yyk] != NULL)
04522     {
04523       yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
04524       YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
04525                   (unsigned long int) yyk, yystate));
04526 
04527       YYASSERT (yystate != YYFINAL);
04528 
04529       if (yyisDefaultedState (yystate))
04530         {
04531           yyrule = yydefaultAction (yystate);
04532           if (yyrule == 0)
04533             {
04534               YYDPRINTF ((stderr, "Stack %lu dies.\n",
04535                           (unsigned long int) yyk));
04536               yymarkStackDeleted (yystackp, yyk);
04537               return yyok;
04538             }
04539           YYCHK (yyglrReduce (yystackp, yyk, yyrule, yyfalse));
04540         }
04541       else
04542         {
04543           yySymbol yytoken;
04544           yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
04545           if (yychar == YYEMPTY)
04546             {
04547               YYDPRINTF ((stderr, "Reading a token: "));
04548               yychar = YYLEX;
04549               yytoken = YYTRANSLATE (yychar);
04550               YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
04551             }
04552           else
04553             yytoken = YYTRANSLATE (yychar);
04554           yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
04555 
04556           while (*yyconflicts != 0)
04557             {
04558               size_t yynewStack = yysplitStack (yystackp, yyk);
04559               YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
04560                           (unsigned long int) yynewStack,
04561                           (unsigned long int) yyk));
04562               YYCHK (yyglrReduce (yystackp, yynewStack,
04563                                   *yyconflicts, yyfalse));
04564               YYCHK (yyprocessOneStack (yystackp, yynewStack,
04565                                         yyposn));
04566               yyconflicts += 1;
04567             }
04568 
04569           if (yyisShiftAction (yyaction))
04570             break;
04571           else if (yyisErrorAction (yyaction))
04572             {
04573               YYDPRINTF ((stderr, "Stack %lu dies.\n",
04574                           (unsigned long int) yyk));
04575               yymarkStackDeleted (yystackp, yyk);
04576               break;
04577             }
04578           else
04579             YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
04580                                 yyfalse));
04581         }
04582     }
04583   return yyok;
04584 }
04585 
04586 /*ARGSUSED*/ static void
04587 yyreportSyntaxError (yyGLRStack* yystackp)
04588 {
04589   if (yystackp->yyerrState == 0)
04590     {
04591 #if YYERROR_VERBOSE
04592       int yyn;
04593       yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
04594       if (YYPACT_NINF < yyn && yyn <= YYLAST)
04595         {
04596           yySymbol yytoken = YYTRANSLATE (yychar);
04597           size_t yysize0 = yytnamerr (NULL, yytokenName (yytoken));
04598           size_t yysize = yysize0;
04599           size_t yysize1;
04600           yybool yysize_overflow = yyfalse;
04601           char* yymsg = NULL;
04602           enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
04603           char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
04604           int yyx;
04605           char *yyfmt;
04606           char const *yyf;
04607           static char const yyunexpected[] = "parse error, unexpected %s";
04608           static char const yyexpecting[] = ", expecting %s";
04609           static char const yyor[] = " or %s";
04610           char yyformat[sizeof yyunexpected
04611                         + sizeof yyexpecting - 1
04612                         + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
04613                            * (sizeof yyor - 1))];
04614           char const *yyprefix = yyexpecting;
04615 
04616           /* Start YYX at -YYN if negative to avoid negative indexes in
04617              YYCHECK.  */
04618           int yyxbegin = yyn < 0 ? -yyn : 0;
04619 
04620           /* Stay within bounds of both yycheck and yytname.  */
04621           int yychecklim = YYLAST - yyn + 1;
04622           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
04623           int yycount = 1;
04624 
04625           yyarg[0] = yytokenName (yytoken);
04626           yyfmt = yystpcpy (yyformat, yyunexpected);
04627 
04628           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
04629             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
04630               {
04631                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
04632                   {
04633                     yycount = 1;
04634                     yysize = yysize0;
04635                     yyformat[sizeof yyunexpected - 1] = '\0';
04636                     break;
04637                   }
04638                 yyarg[yycount++] = yytokenName (yyx);
04639                 yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx));
04640                 yysize_overflow |= yysize1 < yysize;
04641                 yysize = yysize1;
04642                 yyfmt = yystpcpy (yyfmt, yyprefix);
04643                 yyprefix = yyor;
04644               }
04645 
04646           yyf = YY_(yyformat);
04647           yysize1 = yysize + strlen (yyf);
04648           yysize_overflow |= yysize1 < yysize;
04649           yysize = yysize1;
04650 
04651           if (!yysize_overflow)
04652             yymsg = (char *) YYMALLOC (yysize);
04653 
04654           if (yymsg)
04655             {
04656               char *yyp = yymsg;
04657               int yyi = 0;
04658               while ((*yyp = *yyf))
04659                 {
04660                   if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
04661                     {
04662                       yyp += yytnamerr (yyp, yyarg[yyi++]);
04663                       yyf += 2;
04664                     }
04665                   else
04666                     {
04667                       yyp++;
04668                       yyf++;
04669                     }
04670                 }
04671               yyerror (yymsg);
04672               YYFREE (yymsg);
04673             }
04674           else
04675             {
04676               yyerror (YY_("parse error"));
04677               yyMemoryExhausted (yystackp);
04678             }
04679         }
04680       else
04681 #endif /* YYERROR_VERBOSE */
04682         yyerror (YY_("parse error"));
04683       yynerrs += 1;
04684     }
04685 }
04686 
04687 /* Recover from a parse error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
04688    yylval, and yylloc are the syntactic category, semantic value, and location
04689    of the look-ahead.  */
04690 /*ARGSUSED*/ static void
04691 yyrecoverSyntaxError (yyGLRStack* yystackp)
04692 {
04693   size_t yyk;
04694   int yyj;
04695 
04696   if (yystackp->yyerrState == 3)
04697     /* We just shifted the error token and (perhaps) took some
04698        reductions.  Skip tokens until we can proceed.  */
04699     while (YYID (yytrue))
04700       {
04701         yySymbol yytoken;
04702         if (yychar == YYEOF)
04703           yyFail (yystackp, NULL);
04704         if (yychar != YYEMPTY)
04705           {
04706             yytoken = YYTRANSLATE (yychar);
04707             yydestruct ("Error: discarding",
04708                         yytoken, &yylval);
04709           }
04710         YYDPRINTF ((stderr, "Reading a token: "));
04711         yychar = YYLEX;
04712         yytoken = YYTRANSLATE (yychar);
04713         YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
04714         yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
04715         if (yyis_pact_ninf (yyj))
04716           return;
04717         yyj += yytoken;
04718         if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
04719           {
04720             if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
04721               return;
04722           }
04723         else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
04724           return;
04725       }
04726 
04727   /* Reduce to one stack.  */
04728   for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
04729     if (yystackp->yytops.yystates[yyk] != NULL)
04730       break;
04731   if (yyk >= yystackp->yytops.yysize)
04732     yyFail (yystackp, NULL);
04733   for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
04734     yymarkStackDeleted (yystackp, yyk);
04735   yyremoveDeletes (yystackp);
04736   yycompressStack (yystackp);
04737 
04738   /* Now pop stack until we find a state that shifts the error token.  */
04739   yystackp->yyerrState = 3;
04740   while (yystackp->yytops.yystates[0] != NULL)
04741     {
04742       yyGLRState *yys = yystackp->yytops.yystates[0];
04743       yyj = yypact[yys->yylrState];
04744       if (! yyis_pact_ninf (yyj))
04745         {
04746           yyj += YYTERROR;
04747           if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
04748               && yyisShiftAction (yytable[yyj]))
04749             {
04750               /* Shift the error token having adjusted its location.  */
04751               YYLTYPE yyerrloc;yyerrloc.yydummy = 'a';
04752               YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
04753                                &yylval, &yyerrloc);
04754               yyglrShift (yystackp, 0, yytable[yyj],
04755                           yys->yyposn, &yylval, &yyerrloc);
04756               yys = yystackp->yytops.yystates[0];
04757               break;
04758             }
04759         }
04760 
04761       yydestroyGLRState ("Error: popping", yys);
04762       yystackp->yytops.yystates[0] = yys->yypred;
04763       yystackp->yynextFree -= 1;
04764       yystackp->yyspaceLeft += 1;
04765     }
04766   if (yystackp->yytops.yystates[0] == NULL)
04767     yyFail (yystackp, NULL);
04768 }
04769 
04770 #define YYCHK1(YYE)                                                          \
04771   do {                                                                       \
04772     switch (YYE) {                                                           \
04773     case yyok:                                                               \
04774       break;                                                                 \
04775     case yyabort:                                                            \
04776       goto yyabortlab;                                                       \
04777     case yyaccept:                                                           \
04778       goto yyacceptlab;                                                      \
04779     case yyerr:                                                              \
04780       goto yyuser_error;                                                     \
04781     default:                                                                 \
04782       goto yybuglab;                                                         \
04783     }                                                                        \
04784   } while (YYID (0))
04785 
04786 
04787 /*----------.
04788 | yyparse.  |
04789 `----------*/
04790 
04791 int
04792 yyparse (void)
04793 {
04794   int yyresult;
04795   yyGLRStack yystack;
04796   yyGLRStack* const yystackp = &yystack;
04797   size_t yyposn;
04798 
04799   YYDPRINTF ((stderr, "Starting parse\n"));
04800 
04801   yychar = YYEMPTY;
04802   yylval = yyval_default;
04803 
04804 
04805   if (! yyinitGLRStack (yystackp, YYINITDEPTH))
04806     goto yyexhaustedlab;
04807   switch (YYSETJMP (yystack.yyexception_buffer))
04808     {
04809     case 0: break;
04810     case 1: goto yyabortlab;
04811     case 2: goto yyexhaustedlab;
04812     default: goto yybuglab;
04813     }
04814   yyglrShift (&yystack, 0, 0, 0, &yylval, &yylloc);
04815   yyposn = 0;
04816 
04817   while (YYID (yytrue))
04818     {
04819       /* For efficiency, we have two loops, the first of which is
04820          specialized to deterministic operation (single stack, no
04821          potential ambiguity).  */
04822       /* Standard mode */
04823       while (YYID (yytrue))
04824         {
04825           yyRuleNum yyrule;
04826           int yyaction;
04827           const short int* yyconflicts;
04828 
04829           yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
04830           YYDPRINTF ((stderr, "Entering state %d\n", yystate));
04831           if (yystate == YYFINAL)
04832             goto yyacceptlab;
04833           if (yyisDefaultedState (yystate))
04834             {
04835               yyrule = yydefaultAction (yystate);
04836               if (yyrule == 0)
04837                 {
04838 
04839                   yyreportSyntaxError (&yystack);
04840                   goto yyuser_error;
04841                 }
04842               YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue));
04843             }
04844           else
04845             {
04846               yySymbol yytoken;
04847               if (yychar == YYEMPTY)
04848                 {
04849                   YYDPRINTF ((stderr, "Reading a token: "));
04850                   yychar = YYLEX;
04851                   yytoken = YYTRANSLATE (yychar);
04852                   YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
04853                 }
04854               else
04855                 yytoken = YYTRANSLATE (yychar);
04856               yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
04857               if (*yyconflicts != 0)
04858                 break;
04859               if (yyisShiftAction (yyaction))
04860                 {
04861                   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
04862                   if (yychar != YYEOF)
04863                     yychar = YYEMPTY;
04864                   yyposn += 1;
04865                   yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
04866                   if (0 < yystack.yyerrState)
04867                     yystack.yyerrState -= 1;
04868                 }
04869               else if (yyisErrorAction (yyaction))
04870                 {
04871 
04872                   yyreportSyntaxError (&yystack);
04873                   goto yyuser_error;
04874                 }
04875               else
04876                 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue));
04877             }
04878         }
04879 
04880       while (YYID (yytrue))
04881         {
04882           yySymbol yytoken_to_shift;
04883           size_t yys;
04884 
04885           for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
04886             yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
04887 
04888           /* yyprocessOneStack returns one of three things:
04889 
04890               - An error flag.  If the caller is yyprocessOneStack, it
04891                 immediately returns as well.  When the caller is finally
04892                 yyparse, it jumps to an error label via YYCHK1.
04893 
04894               - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
04895                 (&yystack, yys), which sets the top state of yys to NULL.  Thus,
04896                 yyparse's following invocation of yyremoveDeletes will remove
04897                 the stack.
04898 
04899               - yyok, when ready to shift a token.
04900 
04901              Except in the first case, yyparse will invoke yyremoveDeletes and
04902              then shift the next token onto all remaining stacks.  This
04903              synchronization of the shift (that is, after all preceding
04904              reductions on all stacks) helps prevent double destructor calls
04905              on yylval in the event of memory exhaustion.  */
04906 
04907           for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
04908             YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn));
04909           yyremoveDeletes (&yystack);
04910           if (yystack.yytops.yysize == 0)
04911             {
04912               yyundeleteLastStack (&yystack);
04913               if (yystack.yytops.yysize == 0)
04914                 yyFail (&yystack, YY_("parse error"));
04915               YYCHK1 (yyresolveStack (&yystack));
04916               YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
04917 
04918               yyreportSyntaxError (&yystack);
04919               goto yyuser_error;
04920             }
04921 
04922           /* If any yyglrShift call fails, it will fail after shifting.  Thus,
04923              a copy of yylval will already be on stack 0 in the event of a
04924              failure in the following loop.  Thus, yychar is set to YYEMPTY
04925              before the loop to make sure the user destructor for yylval isn't
04926              called twice.  */
04927           yytoken_to_shift = YYTRANSLATE (yychar);
04928           yychar = YYEMPTY;
04929           yyposn += 1;
04930           for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
04931             {
04932               int yyaction;
04933               const short int* yyconflicts;
04934               yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
04935               yygetLRActions (yystate, yytoken_to_shift, &yyaction,
04936                               &yyconflicts);
04937               /* Note that yyconflicts were handled by yyprocessOneStack.  */
04938               YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
04939               YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
04940               yyglrShift (&yystack, yys, yyaction, yyposn,
04941                           &yylval, &yylloc);
04942               YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
04943                           (unsigned long int) yys,
04944                           yystack.yytops.yystates[yys]->yylrState));
04945             }
04946 
04947           if (yystack.yytops.yysize == 1)
04948             {
04949               YYCHK1 (yyresolveStack (&yystack));
04950               YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
04951               yycompressStack (&yystack);
04952               break;
04953             }
04954         }
04955       continue;
04956     yyuser_error:
04957       yyrecoverSyntaxError (&yystack);
04958       yyposn = yystack.yytops.yystates[0]->yyposn;
04959     }
04960 
04961  yyacceptlab:
04962   yyresult = 0;
04963   goto yyreturn;
04964 
04965  yybuglab:
04966   YYASSERT (yyfalse);
04967   goto yyabortlab;
04968 
04969  yyabortlab:
04970   yyresult = 1;
04971   goto yyreturn;
04972 
04973  yyexhaustedlab:
04974   yyerror (YY_("memory exhausted"));
04975   yyresult = 2;
04976   goto yyreturn;
04977 
04978  yyreturn:
04979   if (yychar != YYEOF && yychar != YYEMPTY)
04980     yydestruct ("Cleanup: discarding lookahead",
04981                 YYTRANSLATE (yychar),
04982                 &yylval);
04983 
04984   /* If the stack is well-formed, pop the stack until it is empty,
04985      destroying its entries as we go.  But free the stack regardless
04986      of whether it is well-formed.  */
04987   if (yystack.yyitems)
04988     {
04989       yyGLRState** yystates = yystack.yytops.yystates;
04990       if (yystates)
04991         {
04992           size_t yysize = yystack.yytops.yysize;
04993           size_t yyk;
04994           for (yyk = 0; yyk < yysize; yyk += 1)
04995             if (yystates[yyk])
04996               {
04997                 while (yystates[yyk])
04998                   {
04999                     yyGLRState *yys = yystates[yyk];
05000                     yydestroyGLRState ("Cleanup: popping", yys);
05001                     yystates[yyk] = yys->yypred;
05002                     yystack.yynextFree -= 1;
05003                     yystack.yyspaceLeft += 1;
05004                   }
05005                 break;
05006               }
05007         }
05008       yyfreeGLRStack (&yystack);
05009     }
05010 
05011   /* Make sure YYID is used.  */
05012   return YYID (yyresult);
05013 }
05014 
05015 /* DEBUGGING ONLY */
05016 #ifdef YYDEBUG
05017 static void yypstack (yyGLRStack* yystackp, size_t yyk)
05018   __attribute__ ((__unused__));
05019 static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
05020 
05021 static void
05022 yy_yypstack (yyGLRState* yys)
05023 {
05024   if (yys->yypred)
05025     {
05026       yy_yypstack (yys->yypred);
05027       fprintf (stderr, " -> ");
05028     }
05029   fprintf (stderr, "%d@%lu", yys->yylrState, (unsigned long int) yys->yyposn);
05030 }
05031 
05032 static void
05033 yypstates (yyGLRState* yyst)
05034 {
05035   if (yyst == NULL)
05036     fprintf (stderr, "<null>");
05037   else
05038     yy_yypstack (yyst);
05039   fprintf (stderr, "\n");
05040 }
05041 
05042 static void
05043 yypstack (yyGLRStack* yystackp, size_t yyk)
05044 {
05045   yypstates (yystackp->yytops.yystates[yyk]);
05046 }
05047 
05048 #define YYINDEX(YYX)                                                         \
05049     ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
05050 
05051 
05052 static void
05053 yypdumpstack (yyGLRStack* yystackp)
05054 {
05055   yyGLRStackItem* yyp;
05056   size_t yyi;
05057   for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
05058     {
05059       fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystackp->yyitems));
05060       if (*(yybool *) yyp)
05061         {
05062           fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
05063                    yyp->yystate.yyresolved, yyp->yystate.yylrState,
05064                    (unsigned long int) yyp->yystate.yyposn,
05065                    (long int) YYINDEX (yyp->yystate.yypred));
05066           if (! yyp->yystate.yyresolved)
05067             fprintf (stderr, ", firstVal: %ld",
05068                      (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
05069         }
05070       else
05071         {
05072           fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
05073                    yyp->yyoption.yyrule - 1,
05074                    (long int) YYINDEX (yyp->yyoption.yystate),
05075                    (long int) YYINDEX (yyp->yyoption.yynext));
05076         }
05077       fprintf (stderr, "\n");
05078     }
05079   fprintf (stderr, "Tops:");
05080   for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
05081     fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,
05082              (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
05083   fprintf (stderr, "\n");
05084 }
05085 #endif
05086 
05087 
05088 #line 2246 "../src/parser/fol.y"
05089 
05090 
05091 /******************* function definitions ****************************/
05092 
05093   //warnDuplicates set to true by default
05094 bool runYYParser(MLN* const & mln, Domain* const & dom,
05095                  const char* const & fileName, 
05096                  const bool& allPredsExceptQueriesAreClosedWorld,
05097                  const StringHashArray* const & openWorldPredNames,
05098                  const StringHashArray* const & closedWorldPredNames,
05099                  const StringHashArray* const & queryPredNames,
05100                  const bool& addUnitClauses, const bool& warnDuplicates,
05101                  const double& defaultWt, const bool& mustHaveWtOrFullStop,
05102                  const Domain* const & domain0, const bool& lazyInference,
05103                  const bool& flipWtsOfFlippedClause)
05104 {
05105   zzinit();
05106   if (fileName) { yyin = fopen(fileName, "r" ); zzinFileName = fileName; }
05107   else            yyin = stdin;
05108   if (yyin == NULL) zzexit("Failed to open file %s.", fileName);
05109 
05110   signal(SIGFPE,zzsigHandler);
05111   signal(SIGABRT,zzsigHandler);
05112   signal(SIGILL,zzsigHandler);
05113   signal(SIGSEGV,zzsigHandler);
05114 
05115   zzwarnDuplicates = warnDuplicates;
05116   zzdefaultWt = defaultWt;
05117   zzmustHaveWtOrFullStop = mustHaveWtOrFullStop;
05118   zzflipWtsOfFlippedClause = flipWtsOfFlippedClause;
05119 
05120   ungetc('\n', yyin); // pretend that file begin with a newline
05121   zzmln = mln;
05122   zzdomain = dom;
05123 
05124   zzanyTypeId = zzdomain->getTypeId(PredicateTemplate::ANY_TYPE_NAME);
05125   zzassert(zzanyTypeId >= 0, "expecting zzanyTypeId >= 0");
05126 
05127   // Declare internally implemented predicates and functions
05128   //declareInternalPredicatesAndFunctions();
05129 
05130   zzisParsing = true;
05131   yyparse();
05132   zzisParsing = false;
05133 
05134   zzcheckAllTypesHaveConstants(zzdomain);
05135   zzcreateBlocks(zzdomain);
05136   
05137   // Insert groundings generated from internally implemented functions and predicates
05138   zzgenerateGroundingsFromInternalPredicatesAndFunctions();
05139 
05140   // Insert groundings generated from linked-in predicates
05141   if (zzusingLinkedPredicates) zzgenerateGroundingsFromLinkedPredicates(zzdomain);
05142 
05143   // Insert groundings generated from linked-in functions
05144   if (zzusingLinkedFunctions) zzgenerateGroundingsFromLinkedFunctions(zzdomain);
05145 
05146   if (zzok)
05147   {
05148       //append the formulas to MLN and set the weights of the hard clauses
05149     cout << "Adding clauses to MLN..." << endl;
05150     zzappendFormulasToMLN(zzformulaInfos, mln, domain0);
05151 
05152     if (addUnitClauses) zzappendUnitClausesToMLN(zzdomain, zzmln, zzdefaultWt);
05153 
05154     zzmln->setClauseInfoPriorMeansToClauseWts();
05155 
05156       // Change the constant ids so that constants of same type are ordered 
05157       // consecutively. Also ensure that the constants in the mln and map is 
05158       // consistent with the new constant ids
05159     zzdomain->reorderConstants(zzmln, zzpredIdToGndPredMap);
05160 
05161     zzmln->compress();
05162 
05163     Array<bool> isClosedWorldArr; 
05164     zzfillClosedWorldArray(isClosedWorldArr,allPredsExceptQueriesAreClosedWorld,
05165                            openWorldPredNames, closedWorldPredNames,
05166                            queryPredNames);
05167 
05168     Database* db = new Database(zzdomain, isClosedWorldArr, zzstoreGroundPreds);
05169     if (lazyInference) db->setLazyFlag();
05170     zzaddGndPredsToDb(db);
05171     zzdomain->setDB(db);
05172     zzdomain->compress();
05173   }
05174   
05175   if (zznumErrors > 0) cout << "Num of errors detected = " << zznumErrors<<endl;
05176 
05177   zzcleanUp();
05178 
05179   signal(SIGFPE,SIG_DFL);
05180   signal(SIGABRT,SIG_DFL);
05181   signal(SIGILL,SIG_DFL);
05182   signal(SIGSEGV,SIG_DFL);
05183 
05184   return zzok;
05185 }
05186 
05187 
05188 

Generated on Sun Jun 7 11:55:18 2009 for Alchemy by  doxygen 1.5.1