pomdp_spec.tab.cc
Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.3.  */
00002 
00003 /* Skeleton implementation for Bison's Yacc-like parsers in C
00004 
00005    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00006    Free Software Foundation, Inc.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021    Boston, MA 02110-1301, USA.  */
00022 
00023 /* As a special exception, you may create a larger work that contains
00024    part or all of the Bison parser skeleton and distribute that work
00025    under terms of your choice, so long as that work isn't itself a
00026    parser generator using the skeleton or a modified version thereof
00027    as a parser skeleton.  Alternatively, if you modify or redistribute
00028    the parser skeleton itself, you may (at your option) remove this
00029    special exception, which will cause the skeleton and the resulting
00030    Bison output files to be licensed under the GNU General Public
00031    License without this special exception.
00032 
00033    This special exception was added by the Free Software Foundation in
00034    version 2.2 of Bison.  */
00035 
00036 /* C LALR(1) parser skeleton written by Richard Stallman, by
00037    simplifying the original so-called "semantic" parser.  */
00038 
00039 /* All symbols defined below should begin with yy or YY, to avoid
00040    infringing on user name space.  This should be done even for local
00041    variables, as they might otherwise be expanded by user macros.
00042    There are some unavoidable exceptions within include files to
00043    define necessary library symbols; they are noted "INFRINGES ON
00044    USER NAME SPACE" below.  */
00045 
00046 /* Identify Bison output.  */
00047 #define YYBISON 1
00048 
00049 /* Bison version.  */
00050 #define YYBISON_VERSION "2.3"
00051 
00052 /* Skeleton name.  */
00053 #define YYSKELETON_NAME "yacc.c"
00054 
00055 /* Pure parsers.  */
00056 #define YYPURE 0
00057 
00058 /* Using locations.  */
00059 #define YYLSP_NEEDED 0
00060 
00061 
00062 
00063 /* Tokens.  */
00064 #ifndef YYTOKENTYPE
00065 # define YYTOKENTYPE
00066    /* Put the tokens into the symbol table, so that GDB and other debuggers
00067       know about them.  */
00068    enum yytokentype {
00069      INTTOK = 1,
00070      FLOATTOK = 2,
00071      COLONTOK = 3,
00072      MINUSTOK = 4,
00073      PLUSTOK = 5,
00074      STRINGTOK = 6,
00075      ASTERICKTOK = 7,
00076      DISCOUNTTOK = 8,
00077      VALUESTOK = 9,
00078      STATETOK = 10,
00079      ACTIONTOK = 11,
00080      OBSTOK = 12,
00081      TTOK = 13,
00082      OTOK = 14,
00083      RTOK = 15,
00084      UNIFORMTOK = 16,
00085      IDENTITYTOK = 17,
00086      REWARDTOK = 18,
00087      COSTTOK = 19,
00088      RESETTOK = 20,
00089      STARTTOK = 21,
00090      INCLUDETOK = 22,
00091      EXCLUDETOK = 23,
00092      EOFTOK = 258
00093    };
00094 #endif
00095 /* Tokens.  */
00096 #define INTTOK 1
00097 #define FLOATTOK 2
00098 #define COLONTOK 3
00099 #define MINUSTOK 4
00100 #define PLUSTOK 5
00101 #define STRINGTOK 6
00102 #define ASTERICKTOK 7
00103 #define DISCOUNTTOK 8
00104 #define VALUESTOK 9
00105 #define STATETOK 10
00106 #define ACTIONTOK 11
00107 #define OBSTOK 12
00108 #define TTOK 13
00109 #define OTOK 14
00110 #define RTOK 15
00111 #define UNIFORMTOK 16
00112 #define IDENTITYTOK 17
00113 #define REWARDTOK 18
00114 #define COSTTOK 19
00115 #define RESETTOK 20
00116 #define STARTTOK 21
00117 #define INCLUDETOK 22
00118 #define EXCLUDETOK 23
00119 #define EOFTOK 258
00120 
00121 
00122 
00123 
00124 /* Copy the first part of user declarations.  */
00125 #line 1 "pomdp_spec.y"
00126 
00127 /*
00128   *****
00129   Copyright 1994-1997, Brown University
00130   Copyright 1998, 1999, Anthony R. Cassandra
00131 
00132                            All Rights Reserved
00133                            
00134   Permission to use, copy, modify, and distribute this software and its
00135   documentation for any purpose other than its incorporation into a
00136   commercial product is hereby granted without fee, provided that the
00137   above copyright notice appear in all copies and that both that
00138   copyright notice and this permission notice appear in supporting
00139   documentation.
00140   
00141   ANTHONY CASSANDRA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00142   INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00143   PARTICULAR PURPOSE.  IN NO EVENT SHALL ANTHONY CASSANDRA BE LIABLE FOR
00144   ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00145   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00146   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00147   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00148   *****
00149 
00150 */
00151 #include <stdio.h>
00152 #include <stdlib.h>
00153 #include "parse_err.h"
00154 #include "mdpCassandra.h"
00155 #include "parse_hash.h"
00156 #include "parse_constant.h"
00157 #include "sparse-matrix.h"
00158 #include "imm-reward.h"
00159 
00160 #define YACCtrace(X)       /* printf(X);fflush(stdout) */
00161 
00162 /* When reading in matrices we need to know what type we are reading
00163    and also we need to keep track of where in the matrix we are
00164    including how to update the row and col after each entry is read. */
00165 typedef enum { mc_none, mc_trans_single, mc_trans_row, mc_trans_all,
00166                mc_obs_single, mc_obs_row, mc_obs_all,
00167                mc_reward_single, mc_reward_row, 
00168                mc_reward_all, mc_reward_mdp_only,
00169                mc_start_belief, mc_mdp_start, 
00170                mc_start_include, mc_start_exclude } Matrix_Context;
00171 
00172 extern int yylex();
00173 
00174 /* Forward declaration for action routines which appear at end of file */
00175 void yyerror(char *string);
00176 void checkMatrix();
00177 void enterString( Constant_Block *block );
00178 void enterUniformMatrix( );
00179 void enterIdentityMatrix( );
00180 void enterResetMatrix( );
00181 void enterMatrix( REAL_VALUE value );
00182 void setMatrixContext( Matrix_Context context, 
00183                       int a, int i, int j, int obs );
00184 void enterStartState( int i );
00185 void setStartStateUniform();
00186 void endStartStates();
00187 void verifyPreamble();
00188 void checkProbs();
00189 
00190 /*  Helps to give more meaningful error messages */
00191 long currentLineNumber = 1;
00192 
00193 /* This sets the context needed when names are given the the states, 
00194    actions and/or observations */
00195 Mnemonic_Type curMnemonic = nt_unknown;
00196 
00197 Matrix_Context curMatrixContext = mc_none;
00198 
00199 /* These variable are used to keep track what type of matrix is being entered and
00200    which element is currently being processed.  They are initialized by the
00201    setMatrixContext() routine and updated by the enterMatrix() routine. */
00202 int curRow;
00203 int curCol;
00204 int minA, maxA;
00205 int minI, maxI;
00206 int minJ, maxJ;
00207 int minObs, maxObs;
00208 
00209 /*  These variables will keep the intermediate representation for the
00210     matrices.  We cannot know how to set up the sparse matrices until
00211     all entries are read in, so we must have this intermediate 
00212     representation, which will will convert when it has all been read in.
00213     We allocate this memory once we know how big they must be and we
00214     will free all of this when we convert it to its final sparse format.
00215     */
00216 I_Matrix *IP;   /* For transition matrices. */
00217 I_Matrix *IR;   /* For observation matrices. */
00218 I_Matrix **IW;  /* For reward matrices */
00219 
00220 /* These variables are used by the parser only, to keep some state
00221    information. 
00222 */
00223 /* These are set when the appropriate preamble line is encountered.  This will
00224    allow us to check to make sure each is specified.  If observations are not
00225    defined then we will assume it is a regular MDP, and otherwise assume it 
00226    is a POMDP
00227    */
00228 int discountDefined = 0;
00229 int valuesDefined = 0;
00230 int statesDefined = 0;
00231 int actionsDefined = 0;
00232 int observationsDefined = 0;
00233 
00234 /* We only want to check when observation probs. are specified, but
00235    there was no observations in preamble. */
00236 int observationSpecDefined = 0;
00237 
00238 /* When we encounter a matrix with too many entries.  We would like
00239    to only generate one error message, instead of one for each entry.
00240    This variable is cleared at the start of reading  a matrix and
00241    set when there are too many entries. */
00242 int gTooManyEntries = 0;
00243 
00244 
00245 
00246 /* Enabling traces.  */
00247 #ifndef YYDEBUG
00248 # define YYDEBUG 0
00249 #endif
00250 
00251 /* Enabling verbose error messages.  */
00252 #ifdef YYERROR_VERBOSE
00253 # undef YYERROR_VERBOSE
00254 # define YYERROR_VERBOSE 1
00255 #else
00256 # define YYERROR_VERBOSE 0
00257 #endif
00258 
00259 /* Enabling the token table.  */
00260 #ifndef YYTOKEN_TABLE
00261 # define YYTOKEN_TABLE 0
00262 #endif
00263 
00264 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
00265 typedef union YYSTYPE
00266 #line 130 "pomdp_spec.y"
00267 {
00268   Constant_Block *constBlk;
00269   int i_num;
00270   REAL_VALUE f_num;
00271 }
00272 /* Line 187 of yacc.c.  */
00273 #line 274 "include/pomdp_spec.tab.cc"
00274         YYSTYPE;
00275 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
00276 # define YYSTYPE_IS_DECLARED 1
00277 # define YYSTYPE_IS_TRIVIAL 1
00278 #endif
00279 
00280 
00281 
00282 /* Copy the second part of user declarations.  */
00283 
00284 
00285 /* Line 216 of yacc.c.  */
00286 #line 287 "include/pomdp_spec.tab.cc"
00287 
00288 #ifdef short
00289 # undef short
00290 #endif
00291 
00292 #ifdef YYTYPE_UINT8
00293 typedef YYTYPE_UINT8 yytype_uint8;
00294 #else
00295 typedef unsigned char yytype_uint8;
00296 #endif
00297 
00298 #ifdef YYTYPE_INT8
00299 typedef YYTYPE_INT8 yytype_int8;
00300 #elif (defined __STDC__ || defined __C99__FUNC__ \
00301      || defined __cplusplus || defined _MSC_VER)
00302 typedef signed char yytype_int8;
00303 #else
00304 typedef short int yytype_int8;
00305 #endif
00306 
00307 #ifdef YYTYPE_UINT16
00308 typedef YYTYPE_UINT16 yytype_uint16;
00309 #else
00310 typedef unsigned short int yytype_uint16;
00311 #endif
00312 
00313 #ifdef YYTYPE_INT16
00314 typedef YYTYPE_INT16 yytype_int16;
00315 #else
00316 typedef short int yytype_int16;
00317 #endif
00318 
00319 #ifndef YYSIZE_T
00320 # ifdef __SIZE_TYPE__
00321 #  define YYSIZE_T __SIZE_TYPE__
00322 # elif defined size_t
00323 #  define YYSIZE_T size_t
00324 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
00325      || defined __cplusplus || defined _MSC_VER)
00326 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
00327 #  define YYSIZE_T size_t
00328 # else
00329 #  define YYSIZE_T unsigned int
00330 # endif
00331 #endif
00332 
00333 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
00334 
00335 #ifndef YY_
00336 # if YYENABLE_NLS
00337 #  if ENABLE_NLS
00338 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
00339 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
00340 #  endif
00341 # endif
00342 # ifndef YY_
00343 #  define YY_(msgid) msgid
00344 # endif
00345 #endif
00346 
00347 /* Suppress unused-variable warnings by "using" E.  */
00348 #if ! defined lint || defined __GNUC__
00349 # define YYUSE(e) ((void) (e))
00350 #else
00351 # define YYUSE(e) /* empty */
00352 #endif
00353 
00354 /* Identity function, used to suppress warnings about constant conditions.  */
00355 #ifndef lint
00356 # define YYID(n) (n)
00357 #else
00358 #if (defined __STDC__ || defined __C99__FUNC__ \
00359      || defined __cplusplus || defined _MSC_VER)
00360 static int
00361 YYID (int i)
00362 #else
00363 static int
00364 YYID (i)
00365     int i;
00366 #endif
00367 {
00368   return i;
00369 }
00370 #endif
00371 
00372 #if ! defined yyoverflow || YYERROR_VERBOSE
00373 
00374 /* The parser invokes alloca or malloc; define the necessary symbols.  */
00375 
00376 # ifdef YYSTACK_USE_ALLOCA
00377 #  if YYSTACK_USE_ALLOCA
00378 #   ifdef __GNUC__
00379 #    define YYSTACK_ALLOC __builtin_alloca
00380 #   elif defined __BUILTIN_VA_ARG_INCR
00381 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
00382 #   elif defined _AIX
00383 #    define YYSTACK_ALLOC __alloca
00384 #   elif defined _MSC_VER
00385 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
00386 #    define alloca _alloca
00387 #   else
00388 #    define YYSTACK_ALLOC alloca
00389 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
00390      || defined __cplusplus || defined _MSC_VER)
00391 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
00392 #     ifndef _STDLIB_H
00393 #      define _STDLIB_H 1
00394 #     endif
00395 #    endif
00396 #   endif
00397 #  endif
00398 # endif
00399 
00400 # ifdef YYSTACK_ALLOC
00401    /* Pacify GCC's `empty if-body' warning.  */
00402 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
00403 #  ifndef YYSTACK_ALLOC_MAXIMUM
00404     /* The OS might guarantee only one guard page at the bottom of the stack,
00405        and a page size can be as small as 4096 bytes.  So we cannot safely
00406        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
00407        to allow for a few compiler-allocated temporary stack slots.  */
00408 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
00409 #  endif
00410 # else
00411 #  define YYSTACK_ALLOC YYMALLOC
00412 #  define YYSTACK_FREE YYFREE
00413 #  ifndef YYSTACK_ALLOC_MAXIMUM
00414 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
00415 #  endif
00416 #  if (defined __cplusplus && ! defined _STDLIB_H \
00417        && ! ((defined YYMALLOC || defined malloc) \
00418              && (defined YYFREE || defined free)))
00419 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
00420 #   ifndef _STDLIB_H
00421 #    define _STDLIB_H 1
00422 #   endif
00423 #  endif
00424 #  ifndef YYMALLOC
00425 #   define YYMALLOC malloc
00426 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
00427      || defined __cplusplus || defined _MSC_VER)
00428 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
00429 #   endif
00430 #  endif
00431 #  ifndef YYFREE
00432 #   define YYFREE free
00433 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
00434      || defined __cplusplus || defined _MSC_VER)
00435 void free (void *); /* INFRINGES ON USER NAME SPACE */
00436 #   endif
00437 #  endif
00438 # endif
00439 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
00440 
00441 
00442 #if (! defined yyoverflow \
00443      && (! defined __cplusplus \
00444          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
00445 
00446 /* A type that is properly aligned for any stack member.  */
00447 union yyalloc
00448 {
00449   yytype_int16 yyss;
00450   YYSTYPE yyvs;
00451   };
00452 
00453 /* The size of the maximum gap between one aligned stack and the next.  */
00454 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
00455 
00456 /* The size of an array large to enough to hold all stacks, each with
00457    N elements.  */
00458 # define YYSTACK_BYTES(N) \
00459      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
00460       + YYSTACK_GAP_MAXIMUM)
00461 
00462 /* Copy COUNT objects from FROM to TO.  The source and destination do
00463    not overlap.  */
00464 # ifndef YYCOPY
00465 #  if defined __GNUC__ && 1 < __GNUC__
00466 #   define YYCOPY(To, From, Count) \
00467       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
00468 #  else
00469 #   define YYCOPY(To, From, Count)              \
00470       do                                        \
00471         {                                       \
00472           YYSIZE_T yyi;                         \
00473           for (yyi = 0; yyi < (Count); yyi++)   \
00474             (To)[yyi] = (From)[yyi];            \
00475         }                                       \
00476       while (YYID (0))
00477 #  endif
00478 # endif
00479 
00480 /* Relocate STACK from its old location to the new one.  The
00481    local variables YYSIZE and YYSTACKSIZE give the old and new number of
00482    elements in the stack, and YYPTR gives the new location of the
00483    stack.  Advance YYPTR to a properly aligned location for the next
00484    stack.  */
00485 # define YYSTACK_RELOCATE(Stack)                                        \
00486     do                                                                  \
00487       {                                                                 \
00488         YYSIZE_T yynewbytes;                                            \
00489         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
00490         Stack = &yyptr->Stack;                                          \
00491         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
00492         yyptr += yynewbytes / sizeof (*yyptr);                          \
00493       }                                                                 \
00494     while (YYID (0))
00495 
00496 #endif
00497 
00498 /* YYFINAL -- State number of the termination state.  */
00499 #define YYFINAL  3
00500 /* YYLAST -- Last index in YYTABLE.  */
00501 #define YYLAST   115
00502 
00503 /* YYNTOKENS -- Number of terminals.  */
00504 #define YYNTOKENS  27
00505 /* YYNNTS -- Number of nonterminals.  */
00506 #define YYNNTS  52
00507 /* YYNRULES -- Number of rules.  */
00508 #define YYNRULES  93
00509 /* YYNRULES -- Number of states.  */
00510 #define YYNSTATES  133
00511 
00512 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
00513 #define YYUNDEFTOK  2
00514 #define YYMAXUTOK   259
00515 
00516 #define YYTRANSLATE(YYX)                                                \
00517   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
00518 
00519 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
00520 static const yytype_uint8 yytranslate[] =
00521 {
00522        0,     3,     4,     5,     6,     7,     8,     9,    10,    11,
00523       12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
00524       22,    23,    24,    25,     2,     2,     2,     2,     2,     2,
00525        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00526        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00527        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00528        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00529        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00530        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00531        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00532        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00533        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00534        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00535        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00536        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00537        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00538        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00539        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00540        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00541        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00542        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00543        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00544        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00545        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00546        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
00547        2,     2,     2,     2,     2,     2,     1,     2,    26,     2
00548 };
00549 
00550 #if YYDEBUG
00551 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
00552    YYRHS.  */
00553 static const yytype_uint8 yyprhs[] =
00554 {
00555        0,     0,     3,     4,     5,    11,    14,    15,    17,    19,
00556       21,    23,    25,    29,    33,    35,    37,    38,    43,    45,
00557       47,    48,    53,    55,    57,    58,    63,    65,    67,    68,
00558       73,    77,    78,    84,    85,    91,    92,    95,    97,   100,
00559      101,   103,   105,   107,   111,   112,   120,   121,   127,   128,
00560      132,   136,   137,   145,   146,   152,   153,   157,   161,   162,
00561      172,   173,   181,   182,   188,   189,   193,   195,   197,   199,
00562      201,   203,   205,   208,   210,   213,   215,   217,   219,   221,
00563      223,   225,   227,   229,   231,   233,   236,   238,   240,   242,
00564      245,   248,   250,   252
00565 };
00566 
00567 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
00568 static const yytype_int8 yyrhs[] =
00569 {
00570       28,     0,    -1,    -1,    -1,    31,    29,    45,    30,    50,
00571       -1,    31,    32,    -1,    -1,    33,    -1,    34,    -1,    36,
00572       -1,    39,    -1,    42,    -1,    10,     5,    77,    -1,    11,
00573        5,    35,    -1,    20,    -1,    21,    -1,    -1,    12,     5,
00574       37,    38,    -1,     3,    -1,    75,    -1,    -1,    13,     5,
00575       40,    41,    -1,     3,    -1,    75,    -1,    -1,    14,     5,
00576       43,    44,    -1,     3,    -1,    75,    -1,    -1,    23,     5,
00577       46,    69,    -1,    23,     5,     8,    -1,    -1,    23,    24,
00578        5,    47,    49,    -1,    -1,    23,    25,     5,    48,    49,
00579       -1,    -1,    49,    72,    -1,    72,    -1,    50,    51,    -1,
00580       -1,    52,    -1,    57,    -1,    62,    -1,    15,     5,    53,
00581       -1,    -1,    73,     5,    72,     5,    72,    54,    76,    -1,
00582       -1,    73,     5,    72,    55,    69,    -1,    -1,    73,    56,
00583       68,    -1,    16,     5,    58,    -1,    -1,    73,     5,    72,
00584        5,    74,    59,    76,    -1,    -1,    73,     5,    72,    60,
00585       69,    -1,    -1,    73,    61,    69,    -1,    17,     5,    63,
00586       -1,    -1,    73,     5,    72,     5,    72,     5,    74,    64,
00587       77,    -1,    -1,    73,     5,    72,     5,    72,    65,    71,
00588       -1,    -1,    73,     5,    72,    66,    71,    -1,    -1,    73,
00589       67,    71,    -1,    18,    -1,    19,    -1,    70,    -1,    18,
00590       -1,    22,    -1,    70,    -1,    70,    76,    -1,    76,    -1,
00591       71,    77,    -1,    77,    -1,     3,    -1,     8,    -1,     9,
00592       -1,     3,    -1,     8,    -1,     9,    -1,     3,    -1,     8,
00593       -1,     9,    -1,    75,     8,    -1,     8,    -1,     3,    -1,
00594        4,    -1,    78,     3,    -1,    78,     4,    -1,     7,    -1,
00595        6,    -1,    -1
00596 };
00597 
00598 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
00599 static const yytype_uint16 yyrline[] =
00600 {
00601        0,   143,   143,   167,   142,   202,   206,   208,   209,   210,
00602      211,   212,   214,   228,   234,   245,   251,   250,   269,   288,
00603      292,   291,   304,   323,   327,   326,   339,   358,   362,   361,
00604      378,   415,   414,   421,   420,   428,   432,   436,   441,   442,
00605      444,   445,   471,   473,   479,   478,   485,   484,   489,   489,
00606      494,   500,   499,   506,   505,   510,   510,   515,   523,   522,
00607      532,   531,   538,   537,   545,   544,   551,   555,   559,   565,
00608      569,   573,   578,   582,   587,   591,   596,   608,   622,   627,
00609      640,   654,   659,   671,   685,   690,   694,   699,   708,   721,
00610      729,   738,   742,   747
00611 };
00612 #endif
00613 
00614 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
00615 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
00616    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
00617 static const char *const yytname[] =
00618 {
00619   "$end", "error", "$undefined", "INTTOK", "FLOATTOK", "COLONTOK",
00620   "MINUSTOK", "PLUSTOK", "STRINGTOK", "ASTERICKTOK", "DISCOUNTTOK",
00621   "VALUESTOK", "STATETOK", "ACTIONTOK", "OBSTOK", "TTOK", "OTOK", "RTOK",
00622   "UNIFORMTOK", "IDENTITYTOK", "REWARDTOK", "COSTTOK", "RESETTOK",
00623   "STARTTOK", "INCLUDETOK", "EXCLUDETOK", "EOFTOK", "$accept",
00624   "pomdp_file", "@1", "@2", "preamble", "param_type", "discount_param",
00625   "value_param", "value_tail", "state_param", "@3", "state_tail",
00626   "action_param", "@4", "action_tail", "obs_param", "@5", "obs_param_tail",
00627   "start_state", "@6", "@7", "@8", "start_state_list", "param_list",
00628   "param_spec", "trans_prob_spec", "trans_spec_tail", "@9", "@10", "@11",
00629   "obs_prob_spec", "obs_spec_tail", "@12", "@13", "@14", "reward_spec",
00630   "reward_spec_tail", "@15", "@16", "@17", "@18", "ui_matrix", "u_matrix",
00631   "prob_matrix", "num_matrix", "state", "action", "obs", "ident_list",
00632   "prob", "number", "optional_sign", 0
00633 };
00634 #endif
00635 
00636 # ifdef YYPRINT
00637 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
00638    token YYLEX-NUM.  */
00639 static const yytype_uint16 yytoknum[] =
00640 {
00641        0,   256,   259,     1,     2,     3,     4,     5,     6,     7,
00642        8,     9,    10,    11,    12,    13,    14,    15,    16,    17,
00643       18,    19,    20,    21,    22,    23,   258
00644 };
00645 # endif
00646 
00647 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
00648 static const yytype_uint8 yyr1[] =
00649 {
00650        0,    27,    29,    30,    28,    31,    31,    32,    32,    32,
00651       32,    32,    33,    34,    35,    35,    37,    36,    38,    38,
00652       40,    39,    41,    41,    43,    42,    44,    44,    46,    45,
00653       45,    47,    45,    48,    45,    45,    49,    49,    50,    50,
00654       51,    51,    51,    52,    54,    53,    55,    53,    56,    53,
00655       57,    59,    58,    60,    58,    61,    58,    62,    64,    63,
00656       65,    63,    66,    63,    67,    63,    68,    68,    68,    69,
00657       69,    69,    70,    70,    71,    71,    72,    72,    72,    73,
00658       73,    73,    74,    74,    74,    75,    75,    76,    76,    77,
00659       77,    78,    78,    78
00660 };
00661 
00662 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
00663 static const yytype_uint8 yyr2[] =
00664 {
00665        0,     2,     0,     0,     5,     2,     0,     1,     1,     1,
00666        1,     1,     3,     3,     1,     1,     0,     4,     1,     1,
00667        0,     4,     1,     1,     0,     4,     1,     1,     0,     4,
00668        3,     0,     5,     0,     5,     0,     2,     1,     2,     0,
00669        1,     1,     1,     3,     0,     7,     0,     5,     0,     3,
00670        3,     0,     7,     0,     5,     0,     3,     3,     0,     9,
00671        0,     7,     0,     5,     0,     3,     1,     1,     1,     1,
00672        1,     1,     2,     1,     2,     1,     1,     1,     1,     1,
00673        1,     1,     1,     1,     1,     2,     1,     1,     1,     2,
00674        2,     1,     1,     0
00675 };
00676 
00677 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
00678    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
00679    means the default is an error.  */
00680 static const yytype_uint8 yydefact[] =
00681 {
00682        6,     0,     2,     1,     0,     0,     0,     0,     0,    35,
00683        5,     7,     8,     9,    10,    11,    93,     0,    16,    20,
00684       24,     0,     3,    92,    91,    12,     0,    14,    15,    13,
00685        0,     0,     0,    28,     0,     0,    39,    89,    90,    18,
00686       86,    17,    19,    22,    21,    23,    26,    25,    27,    30,
00687        0,    31,    33,     4,    85,    87,    88,    69,    70,    29,
00688       71,    73,     0,     0,     0,     0,     0,    38,    40,    41,
00689       42,    72,    76,    77,    78,    32,    37,    34,     0,     0,
00690        0,    36,    79,    80,    81,    43,    48,    50,    55,    57,
00691       64,     0,     0,     0,     0,     0,    93,    46,    66,    67,
00692       49,    68,    53,    56,    62,    65,    75,     0,     0,     0,
00693        0,     0,    93,    74,    44,    47,    82,    83,    84,    51,
00694       54,    60,    63,     0,     0,     0,    93,    45,    52,    58,
00695       61,    93,    59
00696 };
00697 
00698 /* YYDEFGOTO[NTERM-NUM].  */
00699 static const yytype_int16 yydefgoto[] =
00700 {
00701       -1,     1,     9,    36,     2,    10,    11,    12,    29,    13,
00702       30,    41,    14,    31,    44,    15,    32,    47,    22,    50,
00703       62,    63,    75,    53,    67,    68,    85,   123,   108,    92,
00704       69,    87,   124,   110,    94,    70,    89,   131,   126,   112,
00705       96,   100,    59,    60,   105,    76,    86,   119,    42,    61,
00706      106,    26
00707 };
00708 
00709 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
00710    STATE-NUM.  */
00711 #define YYPACT_NINF -106
00712 static const yytype_int8 yypact[] =
00713 {
00714     -106,    37,    35,  -106,    28,    38,    55,    58,    67,    17,
00715     -106,  -106,  -106,  -106,  -106,  -106,    52,    41,  -106,  -106,
00716     -106,     0,  -106,  -106,  -106,  -106,    63,  -106,  -106,  -106,
00717       27,    33,    36,    44,    70,    71,  -106,  -106,  -106,  -106,
00718     -106,  -106,    69,  -106,  -106,    69,  -106,  -106,    69,  -106,
00719        5,  -106,  -106,    40,  -106,  -106,  -106,  -106,  -106,  -106,
00720       65,  -106,     3,     3,    73,    74,    75,  -106,  -106,  -106,
00721     -106,  -106,  -106,  -106,  -106,     3,  -106,     3,     7,     7,
00722        7,  -106,  -106,  -106,  -106,  -106,    76,  -106,    77,  -106,
00723       78,     3,    10,     3,     5,     3,    52,    79,  -106,  -106,
00724     -106,    65,    80,  -106,    81,    47,  -106,     3,     5,    23,
00725        5,     3,    52,  -106,  -106,  -106,  -106,  -106,  -106,  -106,
00726     -106,    82,    47,    65,    65,    23,    52,  -106,  -106,  -106,
00727       47,    52,  -106
00728 };
00729 
00730 /* YYPGOTO[NTERM-NUM].  */
00731 static const yytype_int8 yypgoto[] =
00732 {
00733     -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,
00734     -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,
00735     -106,  -106,    25,  -106,  -106,  -106,  -106,  -106,  -106,  -106,
00736     -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,  -106,
00737     -106,  -106,   -91,    -2,  -105,   -73,    -9,   -34,    42,   -59,
00738      -16,  -106
00739 };
00740 
00741 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
00742    positive, shift that token.  If negative, reduce the rule which
00743    number is the opposite.  If zero, do what YYDEFACT says.
00744    If YYTABLE_NINF, syntax error.  */
00745 #define YYTABLE_NINF -94
00746 static const yytype_int16 yytable[] =
00747 {
00748       25,    71,    81,   103,    81,    33,    72,   122,    55,    56,
00749       82,    73,    74,    55,    56,    83,    84,   115,    97,   120,
00750      102,   130,   104,    57,    34,    35,   116,    58,    98,    99,
00751       39,   117,   118,    16,   114,    40,    43,     3,   121,    46,
00752       21,    40,    71,    17,    40,     4,     5,     6,     7,     8,
00753      -93,   -93,    49,    23,    24,    64,    65,    66,    23,    24,
00754       18,    27,    28,    19,   127,   128,    37,    38,    55,    56,
00755       88,    90,    20,    45,    48,    51,    52,    54,    78,    79,
00756       80,    91,    93,    95,   107,   109,   111,   125,    77,   113,
00757      101,   129,     0,     0,     0,     0,     0,     0,     0,     0,
00758        0,     0,     0,     0,     0,     0,   113,     0,     0,     0,
00759        0,     0,     0,     0,   113,   132
00760 };
00761 
00762 static const yytype_int16 yycheck[] =
00763 {
00764       16,    60,    75,    94,    77,     5,     3,   112,     3,     4,
00765        3,     8,     9,     3,     4,     8,     9,   108,    91,   110,
00766       93,   126,    95,    18,    24,    25,     3,    22,    18,    19,
00767        3,     8,     9,     5,   107,     8,     3,     0,   111,     3,
00768       23,     8,   101,     5,     8,    10,    11,    12,    13,    14,
00769        3,     4,     8,     6,     7,    15,    16,    17,     6,     7,
00770        5,    20,    21,     5,   123,   124,     3,     4,     3,     4,
00771       79,    80,     5,    31,    32,     5,     5,     8,     5,     5,
00772        5,     5,     5,     5,     5,     5,     5,     5,    63,   105,
00773       92,   125,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
00774       -1,    -1,    -1,    -1,    -1,    -1,   122,    -1,    -1,    -1,
00775       -1,    -1,    -1,    -1,   130,   131
00776 };
00777 
00778 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
00779    symbol of state STATE-NUM.  */
00780 static const yytype_uint8 yystos[] =
00781 {
00782        0,    28,    31,     0,    10,    11,    12,    13,    14,    29,
00783       32,    33,    34,    36,    39,    42,     5,     5,     5,     5,
00784        5,    23,    45,     6,     7,    77,    78,    20,    21,    35,
00785       37,    40,    43,     5,    24,    25,    30,     3,     4,     3,
00786        8,    38,    75,     3,    41,    75,     3,    44,    75,     8,
00787       46,     5,     5,    50,     8,     3,     4,    18,    22,    69,
00788       70,    76,    47,    48,    15,    16,    17,    51,    52,    57,
00789       62,    76,     3,     8,     9,    49,    72,    49,     5,     5,
00790        5,    72,     3,     8,     9,    53,    73,    58,    73,    63,
00791       73,     5,    56,     5,    61,     5,    67,    72,    18,    19,
00792       68,    70,    72,    69,    72,    71,    77,     5,    55,     5,
00793       60,     5,    66,    77,    72,    69,     3,     8,     9,    74,
00794       69,    72,    71,    54,    59,     5,    65,    76,    76,    74,
00795       71,    64,    77
00796 };
00797 
00798 #define yyerrok         (yyerrstatus = 0)
00799 #define yyclearin       (yychar = YYEMPTY)
00800 #define YYEMPTY         (-2)
00801 #define YYEOF           0
00802 
00803 #define YYACCEPT        goto yyacceptlab
00804 #define YYABORT         goto yyabortlab
00805 #define YYERROR         goto yyerrorlab
00806 
00807 
00808 /* Like YYERROR except do call yyerror.  This remains here temporarily
00809    to ease the transition to the new meaning of YYERROR, for GCC.
00810    Once GCC version 2 has supplanted version 1, this can go.  */
00811 
00812 #define YYFAIL          goto yyerrlab
00813 
00814 #define YYRECOVERING()  (!!yyerrstatus)
00815 
00816 #define YYBACKUP(Token, Value)                                  \
00817 do                                                              \
00818   if (yychar == YYEMPTY && yylen == 1)                          \
00819     {                                                           \
00820       yychar = (Token);                                         \
00821       yylval = (Value);                                         \
00822       yytoken = YYTRANSLATE (yychar);                           \
00823       YYPOPSTACK (1);                                           \
00824       goto yybackup;                                            \
00825     }                                                           \
00826   else                                                          \
00827     {                                                           \
00828       yyerror (YY_("syntax error: cannot back up")); \
00829       YYERROR;                                                  \
00830     }                                                           \
00831 while (YYID (0))
00832 
00833 
00834 #define YYTERROR        1
00835 #define YYERRCODE       256
00836 
00837 
00838 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
00839    If N is 0, then set CURRENT to the empty location which ends
00840    the previous symbol: RHS[0] (always defined).  */
00841 
00842 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
00843 #ifndef YYLLOC_DEFAULT
00844 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
00845     do                                                                  \
00846       if (YYID (N))                                                    \
00847         {                                                               \
00848           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
00849           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
00850           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
00851           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
00852         }                                                               \
00853       else                                                              \
00854         {                                                               \
00855           (Current).first_line   = (Current).last_line   =              \
00856             YYRHSLOC (Rhs, 0).last_line;                                \
00857           (Current).first_column = (Current).last_column =              \
00858             YYRHSLOC (Rhs, 0).last_column;                              \
00859         }                                                               \
00860     while (YYID (0))
00861 #endif
00862 
00863 
00864 /* YY_LOCATION_PRINT -- Print the location on the stream.
00865    This macro was not mandated originally: define only if we know
00866    we won't break user code: when these are the locations we know.  */
00867 
00868 #ifndef YY_LOCATION_PRINT
00869 # if YYLTYPE_IS_TRIVIAL
00870 #  define YY_LOCATION_PRINT(File, Loc)                  \
00871      fprintf (File, "%d.%d-%d.%d",                      \
00872               (Loc).first_line, (Loc).first_column,     \
00873               (Loc).last_line,  (Loc).last_column)
00874 # else
00875 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
00876 # endif
00877 #endif
00878 
00879 
00880 /* YYLEX -- calling `yylex' with the right arguments.  */
00881 
00882 #ifdef YYLEX_PARAM
00883 # define YYLEX yylex (YYLEX_PARAM)
00884 #else
00885 # define YYLEX yylex ()
00886 #endif
00887 
00888 /* Enable debugging if requested.  */
00889 #if YYDEBUG
00890 
00891 # ifndef YYFPRINTF
00892 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
00893 #  define YYFPRINTF fprintf
00894 # endif
00895 
00896 # define YYDPRINTF(Args)                        \
00897 do {                                            \
00898   if (yydebug)                                  \
00899     YYFPRINTF Args;                             \
00900 } while (YYID (0))
00901 
00902 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
00903 do {                                                                      \
00904   if (yydebug)                                                            \
00905     {                                                                     \
00906       YYFPRINTF (stderr, "%s ", Title);                                   \
00907       yy_symbol_print (stderr,                                            \
00908                   Type, Value); \
00909       YYFPRINTF (stderr, "\n");                                           \
00910     }                                                                     \
00911 } while (YYID (0))
00912 
00913 
00914 /*--------------------------------.
00915 | Print this symbol on YYOUTPUT.  |
00916 `--------------------------------*/
00917 
00918 /*ARGSUSED*/
00919 #if (defined __STDC__ || defined __C99__FUNC__ \
00920      || defined __cplusplus || defined _MSC_VER)
00921 static void
00922 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
00923 #else
00924 static void
00925 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
00926     FILE *yyoutput;
00927     int yytype;
00928     YYSTYPE const * const yyvaluep;
00929 #endif
00930 {
00931   if (!yyvaluep)
00932     return;
00933 # ifdef YYPRINT
00934   if (yytype < YYNTOKENS)
00935     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
00936 # else
00937   YYUSE (yyoutput);
00938 # endif
00939   switch (yytype)
00940     {
00941       default:
00942         break;
00943     }
00944 }
00945 
00946 
00947 /*--------------------------------.
00948 | Print this symbol on YYOUTPUT.  |
00949 `--------------------------------*/
00950 
00951 #if (defined __STDC__ || defined __C99__FUNC__ \
00952      || defined __cplusplus || defined _MSC_VER)
00953 static void
00954 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
00955 #else
00956 static void
00957 yy_symbol_print (yyoutput, yytype, yyvaluep)
00958     FILE *yyoutput;
00959     int yytype;
00960     YYSTYPE const * const yyvaluep;
00961 #endif
00962 {
00963   if (yytype < YYNTOKENS)
00964     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
00965   else
00966     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
00967 
00968   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
00969   YYFPRINTF (yyoutput, ")");
00970 }
00971 
00972 /*------------------------------------------------------------------.
00973 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
00974 | TOP (included).                                                   |
00975 `------------------------------------------------------------------*/
00976 
00977 #if (defined __STDC__ || defined __C99__FUNC__ \
00978      || defined __cplusplus || defined _MSC_VER)
00979 static void
00980 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
00981 #else
00982 static void
00983 yy_stack_print (bottom, top)
00984     yytype_int16 *bottom;
00985     yytype_int16 *top;
00986 #endif
00987 {
00988   YYFPRINTF (stderr, "Stack now");
00989   for (; bottom <= top; ++bottom)
00990     YYFPRINTF (stderr, " %d", *bottom);
00991   YYFPRINTF (stderr, "\n");
00992 }
00993 
00994 # define YY_STACK_PRINT(Bottom, Top)                            \
00995 do {                                                            \
00996   if (yydebug)                                                  \
00997     yy_stack_print ((Bottom), (Top));                           \
00998 } while (YYID (0))
00999 
01000 
01001 /*------------------------------------------------.
01002 | Report that the YYRULE is going to be reduced.  |
01003 `------------------------------------------------*/
01004 
01005 #if (defined __STDC__ || defined __C99__FUNC__ \
01006      || defined __cplusplus || defined _MSC_VER)
01007 static void
01008 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
01009 #else
01010 static void
01011 yy_reduce_print (yyvsp, yyrule)
01012     YYSTYPE *yyvsp;
01013     int yyrule;
01014 #endif
01015 {
01016   int yynrhs = yyr2[yyrule];
01017   int yyi;
01018   unsigned long int yylno = yyrline[yyrule];
01019   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
01020              yyrule - 1, yylno);
01021   /* The symbols being reduced.  */
01022   for (yyi = 0; yyi < yynrhs; yyi++)
01023     {
01024       fprintf (stderr, "   $%d = ", yyi + 1);
01025       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
01026                        &(yyvsp[(yyi + 1) - (yynrhs)])
01027                                        );
01028       fprintf (stderr, "\n");
01029     }
01030 }
01031 
01032 # define YY_REDUCE_PRINT(Rule)          \
01033 do {                                    \
01034   if (yydebug)                          \
01035     yy_reduce_print (yyvsp, Rule); \
01036 } while (YYID (0))
01037 
01038 /* Nonzero means print parse trace.  It is left uninitialized so that
01039    multiple parsers can coexist.  */
01040 int yydebug;
01041 #else /* !YYDEBUG */
01042 # define YYDPRINTF(Args)
01043 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
01044 # define YY_STACK_PRINT(Bottom, Top)
01045 # define YY_REDUCE_PRINT(Rule)
01046 #endif /* !YYDEBUG */
01047 
01048 
01049 /* YYINITDEPTH -- initial size of the parser's stacks.  */
01050 #ifndef YYINITDEPTH
01051 # define YYINITDEPTH 200
01052 #endif
01053 
01054 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
01055    if the built-in stack extension method is used).
01056 
01057    Do not make this value too large; the results are undefined if
01058    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
01059    evaluated with infinite-precision integer arithmetic.  */
01060 
01061 #ifndef YYMAXDEPTH
01062 # define YYMAXDEPTH 10000
01063 #endif
01064 
01065 
01066 
01067 #if YYERROR_VERBOSE
01068 
01069 # ifndef yystrlen
01070 #  if defined __GLIBC__ && defined _STRING_H
01071 #   define yystrlen strlen
01072 #  else
01073 /* Return the length of YYSTR.  */
01074 #if (defined __STDC__ || defined __C99__FUNC__ \
01075      || defined __cplusplus || defined _MSC_VER)
01076 static YYSIZE_T
01077 yystrlen (const char *yystr)
01078 #else
01079 static YYSIZE_T
01080 yystrlen (yystr)
01081     const char *yystr;
01082 #endif
01083 {
01084   YYSIZE_T yylen;
01085   for (yylen = 0; yystr[yylen]; yylen++)
01086     continue;
01087   return yylen;
01088 }
01089 #  endif
01090 # endif
01091 
01092 # ifndef yystpcpy
01093 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
01094 #   define yystpcpy stpcpy
01095 #  else
01096 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
01097    YYDEST.  */
01098 #if (defined __STDC__ || defined __C99__FUNC__ \
01099      || defined __cplusplus || defined _MSC_VER)
01100 static char *
01101 yystpcpy (char *yydest, const char *yysrc)
01102 #else
01103 static char *
01104 yystpcpy (yydest, yysrc)
01105     char *yydest;
01106     const char *yysrc;
01107 #endif
01108 {
01109   char *yyd = yydest;
01110   const char *yys = yysrc;
01111 
01112   while ((*yyd++ = *yys++) != '\0')
01113     continue;
01114 
01115   return yyd - 1;
01116 }
01117 #  endif
01118 # endif
01119 
01120 # ifndef yytnamerr
01121 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
01122    quotes and backslashes, so that it's suitable for yyerror.  The
01123    heuristic is that REAL_VALUE-quoting is unnecessary unless the string
01124    contains an apostrophe, a comma, or backslash (other than
01125    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
01126    null, do not copy; instead, return the length of what the result
01127    would have been.  */
01128 static YYSIZE_T
01129 yytnamerr (char *yyres, const char *yystr)
01130 {
01131   if (*yystr == '"')
01132     {
01133       YYSIZE_T yyn = 0;
01134       char const *yyp = yystr;
01135 
01136       for (;;)
01137         switch (*++yyp)
01138           {
01139           case '\'':
01140           case ',':
01141             goto do_not_strip_quotes;
01142 
01143           case '\\':
01144             if (*++yyp != '\\')
01145               goto do_not_strip_quotes;
01146             /* Fall through.  */
01147           default:
01148             if (yyres)
01149               yyres[yyn] = *yyp;
01150             yyn++;
01151             break;
01152 
01153           case '"':
01154             if (yyres)
01155               yyres[yyn] = '\0';
01156             return yyn;
01157           }
01158     do_not_strip_quotes: ;
01159     }
01160 
01161   if (! yyres)
01162     return yystrlen (yystr);
01163 
01164   return yystpcpy (yyres, yystr) - yyres;
01165 }
01166 # endif
01167 
01168 /* Copy into YYRESULT an error message about the unexpected token
01169    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
01170    including the terminating null byte.  If YYRESULT is null, do not
01171    copy anything; just return the number of bytes that would be
01172    copied.  As a special case, return 0 if an ordinary "syntax error"
01173    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
01174    size calculation.  */
01175 static YYSIZE_T
01176 yysyntax_error (char *yyresult, int yystate, int yychar)
01177 {
01178   int yyn = yypact[yystate];
01179 
01180   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
01181     return 0;
01182   else
01183     {
01184       int yytype = YYTRANSLATE (yychar);
01185       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
01186       YYSIZE_T yysize = yysize0;
01187       YYSIZE_T yysize1;
01188       int yysize_overflow = 0;
01189       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
01190       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
01191       int yyx;
01192 
01193 # if 0
01194       /* This is so xgettext sees the translatable formats that are
01195          constructed on the fly.  */
01196       YY_("syntax error, unexpected %s");
01197       YY_("syntax error, unexpected %s, expecting %s");
01198       YY_("syntax error, unexpected %s, expecting %s or %s");
01199       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
01200       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
01201 # endif
01202       char *yyfmt;
01203       char const *yyf;
01204       static char const yyunexpected[] = "syntax error, unexpected %s";
01205       static char const yyexpecting[] = ", expecting %s";
01206       static char const yyor[] = " or %s";
01207       char yyformat[sizeof yyunexpected
01208                     + sizeof yyexpecting - 1
01209                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
01210                        * (sizeof yyor - 1))];
01211       char const *yyprefix = yyexpecting;
01212 
01213       /* Start YYX at -YYN if negative to avoid negative indexes in
01214          YYCHECK.  */
01215       int yyxbegin = yyn < 0 ? -yyn : 0;
01216 
01217       /* Stay within bounds of both yycheck and yytname.  */
01218       int yychecklim = YYLAST - yyn + 1;
01219       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
01220       int yycount = 1;
01221 
01222       yyarg[0] = yytname[yytype];
01223       yyfmt = yystpcpy (yyformat, yyunexpected);
01224 
01225       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
01226         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
01227           {
01228             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
01229               {
01230                 yycount = 1;
01231                 yysize = yysize0;
01232                 yyformat[sizeof yyunexpected - 1] = '\0';
01233                 break;
01234               }
01235             yyarg[yycount++] = yytname[yyx];
01236             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
01237             yysize_overflow |= (yysize1 < yysize);
01238             yysize = yysize1;
01239             yyfmt = yystpcpy (yyfmt, yyprefix);
01240             yyprefix = yyor;
01241           }
01242 
01243       yyf = YY_(yyformat);
01244       yysize1 = yysize + yystrlen (yyf);
01245       yysize_overflow |= (yysize1 < yysize);
01246       yysize = yysize1;
01247 
01248       if (yysize_overflow)
01249         return YYSIZE_MAXIMUM;
01250 
01251       if (yyresult)
01252         {
01253           /* Avoid sprintf, as that infringes on the user's name space.
01254              Don't have undefined behavior even if the translation
01255              produced a string with the wrong number of "%s"s.  */
01256           char *yyp = yyresult;
01257           int yyi = 0;
01258           while ((*yyp = *yyf) != '\0')
01259             {
01260               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
01261                 {
01262                   yyp += yytnamerr (yyp, yyarg[yyi++]);
01263                   yyf += 2;
01264                 }
01265               else
01266                 {
01267                   yyp++;
01268                   yyf++;
01269                 }
01270             }
01271         }
01272       return yysize;
01273     }
01274 }
01275 #endif /* YYERROR_VERBOSE */
01276 
01277 
01278 /*-----------------------------------------------.
01279 | Release the memory associated to this symbol.  |
01280 `-----------------------------------------------*/
01281 
01282 /*ARGSUSED*/
01283 #if (defined __STDC__ || defined __C99__FUNC__ \
01284      || defined __cplusplus || defined _MSC_VER)
01285 static void
01286 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
01287 #else
01288 static void
01289 yydestruct (yymsg, yytype, yyvaluep)
01290     const char *yymsg;
01291     int yytype;
01292     YYSTYPE *yyvaluep;
01293 #endif
01294 {
01295   YYUSE (yyvaluep);
01296 
01297   if (!yymsg)
01298     yymsg = "Deleting";
01299   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
01300 
01301   switch (yytype)
01302     {
01303 
01304       default:
01305         break;
01306     }
01307 }
01308 
01309 
01310 /* Prevent warnings from -Wmissing-prototypes.  */
01311 
01312 #ifdef YYPARSE_PARAM
01313 #if defined __STDC__ || defined __cplusplus
01314 int yyparse (void *YYPARSE_PARAM);
01315 #else
01316 int yyparse ();
01317 #endif
01318 #else /* ! YYPARSE_PARAM */
01319 #if defined __STDC__ || defined __cplusplus
01320 int yyparse (void);
01321 #else
01322 int yyparse ();
01323 #endif
01324 #endif /* ! YYPARSE_PARAM */
01325 
01326 
01327 
01328 /* The look-ahead symbol.  */
01329 int yychar;
01330 
01331 /* The semantic value of the look-ahead symbol.  */
01332 YYSTYPE yylval;
01333 
01334 /* Number of syntax errors so far.  */
01335 int yynerrs;
01336 
01337 
01338 
01339 /*----------.
01340 | yyparse.  |
01341 `----------*/
01342 
01343 #ifdef YYPARSE_PARAM
01344 #if (defined __STDC__ || defined __C99__FUNC__ \
01345      || defined __cplusplus || defined _MSC_VER)
01346 int
01347 yyparse (void *YYPARSE_PARAM)
01348 #else
01349 int
01350 yyparse (YYPARSE_PARAM)
01351     void *YYPARSE_PARAM;
01352 #endif
01353 #else /* ! YYPARSE_PARAM */
01354 #if (defined __STDC__ || defined __C99__FUNC__ \
01355      || defined __cplusplus || defined _MSC_VER)
01356 int
01357 yyparse (void)
01358 #else
01359 int
01360 yyparse ()
01361 
01362 #endif
01363 #endif
01364 {
01365   
01366   int yystate;
01367   int yyn;
01368   int yyresult;
01369   /* Number of tokens to shift before error messages enabled.  */
01370   int yyerrstatus;
01371   /* Look-ahead token as an internal (translated) token number.  */
01372   int yytoken = 0;
01373 #if YYERROR_VERBOSE
01374   /* Buffer for error messages, and its allocated size.  */
01375   char yymsgbuf[128];
01376   char *yymsg = yymsgbuf;
01377   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
01378 #endif
01379 
01380   /* Three stacks and their tools:
01381      `yyss': related to states,
01382      `yyvs': related to semantic values,
01383      `yyls': related to locations.
01384 
01385      Refer to the stacks thru separate pointers, to allow yyoverflow
01386      to reallocate them elsewhere.  */
01387 
01388   /* The state stack.  */
01389   yytype_int16 yyssa[YYINITDEPTH];
01390   yytype_int16 *yyss = yyssa;
01391   yytype_int16 *yyssp;
01392 
01393   /* The semantic value stack.  */
01394   YYSTYPE yyvsa[YYINITDEPTH];
01395   YYSTYPE *yyvs = yyvsa;
01396   YYSTYPE *yyvsp;
01397 
01398 
01399 
01400 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
01401 
01402   YYSIZE_T yystacksize = YYINITDEPTH;
01403 
01404   /* The variables used to return semantic value and location from the
01405      action routines.  */
01406   YYSTYPE yyval;
01407 
01408 
01409   /* The number of symbols on the RHS of the reduced rule.
01410      Keep to zero when no symbol should be popped.  */
01411   int yylen = 0;
01412 
01413   YYDPRINTF ((stderr, "Starting parse\n"));
01414 
01415   yystate = 0;
01416   yyerrstatus = 0;
01417   yynerrs = 0;
01418   yychar = YYEMPTY;             /* Cause a token to be read.  */
01419 
01420   /* Initialize stack pointers.
01421      Waste one element of value and location stack
01422      so that they stay on the same level as the state stack.
01423      The wasted elements are never initialized.  */
01424 
01425   yyssp = yyss;
01426   yyvsp = yyvs;
01427 
01428   goto yysetstate;
01429 
01430 /*------------------------------------------------------------.
01431 | yynewstate -- Push a new state, which is found in yystate.  |
01432 `------------------------------------------------------------*/
01433  yynewstate:
01434   /* In all cases, when you get here, the value and location stacks
01435      have just been pushed.  So pushing a state here evens the stacks.  */
01436   yyssp++;
01437 
01438  yysetstate:
01439   *yyssp = yystate;
01440 
01441   if (yyss + yystacksize - 1 <= yyssp)
01442     {
01443       /* Get the current used size of the three stacks, in elements.  */
01444       YYSIZE_T yysize = yyssp - yyss + 1;
01445 
01446 #ifdef yyoverflow
01447       {
01448         /* Give user a chance to reallocate the stack.  Use copies of
01449            these so that the &'s don't force the real ones into
01450            memory.  */
01451         YYSTYPE *yyvs1 = yyvs;
01452         yytype_int16 *yyss1 = yyss;
01453 
01454 
01455         /* Each stack pointer address is followed by the size of the
01456            data in use in that stack, in bytes.  This used to be a
01457            conditional around just the two extra args, but that might
01458            be undefined if yyoverflow is a macro.  */
01459         yyoverflow (YY_("memory exhausted"),
01460                     &yyss1, yysize * sizeof (*yyssp),
01461                     &yyvs1, yysize * sizeof (*yyvsp),
01462 
01463                     &yystacksize);
01464 
01465         yyss = yyss1;
01466         yyvs = yyvs1;
01467       }
01468 #else /* no yyoverflow */
01469 # ifndef YYSTACK_RELOCATE
01470       goto yyexhaustedlab;
01471 # else
01472       /* Extend the stack our own way.  */
01473       if (YYMAXDEPTH <= yystacksize)
01474         goto yyexhaustedlab;
01475       yystacksize *= 2;
01476       if (YYMAXDEPTH < yystacksize)
01477         yystacksize = YYMAXDEPTH;
01478 
01479       {
01480         yytype_int16 *yyss1 = yyss;
01481         union yyalloc *yyptr =
01482           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
01483         if (! yyptr)
01484           goto yyexhaustedlab;
01485         YYSTACK_RELOCATE (yyss);
01486         YYSTACK_RELOCATE (yyvs);
01487 
01488 #  undef YYSTACK_RELOCATE
01489         if (yyss1 != yyssa)
01490           YYSTACK_FREE (yyss1);
01491       }
01492 # endif
01493 #endif /* no yyoverflow */
01494 
01495       yyssp = yyss + yysize - 1;
01496       yyvsp = yyvs + yysize - 1;
01497 
01498 
01499       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
01500                   (unsigned long int) yystacksize));
01501 
01502       if (yyss + yystacksize - 1 <= yyssp)
01503         YYABORT;
01504     }
01505 
01506   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
01507 
01508   goto yybackup;
01509 
01510 /*-----------.
01511 | yybackup.  |
01512 `-----------*/
01513 yybackup:
01514 
01515   /* Do appropriate processing given the current state.  Read a
01516      look-ahead token if we need one and don't already have one.  */
01517 
01518   /* First try to decide what to do without reference to look-ahead token.  */
01519   yyn = yypact[yystate];
01520   if (yyn == YYPACT_NINF)
01521     goto yydefault;
01522 
01523   /* Not known => get a look-ahead token if don't already have one.  */
01524 
01525   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
01526   if (yychar == YYEMPTY)
01527     {
01528       YYDPRINTF ((stderr, "Reading a token: "));
01529       yychar = YYLEX;
01530     }
01531 
01532   if (yychar <= YYEOF)
01533     {
01534       yychar = yytoken = YYEOF;
01535       YYDPRINTF ((stderr, "Now at end of input.\n"));
01536     }
01537   else
01538     {
01539       yytoken = YYTRANSLATE (yychar);
01540       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
01541     }
01542 
01543   /* If the proper action on seeing token YYTOKEN is to reduce or to
01544      detect an error, take that action.  */
01545   yyn += yytoken;
01546   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
01547     goto yydefault;
01548   yyn = yytable[yyn];
01549   if (yyn <= 0)
01550     {
01551       if (yyn == 0 || yyn == YYTABLE_NINF)
01552         goto yyerrlab;
01553       yyn = -yyn;
01554       goto yyreduce;
01555     }
01556 
01557   if (yyn == YYFINAL)
01558     YYACCEPT;
01559 
01560   /* Count tokens shifted since error; after three, turn off error
01561      status.  */
01562   if (yyerrstatus)
01563     yyerrstatus--;
01564 
01565   /* Shift the look-ahead token.  */
01566   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
01567 
01568   /* Discard the shifted token unless it is eof.  */
01569   if (yychar != YYEOF)
01570     yychar = YYEMPTY;
01571 
01572   yystate = yyn;
01573   *++yyvsp = yylval;
01574 
01575   goto yynewstate;
01576 
01577 
01578 /*-----------------------------------------------------------.
01579 | yydefault -- do the default action for the current state.  |
01580 `-----------------------------------------------------------*/
01581 yydefault:
01582   yyn = yydefact[yystate];
01583   if (yyn == 0)
01584     goto yyerrlab;
01585   goto yyreduce;
01586 
01587 
01588 /*-----------------------------.
01589 | yyreduce -- Do a reduction.  |
01590 `-----------------------------*/
01591 yyreduce:
01592   /* yyn is the number of a rule to reduce with.  */
01593   yylen = yyr2[yyn];
01594 
01595   /* If YYLEN is nonzero, implement the default value of the action:
01596      `$$ = $1'.
01597 
01598      Otherwise, the following line sets YYVAL to garbage.
01599      This behavior is undocumented and Bison
01600      users should not rely upon it.  Assigning to YYVAL
01601      unconditionally makes the parser a bit smaller, and it avoids a
01602      GCC warning that YYVAL may be used uninitialized.  */
01603   yyval = yyvsp[1-yylen];
01604 
01605 
01606   YY_REDUCE_PRINT (yyn);
01607   switch (yyn)
01608     {
01609         case 2:
01610 #line 143 "pomdp_spec.y"
01611     { 
01612                     /* The preamble is a section of the file which */
01613                     /* must come first and whcih contains some global */
01614                     /* properties of the MDP that the file */
01615                     /* specifies. (e.g., number of states).  The */
01616                     /* observations are optional and its presence or */
01617                     /* absence is what first tells the parser whether */
01618                     /* it is parsing an MDP or a POMDP. */
01619 
01620                     verifyPreamble();  /* make sure all things are */
01621                                        /* defined */
01622 
01623                     /* While we parse we use an intermediate */
01624                     /* representation which will be converted to the */
01625                     /* sparse representation when we are finished */
01626                     /* parsing.  After the preamble we are ready to */
01627                     /* start filling in values and we know how big the */
01628                     /* problem is, so we allocate the space for the */
01629                     /* intermediate forms */
01630 
01631                     allocateIntermediateMDP();  
01632                   ;}
01633     break;
01634 
01635   case 3:
01636 #line 167 "pomdp_spec.y"
01637     { 
01638                     /* Some type of algorithms want a place to start */
01639                     /* off the problem, especially when doing */
01640                     /* simulation type experiments.  This is an */
01641                     /* optional argument that allows specification of */
01642                     /* this.   In a POMDP this is a belief state, but */
01643                     /* in an MDP this is a single state.  If none is */
01644                     /* specified for a POMDP, then the uniform */
01645                     /* distribution over all states is used.  If none */
01646                     /* is specified for an MDP, then random states */
01647                     /* will be assumed. */
01648 
01649                     endStartStates(); 
01650                   ;}
01651     break;
01652 
01653   case 4:
01654 #line 186 "pomdp_spec.y"
01655     {
01656                     /* This is the very last thing we do while */
01657                     /* parsing.  Even though the file may conform to */
01658                     /* the syntax, the semantics of the problem */
01659                     /* specification requires probability */
01660                     /* distributions.  This routine will make sure */
01661                     /* that the appropriate things sum to 1.0 to make */
01662                     /* a valid probability distribution. This will */
01663                     /* also generate the error message when */
01664                     /* observation probabilities are specified in an */
01665                     /* MDP problem, since this is illegal. */
01666 
01667                      checkProbs();
01668                      YACCtrace("pomdp_file -> preamble params\n");
01669                   ;}
01670     break;
01671 
01672   case 5:
01673 #line 203 "pomdp_spec.y"
01674     {
01675                    YACCtrace("preamble -> preamble param_type\n");
01676                 ;}
01677     break;
01678 
01679   case 12:
01680 #line 215 "pomdp_spec.y"
01681     {
01682                   /* The discount factor only makes sense when in the */
01683                   /* range 0 to 1, so it is an error to specify */
01684                   /* anything outside this range. */
01685 
01686                    gDiscount = (yyvsp[(3) - (3)].f_num);
01687                    if(( gDiscount < 0.0 ) || ( gDiscount > 1.0 ))
01688                       ERR_enter("Parser<ytab>:", currentLineNumber,
01689                                 BAD_DISCOUNT_VAL, "");
01690                    discountDefined = 1;
01691                    YACCtrace("discount_param -> DISCOUNTTOK COLONTOK number\n");
01692                 ;}
01693     break;
01694 
01695   case 13:
01696 #line 229 "pomdp_spec.y"
01697     {
01698                    valuesDefined = 1;
01699                    YACCtrace("value_param -> VALUESTOK COLONTOK value_tail\n");
01700                 ;}
01701     break;
01702 
01703   case 14:
01704 #line 242 "pomdp_spec.y"
01705     {
01706                    gValueType = REWARD_value_type;
01707                 ;}
01708     break;
01709 
01710   case 15:
01711 #line 246 "pomdp_spec.y"
01712     {
01713                    gValueType = COST_value_type;
01714                 ;}
01715     break;
01716 
01717   case 16:
01718 #line 251 "pomdp_spec.y"
01719     { 
01720                   /* Since are able to enumerate the states and refer */
01721                   /* to them by identifiers, we will need to set the */
01722                   /* current state to indicate that we are parsing */
01723                   /* states.  This is important, since we will parse */
01724                   /* observatons and actions in exactly the same */
01725                   /* manner with the same code.  */
01726  
01727                   curMnemonic = nt_state; 
01728 
01729                 ;}
01730     break;
01731 
01732   case 17:
01733 #line 263 "pomdp_spec.y"
01734     {
01735                    statesDefined = 1;
01736                    curMnemonic = nt_unknown;
01737                    YACCtrace("state_param -> STATETOK COLONTOK state_tail\n");
01738                 ;}
01739     break;
01740 
01741   case 18:
01742 #line 270 "pomdp_spec.y"
01743     {
01744 
01745                   /*  For the number of states, we can just have a */
01746                   /*  number indicating how many there are, or ... */
01747 
01748                    gNumStates = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
01749                    if( gNumStates < 1 ) {
01750                       ERR_enter("Parser<ytab>:", currentLineNumber, 
01751                                 BAD_NUM_STATES, "");
01752                       gNumStates = 1;
01753                    }
01754 
01755                    /* Since we use some temporary storage to hold the
01756                       integer as we parse, we free the memory when we
01757                       are done with the value */
01758 
01759                    free( (yyvsp[(1) - (1)].constBlk) );
01760                 ;}
01761     break;
01762 
01763   case 20:
01764 #line 292 "pomdp_spec.y"
01765     {
01766                   /* See state_param for explanation of this */
01767 
01768                   curMnemonic = nt_action;  
01769                 ;}
01770     break;
01771 
01772   case 21:
01773 #line 298 "pomdp_spec.y"
01774     {
01775                    actionsDefined = 1;
01776                    curMnemonic = nt_unknown;
01777                    YACCtrace("action_param -> ACTIONTOK COLONTOK action_tail\n");
01778                 ;}
01779     break;
01780 
01781   case 22:
01782 #line 305 "pomdp_spec.y"
01783     {
01784 
01785                   /*  For the number of actions, we can just have a */
01786                   /*  number indicating how many there are, or ... */
01787 
01788                    gNumActions = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
01789                    if( gNumActions < 1 ) {
01790                       ERR_enter("Parser<ytab>:", currentLineNumber, 
01791                                 BAD_NUM_ACTIONS, "" );
01792                       gNumActions = 1;
01793                    }
01794                    
01795                    /* Since we use some temporary storage to hold the
01796                       integer as we parse, we free the memory when we
01797                       are done with the value */
01798 
01799                    free( (yyvsp[(1) - (1)].constBlk) );
01800                 ;}
01801     break;
01802 
01803   case 24:
01804 #line 327 "pomdp_spec.y"
01805     { 
01806                   /* See state_param for explanation of this */
01807 
01808                   curMnemonic = nt_observation; 
01809                 ;}
01810     break;
01811 
01812   case 25:
01813 #line 333 "pomdp_spec.y"
01814     {
01815                    observationsDefined = 1;
01816                    curMnemonic = nt_unknown;
01817                    YACCtrace("obs_param -> OBSTOK COLONTOK obs_param_tail\n");
01818                 ;}
01819     break;
01820 
01821   case 26:
01822 #line 340 "pomdp_spec.y"
01823     {
01824 
01825                   /*  For the number of observation, we can just have a */
01826                   /*  number indicating how many there are, or ... */
01827 
01828                    gNumObservations = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
01829                    if( gNumObservations < 1 ) {
01830                       ERR_enter("Parser<ytab>:", currentLineNumber, 
01831                                 BAD_NUM_OBS, "" );
01832                       gNumObservations = 1;
01833                    }
01834 
01835                    /* Since we use some temporary storage to hold the
01836                       integer as we parse, we free the memory when we
01837                       are done with the value */
01838 
01839                    free( (yyvsp[(1) - (1)].constBlk) );
01840                 ;}
01841     break;
01842 
01843   case 28:
01844 #line 362 "pomdp_spec.y"
01845     { 
01846                   /* There are a number of different formats for the */
01847                   /* start state.  This one is valid for either a */
01848                   /* POMDP or an MDP.  With a POMDP it will expect a */
01849                   /* list of probabilities, one for each state, */
01850                   /* representing the initial belief state.  For an */
01851                   /* MDP there can be only a single integer */
01852                   /* representing the starting state. */
01853 
01854                   if( gProblemType == POMDP_problem_type )
01855                     setMatrixContext(mc_start_belief, 0, 0, 0, 0); 
01856                   else
01857                     setMatrixContext(mc_mdp_start, 0, 0, 0, 0); 
01858                 ;}
01859     break;
01860 
01861   case 30:
01862 #line 395 "pomdp_spec.y"
01863     {
01864                    int num;
01865 
01866                    num = H_lookup( (yyvsp[(3) - (3)].constBlk)->theValue.theString, nt_state );
01867                    if(( num < 0 ) || (num >= gNumStates )) {
01868                      ERR_enter("Parser<ytab>:", currentLineNumber, 
01869                                  BAD_STATE_STR, (yyvsp[(3) - (3)].constBlk)->theValue.theString );
01870                    }
01871                    else
01872                      if( gProblemType == MDP_problem_type )
01873                        gInitialState = num;
01874                      else
01875                        gInitialBelief[num] = 1.0;
01876 
01877 
01878                    free( (yyvsp[(3) - (3)].constBlk)->theValue.theString );
01879                    free( (yyvsp[(3) - (3)].constBlk) );
01880                 ;}
01881     break;
01882 
01883   case 31:
01884 #line 415 "pomdp_spec.y"
01885     { 
01886                   setMatrixContext(mc_start_include, 0, 0, 0, 0); 
01887                 ;}
01888     break;
01889 
01890   case 33:
01891 #line 421 "pomdp_spec.y"
01892     { 
01893                   setMatrixContext(mc_start_exclude, 0, 0, 0, 0); 
01894                 ;}
01895     break;
01896 
01897   case 35:
01898 #line 428 "pomdp_spec.y"
01899     { 
01900                   setStartStateUniform(); 
01901                 ;}
01902     break;
01903 
01904   case 36:
01905 #line 433 "pomdp_spec.y"
01906     {
01907                   enterStartState( (yyvsp[(2) - (2)].i_num) );
01908                 ;}
01909     break;
01910 
01911   case 37:
01912 #line 437 "pomdp_spec.y"
01913     {
01914                   enterStartState( (yyvsp[(1) - (1)].i_num) );
01915                 ;}
01916     break;
01917 
01918   case 41:
01919 #line 446 "pomdp_spec.y"
01920     {
01921                     /* If there are observation specifications defined,
01922                        but no observations listed in the preamble, then
01923                        this is an error, since regular MDPs don't have
01924                        the concept of observations.  However, it could 
01925                        be a POMDP that was just missing the preamble 
01926                        part.  The way we handle this is to go ahead 
01927                        and parse the observation specifications, but
01928                        always check before we actually enter values in
01929                        a matrix (see the enterMatrix() routine.)  This
01930                        way we can determine if there are any problems 
01931                        with the observation specifications.  We cannot
01932                        add entries to the matrices since there will be
01933                        no memory allocated for it.  We want to
01934                        generate an error for this case, but don't want
01935                        a separate error for each observation
01936                        specification, so we define a variable that is
01937                        just a flag for whether or not any observation
01938                        specificiations have been defined.  After we
01939                        are all done parsing we will check this flag
01940                        and generate an error if needed.
01941                        */
01942 
01943                       observationSpecDefined = 1;
01944                   ;}
01945     break;
01946 
01947   case 43:
01948 #line 474 "pomdp_spec.y"
01949     {
01950                    YACCtrace("trans_prob_spec -> TTOK COLONTOK trans_spec_tail\n");
01951                 ;}
01952     break;
01953 
01954   case 44:
01955 #line 479 "pomdp_spec.y"
01956     { setMatrixContext(mc_trans_single, (yyvsp[(1) - (5)].i_num), (yyvsp[(3) - (5)].i_num), (yyvsp[(5) - (5)].i_num), 0); ;}
01957     break;
01958 
01959   case 45:
01960 #line 480 "pomdp_spec.y"
01961     {
01962                    enterMatrix( (yyvsp[(7) - (7)].f_num) );
01963                    YACCtrace("trans_spec_tail -> action COLONTOK state COLONTOK state prob \n");
01964                 ;}
01965     break;
01966 
01967   case 46:
01968 #line 485 "pomdp_spec.y"
01969     { setMatrixContext(mc_trans_row, (yyvsp[(1) - (3)].i_num), (yyvsp[(3) - (3)].i_num), 0, 0); ;}
01970     break;
01971 
01972   case 47:
01973 #line 486 "pomdp_spec.y"
01974     {
01975                    YACCtrace("trans_spec_tail -> action COLONTOK state ui_matrix \n");
01976                 ;}
01977     break;
01978 
01979   case 48:
01980 #line 489 "pomdp_spec.y"
01981     { setMatrixContext(mc_trans_all, (yyvsp[(1) - (1)].i_num), 0, 0, 0); ;}
01982     break;
01983 
01984   case 49:
01985 #line 490 "pomdp_spec.y"
01986     {
01987                    YACCtrace("trans_spec_tail -> action ui_matrix\n");
01988                 ;}
01989     break;
01990 
01991   case 50:
01992 #line 495 "pomdp_spec.y"
01993     {
01994                    YACCtrace("obs_prob_spec -> OTOK COLONTOK  obs_spec_tail\n");
01995                 ;}
01996     break;
01997 
01998   case 51:
01999 #line 500 "pomdp_spec.y"
02000     { setMatrixContext(mc_obs_single, (yyvsp[(1) - (5)].i_num), 0, (yyvsp[(3) - (5)].i_num), (yyvsp[(5) - (5)].i_num)); ;}
02001     break;
02002 
02003   case 52:
02004 #line 501 "pomdp_spec.y"
02005     {
02006                    enterMatrix( (yyvsp[(7) - (7)].f_num) );
02007                    YACCtrace("obs_spec_tail -> action COLONTOK state COLONTOK obs prob \n");
02008                 ;}
02009     break;
02010 
02011   case 53:
02012 #line 506 "pomdp_spec.y"
02013     { setMatrixContext(mc_obs_row, (yyvsp[(1) - (3)].i_num), 0, (yyvsp[(3) - (3)].i_num), 0); ;}
02014     break;
02015 
02016   case 54:
02017 #line 507 "pomdp_spec.y"
02018     {
02019                    YACCtrace("obs_spec_tail -> action COLONTOK state COLONTOK u_matrix\n");
02020                 ;}
02021     break;
02022 
02023   case 55:
02024 #line 510 "pomdp_spec.y"
02025     { setMatrixContext(mc_obs_all, (yyvsp[(1) - (1)].i_num), 0, 0, 0); ;}
02026     break;
02027 
02028   case 56:
02029 #line 511 "pomdp_spec.y"
02030     {
02031                    YACCtrace("obs_spec_tail -> action u_matrix\n");
02032                 ;}
02033     break;
02034 
02035   case 57:
02036 #line 516 "pomdp_spec.y"
02037     {
02038                    YACCtrace("reward_spec -> RTOK COLONTOK  reward_spec_tail\n");
02039                 ;}
02040     break;
02041 
02042   case 58:
02043 #line 523 "pomdp_spec.y"
02044     { setMatrixContext(mc_reward_single, (yyvsp[(1) - (7)].i_num), (yyvsp[(3) - (7)].i_num), (yyvsp[(5) - (7)].i_num), (yyvsp[(7) - (7)].i_num)); ;}
02045     break;
02046 
02047   case 59:
02048 #line 524 "pomdp_spec.y"
02049     {
02050                    enterMatrix( (yyvsp[(9) - (9)].f_num) );
02051 
02052                    /* Only need this for the call to doneImmReward */
02053                    checkMatrix();  
02054                    YACCtrace("reward_spec_tail -> action COLONTOK state COLONTOK state COLONTOK obs number\n");
02055                 ;}
02056     break;
02057 
02058   case 60:
02059 #line 532 "pomdp_spec.y"
02060     { setMatrixContext(mc_reward_row, (yyvsp[(1) - (5)].i_num), (yyvsp[(3) - (5)].i_num), (yyvsp[(5) - (5)].i_num), 0); ;}
02061     break;
02062 
02063   case 61:
02064 #line 533 "pomdp_spec.y"
02065     {
02066                    checkMatrix();
02067                    YACCtrace("reward_spec_tail -> action COLONTOK state COLONTOK state num_matrix\n");
02068                  ;}
02069     break;
02070 
02071   case 62:
02072 #line 538 "pomdp_spec.y"
02073     { setMatrixContext(mc_reward_all, (yyvsp[(1) - (3)].i_num), (yyvsp[(3) - (3)].i_num), 0, 0); ;}
02074     break;
02075 
02076   case 63:
02077 #line 539 "pomdp_spec.y"
02078     {
02079                    checkMatrix();
02080                    YACCtrace("reward_spec_tail -> action COLONTOK state num_matrix\n");
02081                 ;}
02082     break;
02083 
02084   case 64:
02085 #line 545 "pomdp_spec.y"
02086     { setMatrixContext(mc_reward_mdp_only, (yyvsp[(1) - (1)].i_num), 0, 0, 0); ;}
02087     break;
02088 
02089   case 65:
02090 #line 546 "pomdp_spec.y"
02091     {
02092                    checkMatrix();
02093                    YACCtrace("reward_spec_tail -> action num_matrix\n");
02094                 ;}
02095     break;
02096 
02097   case 66:
02098 #line 552 "pomdp_spec.y"
02099     {
02100                    enterUniformMatrix();
02101                 ;}
02102     break;
02103 
02104   case 67:
02105 #line 556 "pomdp_spec.y"
02106     {
02107                    enterIdentityMatrix();
02108                 ;}
02109     break;
02110 
02111   case 68:
02112 #line 560 "pomdp_spec.y"
02113     {
02114                    checkMatrix();
02115                 ;}
02116     break;
02117 
02118   case 69:
02119 #line 566 "pomdp_spec.y"
02120     {
02121                    enterUniformMatrix();
02122                 ;}
02123     break;
02124 
02125   case 70:
02126 #line 570 "pomdp_spec.y"
02127     {
02128                   enterResetMatrix();
02129                 ;}
02130     break;
02131 
02132   case 71:
02133 #line 574 "pomdp_spec.y"
02134     {
02135                    checkMatrix();
02136                 ;}
02137     break;
02138 
02139   case 72:
02140 #line 579 "pomdp_spec.y"
02141     {
02142                    enterMatrix( (yyvsp[(2) - (2)].f_num) );
02143                 ;}
02144     break;
02145 
02146   case 73:
02147 #line 583 "pomdp_spec.y"
02148     {
02149                    enterMatrix( (yyvsp[(1) - (1)].f_num) );
02150                 ;}
02151     break;
02152 
02153   case 74:
02154 #line 588 "pomdp_spec.y"
02155     {
02156                    enterMatrix( (yyvsp[(2) - (2)].f_num) );
02157                 ;}
02158     break;
02159 
02160   case 75:
02161 #line 592 "pomdp_spec.y"
02162     {
02163                    enterMatrix( (yyvsp[(1) - (1)].f_num) );
02164                 ;}
02165     break;
02166 
02167   case 76:
02168 #line 597 "pomdp_spec.y"
02169     {
02170                    if(( (yyvsp[(1) - (1)].constBlk)->theValue.theInt < 0 ) 
02171                       || ((yyvsp[(1) - (1)].constBlk)->theValue.theInt >= gNumStates )) {
02172                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02173                                 BAD_STATE_VAL, "");
02174                       (yyval.i_num) = 0;
02175                    }
02176                    else
02177                       (yyval.i_num) = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
02178                    free( (yyvsp[(1) - (1)].constBlk) );
02179                 ;}
02180     break;
02181 
02182   case 77:
02183 #line 609 "pomdp_spec.y"
02184     {
02185                    int num;
02186                    num = H_lookup( (yyvsp[(1) - (1)].constBlk)->theValue.theString, nt_state );
02187                    if(( num < 0 ) || (num >= gNumStates )) {
02188                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02189                                 BAD_STATE_STR, (yyvsp[(1) - (1)].constBlk)->theValue.theString );
02190                       (yyval.i_num) = 0;
02191                    }
02192                    else
02193                       (yyval.i_num) = num;
02194                    free( (yyvsp[(1) - (1)].constBlk)->theValue.theString );
02195                    free( (yyvsp[(1) - (1)].constBlk) );
02196                 ;}
02197     break;
02198 
02199   case 78:
02200 #line 623 "pomdp_spec.y"
02201     {
02202                    (yyval.i_num) = WILDCARD_SPEC;
02203                 ;}
02204     break;
02205 
02206   case 79:
02207 #line 628 "pomdp_spec.y"
02208     {
02209                    (yyval.i_num) = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
02210                    if(( (yyvsp[(1) - (1)].constBlk)->theValue.theInt < 0 ) 
02211                       || ((yyvsp[(1) - (1)].constBlk)->theValue.theInt >= gNumActions )) {
02212                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02213                                 BAD_ACTION_VAL, "" );
02214                       (yyval.i_num) = 0;
02215                    }
02216                    else
02217                       (yyval.i_num) = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
02218                    free( (yyvsp[(1) - (1)].constBlk) );
02219                 ;}
02220     break;
02221 
02222   case 80:
02223 #line 641 "pomdp_spec.y"
02224     {
02225                    int num;
02226                    num = H_lookup( (yyvsp[(1) - (1)].constBlk)->theValue.theString, nt_action );
02227                    if(( num < 0 ) || (num >= gNumActions )) {
02228                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02229                                 BAD_ACTION_STR, (yyvsp[(1) - (1)].constBlk)->theValue.theString );
02230                       (yyval.i_num) = 0;
02231                    }
02232                    else
02233                       (yyval.i_num) = num;
02234                    free( (yyvsp[(1) - (1)].constBlk)->theValue.theString );
02235                    free( (yyvsp[(1) - (1)].constBlk) );
02236                 ;}
02237     break;
02238 
02239   case 81:
02240 #line 655 "pomdp_spec.y"
02241     {
02242                    (yyval.i_num) = WILDCARD_SPEC;
02243                 ;}
02244     break;
02245 
02246   case 82:
02247 #line 660 "pomdp_spec.y"
02248     {
02249                    if(( (yyvsp[(1) - (1)].constBlk)->theValue.theInt < 0 ) 
02250                       || ((yyvsp[(1) - (1)].constBlk)->theValue.theInt >= gNumObservations )) {
02251                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02252                                 BAD_OBS_VAL, "");
02253                       (yyval.i_num) = 0;
02254                    }
02255                    else
02256                       (yyval.i_num) = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
02257                    free( (yyvsp[(1) - (1)].constBlk) );
02258                 ;}
02259     break;
02260 
02261   case 83:
02262 #line 672 "pomdp_spec.y"
02263     {
02264                    int num;
02265                    num = H_lookup( (yyvsp[(1) - (1)].constBlk)->theValue.theString, nt_observation );
02266                    if(( num < 0 ) || (num >= gNumObservations )) { 
02267                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02268                                 BAD_OBS_STR, (yyvsp[(1) - (1)].constBlk)->theValue.theString);
02269                       (yyval.i_num) = 0;
02270                    }
02271                    else
02272                       (yyval.i_num) = num;
02273                    free( (yyvsp[(1) - (1)].constBlk)->theValue.theString );
02274                    free( (yyvsp[(1) - (1)].constBlk) );
02275                ;}
02276     break;
02277 
02278   case 84:
02279 #line 686 "pomdp_spec.y"
02280     {
02281                    (yyval.i_num) = WILDCARD_SPEC;
02282                 ;}
02283     break;
02284 
02285   case 85:
02286 #line 691 "pomdp_spec.y"
02287     {
02288                    enterString( (yyvsp[(2) - (2)].constBlk) );
02289                 ;}
02290     break;
02291 
02292   case 86:
02293 #line 695 "pomdp_spec.y"
02294     {
02295                    enterString( (yyvsp[(1) - (1)].constBlk) );
02296                 ;}
02297     break;
02298 
02299   case 87:
02300 #line 700 "pomdp_spec.y"
02301     {
02302                   (yyval.f_num) = (yyvsp[(1) - (1)].constBlk)->theValue.theInt;
02303                   if( curMatrixContext != mc_mdp_start )
02304                     if(( (yyval.f_num) < 0 ) || ((yyval.f_num) > 1 ))
02305                       ERR_enter("Parser<ytab>:", currentLineNumber, 
02306                                 BAD_PROB_VAL, "");
02307                   free( (yyvsp[(1) - (1)].constBlk) );
02308                 ;}
02309     break;
02310 
02311   case 88:
02312 #line 709 "pomdp_spec.y"
02313     {
02314                    (yyval.f_num) = (yyvsp[(1) - (1)].constBlk)->theValue.theFloat;
02315                    if( curMatrixContext == mc_mdp_start )
02316                      ERR_enter("Parser<ytab>:", currentLineNumber, 
02317                                BAD_START_STATE_TYPE, "" );
02318                    else
02319                      if(( (yyval.f_num) < 0.0 ) || ((yyval.f_num) > 1.0 ))
02320                        ERR_enter("Parser<ytab>:", currentLineNumber, 
02321                                  BAD_PROB_VAL, "" );
02322                    free( (yyvsp[(1) - (1)].constBlk) );
02323                 ;}
02324     break;
02325 
02326   case 89:
02327 #line 722 "pomdp_spec.y"
02328     {
02329                    if( (yyvsp[(1) - (2)].i_num) )
02330                       (yyval.f_num) = (yyvsp[(2) - (2)].constBlk)->theValue.theInt * -1.0;
02331                    else
02332                       (yyval.f_num) = (yyvsp[(2) - (2)].constBlk)->theValue.theInt;
02333                    free( (yyvsp[(2) - (2)].constBlk) );
02334                 ;}
02335     break;
02336 
02337   case 90:
02338 #line 730 "pomdp_spec.y"
02339     {
02340                    if( (yyvsp[(1) - (2)].i_num) )
02341                       (yyval.f_num) = (yyvsp[(2) - (2)].constBlk)->theValue.theFloat * -1.0;
02342                    else
02343                       (yyval.f_num) = (yyvsp[(2) - (2)].constBlk)->theValue.theFloat;
02344                    free( (yyvsp[(2) - (2)].constBlk) );
02345                 ;}
02346     break;
02347 
02348   case 91:
02349 #line 739 "pomdp_spec.y"
02350     {
02351                    (yyval.i_num) = 0;
02352                 ;}
02353     break;
02354 
02355   case 92:
02356 #line 743 "pomdp_spec.y"
02357     {
02358                    (yyval.i_num) = 1;
02359                 ;}
02360     break;
02361 
02362   case 93:
02363 #line 747 "pomdp_spec.y"
02364     {
02365                    (yyval.i_num) = 0;
02366                 ;}
02367     break;
02368 
02369 
02370 /* Line 1267 of yacc.c.  */
02371 #line 2372 "include/pomdp_spec.tab.cc"
02372       default: break;
02373     }
02374   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
02375 
02376   YYPOPSTACK (yylen);
02377   yylen = 0;
02378   YY_STACK_PRINT (yyss, yyssp);
02379 
02380   *++yyvsp = yyval;
02381 
02382 
02383   /* Now `shift' the result of the reduction.  Determine what state
02384      that goes to, based on the state we popped back to and the rule
02385      number reduced by.  */
02386 
02387   yyn = yyr1[yyn];
02388 
02389   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
02390   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
02391     yystate = yytable[yystate];
02392   else
02393     yystate = yydefgoto[yyn - YYNTOKENS];
02394 
02395   goto yynewstate;
02396 
02397 
02398 /*------------------------------------.
02399 | yyerrlab -- here on detecting error |
02400 `------------------------------------*/
02401 yyerrlab:
02402   /* If not already recovering from an error, report this error.  */
02403   if (!yyerrstatus)
02404     {
02405       ++yynerrs;
02406 #if ! YYERROR_VERBOSE
02407       yyerror (YY_("syntax error"));
02408 #else
02409       {
02410         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
02411         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
02412           {
02413             YYSIZE_T yyalloc = 2 * yysize;
02414             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
02415               yyalloc = YYSTACK_ALLOC_MAXIMUM;
02416             if (yymsg != yymsgbuf)
02417               YYSTACK_FREE (yymsg);
02418             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
02419             if (yymsg)
02420               yymsg_alloc = yyalloc;
02421             else
02422               {
02423                 yymsg = yymsgbuf;
02424                 yymsg_alloc = sizeof yymsgbuf;
02425               }
02426           }
02427 
02428         if (0 < yysize && yysize <= yymsg_alloc)
02429           {
02430             (void) yysyntax_error (yymsg, yystate, yychar);
02431             yyerror (yymsg);
02432           }
02433         else
02434           {
02435             yyerror (YY_("syntax error"));
02436             if (yysize != 0)
02437               goto yyexhaustedlab;
02438           }
02439       }
02440 #endif
02441     }
02442 
02443 
02444 
02445   if (yyerrstatus == 3)
02446     {
02447       /* If just tried and failed to reuse look-ahead token after an
02448          error, discard it.  */
02449 
02450       if (yychar <= YYEOF)
02451         {
02452           /* Return failure if at end of input.  */
02453           if (yychar == YYEOF)
02454             YYABORT;
02455         }
02456       else
02457         {
02458           yydestruct ("Error: discarding",
02459                       yytoken, &yylval);
02460           yychar = YYEMPTY;
02461         }
02462     }
02463 
02464   /* Else will try to reuse look-ahead token after shifting the error
02465      token.  */
02466   goto yyerrlab1;
02467 
02468 
02469 /*---------------------------------------------------.
02470 | yyerrorlab -- error raised explicitly by YYERROR.  |
02471 `---------------------------------------------------*/
02472 yyerrorlab:
02473 
02474   /* Pacify compilers like GCC when the user code never invokes
02475      YYERROR and the label yyerrorlab therefore never appears in user
02476      code.  */
02477   if (/*CONSTCOND*/ 0)
02478      goto yyerrorlab;
02479 
02480   /* Do not reclaim the symbols of the rule which action triggered
02481      this YYERROR.  */
02482   YYPOPSTACK (yylen);
02483   yylen = 0;
02484   YY_STACK_PRINT (yyss, yyssp);
02485   yystate = *yyssp;
02486   goto yyerrlab1;
02487 
02488 
02489 /*-------------------------------------------------------------.
02490 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
02491 `-------------------------------------------------------------*/
02492 yyerrlab1:
02493   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
02494 
02495   for (;;)
02496     {
02497       yyn = yypact[yystate];
02498       if (yyn != YYPACT_NINF)
02499         {
02500           yyn += YYTERROR;
02501           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
02502             {
02503               yyn = yytable[yyn];
02504               if (0 < yyn)
02505                 break;
02506             }
02507         }
02508 
02509       /* Pop the current state because it cannot handle the error token.  */
02510       if (yyssp == yyss)
02511         YYABORT;
02512 
02513 
02514       yydestruct ("Error: popping",
02515                   yystos[yystate], yyvsp);
02516       YYPOPSTACK (1);
02517       yystate = *yyssp;
02518       YY_STACK_PRINT (yyss, yyssp);
02519     }
02520 
02521   if (yyn == YYFINAL)
02522     YYACCEPT;
02523 
02524   *++yyvsp = yylval;
02525 
02526 
02527   /* Shift the error token.  */
02528   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
02529 
02530   yystate = yyn;
02531   goto yynewstate;
02532 
02533 
02534 /*-------------------------------------.
02535 | yyacceptlab -- YYACCEPT comes here.  |
02536 `-------------------------------------*/
02537 yyacceptlab:
02538   yyresult = 0;
02539   goto yyreturn;
02540 
02541 /*-----------------------------------.
02542 | yyabortlab -- YYABORT comes here.  |
02543 `-----------------------------------*/
02544 yyabortlab:
02545   yyresult = 1;
02546   goto yyreturn;
02547 
02548 #ifndef yyoverflow
02549 /*-------------------------------------------------.
02550 | yyexhaustedlab -- memory exhaustion comes here.  |
02551 `-------------------------------------------------*/
02552 yyexhaustedlab:
02553   yyerror (YY_("memory exhausted"));
02554   yyresult = 2;
02555   /* Fall through.  */
02556 #endif
02557 
02558 yyreturn:
02559   if (yychar != YYEOF && yychar != YYEMPTY)
02560      yydestruct ("Cleanup: discarding lookahead",
02561                  yytoken, &yylval);
02562   /* Do not reclaim the symbols of the rule which action triggered
02563      this YYABORT or YYACCEPT.  */
02564   YYPOPSTACK (yylen);
02565   YY_STACK_PRINT (yyss, yyssp);
02566   while (yyssp != yyss)
02567     {
02568       yydestruct ("Cleanup: popping",
02569                   yystos[*yyssp], yyvsp);
02570       YYPOPSTACK (1);
02571     }
02572 #ifndef yyoverflow
02573   if (yyss != yyssa)
02574     YYSTACK_FREE (yyss);
02575 #endif
02576 #if YYERROR_VERBOSE
02577   if (yymsg != yymsgbuf)
02578     YYSTACK_FREE (yymsg);
02579 #endif
02580   /* Make sure YYID is used.  */
02581   return YYID (yyresult);
02582 }
02583 
02584 
02585 #line 754 "pomdp_spec.y"
02586 
02587 
02588 /********************************************************************/
02589 /*              External Routines                                   */
02590 /********************************************************************/
02591 
02592 #define EPSILON  0.00001  /* tolerance for sum of probs == 1 */
02593 
02594 Constant_Block *aConst;
02595 
02596 /******************************************************************************/
02597 void yyerror(char *string)
02598 {
02599    ERR_enter("Parser<yyparse>", currentLineNumber, PARSE_ERR,"");
02600 }  /* yyerror */
02601 /******************************************************************************/
02602 void checkMatrix() {
02603 /* When a matrix is finished being read for the exactly correct number of
02604    values, curRow should be 0 and curCol should be -1.  For the cases
02605    where we are only interested in a row of entries curCol should be -1.
02606    If we get too many entries, then we will catch this as we parse the 
02607    extra entries.  Therefore, here we only need to check for too few 
02608    entries.
02609    */
02610 
02611    switch( curMatrixContext ) {
02612    case mc_trans_row:
02613       if( curCol < gNumStates )
02614          ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02615                    TOO_FEW_ENTRIES, "");
02616       break;
02617    case mc_trans_all:
02618       if((curRow < (gNumStates-1) )
02619          || ((curRow == (gNumStates-1))
02620              && ( curCol < gNumStates ))) 
02621         ERR_enter("Parser<checkMatrix>:", currentLineNumber,  
02622                    TOO_FEW_ENTRIES, "" );
02623       break;
02624    case mc_obs_row:
02625       if( curCol < gNumObservations )
02626          ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02627                    TOO_FEW_ENTRIES, "");
02628       break;
02629    case mc_obs_all:
02630       if((curRow < (gNumStates-1) )
02631          || ((curRow == (gNumStates-1))
02632              && ( curCol < gNumObservations ))) 
02633          ERR_enter("Parser<checkMatrix>:", currentLineNumber,  
02634                    TOO_FEW_ENTRIES, "" );
02635       break;
02636    case mc_start_belief:
02637       if( curCol < gNumStates )
02638         ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02639                   TOO_FEW_ENTRIES, "");
02640       break;
02641 
02642     case mc_mdp_start:
02643       /* We will check for invalid multiple entries for MDP in 
02644          enterMatrix() */
02645       break;
02646 
02647     case mc_reward_row:
02648       if( gProblemType == POMDP_problem_type )
02649         if( curCol < gNumObservations )
02650           ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02651                     TOO_FEW_ENTRIES, "");
02652       break;
02653 
02654     case mc_reward_all:
02655       if( gProblemType == POMDP_problem_type ) {
02656         if((curRow < (gNumStates-1) )
02657            || ((curRow == (gNumStates-1))
02658                && ( curCol < gNumObservations ))) 
02659           ERR_enter("Parser<checkMatrix>:", currentLineNumber,  
02660                     TOO_FEW_ENTRIES, "" );
02661       }
02662       else
02663         if( curCol < gNumStates )
02664           ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02665                     TOO_FEW_ENTRIES, "");
02666       
02667       break;
02668     case mc_reward_single:
02669       /* Don't need to do anything */
02670       break;
02671 
02672     case mc_reward_mdp_only:
02673       if((curRow < (gNumStates-1) )
02674          || ((curRow == (gNumStates-1))
02675              && ( curCol < gNumStates ))) 
02676         ERR_enter("Parser<checkMatrix>:", currentLineNumber,  
02677                   TOO_FEW_ENTRIES, "" );
02678       break;
02679 
02680    default:
02681       ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02682                 BAD_MATRIX_CONTEXT, "" );
02683       break;
02684    }  /* switch */
02685 
02686    if( gTooManyEntries )
02687      ERR_enter("Parser<checkMatrix>:", currentLineNumber, 
02688                TOO_MANY_ENTRIES, "" );
02689 
02690    /* After reading a line for immediate rewards for a pomdp, we must tell
02691       the data structures for the special representation that we are done */
02692    switch( curMatrixContext ) {
02693    case mc_reward_row:
02694    case mc_reward_all:
02695    case mc_reward_mdp_only:
02696      doneImmReward();
02697      break;
02698 
02699      /* This case is only valid for POMDPs, so if we have an MDP, we
02700         never would have started a new immediate reward, so calling 
02701         the doneImmReward will be in error.  */
02702    case mc_reward_single:
02703      if( gProblemType == POMDP_problem_type )
02704        doneImmReward();
02705      break;
02706    default:
02707      break;
02708    }  /* switch */
02709    
02710 
02711    curMatrixContext = mc_none;  /* reset this as a safety precaution */
02712 }  /* checkMatrix */
02713 /******************************************************************************/
02714 void enterString( Constant_Block *block ) {
02715    
02716    if( H_enter( block->theValue.theString, curMnemonic ) == 0 )
02717       ERR_enter("Parser<enterString>:", currentLineNumber, 
02718                 DUPLICATE_STRING, block->theValue.theString );
02719 
02720    free( block->theValue.theString );
02721    free( block );
02722 }  /* enterString */
02723 /******************************************************************************/
02724 void enterUniformMatrix( ) {
02725    int a, i, j, obs;
02726    REAL_VALUE prob;
02727 
02728    switch( curMatrixContext ) {
02729    case mc_trans_row:
02730       prob = 1.0/gNumStates;
02731       for( a = minA; a <= maxA; a++ )
02732          for( i = minI; i <= maxI; i++ )
02733             for( j = 0; j < gNumStates; j++ )
02734                addEntryToIMatrix( IP[a], i, j, prob );
02735       break;
02736    case mc_trans_all:
02737       prob = 1.0/gNumStates;
02738       for( a = minA; a <= maxA; a++ )
02739          for( i = 0; i < gNumStates; i++ )
02740             for( j = 0; j < gNumStates; j++ )
02741                addEntryToIMatrix( IP[a], i, j, prob );
02742       break;
02743    case mc_obs_row:
02744       prob = 1.0/gNumObservations;
02745       for( a = minA; a <= maxA; a++ )
02746          for( j = minJ; j <= maxJ; j++ )
02747             for( obs = 0; obs < gNumObservations; obs++ )
02748                addEntryToIMatrix( IR[a], j, obs, prob );
02749       break;
02750    case mc_obs_all:
02751       prob = 1.0/gNumObservations;
02752       for( a = minA; a <= maxA; a++ )
02753          for( j = 0; j < gNumStates; j++ )
02754             for( obs = 0; obs < gNumObservations; obs++ )
02755                addEntryToIMatrix( IR[a], j, obs, prob );
02756       break;
02757    case mc_start_belief:
02758       setStartStateUniform();
02759       break;
02760    case mc_mdp_start:
02761       /* This is meaning less for an MDP */
02762       ERR_enter("Parser<enterUniformMatrix>:", currentLineNumber, 
02763                 BAD_START_STATE_TYPE, "" );
02764       break;
02765    default:
02766       ERR_enter("Parser<enterUniformMatrix>:", currentLineNumber, 
02767                 BAD_MATRIX_CONTEXT, "" );
02768       break;
02769    }  /* switch */
02770 }  /* enterUniformMatrix */
02771 /******************************************************************************/
02772 void enterIdentityMatrix( ) {
02773    int a, i,j;
02774 
02775    switch( curMatrixContext ) {
02776    case mc_trans_all:
02777       for( a = minA; a <= maxA; a++ )
02778          for( i = 0; i < gNumStates; i++ )
02779             for( j = 0; j < gNumStates; j++ )
02780                if( i == j )
02781                  addEntryToIMatrix( IP[a], i, j, 1.0 );
02782                else
02783                  addEntryToIMatrix( IP[a], i, j, 0.0 );
02784       break;
02785    default:
02786       ERR_enter("Parser<enterIdentityMatrix>:", currentLineNumber, 
02787                 BAD_MATRIX_CONTEXT, "" );
02788       break;
02789    }  /* switch */
02790 }  /* enterIdentityMatrix */
02791 /******************************************************************************/
02792 void enterResetMatrix( ) {
02793   int a, i, j;
02794 
02795   if( curMatrixContext != mc_trans_row ) {
02796     ERR_enter("Parser<enterMatrix>:", currentLineNumber, 
02797               BAD_RESET_USAGE, "" );
02798     return;
02799   }
02800 
02801   if( gProblemType == POMDP_problem_type )
02802     for( a = minA; a <= maxA; a++ )
02803       for( i = minI; i <= maxI; i++ )
02804         for( j = 0; j < gNumStates; j++ )
02805           addEntryToIMatrix( IP[a], i, j, gInitialBelief[j] );
02806   
02807   else  /* It is an MDP */
02808     for( a = minA; a <= maxA; a++ )
02809       for( i = minI; i <= maxI; i++ )
02810         addEntryToIMatrix( IP[a], i, gInitialState, 1.0 );
02811   
02812 
02813 }  /* enterResetMatrix */
02814 /******************************************************************************/
02815 void enterMatrix( REAL_VALUE value ) {
02816 /*
02817   For the '_single' context types we never have to worry about setting or 
02818   checking the bounds on the current row or col.  For all other we do and
02819   how this is done depends on the context.  Notice that we are filling in the 
02820   elements in reverse order due to the left-recursive grammar.  Thus
02821   we need to update the col and row backwards 
02822   */
02823    int a, i, j, obs;
02824 
02825    switch( curMatrixContext ) {
02826    case mc_trans_single:
02827       for( a = minA; a <= maxA; a++ )
02828          for( i = minI; i <= maxI; i++ )
02829             for( j = minJ; j <= maxJ; j++ )
02830               addEntryToIMatrix( IP[a], i, j, value );
02831       break;
02832    case mc_trans_row:
02833       if( curCol < gNumStates ) {
02834          for( a = minA; a <= maxA; a++ )
02835             for( i = minI; i <= maxI; i++ )
02836               addEntryToIMatrix( IP[a], i, curCol, value );
02837          curCol++;
02838       }
02839       else
02840         gTooManyEntries = 1;
02841 
02842       break;
02843    case mc_trans_all:
02844       if( curCol >= gNumStates ) {
02845          curRow++;
02846          curCol = 0;;
02847       }
02848 
02849       if( curRow < gNumStates ) {
02850          for( a = minA; a <= maxA; a++ )
02851            addEntryToIMatrix( IP[a], curRow, curCol, value );
02852          curCol++;
02853       } else {
02854         gTooManyEntries = 1;
02855       }
02856 
02857       break;
02858 
02859    case mc_obs_single:
02860 
02861      if( gProblemType == POMDP_problem_type ) {
02862        /* We ignore this if it is an MDP */
02863        
02864        for( a = minA; a <= maxA; a++ )
02865          for( j = minJ; j <= maxJ; j++ )
02866            for( obs = minObs; obs <= maxObs; obs++ )
02867              addEntryToIMatrix( IR[a], j, obs, value );
02868      }
02869      break;
02870 
02871    case mc_obs_row:
02872      {
02873        if( gProblemType == POMDP_problem_type ) {
02874          /* We ignore this if it is an MDP */
02875          
02876          if( curCol < gNumObservations ) {
02877            
02878            for( a = minA; a <= maxA; a++ ) {
02879              for( j = minJ; j <= maxJ; j++ ) {
02880                addEntryToIMatrix( IR[a], j, curCol, value );
02881              }
02882            }
02883            curCol++;
02884          } else {
02885            gTooManyEntries = 1;
02886          }
02887        }
02888 
02889        break;
02890      }
02891 
02892    case mc_obs_all:
02893       if( curCol >= gNumObservations ) {
02894          curRow++;
02895          curCol = 0;
02896       }
02897 
02898       if( gProblemType == POMDP_problem_type ) {
02899         /* We ignore this if it is an MDP */
02900         
02901         if( curRow < gNumStates ) {
02902           for( a = minA; a <= maxA; a++ )
02903             addEntryToIMatrix( IR[a], curRow, curCol, value );
02904           
02905           curCol++;
02906         } else {
02907           gTooManyEntries = 1;
02908         }
02909       }
02910       break;
02911 
02912 /* This is a special case for POMDPs, since we need a special 
02913    representation for immediate rewards for POMDP's.  Note that this 
02914    is not valid syntax for an MDP, but we flag this error when we set 
02915    the matrix context, so we ignore the MDP case here.
02916    */
02917    case mc_reward_single:
02918       if( gProblemType == POMDP_problem_type ) {
02919 
02920         if( curCol == 0 ) {
02921           enterImmReward( 0, 0, 0, value );
02922           curCol++;
02923         }
02924         else
02925           gTooManyEntries = 1;
02926 
02927       }
02928      break;
02929 
02930     case mc_reward_row:
02931       if( gProblemType == POMDP_problem_type ) {
02932 
02933         /* This is a special case for POMDPs, since we need a special 
02934            representation for immediate rewards for POMDP's */
02935    
02936         if( curCol < gNumObservations ) {
02937           enterImmReward( 0, 0, curCol, value );
02938           curCol++;
02939         }
02940         else
02941           gTooManyEntries = 1;
02942 
02943       }  /* if POMDP problem */
02944 
02945       else /* we are dealing with an MDP, so there should only be 
02946               a single entry */
02947         if( curCol == 0 ) {
02948           enterImmReward( 0, 0, 0, value );
02949           curCol++;
02950         }
02951         else
02952           gTooManyEntries = 1;
02953 
02954 
02955      break;
02956 
02957    case mc_reward_all:
02958 
02959       /* This is a special case for POMDPs, since we need a special 
02960          representation for immediate rewards for POMDP's */
02961 
02962       if( gProblemType == POMDP_problem_type ) {
02963         if( curCol >= gNumObservations ) {
02964           curRow++;
02965           curCol = 0;
02966         }
02967         if( curRow < gNumStates ) {
02968           enterImmReward( 0, curRow, curCol, value );
02969           curCol++;
02970         }
02971         else
02972           gTooManyEntries = 1;
02973 
02974       }  /* If POMDP problem */
02975 
02976       /* Otherwise it is an MDP and we should be expecting an entire
02977          row of rewards. */
02978 
02979       else  /* MDP */
02980         if( curCol < gNumStates ) {
02981           enterImmReward( 0, curCol, 0, value );
02982           curCol++;
02983         }
02984         else
02985           gTooManyEntries = 1;
02986 
02987       break;
02988 
02989       /* This is a special case for an MDP only where we specify
02990          the entire matrix of rewards. If we are erroneously 
02991          definining a POMDP, this error will be flagged in the 
02992          setMatrixContext() routine.
02993          */
02994 
02995     case mc_reward_mdp_only:
02996       if( gProblemType == MDP_problem_type ) {
02997         if( curCol >= gNumStates ) {
02998           curRow++;
02999           curCol = 0;
03000         }
03001         if( curRow < gNumStates ) {
03002           enterImmReward( curRow, curCol, 0, value );
03003           curCol++;
03004         }
03005         else
03006           gTooManyEntries = 1;
03007 
03008       }
03009       break;
03010 
03011     case mc_mdp_start:
03012 
03013       /* For an MDP we only want to see a single value and */
03014       /* we want it to correspond to a valid state number. */
03015 
03016       if( curCol > 0 )
03017         gTooManyEntries = 1;
03018 
03019       else {
03020         gInitialState = (int) value;
03021         curCol++;
03022       }
03023       break;
03024           
03025    case mc_start_belief:
03026 
03027       /* This will process the individual entries when a starting */
03028       /* belief state is fully specified.  When it is a POMDP, we need */
03029       /* an entry for each state, so we keep the curCol variable */
03030       /* updated.  */
03031 
03032       if( curCol < gNumStates ) {
03033         gInitialBelief[curCol] = value;
03034         curCol++;
03035       }
03036       else
03037         gTooManyEntries = 1;
03038 
03039       break;
03040 
03041    default:
03042       ERR_enter("Parser<enterMatrix>:", currentLineNumber, 
03043                 BAD_MATRIX_CONTEXT, "");
03044       break;
03045    }  /* switch */
03046 
03047 }  /* enterMatrix */
03048 /******************************************************************************/
03049 void setMatrixContext( Matrix_Context context, 
03050                       int a, int i, int j, int obs ) {
03051 /* 
03052    Note that we must enter the matrix entries in reverse order because
03053    the matrices are defined with left-recursive rules.  Set the a, i,
03054    and j parameters to be less than zero when you want to define it
03055    for all possible values.  
03056 
03057    Rewards for MDPs and POMDPs differ since in the former, rewards are not
03058    based upon an observations.  This complicates things since not only is one 
03059    of the reward syntax options not valid, but the semantics of all the
03060    rewards change as well.  I have chosen to handle this in this routine.  
03061    I will check for the appropriate type and set the context to handle the
03062    proper amount of entries.
03063 */
03064   int state;
03065 
03066    curMatrixContext = context;
03067    gTooManyEntries = 0;  /* Clear this out before reading any */
03068 
03069    curRow = 0;  /* This is ignored for some contexts */
03070    curCol = 0;
03071 
03072    switch( curMatrixContext ) {
03073 
03074 #if 0
03075    mc_start_belief:
03076      
03077      break;
03078 #endif
03079 
03080    case mc_start_include:
03081 
03082      /* When we specify the starting belief state as a list of states */
03083      /* to include, we initialize all state to 0.0, since as we read */
03084      /* the states we will set that particular value to 1.0.  After it */
03085      /* is all done we can then just normalize the belief state */
03086 
03087      if( gProblemType == POMDP_problem_type )
03088        for( state = 0; state < gNumStates; state++ )
03089          gInitialBelief[state] = 0.0;
03090 
03091      else  /* It is an MDP which is not valid */
03092        ERR_enter("Parser<setMatrixContext>:", currentLineNumber, 
03093                  BAD_START_STATE_TYPE, "");
03094       
03095      break;
03096 
03097    case mc_start_exclude:
03098 
03099      /* When we are specifying the starting belief state as a a list */
03100      /* of states, we initialize all states to 1.0 and as we read each */
03101      /* in the list we clear it out to be zero.  fter it */
03102      /* is all done we can then just normalize the belief state */
03103 
03104      if( gProblemType == POMDP_problem_type )
03105        for( state = 0; state < gNumStates; state++ )
03106          gInitialBelief[state] = 1.0;
03107 
03108      else  /* It is an MDP which is not valid */
03109        ERR_enter("Parser<setMatrixContext>:", currentLineNumber, 
03110                  BAD_START_STATE_TYPE, "");
03111 
03112      break;
03113 
03114   /* We need a special representation for the immediate rewards.
03115      These four cases initialize the data structure that will be
03116      needed for immediate rewards by calling newImmReward.  Note that
03117      the arguments will differe depending upon whether it is an
03118      MDP or POMDP.
03119      */
03120   case mc_reward_mdp_only:
03121     if( gProblemType == POMDP_problem_type )  {
03122        ERR_enter("Parser<setMatrixContext>:", currentLineNumber, 
03123                  BAD_REWARD_SYNTAX, "");
03124     }
03125     else {
03126       newImmReward( a, NOT_PRESENT, NOT_PRESENT, 0 );
03127     } 
03128     break;
03129  
03130   case mc_reward_all:   
03131     if( gProblemType == POMDP_problem_type ) 
03132       newImmReward( a, i, NOT_PRESENT, NOT_PRESENT );
03133 
03134     else {
03135       newImmReward( a, i, NOT_PRESENT, 0 );
03136     }
03137     break;
03138   case mc_reward_row:
03139     if( gProblemType == POMDP_problem_type ) 
03140       newImmReward( a, i, j, NOT_PRESENT );
03141     
03142     else {
03143       newImmReward( a, i, j, 0 );
03144     } 
03145     break;
03146   case mc_reward_single:
03147 
03148     if( gProblemType == MDP_problem_type ) {
03149        ERR_enter("Parser<setMatrixContext>:", currentLineNumber, 
03150                  BAD_REWARD_SYNTAX, "");
03151     }
03152     else {
03153        newImmReward( a, i, j, obs );
03154      }
03155     break;
03156 
03157    default:
03158      break;
03159    }
03160 
03161   /* These variable settings will define the range over which the current 
03162      matrix context will have effect.  This accounts for wildcards by
03163      setting the range to include everything.  When a single entry was
03164      specified, the range is that single number.  When we actually 
03165      start to read the matrix, each entry we see will apply for the
03166      entire range specified, though for specific entries the range 
03167      will be a single number.
03168      */
03169    if( a < 0 ) {
03170       minA = 0;
03171       maxA = gNumActions - 1;
03172    }
03173    else
03174       minA = maxA = a;
03175 
03176    if( i < 0 ) {
03177       minI = 0;
03178       maxI = gNumStates - 1;
03179    }
03180    else
03181       minI = maxI = i;
03182 
03183    if( j < 0 ) {
03184       minJ = 0;
03185       maxJ = gNumStates - 1;
03186    }
03187    else
03188       minJ = maxJ = j;
03189 
03190    if( obs < 0 ) {
03191       minObs = 0;
03192       maxObs = gNumObservations - 1;
03193    }
03194    else
03195       minObs = maxObs = obs;
03196 
03197 }  /* setMatrixContext */
03198 /******************************************************************************/
03199 void enterStartState( int i ) {
03200 /*
03201    This is not valid for an MDP, but the error has already been flagged
03202    in the setMatrixContext() routine.  Therefore, if just igore this if 
03203    it is an MDP.
03204 */
03205 
03206   if( gProblemType == MDP_problem_type )
03207     return;
03208 
03209   switch( curMatrixContext ) {
03210   case mc_start_include:
03211     gInitialBelief[i] = 1.0;
03212     break;
03213   case mc_start_exclude:
03214     gInitialBelief[i] = 0.0;
03215     break;
03216   default:
03217     ERR_enter("Parser<enterStartState>:", currentLineNumber, 
03218               BAD_MATRIX_CONTEXT, "");
03219       break;
03220   } /* switch */
03221 }  /* enterStartState */
03222 /******************************************************************************/
03223 void setStartStateUniform() {
03224   int i;
03225   REAL_VALUE prob;
03226 
03227   if( gProblemType != POMDP_problem_type )
03228     return;
03229 
03230   prob = 1.0/gNumStates;
03231   for( i = 0; i < gNumStates; i++ )
03232     gInitialBelief[i] = prob;
03233 
03234 }  /*  setStartStateUniform*/
03235 /******************************************************************************/
03236 void endStartStates() {
03237 /*
03238    There are a few cases where the matrix context will not be
03239    set at this point.  When there is a list of probabilities
03240    or if it is an MDP the context will have been cleared.
03241    */
03242   int i;
03243   REAL_VALUE prob;
03244 
03245   if( gProblemType == MDP_problem_type ) {
03246     curMatrixContext = mc_none;  /* just to be sure */
03247     return;
03248   }
03249     
03250   switch( curMatrixContext ) {
03251   case mc_start_include:
03252   case mc_start_exclude:
03253     /* At this point gInitialBelief should be a vector of 1.0's and 0.0's
03254        being set as each is either included or excluded.  Now we need to
03255        normalized them to make it a true probability distribution */
03256     prob = 0.0;
03257     for( i = 0; i < gNumStates; i++ )
03258       prob += gInitialBelief[i];
03259     if( prob <= 0.0 ) {
03260       ERR_enter("Parser<endStartStates>:", currentLineNumber, 
03261                 BAD_START_PROB_SUM, "" );
03262       return;
03263     }
03264     for( i = 0; i < gNumStates; i++ )
03265       gInitialBelief[i] /= prob;
03266     break;
03267 
03268   default:  /* Make sure we have a valid prob. distribution */
03269     prob = 0.0;
03270     for( i = 0; i < gNumStates; i++ ) 
03271       prob += gInitialBelief[i];
03272     if((prob < ( 1.0 - EPSILON)) || (prob > (1.0 + EPSILON))) {
03273       ERR_enter("Parser<endStartStates>:", NO_LINE, 
03274                 BAD_START_PROB_SUM, "" );
03275     }
03276     break;
03277   }  /* switch */
03278 
03279   curMatrixContext = mc_none;
03280 
03281 }  /* endStartStates */
03282 /******************************************************************************/
03283 void verifyPreamble() {
03284 /* 
03285    When a param is not defined, set these to non-zero so parsing can
03286    proceed even in the absence of specifying these values.  When an
03287    out of range value is encountered the parser will flag the error,
03288    but return 0 so that more errors can be detected 
03289    */
03290 
03291    if( discountDefined == 0 )
03292       ERR_enter("Parser<verifyPreamble>:", currentLineNumber, 
03293                 MISSING_DISCOUNT, "" );
03294    if( valuesDefined == 0 )
03295       ERR_enter("Parser<verifyPreamble>:", currentLineNumber,
03296                 MISSING_VALUES, "" );
03297    if( statesDefined == 0 ) {
03298       ERR_enter("Parser<verifyPreamble>:", currentLineNumber, 
03299                 MISSING_STATES, "" );
03300       gNumStates = 1;
03301    }
03302    if( actionsDefined == 0 ) {
03303       ERR_enter("Parser<verifyPreamble>:", currentLineNumber, 
03304                 MISSING_ACTIONS, "" );
03305       gNumActions = 1;
03306    }
03307 
03308    /* If we do not see this, them we must be parsing an MDP */
03309    if( observationsDefined == 0 ) {
03310      gNumObservations = 0;
03311      gProblemType = MDP_problem_type;
03312    }
03313 
03314    else
03315      gProblemType = POMDP_problem_type;
03316 
03317 }  /* verifyPreamble */
03318 /******************************************************************************/
03319 void checkProbs() {
03320    int a,i,j;
03321    REAL_VALUE sum;
03322    char str[40];
03323 
03324    
03325    for( a = 0; a < gNumActions; a++ )
03326       for( i = 0; i < gNumStates; i++ ) {
03327          sum = sumIMatrixRowValues( IP[a], i );
03328          if((sum < ( 1.0 - EPSILON)) || (sum > (1.0 + EPSILON))) {
03329             sprintf( str, "action=%d, state=%d (%.5lf)", a, i, sum );
03330             ERR_enter("Parser<checkProbs>:", NO_LINE, 
03331                       BAD_TRANS_PROB_SUM, str );
03332          }
03333       } /* for i */
03334 
03335    if( gProblemType == POMDP_problem_type )
03336      for( a = 0; a < gNumActions; a++ )
03337        for( j = 0; j < gNumStates; j++ ) {
03338          sum = sumIMatrixRowValues( IR[a], j );
03339          if((sum < ( 1.0 - EPSILON)) || (sum > (1.0 + EPSILON))) {
03340            sprintf( str, "action=%d, state=%d (%.5lf)", a, j, sum );
03341            ERR_enter("Parser<checkProbs>:", NO_LINE, 
03342                      BAD_OBS_PROB_SUM, str );
03343          } /* if sum not == 1 */
03344        }  /* for j */
03345 
03346    /* Now see if we had observation specs defined in an MDP */
03347 
03348    if( observationSpecDefined && (gProblemType == MDP_problem_type))
03349      ERR_enter("Parser<checkProbs>:", NO_LINE, 
03350                OBS_IN_MDP_PROBLEM, "" );
03351 
03352 }  /* checkProbs */
03353 /************************************************************************/
03354 void initParser() {
03355 /*
03356    This routine will reset all the state variables used by the parser
03357    in case it will parse multiple files.
03358 */
03359    observationSpecDefined = 0;
03360    discountDefined = 0;
03361    valuesDefined = 0;
03362    statesDefined = 0;
03363    actionsDefined = 0;
03364    observationsDefined = 0;
03365    observationSpecDefined = 0;
03366    currentLineNumber = 1;
03367    curMnemonic = nt_unknown;
03368    curMatrixContext = mc_none;
03369 
03370 }  /* initParser */
03371 /************************************************************************/
03372 int readMDPFile( FILE *file ) {
03373    int returnValue;
03374    extern FILE *yyin;
03375 
03376    initParser();
03377 
03378    ERR_initialize();
03379    H_create();
03380    yyin = file;
03381 
03382    returnValue = yyparse();
03383 #if USE_DEBUG_PRINT
03384      printf("pomdp_spec: done parsing, beginning conversion to sparse-matrix\n");
03385 #endif
03386 
03387    /* If there are syntax errors, then we have to do something if we 
03388       want to parse another file without restarting.  It seems that
03389       a syntax error bombs the code out, but leaves the file pointer
03390       at the place it bombed.  Thus, another call to yyparse() will
03391       pick up where it left off and not necessarily at the start of a 
03392       new file.
03393 
03394       Unfortunately, I do not know how to do this yet.
03395       */
03396    if (returnValue != 0) {
03397       printf("\nERROR: POMDP model file contains syntax errors!\n");
03398     }
03399 
03400    if (ERR_dump() || returnValue ) 
03401       return( 0 );
03402 
03403    ERR_cleanUp();
03404    H_destroy();
03405 
03406    /* This is where intermediate matrix representation are
03407       converted into their final representation */
03408    convertMatrices();
03409 
03410    return( 1 );
03411 }  /* readPomdpFile */
03412 /************************************************************************/
03413 #if 0
03414 int yywrap()
03415 {
03416    return 1;
03417 }
03418 #endif
03419 /************************************************************************/
03420 


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29