Logo Search packages:      
Sourcecode: rasqal version File versions  Download package

sparql_parser.c

/* A Bison parser, made by GNU Bison 1.875c.  */

/* Skeleton parser for Yacc-like parsing with Bison,
   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

/* As a special exception, when this file is copied by Bison into a
   Bison output file, you may use that output file without restriction.
   This special exception was added by the Free Software Foundation
   in version 1.24 of Bison.  */

/* Written by Richard Stallman by simplifying the original so called
   ``semantic'' parser.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

/* Identify Bison output.  */
#define YYBISON 1

/* Skeleton name.  */
#define YYSKELETON_NAME "yacc.c"

/* Pure parsers.  */
#define YYPURE 1

/* Using locations.  */
#define YYLSP_NEEDED 0

/* If NAME_PREFIX is specified substitute the variables and functions
   names.  */
#define yyparse sparql_parser_parse
#define yylex   sparql_parser_lex
#define yyerror sparql_parser_error
#define yylval  sparql_parser_lval
#define yychar  sparql_parser_char
#define yydebug sparql_parser_debug
#define yynerrs sparql_parser_nerrs


/* Tokens.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
   /* Put the tokens into the symbol table, so that GDB and other debuggers
      know about them.  */
   enum yytokentype {
     SELECT = 258,
     FROM = 259,
     WHERE = 260,
     OPTIONAL = 261,
     PREFIX = 262,
     DESCRIBE = 263,
     CONSTRUCT = 264,
     ASK = 265,
     DISTINCT = 266,
     LIMIT = 267,
     UNION = 268,
     BASE = 269,
     BOUND = 270,
     STR = 271,
     LANG = 272,
     DATATYPE = 273,
     ISURI = 274,
     ISBLANK = 275,
     ISLITERAL = 276,
     GRAPH = 277,
     NAMED = 278,
     FILTER = 279,
     OFFSET = 280,
     A = 281,
     ORDER = 282,
     BY = 283,
     REGEX = 284,
     ASC = 285,
     DESC = 286,
     SC_AND = 287,
     SC_OR = 288,
     GE = 289,
     LE = 290,
     GT = 291,
     LT = 292,
     NEQ = 293,
     EQ = 294,
     FLOATING_POINT_LITERAL = 295,
     STRING_LITERAL = 296,
     INTEGER_LITERAL = 297,
     BOOLEAN_LITERAL = 298,
     NULL_LITERAL = 299,
     URI_LITERAL = 300,
     URI_LITERAL_BRACE = 301,
     QNAME_LITERAL = 302,
     BLANK_LITERAL = 303,
     QNAME_LITERAL_BRACE = 304,
     IDENTIFIER = 305
   };
#endif
#define SELECT 258
#define FROM 259
#define WHERE 260
#define OPTIONAL 261
#define PREFIX 262
#define DESCRIBE 263
#define CONSTRUCT 264
#define ASK 265
#define DISTINCT 266
#define LIMIT 267
#define UNION 268
#define BASE 269
#define BOUND 270
#define STR 271
#define LANG 272
#define DATATYPE 273
#define ISURI 274
#define ISBLANK 275
#define ISLITERAL 276
#define GRAPH 277
#define NAMED 278
#define FILTER 279
#define OFFSET 280
#define A 281
#define ORDER 282
#define BY 283
#define REGEX 284
#define ASC 285
#define DESC 286
#define SC_AND 287
#define SC_OR 288
#define GE 289
#define LE 290
#define GT 291
#define LT 292
#define NEQ 293
#define EQ 294
#define FLOATING_POINT_LITERAL 295
#define STRING_LITERAL 296
#define INTEGER_LITERAL 297
#define BOOLEAN_LITERAL 298
#define NULL_LITERAL 299
#define URI_LITERAL 300
#define URI_LITERAL_BRACE 301
#define QNAME_LITERAL 302
#define BLANK_LITERAL 303
#define QNAME_LITERAL_BRACE 304
#define IDENTIFIER 305




/* Copy the first part of user declarations.  */
#line 33 "./sparql_parser.y"

#ifdef HAVE_CONFIG_H
#include <rasqal_config.h>
#endif

#ifdef WIN32
#include <win32_rasqal_config.h>
#endif

#include <stdio.h>
#include <stdarg.h>

#include <rasqal.h>
#include <rasqal_internal.h>

#include <sparql_parser.h>

#define YY_DECL int sparql_lexer_lex (YYSTYPE *sparql_parser_lval, yyscan_t yyscanner)
#define YY_NO_UNISTD_H 1
#include <sparql_lexer.h>

#include <sparql_common.h>

/*
#undef RASQAL_DEBUG
#define RASQAL_DEBUG 2
*/

/* Make verbose error messages for syntax errors */
#define YYERROR_VERBOSE 1

/* Slow down the grammar operation and watch it work */
#if RASQAL_DEBUG > 2
#define YYDEBUG 1
#endif

/* the lexer does not seem to track this */
#undef RASQAL_SPARQL_USE_ERROR_COLUMNS

/* Missing sparql_lexer.c/h prototypes */
int sparql_lexer_get_column(yyscan_t yyscanner);
/* Not used here */
/* void sparql_lexer_set_column(int  column_no , yyscan_t yyscanner);*/


/* What the lexer wants */
extern int sparql_lexer_lex (YYSTYPE *sparql_parser_lval, yyscan_t scanner);
#define YYLEX_PARAM ((rasqal_sparql_query_engine*)(((rasqal_query*)rq)->context))->scanner

/* Pure parser argument (a void*) */
#define YYPARSE_PARAM rq

/* Make the yyerror below use the rdf_parser */
#undef yyerror
#define yyerror(message) sparql_query_error((rasqal_query*)rq, message)

/* Make lex/yacc interface as small as possible */
#undef yylex
#define yylex sparql_lexer_lex


static int sparql_parse(rasqal_query* rq, const unsigned char *string);
static void sparql_query_error(rasqal_query* rq, const char *message);
static void sparql_query_error_full(rasqal_query *rq, const char *message, ...);


/* Enabling traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif

/* Enabling verbose error messages.  */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif

#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 107 "./sparql_parser.y"
typedef union YYSTYPE {
  raptor_sequence *seq;
  rasqal_variable *variable;
  rasqal_literal *literal;
  rasqal_triple *triple;
  rasqal_expression *expr;
  rasqal_graph_pattern *graph_pattern;
  double floating;
  raptor_uri *uri;
  unsigned char *name;
  rasqal_formula *formula;
} YYSTYPE;
/* Line 191 of yacc.c.  */
#line 264 "sparql_parser.c"
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif



/* Copy the second part of user declarations.  */


/* Line 214 of yacc.c.  */
#line 276 "sparql_parser.c"

#if ! defined (yyoverflow) || YYERROR_VERBOSE

# ifndef YYFREE
#  define YYFREE free
# endif
# ifndef YYMALLOC
#  define YYMALLOC malloc
# endif

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# ifdef YYSTACK_USE_ALLOCA
#  if YYSTACK_USE_ALLOCA
#   define YYSTACK_ALLOC alloca
#  endif
# else
#  if defined (alloca) || defined (_ALLOCA_H)
#   define YYSTACK_ALLOC alloca
#  else
#   ifdef __GNUC__
#    define YYSTACK_ALLOC __builtin_alloca
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's `empty if-body' warning. */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# else
#  if defined (__STDC__) || defined (__cplusplus)
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   define YYSIZE_T size_t
#  endif
#  define YYSTACK_ALLOC YYMALLOC
#  define YYSTACK_FREE YYFREE
# endif
#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */


#if (! defined (yyoverflow) \
     && (! defined (__cplusplus) \
       || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  short yyss;
  YYSTYPE yyvs;
  };

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# define YYSTACK_BYTES(N) \
     ((N) * (sizeof (short) + sizeof (YYSTYPE))                   \
      + YYSTACK_GAP_MAXIMUM)

/* Copy COUNT objects from FROM to TO.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if defined (__GNUC__) && 1 < __GNUC__
#   define YYCOPY(To, From, Count) \
      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
#  else
#   define YYCOPY(To, From, Count)        \
      do                            \
      {                             \
        register YYSIZE_T yyi;            \
        for (yyi = 0; yyi < (Count); yyi++)     \
          (To)[yyi] = (From)[yyi];        \
      }                             \
      while (0)
#  endif
# endif

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack)                            \
    do                                                      \
      {                                                     \
      YYSIZE_T yynewbytes;                                  \
      YYCOPY (&yyptr->Stack, Stack, yysize);                      \
      Stack = &yyptr->Stack;                                \
      yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
      yyptr += yynewbytes / sizeof (*yyptr);                      \
      }                                                     \
    while (0)

#endif

#if defined (__STDC__) || defined (__cplusplus)
   typedef signed char yysigned_char;
#else
   typedef short yysigned_char;
#endif

/* YYFINAL -- State number of the termination state. */
#define YYFINAL  5
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   396

/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS  69
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS  62
/* YYNRULES -- Number of rules. */
#define YYNRULES  157
/* YYNRULES -- Number of states. */
#define YYNSTATES  261

/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
#define YYUNDEFTOK  2
#define YYMAXUTOK   305

#define YYTRANSLATE(YYX)                                    \
  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)

/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
static const unsigned char yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,    55,     2,     2,    40,    53,     2,     2,
      33,    34,    51,    49,    32,    50,    67,    52,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,    68,
       2,     2,     2,    39,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,    35,     2,    36,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,    37,     2,    38,    54,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
      25,    26,    27,    28,    29,    30,    31,    41,    42,    43,
      44,    45,    46,    47,    48,    56,    57,    58,    59,    60,
      61,    62,    63,    64,    65,    66
};

#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
   YYRHS.  */
static const unsigned short yyprhs[] =
{
       0,     0,     3,    12,    14,    16,    18,    20,    23,    24,
      29,    30,    34,    38,    41,    44,    47,    50,    53,    56,
      58,    60,    63,    64,    67,    70,    72,    76,    79,    81,
      82,    86,    87,    90,    92,    97,   102,   107,   112,   114,
     116,   120,   123,   124,   127,   128,   133,   137,   139,   140,
     144,   149,   151,   153,   155,   157,   159,   161,   164,   168,
     172,   176,   178,   183,   187,   189,   192,   194,   195,   199,
     202,   203,   206,   209,   210,   212,   214,   216,   218,   220,
     222,   226,   228,   231,   233,   237,   240,   243,   247,   250,
     254,   256,   258,   261,   265,   267,   269,   271,   273,   275,
     277,   279,   281,   283,   286,   289,   293,   295,   299,   301,
     305,   309,   313,   317,   321,   325,   327,   331,   335,   337,
     341,   345,   349,   351,   354,   357,   360,   363,   365,   370,
     375,   380,   387,   396,   401,   406,   411,   416,   418,   420,
     422,   424,   428,   432,   436,   438,   439,   441,   443,   445,
     447,   449,   451,   453,   455,   457,   459,   461
};

/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const short yyrhs[] =
{
      70,     0,    -1,    72,    73,    71,    78,    82,    83,    86,
      87,    -1,    74,    -1,    76,    -1,    75,    -1,    77,    -1,
      14,    61,    -1,    -1,    73,     7,    66,    61,    -1,    -1,
       3,    11,   111,    -1,     3,    11,    51,    -1,     3,   111,
      -1,     3,    51,    -1,     8,   110,    -1,     8,    51,    -1,
       9,    96,    -1,     9,    51,    -1,    10,    -1,    79,    -1,
      79,    80,    -1,    -1,     4,   128,    -1,    80,    81,    -1,
      81,    -1,     4,    23,   128,    -1,     5,    88,    -1,    88,
      -1,    -1,    27,    28,    84,    -1,    -1,    84,    85,    -1,
      85,    -1,    30,    33,   117,    34,    -1,    31,    33,   117,
      34,    -1,    30,    35,   117,    36,    -1,    31,    35,   117,
      36,    -1,   125,    -1,   116,    -1,    33,   117,    34,    -1,
      12,    58,    -1,    -1,    25,    58,    -1,    -1,    37,    90,
      89,    38,    -1,    37,    89,    38,    -1,    67,    -1,    -1,
      90,    89,    91,    -1,    90,    67,    24,   117,    -1,    91,
      -1,    98,    -1,    92,    -1,    94,    -1,    88,    -1,    93,
      -1,     6,    88,    -1,    22,   112,    88,    -1,    88,    13,
      95,    -1,    95,    13,    88,    -1,    88,    -1,    37,    97,
      89,    38,    -1,    97,    67,    98,    -1,    98,    -1,   104,
      99,    -1,   100,    -1,    -1,   105,   102,   101,    -1,    68,
      99,    -1,    -1,   106,   103,    -1,    32,   102,    -1,    -1,
     114,    -1,   107,    -1,   115,    -1,    26,    -1,   114,    -1,
     107,    -1,    35,   100,    36,    -1,   109,    -1,   108,   106,
      -1,   106,    -1,    33,   108,    34,    -1,    33,    34,    -1,
     110,   116,    -1,   110,    32,   116,    -1,   110,   128,    -1,
     110,    32,   128,    -1,   116,    -1,   128,    -1,   111,   116,
      -1,   111,    32,   116,    -1,   116,    -1,   116,    -1,   128,
      -1,   116,    -1,   127,    -1,   113,    -1,   130,    -1,   112,
      -1,   130,    -1,    39,    66,    -1,    40,    66,    -1,   118,
      42,   117,    -1,   118,    -1,   119,    41,   119,    -1,   119,
      -1,   120,    48,   120,    -1,   120,    47,   120,    -1,   120,
      46,   120,    -1,   120,    45,   120,    -1,   120,    44,   120,
      -1,   120,    43,   120,    -1,   120,    -1,   121,    49,   120,
      -1,   121,    50,   120,    -1,   121,    -1,   122,    51,   121,
      -1,   122,    52,   121,    -1,   122,    53,   121,    -1,   122,
      -1,    50,   123,    -1,    54,   123,    -1,    55,   123,    -1,
      49,   123,    -1,   123,    -1,    16,    33,   113,    34,    -1,
      17,    33,   113,    34,    -1,    18,    33,   113,    34,    -1,
      29,    33,   117,    32,   127,    34,    -1,    29,    33,   117,
      32,   127,    32,   127,    34,    -1,    15,    33,   116,    34,
      -1,    19,    33,   113,    34,    -1,    20,    33,   113,    34,
      -1,    21,    33,   113,    34,    -1,   125,    -1,   124,    -1,
     116,    -1,   127,    -1,    33,   117,    34,    -1,   129,   126,
      34,    -1,   126,    32,   117,    -1,   117,    -1,    -1,   128,
      -1,    58,    -1,    56,    -1,    57,    -1,    59,    -1,    60,
      -1,    61,    -1,    63,    -1,    62,    -1,    65,    -1,    64,
      -1,    35,    36,    -1
};

/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
static const unsigned short yyrline[] =
{
       0,   208,   208,   217,   222,   227,   232,   242,   249,   256,
     264,   271,   276,   282,   286,   295,   299,   307,   311,   320,
     327,   328,   329,   334,   346,   347,   351,   366,   370,   375,
     380,   388,   393,   399,   409,   413,   417,   422,   427,   432,
     439,   448,   458,   462,   471,   475,   485,   492,   493,   500,
     517,   531,   555,   580,   584,   588,   592,   600,   620,   640,
     655,   661,   678,   686,   696,   718,   778,   783,   792,   864,
     869,   876,   926,   931,   938,   943,   951,   956,   972,   977,
     985,  1032,  1043,  1073,  1100,  1159,  1172,  1177,  1182,  1187,
    1192,  1198,  1207,  1212,  1217,  1231,  1235,  1243,  1247,  1254,
    1258,  1266,  1270,  1277,  1281,  1291,  1295,  1304,  1309,  1318,
    1322,  1326,  1330,  1334,  1338,  1342,  1351,  1355,  1359,  1366,
    1370,  1374,  1378,  1385,  1389,  1393,  1397,  1401,  1408,  1413,
    1418,  1423,  1437,  1458,  1464,  1469,  1474,  1479,  1483,  1491,
    1496,  1500,  1507,  1521,  1527,  1534,  1543,  1547,  1551,  1555,
    1559,  1563,  1578,  1582,  1594,  1598,  1612,  1615
};
#endif

#if YYDEBUG || YYERROR_VERBOSE
/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
  "$end", "error", "$undefined", "SELECT", "FROM", "WHERE", "OPTIONAL",
  "PREFIX", "DESCRIBE", "CONSTRUCT", "ASK", "DISTINCT", "LIMIT", "UNION",
  "BASE", "BOUND", "STR", "LANG", "DATATYPE", "ISURI", "ISBLANK",
  "ISLITERAL", "GRAPH", "NAMED", "FILTER", "OFFSET", "A", "ORDER", "BY",
  "REGEX", "ASC", "DESC", "','", "'('", "')'", "'['", "']'", "'{'", "'}'",
  "'?'", "'$'", "SC_AND", "SC_OR", "GE", "LE", "GT", "LT", "NEQ", "EQ",
  "'+'", "'-'", "'*'", "'/'", "'%'", "'~'", "'!'",
  "FLOATING_POINT_LITERAL", "STRING_LITERAL", "INTEGER_LITERAL",
  "BOOLEAN_LITERAL", "NULL_LITERAL", "URI_LITERAL", "URI_LITERAL_BRACE",
  "QNAME_LITERAL", "BLANK_LITERAL", "QNAME_LITERAL_BRACE", "IDENTIFIER",
  "'.'", "';'", "$accept", "Query", "ReportFormat", "BaseDeclOpt",
  "PrefixDeclOpt", "SelectClause", "DescribeClause", "ConstructClause",
  "AskClause", "DatasetClauseOpt", "DefaultGraphClause",
  "NamedGraphClauseList", "NamedGraphClause", "WhereClauseOpt",
  "OrderClauseOpt", "OrderConditionList", "OrderCondition",
  "LimitClauseOpt", "OffsetClauseOpt", "GraphPattern", "DotOptional",
  "PatternElementsList", "PatternElement", "OptionalGraphPattern",
  "GraphGraphPattern", "UnionGraphPattern", "UnionGraphPatternList",
  "ConstructTemplate", "TriplesList", "Triples", "PropertyListOpt",
  "PropertyList", "PropertyListTail", "ObjectList", "ObjectTail",
  "Subject", "Predicate", "Object", "TriplesNode", "ItemList",
  "Collection", "VarOrURIList", "VarList", "VarOrURI", "VarOrLiteral",
  "VarOrLiteralOrBlankNode", "VarOrBnodeOrURI", "Var", "Expression",
  "ConditionalAndExpression", "RelationalExpression", "AdditiveExpression",
  "MultiplicativeExpression", "UnaryExpression", "CallExpression",
  "PrimaryExpression", "FunctionCall", "ArgList", "Literal", "URI",
  "URIBrace", "BlankNode", 0
};
#endif

# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
   token YYLEX-NUM.  */
static const unsigned short yytoknum[] =
{
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
     285,   286,    44,    40,    41,    91,    93,   123,   125,    63,
      36,   287,   288,   289,   290,   291,   292,   293,   294,    43,
      45,    42,    47,    37,   126,    33,   295,   296,   297,   298,
     299,   300,   301,   302,   303,   304,   305,    46,    59
};
# endif

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
static const unsigned char yyr1[] =
{
       0,    69,    70,    71,    71,    71,    71,    72,    72,    73,
      73,    74,    74,    74,    74,    75,    75,    76,    76,    77,
      78,    78,    78,    79,    80,    80,    81,    82,    82,    82,
      83,    83,    84,    84,    85,    85,    85,    85,    85,    85,
      85,    86,    86,    87,    87,    88,    88,    89,    89,    90,
      90,    90,    91,    91,    91,    91,    91,    92,    93,    94,
      95,    95,    96,    97,    97,    98,    99,    99,   100,   101,
     101,   102,   103,   103,   104,   104,   105,   105,   106,   106,
     107,   107,   108,   108,   109,   109,   110,   110,   110,   110,
     110,   110,   111,   111,   111,   112,   112,   113,   113,   114,
     114,   115,   115,   116,   116,   117,   117,   118,   118,   119,
     119,   119,   119,   119,   119,   119,   120,   120,   120,   121,
     121,   121,   121,   122,   122,   122,   122,   122,   123,   123,
     123,   123,   123,   123,   123,   123,   123,   123,   123,   124,
     124,   124,   125,   126,   126,   126,   127,   127,   127,   127,
     127,   127,   128,   128,   129,   129,   130,   130
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
static const unsigned char yyr2[] =
{
       0,     2,     8,     1,     1,     1,     1,     2,     0,     4,
       0,     3,     3,     2,     2,     2,     2,     2,     2,     1,
       1,     2,     0,     2,     2,     1,     3,     2,     1,     0,
       3,     0,     2,     1,     4,     4,     4,     4,     1,     1,
       3,     2,     0,     2,     0,     4,     3,     1,     0,     3,
       4,     1,     1,     1,     1,     1,     1,     2,     3,     3,
       3,     1,     4,     3,     1,     2,     1,     0,     3,     2,
       0,     2,     2,     0,     1,     1,     1,     1,     1,     1,
       3,     1,     2,     1,     3,     2,     2,     3,     2,     3,
       1,     1,     2,     3,     1,     1,     1,     1,     1,     1,
       1,     1,     1,     2,     2,     3,     1,     3,     1,     3,
       3,     3,     3,     3,     3,     1,     3,     3,     1,     3,
       3,     3,     1,     2,     2,     2,     2,     1,     4,     4,
       4,     6,     8,     4,     4,     4,     4,     1,     1,     1,
       1,     3,     3,     3,     1,     0,     1,     1,     1,     1,
       1,     1,     1,     1,     1,     1,     1,     2
};

/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
   means the default is an error.  */
static const unsigned char yydefact[] =
{
       8,     0,     0,    10,     7,     1,     0,     0,     0,     0,
       0,    19,    22,     3,     5,     4,     6,     0,     0,     0,
      14,    13,    94,     0,    16,   152,   153,    15,    90,    91,
       0,    18,    17,     0,    29,    20,    12,    11,   103,   104,
       0,    92,     9,     0,    86,    88,     0,     0,   148,   149,
     147,   150,   151,   156,    48,    64,    67,    75,    81,    99,
      74,    97,    98,   146,   100,    23,     0,    48,    31,    28,
       0,    21,    25,    93,    87,    89,    85,    83,    79,     0,
      78,    77,     0,   157,     0,     0,   101,    76,    95,    96,
     102,    47,     0,    65,    66,    27,     0,     0,    47,    55,
       0,    48,    51,    53,    56,    54,    52,     0,    42,     0,
      24,    84,    82,    80,    70,    73,    63,    62,    57,     0,
       0,    46,    47,     0,     0,     0,    44,    26,    67,    68,
       0,    71,    58,    61,    59,     0,    45,    49,     0,     0,
       0,   154,   155,    30,    33,    39,    38,   145,    41,     0,
       2,    69,    72,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,   139,    50,   106,
     108,   115,   118,   122,   127,   138,   137,   140,     0,     0,
       0,     0,     0,    32,   144,     0,    43,    60,     0,     0,
       0,     0,     0,     0,     0,     0,     0,   126,   123,   124,
     125,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,    40,     0,
     142,     0,     0,     0,     0,     0,     0,     0,     0,   141,
     105,   107,   114,   113,   112,   111,   110,   109,   116,   117,
     119,   120,   121,    34,    36,    35,    37,   143,   133,   128,
     129,   130,   134,   135,   136,     0,     0,     0,   131,     0,
     132
};

/* YYDEFGOTO[NTERM-NUM]. */
static const short yydefgoto[] =
{
      -1,     2,    12,     3,     6,    13,    14,    15,    16,    34,
      35,    71,    72,    68,   108,   143,   144,   126,   150,    99,
      92,   101,   102,   103,   104,   105,   134,    32,    54,   106,
      93,    94,   129,   114,   131,    56,    85,   115,    57,    79,
      58,    27,    21,    86,    59,    60,    87,   167,   168,   169,
     170,   171,   172,   173,   174,   175,   176,   185,   177,    63,
     147,    64
};

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
#define YYPACT_NINF -121
static const short yypact[] =
{
      -1,   -43,    26,  -121,  -121,  -121,   148,     0,   -14,   -31,
       9,  -121,    30,  -121,  -121,  -121,  -121,    52,    -9,    19,
    -121,    79,  -121,     8,  -121,  -121,  -121,    41,  -121,  -121,
     324,  -121,  -121,     3,    22,    78,  -121,    79,  -121,  -121,
     -18,  -121,  -121,   114,  -121,  -121,   283,   234,  -121,  -121,
    -121,  -121,  -121,  -121,    21,  -121,   158,  -121,  -121,  -121,
    -121,  -121,  -121,  -121,  -121,  -121,    60,   109,    72,  -121,
      82,    78,  -121,  -121,  -121,  -121,  -121,  -121,  -121,   315,
    -121,  -121,    74,  -121,    89,   324,  -121,  -121,  -121,  -121,
    -121,   324,    75,  -121,  -121,  -121,    60,   114,  -121,   101,
      92,    65,  -121,  -121,  -121,  -121,  -121,    99,   127,     3,
    -121,  -121,  -121,  -121,    84,   113,  -121,  -121,  -121,    60,
      60,  -121,   126,   172,   184,   116,   146,  -121,   158,  -121,
     324,  -121,  -121,  -121,   170,   222,  -121,  -121,    -4,    37,
     222,  -121,  -121,   184,  -121,  -121,  -121,   222,  -121,   137,
    -121,  -121,  -121,    60,   152,   163,   175,   180,   183,   185,
     187,   193,   222,   273,   273,   273,   273,  -121,  -121,   192,
     203,   220,    29,   201,  -121,  -121,  -121,  -121,   222,   222,
     222,   222,   211,  -121,  -121,    42,  -121,  -121,   -18,    77,
      77,    77,    77,    77,    77,   222,   213,  -121,  -121,  -121,
    -121,   222,   222,   222,   222,   222,   222,   222,   222,   222,
     222,   222,   222,   222,   214,   223,   216,   239,  -121,   222,
    -121,   252,   262,   265,   266,   267,   269,   270,   275,  -121,
    -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,
    -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,
    -121,  -121,  -121,  -121,  -121,   143,    62,   143,  -121,   271,
    -121
};

/* YYPGOTO[NTERM-NUM].  */
static const short yypgoto[] =
{
    -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,  -121,
    -121,  -121,   237,  -121,  -121,  -121,   166,  -121,  -121,   -33,
     -65,  -121,   188,  -121,  -121,  -121,  -121,  -121,  -121,   -24,
     182,   268,  -121,   189,  -121,  -121,  -121,   -36,   -32,  -121,
    -121,  -121,   297,   224,   176,   -29,  -121,    -2,   -72,  -121,
     118,   186,    45,  -121,    16,  -121,  -120,  -121,   -30,    15,
    -121,   -44
};

/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
   positive, shift that token.  If negative, reduce the rule which
   number is the opposite.  If zero, do what YYDEFACT says.
   If YYTABLE_NINF, syntax error.  */
#define YYTABLE_NINF -1
static const unsigned short yytable[] =
{
      62,    69,   100,    90,   146,    22,    55,    28,    18,    19,
      77,    17,    90,     1,    78,    22,    62,    80,     4,    41,
      24,    18,    19,   146,    29,    44,     5,    66,    61,   178,
      25,   179,    26,    95,    33,    41,   123,    62,    73,    18,
      19,    74,    45,   112,    61,    88,    30,    78,    65,    62,
      80,    20,    23,    78,    88,    62,    80,    38,    75,    67,
      31,    62,    89,   118,    25,    61,    26,   116,   182,    42,
     180,    89,   181,    43,   219,   184,   220,    61,   209,   210,
      18,    19,    70,    61,    90,    39,   132,   133,    91,    61,
     196,    18,    19,    62,   257,    88,   258,    67,    78,   107,
      62,    80,    25,    36,    26,   109,   214,   215,   216,   217,
      83,    40,    89,   117,   120,    96,    18,    19,    18,    19,
     187,    61,   145,   228,   127,   113,    88,   124,    61,   230,
     121,    97,   122,    48,    49,    50,    51,    52,    25,   125,
      26,   145,    46,    89,    47,   130,    67,   247,    18,    19,
     135,     7,   128,    18,    19,     8,     9,    10,    11,    62,
      62,    62,    62,    62,    62,    48,    49,    50,    51,    52,
      25,   149,    26,    53,   148,    25,    98,    26,    96,   197,
     198,   199,   200,   153,    81,   188,   221,    61,    61,    61,
      61,    61,    61,    82,    97,   186,   189,    18,    19,    48,
      49,    50,    51,    52,    25,    46,    26,    47,   190,    67,
     136,    18,    19,   191,   138,   139,   192,   140,   193,    25,
     194,    26,    53,    18,    19,   256,   195,   259,    48,    49,
      50,    51,    52,    25,   201,    26,    53,   154,   155,   156,
     157,   158,   159,   160,   202,   218,   141,   229,   243,   142,
     245,   161,   211,   212,   213,   162,   240,   241,   242,   244,
      81,    18,    19,   203,   204,   205,   206,   207,   208,    82,
      83,   163,   164,    18,    19,   246,   165,   166,    48,    49,
      50,    51,    52,    25,   141,    26,   248,   142,   154,   155,
     156,   157,   158,   159,   160,    25,   249,    26,    53,   250,
     251,   252,   161,   253,   254,   260,   162,   255,   110,   183,
     151,   137,    18,    19,    37,    84,    46,    76,    47,   152,
     231,   119,    18,    19,     0,     0,     0,     0,     0,    48,
      49,    50,    51,    52,    25,   141,    26,     0,   142,    48,
      49,    50,    51,    52,    25,     0,    26,    53,    46,   111,
      47,     0,     0,     0,    18,    19,     0,    46,     0,    47,
       0,     0,     0,    18,    19,   222,   223,   224,   225,   226,
     227,    48,    49,    50,    51,    52,    25,     0,    26,    53,
      48,    49,    50,    51,    52,    25,     0,    26,    53,   232,
     233,   234,   235,   236,   237,   238,   239
};

static const short yycheck[] =
{
      30,    34,    67,    47,   124,     7,    30,     9,    39,    40,
      46,    11,    56,    14,    46,    17,    46,    46,    61,    21,
      51,    39,    40,   143,     9,    27,     0,     5,    30,    33,
      61,    35,    63,    66,     4,    37,   101,    67,    40,    39,
      40,    43,    27,    79,    46,    47,    37,    79,    33,    79,
      79,    51,    66,    85,    56,    85,    85,    66,    43,    37,
      51,    91,    47,    96,    61,    67,    63,    91,   140,    61,
      33,    56,    35,    32,    32,   147,    34,    79,    49,    50,
      39,    40,     4,    85,   128,    66,   119,   120,    67,    91,
     162,    39,    40,   123,    32,    97,    34,    37,   130,    27,
     130,   130,    61,    51,    63,    23,   178,   179,   180,   181,
      36,    32,    97,    38,    13,     6,    39,    40,    39,    40,
     153,   123,   124,   195,   109,    36,   128,    28,   130,   201,
      38,    22,    67,    56,    57,    58,    59,    60,    61,    12,
      63,   143,    33,   128,    35,    32,    37,   219,    39,    40,
      24,     3,    68,    39,    40,     7,     8,     9,    10,   189,
     190,   191,   192,   193,   194,    56,    57,    58,    59,    60,
      61,    25,    63,    64,    58,    61,    67,    63,     6,   163,
     164,   165,   166,    13,    26,    33,   188,   189,   190,   191,
     192,   193,   194,    35,    22,    58,    33,    39,    40,    56,
      57,    58,    59,    60,    61,    33,    63,    35,    33,    37,
      38,    39,    40,    33,    30,    31,    33,    33,    33,    61,
      33,    63,    64,    39,    40,   255,    33,   257,    56,    57,
      58,    59,    60,    61,    42,    63,    64,    15,    16,    17,
      18,    19,    20,    21,    41,    34,    62,    34,    34,    65,
      34,    29,    51,    52,    53,    33,   211,   212,   213,    36,
      26,    39,    40,    43,    44,    45,    46,    47,    48,    35,
      36,    49,    50,    39,    40,    36,    54,    55,    56,    57,
      58,    59,    60,    61,    62,    63,    34,    65,    15,    16,
      17,    18,    19,    20,    21,    61,    34,    63,    64,    34,
      34,    34,    29,    34,    34,    34,    33,    32,    71,   143,
     128,   123,    39,    40,    17,    47,    33,    34,    35,   130,
     202,    97,    39,    40,    -1,    -1,    -1,    -1,    -1,    56,
      57,    58,    59,    60,    61,    62,    63,    -1,    65,    56,
      57,    58,    59,    60,    61,    -1,    63,    64,    33,    34,
      35,    -1,    -1,    -1,    39,    40,    -1,    33,    -1,    35,
      -1,    -1,    -1,    39,    40,   189,   190,   191,   192,   193,
     194,    56,    57,    58,    59,    60,    61,    -1,    63,    64,
      56,    57,    58,    59,    60,    61,    -1,    63,    64,   203,
     204,   205,   206,   207,   208,   209,   210
};

/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
   symbol of state STATE-NUM.  */
static const unsigned char yystos[] =
{
       0,    14,    70,    72,    61,     0,    73,     3,     7,     8,
       9,    10,    71,    74,    75,    76,    77,    11,    39,    40,
      51,   111,   116,    66,    51,    61,    63,   110,   116,   128,
      37,    51,    96,     4,    78,    79,    51,   111,    66,    66,
      32,   116,    61,    32,   116,   128,    33,    35,    56,    57,
      58,    59,    60,    64,    97,    98,   104,   107,   109,   113,
     114,   116,   127,   128,   130,   128,     5,    37,    82,    88,
       4,    80,    81,   116,   116,   128,    34,   106,   107,   108,
     114,    26,    35,    36,   100,   105,   112,   115,   116,   128,
     130,    67,    89,    99,   100,    88,     6,    22,    67,    88,
      89,    90,    91,    92,    93,    94,    98,    27,    83,    23,
      81,    34,   106,    36,   102,   106,    98,    38,    88,   112,
      13,    38,    67,    89,    28,    12,    86,   128,    68,   101,
      32,   103,    88,    88,    95,    24,    38,    91,    30,    31,
      33,    62,    65,    84,    85,   116,   125,   129,    58,    25,
      87,    99,   102,    13,    15,    16,    17,    18,    19,    20,
      21,    29,    33,    49,    50,    54,    55,   116,   117,   118,
     119,   120,   121,   122,   123,   124,   125,   127,    33,    35,
      33,    35,   117,    85,   117,   126,    58,    88,    33,    33,
      33,    33,    33,    33,    33,    33,   117,   123,   123,   123,
     123,    42,    41,    43,    44,    45,    46,    47,    48,    49,
      50,    51,    52,    53,   117,   117,   117,   117,    34,    32,
      34,   116,   113,   113,   113,   113,   113,   113,   117,    34,
     117,   119,   120,   120,   120,   120,   120,   120,   120,   120,
     121,   121,   121,    34,    36,    34,    36,   117,    34,    34,
      34,    34,    34,    34,    34,    32,   127,    32,    34,   127,
      34
};

#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
# define YYSIZE_T __SIZE_TYPE__
#endif
#if ! defined (YYSIZE_T) && defined (size_t)
# define YYSIZE_T size_t
#endif
#if ! defined (YYSIZE_T)
# if defined (__STDC__) || defined (__cplusplus)
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  define YYSIZE_T size_t
# endif
#endif
#if ! defined (YYSIZE_T)
# define YYSIZE_T unsigned int
#endif

#define yyerrok         (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY         (-2)
#define YYEOF           0

#define YYACCEPT  goto yyacceptlab
#define YYABORT         goto yyabortlab
#define YYERROR         goto yyerrorlab


/* Like YYERROR except do call yyerror.  This remains here temporarily
   to ease the transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */

#define YYFAIL          goto yyerrlab

#define YYRECOVERING()  (!!yyerrstatus)

#define YYBACKUP(Token, Value)                              \
do                                              \
  if (yychar == YYEMPTY && yylen == 1)                      \
    {                                           \
      yychar = (Token);                               \
      yylval = (Value);                               \
      yytoken = YYTRANSLATE (yychar);                       \
      YYPOPSTACK;                               \
      goto yybackup;                                  \
    }                                           \
  else                                                \
    {                                                 \
      yyerror ("syntax error: cannot back up");\
      YYERROR;                                        \
    }                                           \
while (0)

#define YYTERROR  1
#define YYERRCODE 256

/* YYLLOC_DEFAULT -- Compute the default location (before the actions
   are run).  */

#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N)        \
   ((Current).first_line   = (Rhs)[1].first_line,     \
    (Current).first_column = (Rhs)[1].first_column,   \
    (Current).last_line    = (Rhs)[N].last_line,      \
    (Current).last_column  = (Rhs)[N].last_column)
#endif

/* YYLEX -- calling `yylex' with the right arguments.  */

#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval)
#endif

/* Enable debugging if requested.  */
#if YYDEBUG

# ifndef YYFPRINTF
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
#  define YYFPRINTF fprintf
# endif

# define YYDPRINTF(Args)                  \
do {                                \
  if (yydebug)                            \
    YYFPRINTF Args;                       \
} while (0)

# define YYDSYMPRINT(Args)                \
do {                                \
  if (yydebug)                            \
    yysymprint Args;                      \
} while (0)

# define YYDSYMPRINTF(Title, Token, Value, Location)        \
do {                                            \
  if (yydebug)                                        \
    {                                           \
      YYFPRINTF (stderr, "%s ", Title);                     \
      yysymprint (stderr,                             \
                  Token, Value);    \
      YYFPRINTF (stderr, "\n");                             \
    }                                           \
} while (0)

/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included).                                                   |
`------------------------------------------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yy_stack_print (short *bottom, short *top)
#else
static void
yy_stack_print (bottom, top)
    short *bottom;
    short *top;
#endif
{
  YYFPRINTF (stderr, "Stack now");
  for (/* Nothing. */; bottom <= top; ++bottom)
    YYFPRINTF (stderr, " %d", *bottom);
  YYFPRINTF (stderr, "\n");
}

# define YY_STACK_PRINT(Bottom, Top)                        \
do {                                            \
  if (yydebug)                                        \
    yy_stack_print ((Bottom), (Top));                       \
} while (0)


/*------------------------------------------------.
| Report that the YYRULE is going to be reduced.  |
`------------------------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yy_reduce_print (int yyrule)
#else
static void
yy_reduce_print (yyrule)
    int yyrule;
#endif
{
  int yyi;
  unsigned int yylno = yyrline[yyrule];
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
             yyrule - 1, yylno);
  /* Print the symbols being reduced, and their result.  */
  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
    YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
  YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
}

# define YY_REDUCE_PRINT(Rule)            \
do {                          \
  if (yydebug)                      \
    yy_reduce_print (Rule);         \
} while (0)

/* Nonzero means print parse trace.  It is left uninitialized so that
   multiple parsers can coexist.  */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YYDSYMPRINT(Args)
# define YYDSYMPRINTF(Title, Token, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */


/* YYINITDEPTH -- initial size of the parser's stacks.  */
#ifndef     YYINITDEPTH
# define YYINITDEPTH 200
#endif

/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   if the built-in stack extension method is used).

   Do not make this value too large; the results are undefined if
   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
   evaluated with infinite-precision integer arithmetic.  */

#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif



#if YYERROR_VERBOSE

# ifndef yystrlen
#  if defined (__GLIBC__) && defined (_STRING_H)
#   define yystrlen strlen
#  else
/* Return the length of YYSTR.  */
static YYSIZE_T
#   if defined (__STDC__) || defined (__cplusplus)
yystrlen (const char *yystr)
#   else
yystrlen (yystr)
     const char *yystr;
#   endif
{
  register const char *yys = yystr;

  while (*yys++ != '\0')
    continue;

  return yys - yystr - 1;
}
#  endif
# endif

# ifndef yystpcpy
#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
#   define yystpcpy stpcpy
#  else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
   YYDEST.  */
static char *
#   if defined (__STDC__) || defined (__cplusplus)
yystpcpy (char *yydest, const char *yysrc)
#   else
yystpcpy (yydest, yysrc)
     char *yydest;
     const char *yysrc;
#   endif
{
  register char *yyd = yydest;
  register const char *yys = yysrc;

  while ((*yyd++ = *yys++) != '\0')
    continue;

  return yyd - 1;
}
#  endif
# endif

#endif /* !YYERROR_VERBOSE */



#if YYDEBUG
/*--------------------------------.
| Print this symbol on YYOUTPUT.  |
`--------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
#else
static void
yysymprint (yyoutput, yytype, yyvaluep)
    FILE *yyoutput;
    int yytype;
    YYSTYPE *yyvaluep;
#endif
{
  /* Pacify ``unused variable'' warnings.  */
  (void) yyvaluep;

  if (yytype < YYNTOKENS)
    {
      YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
# ifdef YYPRINT
      YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
# endif
    }
  else
    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);

  switch (yytype)
    {
      default:
        break;
    }
  YYFPRINTF (yyoutput, ")");
}

#endif /* ! YYDEBUG */
/*-----------------------------------------------.
| Release the memory associated to this symbol.  |
`-----------------------------------------------*/

#if defined (__STDC__) || defined (__cplusplus)
static void
yydestruct (int yytype, YYSTYPE *yyvaluep)
#else
static void
yydestruct (yytype, yyvaluep)
    int yytype;
    YYSTYPE *yyvaluep;
#endif
{
  /* Pacify ``unused variable'' warnings.  */
  (void) yyvaluep;

  switch (yytype)
    {

      default:
        break;
    }
}


/* Prevent warnings from -Wmissing-prototypes.  */

#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
int yyparse (void *YYPARSE_PARAM);
# else
int yyparse ();
# endif
#else /* ! YYPARSE_PARAM */
#if defined (__STDC__) || defined (__cplusplus)
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */






/*----------.
| yyparse.  |
`----------*/

#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
int yyparse (void *YYPARSE_PARAM)
# else
int yyparse (YYPARSE_PARAM)
  void *YYPARSE_PARAM;
# endif
#else /* ! YYPARSE_PARAM */
#if defined (__STDC__) || defined (__cplusplus)
int
yyparse (void)
#else
int
yyparse ()

#endif
#endif
{
  /* The lookahead symbol.  */
int yychar;

/* The semantic value of the lookahead symbol.  */
YYSTYPE yylval;

/* Number of syntax errors so far.  */
int yynerrs;

  register int yystate;
  register int yyn;
  int yyresult;
  /* Number of tokens to shift before error messages enabled.  */
  int yyerrstatus;
  /* Lookahead token as an internal (translated) token number.  */
  int yytoken = 0;

  /* Three stacks and their tools:
     `yyss': related to states,
     `yyvs': related to semantic values,
     `yyls': related to locations.

     Refer to the stacks thru separate pointers, to allow yyoverflow
     to reallocate them elsewhere.  */

  /* The state stack.  */
  short     yyssa[YYINITDEPTH];
  short *yyss = yyssa;
  register short *yyssp;

  /* The semantic value stack.  */
  YYSTYPE yyvsa[YYINITDEPTH];
  YYSTYPE *yyvs = yyvsa;
  register YYSTYPE *yyvsp;



#define YYPOPSTACK   (yyvsp--, yyssp--)

  YYSIZE_T yystacksize = YYINITDEPTH;

  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;


  /* When reducing, the number of symbols on the RHS of the reduced
     rule.  */
  int yylen;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY;           /* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss;
  yyvsp = yyvs;

  goto yysetstate;

/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
 yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed. so pushing a state here evens the stacks.
     */
  yyssp++;

 yysetstate:
  *yyssp = yystate;

  if (yyss + yystacksize - 1 <= yyssp)
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYSIZE_T yysize = yyssp - yyss + 1;

#ifdef yyoverflow
      {
      /* Give user a chance to reallocate the stack. Use copies of
         these so that the &'s don't force the real ones into
         memory.  */
      YYSTYPE *yyvs1 = yyvs;
      short *yyss1 = yyss;


      /* Each stack pointer address is followed by the size of the
         data in use in that stack, in bytes.  This used to be a
         conditional around just the two extra args, but that might
         be undefined if yyoverflow is a macro.  */
      yyoverflow ("parser stack overflow",
                &yyss1, yysize * sizeof (*yyssp),
                &yyvs1, yysize * sizeof (*yyvsp),

                &yystacksize);

      yyss = yyss1;
      yyvs = yyvs1;
      }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
      goto yyoverflowlab;
# else
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
      goto yyoverflowlab;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
      yystacksize = YYMAXDEPTH;

      {
      short *yyss1 = yyss;
      union yyalloc *yyptr =
        (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
      if (! yyptr)
        goto yyoverflowlab;
      YYSTACK_RELOCATE (yyss);
      YYSTACK_RELOCATE (yyvs);

#  undef YYSTACK_RELOCATE
      if (yyss1 != yyssa)
        YYSTACK_FREE (yyss1);
      }
# endif
#endif /* no yyoverflow */

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;


      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
              (unsigned long int) yystacksize));

      if (yyss + yystacksize - 1 <= yyssp)
      YYABORT;
    }

  YYDPRINTF ((stderr, "Entering state %d\n", yystate));

  goto yybackup;

/*-----------.
| yybackup.  |
`-----------*/
yybackup:

/* Do appropriate processing given the current state.  */
/* Read a lookahead token if we need one and don't already have one.  */
/* yyresume: */

  /* First try to decide what to do without reference to lookahead token.  */

  yyn = yypact[yystate];
  if (yyn == YYPACT_NINF)
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token: "));
      yychar = YYLEX;
    }

  if (yychar <= YYEOF)
    {
      yychar = yytoken = YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yyn == 0 || yyn == YYTABLE_NINF)
      goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  if (yyn == YYFINAL)
    YYACCEPT;

  /* Shift the lookahead token.  */
  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));

  /* Discard the token being shifted unless it is eof.  */
  if (yychar != YYEOF)
    yychar = YYEMPTY;

  *++yyvsp = yylval;


  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  yystate = yyn;
  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- Do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     `$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
        case 2:
#line 211 "./sparql_parser.y"
    {
}
    break;

  case 3:
#line 218 "./sparql_parser.y"
    {
  ((rasqal_query*)rq)->selects=yyvsp[0].seq;
  ((rasqal_query*)rq)->verb=RASQAL_QUERY_VERB_SELECT;
}
    break;

  case 4:
#line 223 "./sparql_parser.y"
    {
  ((rasqal_query*)rq)->constructs=yyvsp[0].seq;
  ((rasqal_query*)rq)->verb=RASQAL_QUERY_VERB_CONSTRUCT;
}
    break;

  case 5:
#line 228 "./sparql_parser.y"
    {
  ((rasqal_query*)rq)->describes=yyvsp[0].seq;
  ((rasqal_query*)rq)->verb=RASQAL_QUERY_VERB_DESCRIBE;
}
    break;

  case 6:
#line 233 "./sparql_parser.y"
    {
  ((rasqal_query*)rq)->verb=RASQAL_QUERY_VERB_ASK;
}
    break;

  case 7:
#line 243 "./sparql_parser.y"
    {
  if(((rasqal_query*)rq)->base_uri)
    raptor_free_uri(((rasqal_query*)rq)->base_uri);
  ((rasqal_query*)rq)->base_uri=yyvsp[0].uri;
}
    break;

  case 8:
#line 249 "./sparql_parser.y"
    {
  /* nothing to do */
}
    break;

  case 9:
#line 257 "./sparql_parser.y"
    {
  rasqal_prefix *p=rasqal_new_prefix(yyvsp[-1].name, yyvsp[0].uri);
  raptor_sequence *seq=((rasqal_query*)rq)->prefixes;
  raptor_sequence_push(seq, p);
  rasqal_engine_declare_prefix(((rasqal_query*)rq), p);
}
    break;

  case 10:
#line 264 "./sparql_parser.y"
    {
  /* nothing to do, rq->prefixes already initialised */
}
    break;

  case 11:
#line 272 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[0].seq;
  ((rasqal_query*)rq)->distinct=1;
}
    break;

  case 12:
#line 277 "./sparql_parser.y"
    {
  yyval.seq=NULL;
  ((rasqal_query*)rq)->wildcard=1;
  ((rasqal_query*)rq)->distinct=1;
}
    break;

  case 13:
#line 283 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[0].seq;
}
    break;

  case 14:
#line 287 "./sparql_parser.y"
    {
  yyval.seq=NULL;
  ((rasqal_query*)rq)->wildcard=1;
}
    break;

  case 15:
#line 296 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[0].seq;
}
    break;

  case 16:
#line 300 "./sparql_parser.y"
    {
  yyval.seq=NULL;
}
    break;

  case 17:
#line 308 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[0].seq;
}
    break;

  case 18:
#line 312 "./sparql_parser.y"
    {
  yyval.seq=NULL;
  ((rasqal_query*)rq)->wildcard=1;
}
    break;

  case 19:
#line 321 "./sparql_parser.y"
    {
  /* nothing to do */
}
    break;

  case 23:
#line 335 "./sparql_parser.y"
    {
  if(yyvsp[0].literal) {
    raptor_uri* uri=rasqal_literal_as_uri(yyvsp[0].literal);
    rasqal_query_add_data_graph((rasqal_query*)rq, uri, uri, RASQAL_DATA_GRAPH_BACKGROUND);
    rasqal_free_literal(yyvsp[0].literal);
  }
}
    break;

  case 26:
#line 352 "./sparql_parser.y"
    {
  if(yyvsp[0].literal) {
    raptor_uri* uri=rasqal_literal_as_uri(yyvsp[0].literal);
    rasqal_query_add_data_graph((rasqal_query*)rq, uri, uri, RASQAL_DATA_GRAPH_NAMED);
    rasqal_free_literal(yyvsp[0].literal);
  }
}
    break;

  case 27:
#line 367 "./sparql_parser.y"
    {
  ((rasqal_query*)rq)->query_graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 28:
#line 371 "./sparql_parser.y"
    {
  sparql_syntax_warning(((rasqal_query*)rq), "WHERE omitted");
  ((rasqal_query*)rq)->query_graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 30:
#line 381 "./sparql_parser.y"
    {
  if(((rasqal_query*)rq)->verb == RASQAL_QUERY_VERB_ASK) {
    sparql_query_error((rasqal_query*)rq, "ORDER BY cannot be used with ASK");
  } else {
    ((rasqal_query*)rq)->order_conditions_sequence=yyvsp[0].seq;
  }
}
    break;

  case 32:
#line 394 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-1].seq;
  if(yyvsp[0].expr)
    raptor_sequence_push(yyval.seq, yyvsp[0].expr);
}
    break;

  case 33:
#line 400 "./sparql_parser.y"
    {
  yyval.seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_expression, (raptor_sequence_print_handler*)rasqal_expression_print);
  if(yyvsp[0].expr)
    raptor_sequence_push(yyval.seq, yyvsp[0].expr);
}
    break;

  case 34:
#line 410 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_ASC, yyvsp[-1].expr);
}
    break;

  case 35:
#line 414 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_DESC, yyvsp[-1].expr);
}
    break;

  case 36:
#line 418 "./sparql_parser.y"
    {
  RASQAL_DEPRECATED_WARNING((rasqal_query*)rq, "ORDER BY ASC[] is deprecated and replaced by ORDER BY ASC()");
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_ASC, yyvsp[-1].expr);
}
    break;

  case 37:
#line 423 "./sparql_parser.y"
    {
  RASQAL_DEPRECATED_WARNING((rasqal_query*)rq, "ORDER BY DESC[] is deprecated and replaced by ORDER BY DESC()");
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_DESC, yyvsp[-1].expr);
}
    break;

  case 38:
#line 428 "./sparql_parser.y"
    {
  /* The direction of ordering is ascending by default */
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_ASC, yyvsp[0].expr);
}
    break;

  case 39:
#line 433 "./sparql_parser.y"
    {
  rasqal_literal* l=rasqal_new_variable_literal(yyvsp[0].variable);
  rasqal_expression *e=rasqal_new_literal_expression(l);
  /* The direction of ordering is ascending by default */
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_ASC, e);
}
    break;

  case 40:
#line 440 "./sparql_parser.y"
    {
  /* The direction of ordering is ascending by default */
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ORDER_COND_ASC, yyvsp[-1].expr);
}
    break;

  case 41:
#line 449 "./sparql_parser.y"
    {
  if(((rasqal_query*)rq)->verb == RASQAL_QUERY_VERB_ASK) {
    sparql_query_error((rasqal_query*)rq, "LIMIT cannot be used with ASK");
  } else {
    if(yyvsp[0].literal != NULL)
      ((rasqal_query*)rq)->limit=yyvsp[0].literal->value.integer;
  }
  
}
    break;

  case 43:
#line 463 "./sparql_parser.y"
    {
  if(((rasqal_query*)rq)->verb == RASQAL_QUERY_VERB_ASK) {
    sparql_query_error((rasqal_query*)rq, "LIMIT cannot be used with ASK");
  } else {
    if(yyvsp[0].literal != NULL)
      ((rasqal_query*)rq)->offset=yyvsp[0].literal->value.integer;
  }
}
    break;

  case 45:
#line 476 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("GraphPattern 1\n  GraphPattern=");
  rasqal_graph_pattern_print(yyvsp[-2].graph_pattern, stdout);
  fputs("\n\n", stdout);
#endif

  yyval.graph_pattern=yyvsp[-2].graph_pattern;
}
    break;

  case 46:
#line 486 "./sparql_parser.y"
    {
  yyval.graph_pattern=NULL;
}
    break;

  case 49:
#line 501 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("PatternElementList 1\n  PatternElementList=");
  rasqal_graph_pattern_print(yyvsp[-2].graph_pattern, stdout);
  printf(", patternelement=");
  if(yyvsp[0].graph_pattern)
    rasqal_graph_pattern_print(yyvsp[0].graph_pattern, stdout);
  else
    fputs("NULL", stdout);
  fputs("\n\n", stdout);
#endif

  yyval.graph_pattern=yyvsp[-2].graph_pattern;
  if(yyvsp[0].graph_pattern)
    raptor_sequence_push(yyval.graph_pattern->graph_patterns, yyvsp[0].graph_pattern);
}
    break;

  case 50:
#line 518 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("PatternElementsList 2\n  PatternElementsList=");
  rasqal_graph_pattern_print(yyvsp[-3].graph_pattern, stdout);
  printf(", expression=");
  rasqal_expression_print(yyvsp[0].expr, stdout);
  fputs("\n\n", stdout);
#endif


  yyval.graph_pattern=yyvsp[-3].graph_pattern;
  rasqal_graph_pattern_add_constraint(yyval.graph_pattern, yyvsp[0].expr);
}
    break;

  case 51:
#line 532 "./sparql_parser.y"
    {
  raptor_sequence *seq;

#if RASQAL_DEBUG > 1  
  printf("PatternElementsList 3\n  PatternElement=");
  if(yyvsp[0].graph_pattern)
    rasqal_graph_pattern_print(yyvsp[0].graph_pattern, stdout);
  else
    fputs("NULL", stdout);
  fputs("\n\n", stdout);
#endif

  seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_graph_pattern, (raptor_sequence_print_handler*)rasqal_graph_pattern_print);
  if(yyvsp[0].graph_pattern)
    raptor_sequence_push(seq, yyvsp[0].graph_pattern);

  yyval.graph_pattern=rasqal_new_graph_pattern_from_sequence((rasqal_query*)rq, seq, 
                                            RASQAL_GRAPH_PATTERN_OPERATOR_GROUP);
}
    break;

  case 52:
#line 556 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("PatternElement 1\n  Triples=");
  if(yyvsp[0].formula)
    rasqal_formula_print(yyvsp[0].formula, stdout);
  else
    fputs("NULL", stdout);
  fputs("\n\n", stdout);
#endif

  if(yyvsp[0].formula) {
    raptor_sequence *s=((rasqal_query*)rq)->triples;
    raptor_sequence *t=yyvsp[0].formula->triples;
    int offset=raptor_sequence_size(s);
    int triple_pattern_size=raptor_sequence_size(t);
    
    raptor_sequence_join(s, t);

    rasqal_free_formula(yyvsp[0].formula);

    yyval.graph_pattern=rasqal_new_graph_pattern_from_triples((rasqal_query*)rq, s, offset, offset+triple_pattern_size-1, RASQAL_GRAPH_PATTERN_OPERATOR_BASIC);
  } else
    yyval.graph_pattern=NULL;
}
    break;

  case 53:
#line 581 "./sparql_parser.y"
    {
  yyval.graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 54:
#line 585 "./sparql_parser.y"
    {
  yyval.graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 55:
#line 589 "./sparql_parser.y"
    {
  yyval.graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 56:
#line 593 "./sparql_parser.y"
    {
  yyval.graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 57:
#line 601 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("PatternElementForms 4\n  graphpattern=");
  if(yyvsp[0].graph_pattern)
    rasqal_graph_pattern_print(yyvsp[0].graph_pattern, stdout);
  else
    fputs("NULL", stdout);
  fputs("\n\n", stdout);
#endif

  if(yyvsp[0].graph_pattern)
    yyvsp[0].graph_pattern->op = RASQAL_GRAPH_PATTERN_OPERATOR_OPTIONAL;

  yyval.graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 58:
#line 621 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("GraphGraphPattern 2\n  varoruri=");
  rasqal_literal_print(yyvsp[-1].literal, stdout);
  printf(", graphpattern=");
  rasqal_graph_pattern_print(yyvsp[0].graph_pattern, stdout);
  fputs("\n\n", stdout);
#endif

  rasqal_graph_pattern_set_origin(yyvsp[0].graph_pattern, yyvsp[-1].literal);
  yyvsp[0].graph_pattern->op = RASQAL_GRAPH_PATTERN_OPERATOR_GRAPH;

  rasqal_free_literal(yyvsp[-1].literal);
  yyval.graph_pattern=yyvsp[0].graph_pattern;
}
    break;

  case 59:
#line 641 "./sparql_parser.y"
    {
  yyval.graph_pattern=yyvsp[0].graph_pattern;
  raptor_sequence_push(yyval.graph_pattern->graph_patterns, yyvsp[-2].graph_pattern);

#if RASQAL_DEBUG > 1  
  printf("UnionGraphPattern\n  graphpattern=");
  rasqal_graph_pattern_print(yyval.graph_pattern, stdout);
  fputs("\n\n", stdout);
#endif

}
    break;

  case 60:
#line 656 "./sparql_parser.y"
    {
  yyval.graph_pattern=yyvsp[-2].graph_pattern;
  if(yyvsp[0].graph_pattern)
    raptor_sequence_push(yyval.graph_pattern->graph_patterns, yyvsp[0].graph_pattern);
}
    break;

  case 61:
#line 662 "./sparql_parser.y"
    {
  raptor_sequence *seq;
  seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_graph_pattern, (raptor_sequence_print_handler*)rasqal_graph_pattern_print);
  if(yyvsp[0].graph_pattern)
    raptor_sequence_push(seq, yyvsp[0].graph_pattern);
  yyval.graph_pattern=rasqal_new_graph_pattern_from_sequence((rasqal_query*)rq,
                                            seq,
                                            RASQAL_GRAPH_PATTERN_OPERATOR_UNION);
}
    break;

  case 62:
#line 679 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-2].seq;
}
    break;

  case 63:
#line 687 "./sparql_parser.y"
    {
  if(yyvsp[0].formula) {
    if(yyvsp[0].formula->triples)
      raptor_sequence_join(yyvsp[-2].seq, yyvsp[0].formula->triples);

    rasqal_free_formula(yyvsp[0].formula);
  }
  
}
    break;

  case 64:
#line 697 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("TriplesList 2\n  Triples=");
  if(yyvsp[0].formula)
    rasqal_formula_print(yyvsp[0].formula, stdout);
  else
    fputs("NULL", stdout);
  fputs("\n\n", stdout);
#endif

  if(yyvsp[0].formula) {
    yyval.seq=yyvsp[0].formula->triples;
    yyvsp[0].formula->triples=NULL;
    rasqal_free_formula(yyvsp[0].formula);
  } else
    yyval.seq=NULL;
}
    break;

  case 65:
#line 719 "./sparql_parser.y"
    {
  int i;

#if RASQAL_DEBUG > 1  
  printf("Triples 1\n subject=");
  rasqal_formula_print(yyvsp[-1].formula, stdout);
  if(yyvsp[0].formula) {
    printf("\n propertyList (reverse order to syntax)=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n");
  } else     
    printf("\n and empty propertyList\n");
#endif

  if(yyvsp[0].formula) {
    raptor_sequence *seq=yyvsp[0].formula->triples;
    rasqal_literal *subject=yyvsp[-1].formula->value;
    
    /* non-empty property list, handle it  */
    for(i=0; i < raptor_sequence_size(seq); i++) {
      rasqal_triple* t2=(rasqal_triple*)raptor_sequence_get_at(seq, i);
      if(t2->subject)
        continue;
      t2->subject=rasqal_new_literal_from_literal(subject);
    }
#if RASQAL_DEBUG > 1  
    printf(" after substitution propertyList=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n\n");
#endif
  }

  if(yyvsp[-1].formula) {
    if(yyvsp[0].formula && yyvsp[-1].formula->triples) {
      raptor_sequence *seq=yyvsp[0].formula->triples;
      
      raptor_sequence_join(yyvsp[-1].formula->triples, seq);
      yyvsp[0].formula->triples=yyvsp[-1].formula->triples;
      yyvsp[-1].formula->triples=seq;

#if RASQAL_DEBUG > 1  
    printf(" after joining formula=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n\n");
#endif
    }
  }

  if(yyvsp[0].formula) {
    if(yyvsp[-1].formula)
      rasqal_free_formula(yyvsp[-1].formula);
    yyval.formula=yyvsp[0].formula;
  } else
    yyval.formula=yyvsp[-1].formula;
}
    break;

  case 66:
#line 779 "./sparql_parser.y"
    {
  yyval.formula=yyvsp[0].formula;
}
    break;

  case 67:
#line 783 "./sparql_parser.y"
    {
  yyval.formula=NULL;
}
    break;

  case 68:
#line 793 "./sparql_parser.y"
    {
  int i;
  
#if RASQAL_DEBUG > 1  
  printf("PropertyList 1\n Predicate=");
  rasqal_formula_print(yyvsp[-2].formula, stdout);
  printf("\n ObjectList=");
  rasqal_formula_print(yyvsp[-1].formula, stdout);
  printf("\n PropertyListTail=");
  if(yyvsp[0].formula != NULL)
    rasqal_formula_print(yyvsp[0].formula, stdout);
  else
    fputs("NULL", stdout);
  printf("\n");
#endif
  
  if(yyvsp[-1].formula == NULL) {
#if RASQAL_DEBUG > 1  
    printf(" empty ObjectList not processed\n");
#endif
  } else if(yyvsp[-2].formula && yyvsp[-1].formula) {
    raptor_sequence *seq=yyvsp[-1].formula->triples;
    rasqal_literal *predicate=yyvsp[-2].formula->value;

    /* non-empty property list, handle it  */
    for(i=0; i<raptor_sequence_size(seq); i++) {
      rasqal_triple* t2=(rasqal_triple*)raptor_sequence_get_at(seq, i);
      if(!t2->predicate)
        t2->predicate=(rasqal_literal*)rasqal_new_literal_from_literal(predicate);
    }
  
#if RASQAL_DEBUG > 1  
    printf(" after substitution ObjectList=");
    raptor_sequence_print(seq, stdout);
    printf("\n");
#endif
  }

  if (yyvsp[-2].formula && yyvsp[-1].formula) {
    raptor_sequence *seq=yyvsp[-1].formula->triples;

    if(!yyvsp[0].formula) {
      yyvsp[0].formula=rasqal_new_formula();
      yyvsp[0].formula->triples=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_triple, (raptor_sequence_print_handler*)rasqal_triple_print);
    }

    for(i=0; i < raptor_sequence_size(seq); i++) {
      rasqal_triple* t2=(rasqal_triple*)raptor_sequence_get_at(seq, i);
      raptor_sequence_push(yyvsp[0].formula->triples, t2);
    }
    while(raptor_sequence_size(seq))
      raptor_sequence_pop(seq);

#if RASQAL_DEBUG > 1  
    printf(" after appending ObjectList (reverse order)=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n\n");
#endif

    rasqal_free_formula(yyvsp[-1].formula);
  }

  if(yyvsp[-2].formula)
    rasqal_free_formula(yyvsp[-2].formula);

  yyval.formula=yyvsp[0].formula;
}
    break;

  case 69:
#line 865 "./sparql_parser.y"
    {
  yyval.formula=yyvsp[0].formula;
}
    break;

  case 70:
#line 869 "./sparql_parser.y"
    {
  yyval.formula=NULL;
}
    break;

  case 71:
#line 877 "./sparql_parser.y"
    {
  rasqal_triple *triple;

#if RASQAL_DEBUG > 1  
  printf("ObjectList 1\n");
  printf(" Object=\n");
  rasqal_formula_print(yyvsp[-1].formula, stdout);
  printf("\n");
  if(yyvsp[0].formula) {
    printf(" ObjectTail=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n");
  } else
    printf(" and empty ObjectTail\n");
#endif

  if(yyvsp[0].formula)
    yyval.formula=yyvsp[0].formula;
  else
    yyval.formula=rasqal_new_formula();
  
  triple=rasqal_new_triple(NULL, NULL, yyvsp[-1].formula->value);
  yyvsp[-1].formula->value=NULL;

  if(!yyval.formula->triples)
    yyval.formula->triples=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_triple, (raptor_sequence_print_handler*)rasqal_triple_print);

  raptor_sequence_push(yyval.formula->triples, triple);

  if(yyvsp[-1].formula->triples) {
    raptor_sequence *seq=yyval.formula->triples;
      
    raptor_sequence_join(yyvsp[-1].formula->triples, seq);
    yyval.formula->triples=yyvsp[-1].formula->triples;
    yyvsp[-1].formula->triples=seq;
  }

  rasqal_free_formula(yyvsp[-1].formula);

#if RASQAL_DEBUG > 1  
  printf(" objectList is now ");
  raptor_sequence_print(yyval.formula->triples, stdout);
  printf("\n\n");
#endif
}
    break;

  case 72:
#line 927 "./sparql_parser.y"
    {
  yyval.formula=yyvsp[0].formula;
}
    break;

  case 73:
#line 931 "./sparql_parser.y"
    {
  yyval.formula=NULL;
}
    break;

  case 74:
#line 939 "./sparql_parser.y"
    {
  yyval.formula=rasqal_new_formula();
  yyval.formula->value=yyvsp[0].literal;
}
    break;

  case 75:
#line 944 "./sparql_parser.y"
    {
  yyval.formula=yyvsp[0].formula;
}
    break;

  case 76:
#line 952 "./sparql_parser.y"
    {
  yyval.formula=rasqal_new_formula();
  yyval.formula->value=yyvsp[0].literal;
}
    break;

  case 77:
#line 957 "./sparql_parser.y"
    {
  raptor_uri *uri;

#if RASQAL_DEBUG > 1  
  printf("verb Predicate=rdf:type (a)\n");
#endif

  uri=raptor_new_uri_for_rdf_concept("type");
  yyval.formula=rasqal_new_formula();
  yyval.formula->value=rasqal_new_uri_literal(uri);
}
    break;

  case 78:
#line 973 "./sparql_parser.y"
    {
  yyval.formula=rasqal_new_formula();
  yyval.formula->value=yyvsp[0].literal;
}
    break;

  case 79:
#line 978 "./sparql_parser.y"
    {
  yyval.formula=yyvsp[0].formula;
}
    break;

  case 80:
#line 986 "./sparql_parser.y"
    {
  int i;
  const unsigned char *id=rasqal_query_generate_bnodeid((rasqal_query*)rq, NULL);
  
  if(yyvsp[-1].formula == NULL)
    yyval.formula=rasqal_new_formula();
  else {
    yyval.formula=yyvsp[-1].formula;
    if(yyval.formula->value)
      rasqal_free_literal(yyval.formula->value);
  }
  
  yyval.formula->value=rasqal_new_simple_literal(RASQAL_LITERAL_BLANK, id);

  if(yyvsp[-1].formula == NULL) {
#if RASQAL_DEBUG > 1  
    printf("TriplesNode\n PropertyList=");
    rasqal_formula_print(yyval.formula, stdout);
    printf("\n");
#endif
  } else {
    raptor_sequence *seq=yyvsp[-1].formula->triples;

    /* non-empty property list, handle it  */
#if RASQAL_DEBUG > 1  
    printf("TriplesNode\n PropertyList=");
    raptor_sequence_print(seq, stdout);
    printf("\n");
#endif

    for(i=0; i<raptor_sequence_size(seq); i++) {
      rasqal_triple* t2=(rasqal_triple*)raptor_sequence_get_at(seq, i);
      if(t2->subject)
        continue;
      
      t2->subject=(rasqal_literal*)rasqal_new_literal_from_literal(yyval.formula->value);
    }

#if RASQAL_DEBUG > 1
    printf(" after substitution formula=");
    rasqal_formula_print(yyval.formula, stdout);
    printf("\n\n");
#endif
  }
  
}
    break;

  case 81:
#line 1033 "./sparql_parser.y"
    {
  yyval.formula=yyvsp[0].formula;
}
    break;

  case 82:
#line 1044 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("ItemList 1\n");
  if(yyvsp[0].formula) {
    printf(" Object=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n");
  } else  
    printf(" and empty Object\n");
  if(yyvsp[-1].seq) {
    printf(" ItemList=");
    raptor_sequence_print(yyvsp[-1].seq, stdout);
    printf("\n");
  } else
    printf(" and empty ItemList\n");
#endif

  if(!yyvsp[0].formula)
    yyval.seq=NULL;
  else {
    raptor_sequence_push(yyval.seq, yyvsp[0].formula);
#if RASQAL_DEBUG > 1  
    printf(" itemList is now ");
    raptor_sequence_print(yyval.seq, stdout);
    printf("\n\n");
#endif
  }

}
    break;

  case 83:
#line 1074 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("ItemList 2\n");
  if(yyvsp[0].formula) {
    printf(" Object=");
    rasqal_formula_print(yyvsp[0].formula, stdout);
    printf("\n");
  } else  
    printf(" and empty Object\n");
#endif

  yyval.seq=NULL;
  if(yyvsp[0].formula)
    yyval.seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_formula, (raptor_sequence_print_handler*)rasqal_formula_print);

  raptor_sequence_push(yyval.seq, yyvsp[0].formula);
#if RASQAL_DEBUG > 1  
  printf(" ItemList is now ");
  raptor_sequence_print(yyval.seq, stdout);
  printf("\n\n");
#endif
}
    break;

  case 84:
#line 1101 "./sparql_parser.y"
    {
  int i;
  rasqal_query* rdf_query=(rasqal_query*)rq;
  rasqal_literal* first_identifier;
  rasqal_literal* rest_identifier;
  rasqal_literal* object;

#if RASQAL_DEBUG > 1  
  printf("Collection\n ItemList=");
  raptor_sequence_print(yyvsp[-1].seq, stdout);
  printf("\n");
#endif

  first_identifier=rasqal_new_uri_literal(raptor_uri_copy(rasqal_rdf_first_uri));
  rest_identifier=rasqal_new_uri_literal(raptor_uri_copy(rasqal_rdf_rest_uri));
  
  object=rasqal_new_uri_literal(raptor_uri_copy(rasqal_rdf_nil_uri));

  yyval.formula=rasqal_new_formula();
  yyval.formula->triples=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_triple, (raptor_sequence_print_handler*)rasqal_triple_print);

  for(i=raptor_sequence_size(yyvsp[-1].seq)-1; i>=0; i--) {
    rasqal_formula* f=(rasqal_formula*)raptor_sequence_get_at(yyvsp[-1].seq, i);
    const unsigned char *blank_id=rasqal_query_generate_bnodeid(rdf_query, NULL);
    rasqal_literal* blank=rasqal_new_simple_literal(RASQAL_LITERAL_BLANK, blank_id);
    rasqal_triple *t2;

    /* Move existing formula triples */
    if(f->triples)
      raptor_sequence_join(yyval.formula->triples, f->triples);

    /* add new triples we needed */
    t2=rasqal_new_triple(rasqal_new_literal_from_literal(blank),
                         rasqal_new_literal_from_literal(first_identifier),
                         rasqal_new_literal_from_literal(f->value));
    raptor_sequence_push(yyval.formula->triples, t2);

    t2=rasqal_new_triple(rasqal_new_literal_from_literal(blank),
                         rasqal_new_literal_from_literal(rest_identifier),
                         rasqal_new_literal_from_literal(object));
    raptor_sequence_push(yyval.formula->triples, t2);

    rasqal_free_literal(object);

    object=blank;
  }

  yyval.formula->value=object;
  
#if RASQAL_DEBUG > 1
  printf(" after substitution collection=");
  rasqal_formula_print(yyval.formula, stdout);
  printf("\n\n");
#endif

  rasqal_free_literal(first_identifier);
  rasqal_free_literal(rest_identifier);
}
    break;

  case 85:
#line 1160 "./sparql_parser.y"
    {
#if RASQAL_DEBUG > 1  
  printf("Collection\n empty\n");
#endif

  yyval.formula=rasqal_new_formula();
  yyval.formula->value=rasqal_new_uri_literal(raptor_uri_copy(rasqal_rdf_nil_uri));
}
    break;

  case 86:
#line 1173 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-1].seq;
  raptor_sequence_push(yyval.seq, rasqal_new_variable_literal(yyvsp[0].variable));
}
    break;

  case 87:
#line 1178 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-2].seq;
  raptor_sequence_push(yyval.seq, rasqal_new_variable_literal(yyvsp[0].variable));
}
    break;

  case 88:
#line 1183 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-1].seq;
  raptor_sequence_push(yyval.seq, yyvsp[0].literal);
}
    break;

  case 89:
#line 1188 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-2].seq;
  raptor_sequence_push(yyval.seq, yyvsp[0].literal);
}
    break;

  case 90:
#line 1193 "./sparql_parser.y"
    {
  /* rasqal_variable* are freed from the raptor_query field variables */
  yyval.seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_literal, (raptor_sequence_print_handler*)rasqal_literal_print);
  raptor_sequence_push(yyval.seq, rasqal_new_variable_literal(yyvsp[0].variable));
}
    break;

  case 91:
#line 1199 "./sparql_parser.y"
    {
  yyval.seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_literal, (raptor_sequence_print_handler*)rasqal_literal_print);
  raptor_sequence_push(yyval.seq, yyvsp[0].literal);
}
    break;

  case 92:
#line 1208 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-1].seq;
  raptor_sequence_push(yyval.seq, yyvsp[0].variable);
}
    break;

  case 93:
#line 1213 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-2].seq;
  raptor_sequence_push(yyval.seq, yyvsp[0].variable);
}
    break;

  case 94:
#line 1218 "./sparql_parser.y"
    {
  /* The variables are freed from the raptor_query field variables */
  yyval.seq=raptor_new_sequence(NULL, (raptor_sequence_print_handler*)rasqal_variable_print);
  raptor_sequence_push(yyval.seq, yyvsp[0].variable);
}
    break;

  case 95:
#line 1232 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_variable_literal(yyvsp[0].variable);
}
    break;

  case 96:
#line 1236 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 97:
#line 1244 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_variable_literal(yyvsp[0].variable);
}
    break;

  case 98:
#line 1248 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 99:
#line 1255 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 100:
#line 1259 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 101:
#line 1267 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 102:
#line 1271 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 103:
#line 1278 "./sparql_parser.y"
    {
  yyval.variable=rasqal_new_variable((rasqal_query*)rq, yyvsp[0].name, NULL);
}
    break;

  case 104:
#line 1282 "./sparql_parser.y"
    {
  yyval.variable=rasqal_new_variable((rasqal_query*)rq, yyvsp[0].name, NULL);
}
    break;

  case 105:
#line 1292 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_OR, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 106:
#line 1296 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 107:
#line 1305 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_AND, yyvsp[-2].expr, yyvsp[0].expr);
;
}
    break;

  case 108:
#line 1310 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 109:
#line 1319 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_EQ, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 110:
#line 1323 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_NEQ, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 111:
#line 1327 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_LT, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 112:
#line 1331 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_GT, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 113:
#line 1335 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_LE, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 114:
#line 1339 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_GE, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 115:
#line 1343 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 116:
#line 1352 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_PLUS, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 117:
#line 1356 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_MINUS, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 118:
#line 1360 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 119:
#line 1367 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_STAR, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 120:
#line 1371 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_SLASH, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 121:
#line 1375 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_2op_expression(RASQAL_EXPR_REM, yyvsp[-2].expr, yyvsp[0].expr);
}
    break;

  case 122:
#line 1379 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 123:
#line 1386 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_UMINUS, yyvsp[0].expr);
}
    break;

  case 124:
#line 1390 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_BANG, yyvsp[0].expr);
}
    break;

  case 125:
#line 1394 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_BANG, yyvsp[0].expr);
}
    break;

  case 126:
#line 1398 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 127:
#line 1402 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 128:
#line 1409 "./sparql_parser.y"
    {
  rasqal_expression *e=rasqal_new_literal_expression(yyvsp[-1].literal);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_STR, e);
}
    break;

  case 129:
#line 1414 "./sparql_parser.y"
    {
  rasqal_expression *e=rasqal_new_literal_expression(yyvsp[-1].literal);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_LANG, e);
}
    break;

  case 130:
#line 1419 "./sparql_parser.y"
    {
  rasqal_expression *e=rasqal_new_literal_expression(yyvsp[-1].literal);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_DATATYPE, e);
}
    break;

  case 131:
#line 1424 "./sparql_parser.y"
    {
  /* FIXME - regex needs more thought */
  const unsigned char* pattern=rasqal_literal_as_string(yyvsp[-1].literal);
  size_t len=strlen((const char*)pattern);
  unsigned char* npattern;
  rasqal_literal* l;

  npattern=(unsigned char *)RASQAL_MALLOC(cstring, len+1);
  strncpy((char*)npattern, (const char*)pattern, len+1);
  l=rasqal_new_pattern_literal(npattern, NULL);
  yyval.expr=rasqal_new_string_op_expression(RASQAL_EXPR_STR_MATCH, yyvsp[-3].expr, l);
  rasqal_free_literal(yyvsp[-1].literal);
}
    break;

  case 132:
#line 1438 "./sparql_parser.y"
    {
  /* FIXME - regex needs more thought */
  const unsigned char* pattern=rasqal_literal_as_string(yyvsp[-3].literal);
  size_t p_len=strlen((const char*)pattern);
  unsigned char* npattern;
  const char* flags=(const char*)rasqal_literal_as_string(yyvsp[-1].literal);
  size_t f_len=strlen(flags);
  char* nflags;
  rasqal_literal* l;

  npattern=(unsigned char *)RASQAL_MALLOC(cstring, p_len+1);
  strncpy((char*)npattern, (const char*)pattern, p_len+1);
  nflags=(char *)RASQAL_MALLOC(cstring, f_len+1);
  strncpy(nflags, flags, f_len+1);
  l=rasqal_new_pattern_literal(npattern, nflags);

  yyval.expr=rasqal_new_string_op_expression(RASQAL_EXPR_STR_MATCH, yyvsp[-5].expr, l);
  rasqal_free_literal(yyvsp[-3].literal);
  rasqal_free_literal(yyvsp[-1].literal);
}
    break;

  case 133:
#line 1459 "./sparql_parser.y"
    {
  rasqal_literal *l=rasqal_new_variable_literal(yyvsp[-1].variable);
  rasqal_expression *e=rasqal_new_literal_expression(l);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_BOUND, e);
}
    break;

  case 134:
#line 1465 "./sparql_parser.y"
    {
  rasqal_expression *e=rasqal_new_literal_expression(yyvsp[-1].literal);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ISURI, e);
}
    break;

  case 135:
#line 1470 "./sparql_parser.y"
    {
  rasqal_expression *e=rasqal_new_literal_expression(yyvsp[-1].literal);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ISBLANK, e);
}
    break;

  case 136:
#line 1475 "./sparql_parser.y"
    {
  rasqal_expression *e=rasqal_new_literal_expression(yyvsp[-1].literal);
  yyval.expr=rasqal_new_1op_expression(RASQAL_EXPR_ISLITERAL, e);
}
    break;

  case 137:
#line 1480 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 138:
#line 1484 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[0].expr;
}
    break;

  case 139:
#line 1492 "./sparql_parser.y"
    {
  rasqal_literal *l=rasqal_new_variable_literal(yyvsp[0].variable);
  yyval.expr=rasqal_new_literal_expression(l);
}
    break;

  case 140:
#line 1497 "./sparql_parser.y"
    {
  yyval.expr=rasqal_new_literal_expression(yyvsp[0].literal);
}
    break;

  case 141:
#line 1501 "./sparql_parser.y"
    {
  yyval.expr=yyvsp[-1].expr;
}
    break;

  case 142:
#line 1508 "./sparql_parser.y"
    {
  raptor_uri* uri=rasqal_literal_as_uri(yyvsp[-2].literal);
  /* FIXME - pick one */
#if 0
  yyval.expr=rasqal_new_cast_expression(raptor_uri_copy(uri), yyvsp[-1].seq);
#else
  yyval.expr=rasqal_new_function_expression(raptor_uri_copy(uri), yyvsp[-1].seq);
#endif
  rasqal_free_literal(yyvsp[-2].literal);
}
    break;

  case 143:
#line 1522 "./sparql_parser.y"
    {
  yyval.seq=yyvsp[-2].seq;
  if(yyvsp[0].expr)
    raptor_sequence_push(yyval.seq, yyvsp[0].expr);
}
    break;

  case 144:
#line 1528 "./sparql_parser.y"
    {
  yyval.seq=raptor_new_sequence((raptor_sequence_free_handler*)rasqal_free_expression, (raptor_sequence_print_handler*)rasqal_expression_print);
  if(yyvsp[0].expr)
    raptor_sequence_push(yyval.seq, yyvsp[0].expr);
}
    break;

  case 145:
#line 1534 "./sparql_parser.y"
    {
  yyval.seq=NULL;
}
    break;

  case 146:
#line 1544 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 147:
#line 1548 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 148:
#line 1552 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 149:
#line 1556 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 150:
#line 1560 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 151:
#line 1564 "./sparql_parser.y"
    {
  yyval.literal=yyvsp[0].literal;
}
    break;

  case 152:
#line 1579 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_uri_literal(yyvsp[0].uri);
}
    break;

  case 153:
#line 1583 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_simple_literal(RASQAL_LITERAL_QNAME, yyvsp[0].name);
  if(rasqal_literal_expand_qname((rasqal_query*)rq, yyval.literal)) {
    sparql_query_error_full((rasqal_query*)rq,
                            "QName %s cannot be expanded", yyvsp[0].name);
    rasqal_free_literal(yyval.literal);
    yyval.literal=NULL;
  }
}
    break;

  case 154:
#line 1595 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_uri_literal(yyvsp[0].uri);
}
    break;

  case 155:
#line 1599 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_simple_literal(RASQAL_LITERAL_QNAME, yyvsp[0].name);
  if(rasqal_literal_expand_qname((rasqal_query*)rq, yyval.literal)) {
    sparql_query_error_full((rasqal_query*)rq,
                            "QName %s cannot be expanded", yyvsp[0].name);
    rasqal_free_literal(yyval.literal);
    yyval.literal=NULL;
  }
}
    break;

  case 156:
#line 1613 "./sparql_parser.y"
    {
  yyval.literal=rasqal_new_simple_literal(RASQAL_LITERAL_BLANK, yyvsp[0].name);
}
    break;

  case 157:
#line 1616 "./sparql_parser.y"
    {
  const unsigned char *id=rasqal_query_generate_bnodeid((rasqal_query*)rq, NULL);
  yyval.literal=rasqal_new_simple_literal(RASQAL_LITERAL_BLANK, id);
}
    break;


    }

/* Line 1000 of yacc.c.  */
#line 3031 "sparql_parser.c"

  yyvsp -= yylen;
  yyssp -= yylen;


  YY_STACK_PRINT (yyss, yyssp);

  *++yyvsp = yyval;


  /* Now `shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTOKENS];

  goto yynewstate;


/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
#if YYERROR_VERBOSE
      yyn = yypact[yystate];

      if (YYPACT_NINF < yyn && yyn < YYLAST)
      {
        YYSIZE_T yysize = 0;
        int yytype = YYTRANSLATE (yychar);
        const char* yyprefix;
        char *yymsg;
        int yyx;

        /* Start YYX at -YYN if negative to avoid negative indexes in
           YYCHECK.  */
        int yyxbegin = yyn < 0 ? -yyn : 0;

        /* Stay within bounds of both yycheck and yytname.  */
        int yychecklim = YYLAST - yyn;
        int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
        int yycount = 0;

        yyprefix = ", expecting ";
        for (yyx = yyxbegin; yyx < yyxend; ++yyx)
          if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
            {
            yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
            yycount += 1;
            if (yycount == 5)
              {
                yysize = 0;
                break;
              }
            }
        yysize += (sizeof ("syntax error, unexpected ")
                 + yystrlen (yytname[yytype]));
        yymsg = (char *) YYSTACK_ALLOC (yysize);
        if (yymsg != 0)
          {
            char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
            yyp = yystpcpy (yyp, yytname[yytype]);

            if (yycount < 5)
            {
              yyprefix = ", expecting ";
              for (yyx = yyxbegin; yyx < yyxend; ++yyx)
                if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
                  {
                  yyp = yystpcpy (yyp, yyprefix);
                  yyp = yystpcpy (yyp, yytname[yyx]);
                  yyprefix = " or ";
                  }
            }
            yyerror (yymsg);
            YYSTACK_FREE (yymsg);
          }
        else
          yyerror ("syntax error; also virtual memory exhausted");
      }
      else
#endif /* YYERROR_VERBOSE */
      yyerror ("syntax error");
    }



  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
       error, discard it.  */

      if (yychar <= YYEOF)
        {
          /* If at end of input, pop the error token,
           then the rest of the stack, then return failure.  */
        if (yychar == YYEOF)
           for (;;)
             {
             YYPOPSTACK;
             if (yyssp == yyss)
               YYABORT;
             YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
             yydestruct (yystos[*yyssp], yyvsp);
             }
        }
      else
      {
        YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
        yydestruct (yytoken, &yylval);
        yychar = YYEMPTY;

      }
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:

#ifdef __GNUC__
  /* Pacify GCC when the user code never invokes YYERROR and the label
     yyerrorlab therefore never appears in user code.  */
  if (0)
     goto yyerrorlab;
#endif

  yyvsp -= yylen;
  yyssp -= yylen;
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */

  for (;;)
    {
      yyn = yypact[yystate];
      if (yyn != YYPACT_NINF)
      {
        yyn += YYTERROR;
        if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
          {
            yyn = yytable[yyn];
            if (0 < yyn)
            break;
          }
      }

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
      YYABORT;

      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
      yydestruct (yystos[yystate], yyvsp);
      YYPOPSTACK;
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  if (yyn == YYFINAL)
    YYACCEPT;

  YYDPRINTF ((stderr, "Shifting error token, "));

  *++yyvsp = yylval;


  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

#ifndef yyoverflow
/*----------------------------------------------.
| yyoverflowlab -- parser overflow comes here.  |
`----------------------------------------------*/
yyoverflowlab:
  yyerror ("parser stack overflow");
  yyresult = 2;
  /* Fall through.  */
#endif

yyreturn:
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
  return yyresult;
}


#line 1636 "./sparql_parser.y"



/* Support functions */


/* This is declared in sparql_lexer.h but never used, so we always get
 * a warning unless this dummy code is here.  Used once below in an error case.
 */
static int yy_init_globals (yyscan_t yyscanner ) { return 0; };



/**
 * rasqal_sparql_query_engine_init - Initialise the SPARQL query engine
 *
 * Return value: non 0 on failure
 **/
static int
rasqal_sparql_query_engine_init(rasqal_query* rdf_query, const char *name) {
  /* rasqal_sparql_query_engine* sparql=(rasqal_sparql_query_engine*)rdf_query->context; */

  /* Initialise rdf, rdfs, owl and xsd prefixes and namespaces */
  raptor_namespaces_start_namespace_full(rdf_query->namespaces, 
                                         (const unsigned char*)"rdf",
                                         (const unsigned char*)RAPTOR_RDF_MS_URI,0);
  raptor_namespaces_start_namespace_full(rdf_query->namespaces, 
                                         (const unsigned char*)"rdfs", 
                                         (const unsigned char*)RAPTOR_RDF_SCHEMA_URI,0);
  raptor_namespaces_start_namespace_full(rdf_query->namespaces,
                                         (const unsigned char*)"xsd",
                                         (const unsigned char*)RAPTOR_XMLSCHEMA_DATATYPES_URI, 0);
  raptor_namespaces_start_namespace_full(rdf_query->namespaces,
                                         (const unsigned char*)"owl",
                                         (const unsigned char*)RAPTOR_OWL_URI, 0);

  return 0;
}


/**
 * rasqal_sparql_query_engine_terminate - Free the SPARQL query engine
 *
 * Return value: non 0 on failure
 **/
static void
rasqal_sparql_query_engine_terminate(rasqal_query* rdf_query) {
  rasqal_sparql_query_engine* sparql=(rasqal_sparql_query_engine*)rdf_query->context;

  if(sparql->scanner_set) {
    sparql_lexer_lex_destroy(sparql->scanner);
    sparql->scanner_set=0;
  }

}


static int
rasqal_sparql_query_engine_prepare(rasqal_query* rdf_query) {
  /* rasqal_sparql_query_engine* sparql=(rasqal_sparql_query_engine*)rdf_query->context; */
  int rc;
  
  if(!rdf_query->query_string)
    return 1;
  
  rc=sparql_parse(rdf_query, rdf_query->query_string);
  if(rc)
    return rc;

  /* FIXME - should check remaining query parts  */
  if(rasqal_engine_sequence_has_qname(rdf_query->triples) ||
     rasqal_engine_sequence_has_qname(rdf_query->constructs) ||
     rasqal_engine_query_constraints_has_qname(rdf_query)) {
    sparql_query_error(rdf_query, "SPARQL query has unexpanded QNames");
    return 1;
  }

  return rasqal_engine_prepare(rdf_query);
}


static int
rasqal_sparql_query_engine_execute(rasqal_query* rdf_query,
                                   rasqal_query_results *results) 
{
  /* rasqal_sparql_query_engine* sparql=(rasqal_sparql_query_engine*)rdf_query->context; */
  
  /* nothing needed here */
  return 0;
}


static int
sparql_parse(rasqal_query* rq, const unsigned char *string) {
  rasqal_sparql_query_engine* rqe=(rasqal_sparql_query_engine*)rq->context;
  raptor_locator *locator=&rq->locator;
  char *buf=NULL;
  size_t len;
  void *buffer;

  if(!string || !*string)
    return yy_init_globals(NULL); /* 0 but a way to use yy_init_globals */

  locator->line=1;
  locator->column= -1; /* No column info */
  locator->byte= -1; /* No bytes info */

#if RASQAL_DEBUG > 2
  sparql_parser_debug=1;
#endif

  rqe->lineno=1;

  sparql_lexer_lex_init(&rqe->scanner);
  rqe->scanner_set=1;

  sparql_lexer_set_extra(((rasqal_query*)rq), rqe->scanner);

  /* This
   *   buffer= sparql_lexer__scan_string((const char*)string, rqe->scanner);
   * is replaced by the code below.  
   * 
   * The extra space appended to the buffer is the least-pain
   * workaround to the lexer crashing by reading EOF twice in
   * sparql_copy_regex_token; at least as far as I can diagnose.  The
   * fix here costs little to add as the above function does
   * something very similar to this anyway.
   */
  len= strlen((const char*)string);
  buf= (char *)RASQAL_MALLOC(cstring, len+3);
  strncpy(buf, (const char*)string, len);
  buf[len]= ' ';
  buf[len+1]= buf[len+2]='\0'; /* YY_END_OF_BUFFER_CHAR; */
  buffer= sparql_lexer__scan_buffer(buf, len+3, rqe->scanner);

  sparql_parser_parse(rq);

  if(buf)
    RASQAL_FREE(cstring, buf);

  sparql_lexer_lex_destroy(rqe->scanner);
  rqe->scanner_set=0;

  /* Parsing failed */
  if(rq->failed)
    return 1;
  
  return 0;
}


static void
sparql_query_error(rasqal_query *rq, const char *msg) {
  rasqal_sparql_query_engine* rqe=(rasqal_sparql_query_engine*)rq->context;

  rq->locator.line=rqe->lineno;
#ifdef RASQAL_SPARQL_USE_ERROR_COLUMNS
  /*  rq->locator.column=sparql_lexer_get_column(yyscanner);*/
#endif

  rasqal_query_error(rq, "%s", msg);
}


static void
sparql_query_error_full(rasqal_query *rq, const char *message, ...) {
  va_list arguments;
  rasqal_sparql_query_engine* rqe=(rasqal_sparql_query_engine*)rq->context;

  rq->locator.line=rqe->lineno;
#ifdef RASQAL_SPARQL_USE_ERROR_COLUMNS
  /*  rq->locator.column=sparql_lexer_get_column(yyscanner);*/
#endif

  va_start(arguments, message);

  rasqal_query_error_varargs(rq, message, arguments);

  va_end(arguments);
}


int
sparql_syntax_error(rasqal_query *rq, const char *message, ...)
{
  rasqal_sparql_query_engine *rqe=(rasqal_sparql_query_engine*)rq->context;
  va_list arguments;

  rq->locator.line=rqe->lineno;
#ifdef RASQAL_SPARQL_USE_ERROR_COLUMNS
  /*  rp->locator.column=sparql_lexer_get_column(yyscanner);*/
#endif

  va_start(arguments, message);
  rasqal_query_error_varargs(rq, message, arguments);
  va_end(arguments);

   return (0);
}


int
sparql_syntax_warning(rasqal_query *rq, const char *message, ...)
{
  rasqal_sparql_query_engine *rqe=(rasqal_sparql_query_engine*)rq->context;
  va_list arguments;

  rq->locator.line=rqe->lineno;
#ifdef RASQAL_SPARQL_USE_ERROR_COLUMNS
  /*  rq->locator.column=sparql_lexer_get_column(yyscanner);*/
#endif

  va_start(arguments, message);
  rasqal_query_warning_varargs(rq, message, arguments);
  va_end(arguments);

   return (0);
}


static void
rasqal_sparql_query_engine_register_factory(rasqal_query_engine_factory *factory)
{
  factory->context_length = sizeof(rasqal_sparql_query_engine);

  factory->init      = rasqal_sparql_query_engine_init;
  factory->terminate = rasqal_sparql_query_engine_terminate;
  factory->prepare   = rasqal_sparql_query_engine_prepare;
  factory->execute   = rasqal_sparql_query_engine_execute;
}


void
rasqal_init_query_engine_sparql(void) {
  rasqal_query_engine_register_factory("sparql", 
                                       "SPARQL W3C DAWG RDF Query Language",
                                       NULL,
                                       (const unsigned char*)"http://www.w3.org/TR/rdf-sparql-query/",
                                       &rasqal_sparql_query_engine_register_factory);
}



#ifdef STANDALONE
#include <stdio.h>
#include <locale.h>

#define SPARQL_FILE_BUF_SIZE 2048

int
main(int argc, char *argv[]) 
{
  const char *program=rasqal_basename(argv[0]);
  char query_string[SPARQL_FILE_BUF_SIZE];
  rasqal_query *query;
  FILE *fh;
  int rc;
  char *filename=NULL;
  raptor_uri* base_uri=NULL;
  unsigned char *uri_string;

#if RASQAL_DEBUG > 2
  sparql_parser_debug=1;
#endif

  if(argc > 1) {
    filename=argv[1];
    fh = fopen(argv[1], "r");
    if(!fh) {
      fprintf(stderr, "%s: Cannot open file %s - %s\n", program, filename,
              strerror(errno));
      exit(1);
    }
  } else {
    filename="<stdin>";
    fh = stdin;
  }

  memset(query_string, 0, SPARQL_FILE_BUF_SIZE);
  fread(query_string, SPARQL_FILE_BUF_SIZE, 1, fh);
  
  if(argc>1)
    fclose(fh);

  rasqal_init();

  query=rasqal_new_query("sparql", NULL);

  uri_string=raptor_uri_filename_to_uri_string(filename);
  base_uri=raptor_new_uri(uri_string);

  rc=rasqal_query_prepare(query, (const unsigned char*)query_string, base_uri);

  rasqal_query_print(query, stdout);

  rasqal_free_query(query);

  raptor_free_uri(base_uri);

  raptor_free_memory(uri_string);

  rasqal_finish();

  return rc;
}
#endif


Generated by  Doxygen 1.6.0   Back to index