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

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

#line 10 "sparql_lexer.c"

#line 12 "sparql_lexer.c"

#define  YY_INT_ALIGNED short int

/* A lexical scanner generated by flex */

#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif

/* First, we deal with  platform-specific or compiler-specific issues. */

/* begin standard C headers. */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

/* end standard C headers. */

/* flex integer type definitions */

#ifndef FLEXINT_H
#define FLEXINT_H

/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */

#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L

/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
 * if you want the limit (max/min) macros for int types. 
 */
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS 1
#endif

#include <inttypes.h>
typedef int8_t flex_int8_t;
typedef uint8_t flex_uint8_t;
typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
typedef unsigned char flex_uint8_t; 
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;

/* Limits of integral types. */
#ifndef INT8_MIN
#define INT8_MIN               (-128)
#endif
#ifndef INT16_MIN
#define INT16_MIN              (-32767-1)
#endif
#ifndef INT32_MIN
#define INT32_MIN              (-2147483647-1)
#endif
#ifndef INT8_MAX
#define INT8_MAX               (127)
#endif
#ifndef INT16_MAX
#define INT16_MAX              (32767)
#endif
#ifndef INT32_MAX
#define INT32_MAX              (2147483647)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX              (255U)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX             (65535U)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX             (4294967295U)
#endif

#endif /* ! C99 */

#endif /* ! FLEXINT_H */

#ifdef __cplusplus

/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST

#else	/* ! __cplusplus */

/* C99 requires __STDC__ to be defined as 1. */
#if defined (__STDC__)

#define YY_USE_CONST

#endif	/* defined (__STDC__) */
#endif	/* ! __cplusplus */

#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif

/* Returned upon end-of-file. */
#define YY_NULL 0

/* Promotes a possibly negative, possibly signed char to an unsigned
 * integer for use as an array index.  If the signed char is negative,
 * we want to instead treat it as an 8-bit unsigned char, hence the
 * double cast.
 */
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)

/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t;
#endif

/* For convenience, these vars (plus the bison vars far below)
   are macros in the reentrant scanner. */
#define yyin yyg->yyin_r
#define yyout yyg->yyout_r
#define yyextra yyg->yyextra_r
#define yyleng yyg->yyleng_r
#define yytext yyg->yytext_r
#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
#define yy_flex_debug yyg->yy_flex_debug_r

/* Enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way forced on us by the ()-less
 * definition of BEGIN.
 */
#define BEGIN yyg->yy_start = 1 + 2 *

/* Translate the current start state into a value that can be later handed
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
 * compatibility.
 */
#define YY_START ((yyg->yy_start - 1) / 2)
#define YYSTATE YY_START

/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)

/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE sparql_lexer_restart(yyin ,yyscanner )

#define YY_END_OF_BUFFER_CHAR 0

/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
#define YY_BUF_SIZE 16384
#endif

/* The state buf must be large enough to hold one state per character in the main buffer.
 */
#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))

#ifndef YY_TYPEDEF_YY_BUFFER_STATE
#define YY_TYPEDEF_YY_BUFFER_STATE
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif

#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

    #define YY_LESS_LINENO(n)
    
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
        int yyless_macro_arg = (n); \
        YY_LESS_LINENO(yyless_macro_arg);\
		*yy_cp = yyg->yy_hold_char; \
		YY_RESTORE_YY_MORE_OFFSET \
		yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
		} \
	while ( 0 )

#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )

#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif

#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
	{
	FILE *yy_input_file;

	char *yy_ch_buf;		/* input buffer */
	char *yy_buf_pos;		/* current position in input buffer */

	/* Size of input buffer in bytes, not including room for EOB
	 * characters.
	 */
	yy_size_t yy_buf_size;

	/* Number of characters read into yy_ch_buf, not including EOB
	 * characters.
	 */
	int yy_n_chars;

	/* Whether we "own" the buffer - i.e., we know we created it,
	 * and can realloc() it to grow it, and should free() it to
	 * delete it.
	 */
	int yy_is_our_buffer;

	/* Whether this is an "interactive" input source; if so, and
	 * if we're using stdio for input, then we want to use getc()
	 * instead of fread(), to make sure we stop fetching input after
	 * each newline.
	 */
	int yy_is_interactive;

	/* Whether we're considered to be at the beginning of a line.
	 * If so, '^' rules will be active on the next match, otherwise
	 * not.
	 */
	int yy_at_bol;

    int yy_bs_lineno; /**< The line count. */
    int yy_bs_column; /**< The column count. */
    
	/* Whether to try to fill the input buffer when we reach the
	 * end of it.
	 */
	int yy_fill_buffer;

	int yy_buffer_status;

#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
	/* When an EOF's been seen but there's still some text to process
	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
	 * shouldn't try reading from the input source any more.  We might
	 * still have a bunch of tokens to match, though, because of
	 * possible backing-up.
	 *
	 * When we actually see the EOF, we change the status to "new"
	 * (via sparql_lexer_restart()), so that the user can continue scanning by
	 * just pointing yyin at a new input file.
	 */
#define YY_BUFFER_EOF_PENDING 2

	};
#endif /* !YY_STRUCT_YY_BUFFER_STATE */

/* We provide macros for accessing buffer states in case in the
 * future we want to put the buffer states in a more general
 * "scanner state".
 *
 * Returns the top of the stack, or NULL.
 */
#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
                          ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
                          : NULL)

/* Same as previous macro, but useful when we know that the buffer stack is not
 * NULL or when we need an lvalue. For internal use only.
 */
#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]

void sparql_lexer_restart (FILE *input_file ,yyscan_t yyscanner );
void sparql_lexer__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
YY_BUFFER_STATE sparql_lexer__create_buffer (FILE *file,int size ,yyscan_t yyscanner );
void sparql_lexer__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
void sparql_lexer__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
void sparql_lexer_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
void sparql_lexer_pop_buffer_state (yyscan_t yyscanner );

static void sparql_lexer_ensure_buffer_stack (yyscan_t yyscanner );
static void sparql_lexer__load_buffer_state (yyscan_t yyscanner );
static void sparql_lexer__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );

#define YY_FLUSH_BUFFER sparql_lexer__flush_buffer(YY_CURRENT_BUFFER ,yyscanner)

YY_BUFFER_STATE sparql_lexer__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE sparql_lexer__scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
YY_BUFFER_STATE sparql_lexer__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );

void *sparql_lexer_alloc (yy_size_t ,yyscan_t yyscanner );
void *sparql_lexer_realloc (void *,yy_size_t ,yyscan_t yyscanner );
void sparql_lexer_free (void * ,yyscan_t yyscanner );

#define yy_new_buffer sparql_lexer__create_buffer

#define yy_set_interactive(is_interactive) \
	{ \
	if ( ! YY_CURRENT_BUFFER ){ \
        sparql_lexer_ensure_buffer_stack (yyscanner); \
		YY_CURRENT_BUFFER_LVALUE =    \
            sparql_lexer__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
	} \
	YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
	}

#define yy_set_bol(at_bol) \
	{ \
	if ( ! YY_CURRENT_BUFFER ){\
        sparql_lexer_ensure_buffer_stack (yyscanner); \
		YY_CURRENT_BUFFER_LVALUE =    \
            sparql_lexer__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
	} \
	YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
	}

#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)

/* Begin user sect3 */

typedef unsigned char YY_CHAR;

typedef int yy_state_type;

#define yytext_ptr yytext_r

static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
static yy_state_type yy_try_NUL_trans (yy_state_type current_state  ,yyscan_t yyscanner);
static int yy_get_next_buffer (yyscan_t yyscanner );

/* Done after the current pattern has been matched and before the
 * corresponding action - sets up yytext.
 */
#define YY_DO_BEFORE_ACTION \
	yyg->yytext_ptr = yy_bp; \
	yyleng = (size_t) (yy_cp - yy_bp); \
	yyg->yy_hold_char = *yy_cp; \
	*yy_cp = '\0'; \
	yyg->yy_c_buf_p = yy_cp;

#define YY_NUM_RULES 95
#define YY_END_OF_BUFFER 96
/* This struct is not used in this scanner,
   but its presence is necessary. */
struct yy_trans_info
	{
	flex_int32_t yy_verify;
	flex_int32_t yy_nxt;
	};
static yyconst flex_int16_t yy_accept[419] =
    {   0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,   96,   94,    4,    3,    3,   64,   94,   94,
       49,   94,   94,   44,   45,   62,   68,   43,   69,   52,
       63,   65,   89,   53,   94,   56,   59,   48,   94,   94,
       94,   94,   94,   94,   94,   94,   94,   94,   94,   94,
       94,   94,   94,   94,   94,   94,   46,   47,   94,   42,
       50,   94,   51,   81,   80,   84,   82,   83,   88,   85,
       87,   88,   74,   74,   77,   77,    4,    3,   57,    0,
       71,    0,    0,   93,   93,   55,    0,   70,    0,    0,
       65,   66,    2,    0,   66,    0,   89,   89,   58,   58,

       60,   92,    0,   58,   61,    0,    0,   89,   38,    0,
        0,   30,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,   54,   80,
       82,   83,   85,    0,    0,   86,    0,    0,    0,    0,
        0,    0,   71,   72,    0,    0,   70,   75,    0,    0,
        0,    0,    1,    1,   66,    0,    0,   67,   89,    0,
        0,   92,   92,    0,   32,   11,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,

        0,    0,    0,    0,    0,   19,    0,    0,    0,   90,
       73,   76,   71,    0,   70,    0,    0,   67,    0,   67,
       92,    0,   17,    0,    0,    0,    0,    0,   33,    0,
        0,    0,    0,    6,    0,    0,    0,    0,    0,    0,
       20,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,   78,    0,    0,   90,    0,    0,    0,   71,   71,
        0,    0,   70,   70,    0,    0,    0,    0,   91,   18,
        0,   37,    0,    0,    0,    0,    0,   79,    0,   25,
       36,    0,    0,   22,    0,    0,   14,   26,    0,    0,
       29,    0,    0,   31,    0,    0,   15,    7,    0,    0,

       71,    0,   71,    0,    0,   70,    0,   70,    0,    0,
        0,    0,   39,    0,    0,    0,   27,   40,    0,    0,
        0,   28,    0,    8,    0,    0,    5,   73,    0,    0,
       76,    0,    0,   71,    0,    0,   71,   70,    0,    0,
       70,    0,    0,    0,    0,   35,   23,    0,    0,    0,
       13,    0,   73,    0,    0,   73,    0,    0,   76,    0,
        0,   76,    0,    0,    0,   21,    9,   12,    0,    0,
       16,   41,   73,    0,    0,    0,   73,    0,   76,    0,
        0,    0,   76,    0,   10,   24,    0,   73,   76,    0,
        0,    0,   34,    0,    0,   73,    0,    0,   76,    0,

        0,   73,    0,    0,   73,    0,    0,   76,    0,    0,
       76,    0,    0,   73,    0,   76,    0,    0
    } ;

static yyconst flex_int32_t yy_ec[256] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
        2,    1,    4,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    5,    6,    7,    8,    9,    1,   10,   11,   12,
       13,   14,   15,   16,   17,   18,   19,   20,   20,   20,
       20,   20,   20,   20,   20,   20,   20,   21,   22,   23,
       24,   25,   26,   27,   28,   29,   30,   31,   32,   33,
       34,   35,   36,   37,   38,   39,   40,   41,   42,   43,
       37,   44,   45,   46,   47,   37,   48,   49,   50,   37,
       51,   52,   53,   54,   55,    1,   56,   29,   30,   31,

       32,   33,   34,   35,   36,   37,   38,   39,   40,   41,
       42,   43,   37,   44,   45,   46,   47,   37,   48,   49,
       50,   37,   57,   58,   59,    1,    1,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,

       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
       60,   60,   60,   60,   60
    } ;

static yyconst flex_int32_t yy_meta[61] =
    {   0,
        1,    1,    2,    2,    3,    1,    1,    1,    1,    1,
        1,    4,    1,    1,    1,    1,    5,    6,    1,    7,
        8,    1,    9,    3,    1,    1,    1,   10,   10,   10,
       10,   10,   10,   10,   10,   10,   10,   10,   10,   10,
       10,   10,   10,   10,   10,   10,   10,   10,   10,   10,
        1,   11,    1,   12,    7,   10,    1,    1,    1,   11
    } ;

static yyconst flex_int16_t yy_base[458] =
    {   0,
        0,    0,   60,    0,  120,    0,  180,    0, 1422, 1420,
     1415, 1414, 1424, 2260,  239, 2260, 1419, 1394,  235,  242,
     2260, 1407,  232, 2260, 2260, 2260,  229, 2260,  230, 1396,
      237,  234, 1353, 2260,  287, 2260, 1340, 2260,  237,  330,
      239,  331,  332,  347,  241,  243,  343,  361,  348,  352,
      356,  247,  380,  372,  381,  251, 2260, 2260, 1340,  388,
     2260, 1300, 2260, 2260,    0, 2260,  265,    0, 2260,  269,
     2260,  255, 1283, 1282, 1277, 1274,  273, 2260, 2260,  353,
      387,    0,  351, 2260, 1281, 2260,  367,  396,    0, 1238,
      393,  395, 2260,  353,  398,  414, 2260,  265, 1231, 2260,

     2260,  412, 1230,  407, 2260,  417,  421, 1168,  422,  426,
      427,  428,  435,  433,  441,  440,  445,  451,  452,  447,
      466,  457,  474,  475,  479,  480,  491,  486,  446,  493,
      497,  505,  509,  515,  516,  517,  522,    0, 2260,    0,
      537,    0,  539,  528,  529, 2260, 1172, 1141, 1135, 1127,
     1121, 1097,  226, 2260,    0, 1053,  502, 2260,    0, 1043,
      540,  417, 2260, 1078,  485,  547, 1032, 1028,  540,  553,
     1006,  992,  972,  552,  548,  552,  585,  592,  593,  598,
      597,  602,  606,  608,  610,  614,  619,  623,  624,  558,
      625,  629,  630,  634,  643,  648,  654,  655,  660,  661,

      662,  667,  669,  671,  673,  557,  681,  686,  688,  959,
      403,  686,  878,  460,  862,  635,  871,  867,  863,  840,
     2260,  740,  690,  694,  783,  784,  785,  789,  790,  698,
      791,  699,  703,  705,  797,  795,  796,  805,  803,  804,
      823,  824,  825,  830,  831,  836,  846,  709,  837,  847,
      848,  715,  853,  858,  819,  818,  567,  842,  774,    0,
      802,  854,  766,    0,  713,  863,    0,  712,  717,  867,
      871,  877,  879,  881,  883,  885,  887,  889,  891,  893,
      899,  900,  904,  906,  910,  912,  916,  918,  920,  926,
      930,  931,  932,  936,  937,  938,  942,  944,  978, 1028,

      704,  693,  685,  952,  953,  680,  646,  637,  954,  958,
      982, 1061,  960,  965,  972, 1014,  970,  971, 1015, 1065,
     1069,  977, 1071, 1019, 1023, 1073, 1024, 1121, 1088, 1181,
     1231, 1095, 1291,  642,  612,  597, 2260,  591,  550,  536,
     2260, 1080, 1084, 1103, 1126, 1025, 1029, 1118, 1104, 1334,
     1105, 1335, 1359,  852,  936,  980,    0,  530, 1403,  971,
     1118, 1120,    0,  485, 1236, 1112, 1119, 1157, 1339, 1345,
     1225, 1226,    0,    0, 1078, 1089,  492, 1347,    0,    0,
     1356, 1357,  444, 1358, 1227, 1231, 1353, 1403, 1359, 1341,
     1447, 1445, 1232, 1495, 1545, 1599, 1455, 1659, 1709, 1460,

     1769, 1813, 1405, 1457, 1461,    0,  371, 1857, 1450, 1456,
     1462,    0,  350,    0,    0,    0,    0, 2260, 1917, 1929,
     1941, 1953, 1965, 1974, 1981, 1986, 1991, 1998, 2009, 2021,
     2033, 2042, 2053, 2059,  352,  253, 2066, 2073, 2078, 2085,
     2090, 2095, 2106, 2114, 2119, 2130, 2138, 2145, 2156, 2164,
     2175, 2187, 2199, 2211, 2223, 2235, 2247
    } ;

static yyconst flex_int16_t yy_def[458] =
    {   0,
      418,    1,  418,    3,  418,    5,  418,    7,  419,  419,
      420,  420,  418,  418,  418,  418,  418,  418,  421,  422,
      418,  418,  423,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  424,  418,  418,  418,  418,  418,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  418,  418,  418,  425,
      418,  418,  418,  418,  426,  418,  418,  427,  418,  418,
      418,  428,  429,  429,  430,  430,  418,  418,  418,  421,
      418,  421,  422,  418,  418,  418,  423,  418,  423,  418,
      418,  418,  418,  431,  418,  418,  418,  432,  433,  418,

      418,  433,  433,  433,  418,  425,  425,  424,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  434,  418,  426,
      418,  427,  418,  428,  428,  418,  429,  429,  429,  430,
      430,  430,  418,  418,  435,  418,  418,  418,  436,  418,
      418,  431,  418,  418,  418,  418,  418,  418,  432,  432,
      433,  418,  433,  433,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,

      425,  425,  425,  425,  425,  425,  425,  425,  425,  437,
      429,  430,  438,  439,  440,  441,  418,  418,  418,  418,
      418,  418,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  437,  437,  429,  430,  438,  442,
      443,  444,  440,  445,  446,  447,  222,  222,  418,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  425,  429,  430,

      448,  449,  449,  444,  444,  450,  451,  451,  447,  447,
      425,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  425,  425,  425,  425,  425,  429,  452,  418,
      430,  453,  418,  448,  448,  449,  418,  450,  450,  451,
      418,  425,  425,  425,  425,  425,  425,  425,  425,  425,
      425,  425,  328,  454,  454,  454,  330,  330,  331,  455,
      455,  455,  333,  333,  425,  425,  425,  425,  425,  425,
      425,  425,  353,  353,  454,  454,  429,  454,  359,  359,
      455,  455,  430,  455,  425,  425,  425,  454,  455,  425,
      454,  455,  425,  454,  455,  454,  456,  418,  455,  457,

      418,  396,  454,  454,  454,  398,  398,  399,  455,  455,
      455,  401,  401,  402,  402,  408,  408,    0,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418
    } ;

static yyconst flex_int16_t yy_nxt[2321] =
    {   0,
       14,   15,   16,   17,   15,   18,   19,   20,   21,   22,
       23,   24,   25,   26,   27,   28,   29,   30,   31,   32,
       33,   34,   35,   36,   37,   38,   14,   39,   40,   41,
       42,   43,   44,   45,   46,   47,   46,   46,   48,   46,
       49,   50,   51,   52,   53,   54,   55,   56,   46,   46,
       57,   46,   58,   14,   59,   60,   61,   62,   63,   46,
       64,   64,   64,   64,   64,   64,   64,   64,   64,   64,
       64,   64,   64,   64,   64,   64,   64,   64,   64,   65,
       64,   64,   64,   64,   64,   64,   64,   65,   65,   65,
       65,   65,   65,   65,   65,   65,   65,   65,   65,   65,

       65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
       64,   65,   64,   64,   65,   65,   64,   64,   64,   65,
       66,   67,   66,   66,   67,   66,   66,   66,   66,   66,
       66,   66,   66,   66,   66,   66,   66,   66,   66,   68,
       66,   66,   66,   66,   66,   66,   66,   68,   68,   68,
       68,   68,   68,   68,   68,   68,   68,   68,   68,   68,
       68,   68,   68,   68,   68,   68,   68,   68,   68,   68,
       66,   68,   66,   66,   68,   68,   66,   66,   66,   68,
       69,   70,   69,   69,   70,   69,   69,   69,   69,   69,
       69,   69,   69,   69,   69,   69,   69,   69,   69,   69,

       71,   69,   69,   69,   69,   69,   69,   72,   72,   72,
       72,   72,   72,   72,   72,   72,   72,   72,   72,   72,
       72,   72,   72,   72,   72,   72,   72,   72,   72,   72,
       69,   72,   69,   69,   69,   72,   69,   69,   69,   72,
       77,   81,   88,   77,   84,   85,   90,   90,   91,   91,
       93,   95,  155,   91,  107,   94,  107,  108,  107,  108,
      107,  108,  215,  108,  107,   96,  141,  108,  107,  141,
      143,  108,  145,  143,   77,  146,   97,   77,  131,  156,
      113,  109,  170,   89,  121,  137,   82,   99,   99,   99,
       99,  100,   99,   99,   99,   99,   99,   99,   99,   99,

       99,   99,   99,   99,   99,   99,   99,   99,   99,  100,
      101,  102,   99,   99,  103,  103,  103,  103,  103,  103,
      103,  103,  103,  103,  103,  103,  103,  103,  103,  103,
      103,  103,  103,  103,  103,  103,  103,   99,   99,   99,
       99,  104,  103,   99,   99,   99,   99,  107,  107,  107,
      108,  108,  108,   84,   85,  163,  164,  110,  114,  153,
      107,  213,  115,  108,  107,  107,  116,  108,  108,  107,
      381,  111,  108,  107,  118,  126,  108,  157,  107,  112,
      117,  108,  119,  122,  127,  110,  114,  123,  124,  107,
      120,  375,  108,  154,  128,  129,  125,  107,  107,  130,

      108,  108,  118,  126,   82,  107,  158,  132,  108,  211,
       95,  133,   91,  155,   92,  135,  124,  165,   89,  163,
      164,  136,  159,  173,   96,  134,  161,  174,  167,  166,
      167,  172,  109,  168,  107,  132,  172,  108,  107,  107,
      156,  418,  108,  107,  107,  107,  108,  108,  108,  160,
      107,  175,  107,  108,  151,  108,  257,  107,  107,  176,
      108,  108,  107,  107,  107,  108,  108,  108,  107,  107,
      177,  108,  108,  178,  107,  179,  200,  108,  181,  182,
      260,  180,  261,  107,  184,  183,  108,  185,  188,  186,
      187,  107,  107,  189,  108,  108,  107,  107,  148,  108,

      108,  191,  192,  107,  165,  150,  108,  190,  107,  193,
      107,  108,  194,  108,  107,  195,  166,  108,  196,  197,
      193,  189,  107,  198,  201,  108,  107,  202,  159,  108,
      203,  199,  107,  107,  107,  108,  108,  108,  141,  107,
      143,  141,  108,  143,  204,  145,  145,  205,  146,  418,
      147,   97,  208,  209,  217,  160,  217,  170,  206,  218,
      341,  219,  207,  219,  418,  107,  220,  339,  108,  107,
      170,  222,  108,  148,  107,  107,  172,  108,  108,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,

      222,  222,  107,  222,  236,  108,  222,  222,  339,  107,
      107,  222,  108,  108,  107,  107,  223,  108,  108,  107,
      299,  337,  108,  107,  227,  107,  108,  107,  108,  335,
      108,  107,  224,  228,  108,  229,  107,  225,  226,  108,
      107,  107,  107,  108,  108,  108,  107,  107,  231,  108,
      108,  107,  227,  230,  108,  264,  237,  265,  232,  335,
      107,  341,  234,  108,  233,  107,  235,  238,  108,  240,
      341,  107,  107,  239,  108,  108,  241,  107,  107,  107,
      108,  108,  108,  242,  107,  243,  107,  108,  107,  108,
      107,  108,  246,  108,  247,  245,  212,  339,  107,  244,

      249,  108,  250,  107,  251,  107,  108,  107,  108,  337,
      108,  107,  252,  248,  108,  107,  107,  337,  108,  108,
      107,  335,  107,  108,  270,  108,  107,  253,  221,  108,
      278,  254,  107,  276,  279,  108,  172,  308,  293,  258,
      171,  171,  171,  171,  171,  171,  171,  171,  171,  171,
      171,  171,  171,  171,  171,  171,  267,  268,  171,  267,
      171,  171,  171,  171,  269,  171,  171,  267,  267,  267,
      267,  267,  267,  267,  267,  267,  267,  267,  267,  267,
      267,  267,  267,  267,  267,  267,  267,  267,  267,  267,
      171,  267,  171,  171,  267,  267,  171,  171,  171,  267,

      107,  107,  107,  108,  108,  108,  107,  107,  107,  108,
      108,  108,  107,  107,  107,  108,  108,  108,  277,  160,
      107,  107,  107,  108,  108,  108,  303,  156,  271,  272,
      273,  280,  283,  275,  274,  256,  256,  281,  284,  282,
      107,  107,  107,  108,  108,  108,  277,  107,  107,  285,
      108,  108,  151,  107,  107,  288,  108,  108,  376,  220,
      283,  289,  286,  107,  107,  107,  108,  108,  108,  287,
      107,  305,  290,  108,  260,  107,  377,  296,  108,  291,
      310,  292,  220,  264,  107,  294,  218,  108,  107,  298,
      218,  108,  295,  297,  107,  300,  107,  108,  107,  108,

      107,  108,  107,  108,  107,  108,  107,  108,  107,  108,
      107,  108,  313,  108,  311,  160,  107,  107,  314,  108,
      108,  107,  316,  107,  108,  315,  108,  107,  312,  107,
      108,  156,  108,  107,  317,  107,  108,  107,  108,  321,
      108,  320,  378,  107,  319,  318,  108,  107,  107,  107,
      108,  108,  108,  107,  107,  107,  108,  108,  108,  107,
      377,  107,  108,  325,  108,  322,  323,  321,  326,  305,
      305,  310,  260,  418,  264,  310,  256,  107,  418,  324,
      108,  382,  107,  327,  148,  108,  376,  107,  107,  107,
      108,  108,  108,  344,  107,  383,  172,  108,  328,  107,

      329,  345,  108,  221,  377,  330,  330,  330,  330,  330,
      330,  330,  330,  330,  330,  330,  330,  330,  330,  330,
      330,  330,  330,  330,  330,  330,  330,  330,  342,  330,
      172,  107,  107,  330,  108,  108,  107,  330,  151,  108,
      107,  107,  107,  108,  108,  108,  107,  168,  331,  108,
      332,  168,  347,  351,  346,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  107,  333,
      163,  108,  107,  333,  376,  108,  107,  333,  107,  108,
      107,  108,  147,  108,  355,  378,  216,  107,  350,  150,

      108,  107,  377,  343,  108,  361,  214,  212,  348,  365,
      147,  147,  356,  377,  349,  366,  352,  150,  150,  362,
      107,  107,  107,  108,  108,  108,  350,  148,  384,  107,
      382,  152,  108,  370,  367,  107,  107,  151,  108,  108,
      353,  211,  383,  107,  383,  369,  108,  149,  353,  353,
      353,  353,  353,  353,  353,  353,  353,  353,  353,  353,
      353,  353,  353,  353,  353,  353,  353,  353,  353,  353,
      353,  368,  353,  369,  107,  353,  353,  108,  148,   97,
      353,  147,  147,  147,  147,  147,  147,  148,  147,  147,
      147,  147,  147,  147,  147,  147,  147,  357,  358,  147,

      357,  328,  147,  147,  147,  147,  147,  147,  357,  357,
      357,  357,  357,  357,  357,  357,  357,  357,  357,  357,
      357,  357,  357,  357,  357,  357,  357,  357,  357,  357,
      357,  147,  357,  147,  147,  357,  357,  147,  147,  147,
      357,  151,  107,  107,  107,  108,  108,  108,  107,  107,
      359,  108,  108,  107,  172,  172,  108,   92,  359,  359,
      359,  359,  359,  359,  359,  359,  359,  359,  359,  359,
      359,  359,  359,  359,  359,  359,  359,  359,  359,  359,
      359,  385,  359,   84,  152,  359,  359,  151,  149,  148,
      359,  150,  150,  150,  150,  150,  150,  150,  150,  150,

      150,  151,  150,  150,  150,  150,  150,  363,  364,  150,
      363,  331,  150,  150,  150,  150,  150,  150,  363,  363,
      363,  363,  363,  363,  363,  363,  363,  363,  363,  363,
      363,  363,  363,  363,  363,  363,  363,  363,  363,  363,
      363,  150,  363,  150,  150,  363,  363,  150,  150,  150,
      363,  107,  107,  388,  108,  108,  107,  139,  107,  108,
      138,  108,  107,  105,   97,  108,  382,  384,  389,  389,
      107,  377,  371,  108,  372,  373,  374,  386,  373,  387,
      383,  383,  383,  383,  390,  393,  373,  373,  373,  373,
      373,  373,  373,  373,  373,  373,  373,  373,  373,  373,

      373,  373,  373,  373,  373,  373,  373,  373,  373,  388,
      373,  376,  392,  373,  373,   92,   86,   79,  373,  379,
      380,   78,  379,  418,   76,   76,   74,  377,   74,  377,
      379,  379,  379,  379,  379,  379,  379,  379,  379,  379,
      379,  379,  379,  379,  379,  379,  379,  379,  379,  379,
      379,  379,  379,  376,  379,  382,  391,  379,  379,  375,
      382,  404,  379,  378,  381,  418,  384,  376,  418,  383,
      410,  377,  382,  418,  383,  418,  418,  375,  375,  405,
      383,  377,  381,  381,  411,  377,  383,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  395,  418,

      394,  376,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  396,  418,  397,  418,  377,
      418,  418,  398,  398,  398,  398,  398,  398,  398,  398,
      398,  398,  398,  398,  398,  398,  398,  398,  398,  398,
      398,  398,  398,  398,  398,  418,  398,  418,  418,  418,
      398,  418,  418,  418,  398,  382,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  399,  418,  400,  418,  383,
      418,  418,  401,  401,  401,  401,  401,  401,  401,  401,
      401,  401,  401,  401,  401,  401,  401,  401,  401,  401,
      401,  401,  401,  401,  401,  418,  401,  418,  418,  418,

      401,  418,  418,  418,  401,  376,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  402,  418,
      418,  418,  418,  377,  418,  418,  402,  402,  402,  402,
      402,  402,  402,  402,  402,  402,  402,  402,  402,  402,
      402,  402,  402,  402,  402,  402,  402,  402,  402,  418,
      402,  418,  418,  402,  402,  418,  418,  418,  402,  375,
      375,  375,  375,  375,  375,  376,  375,  375,  375,  375,
      375,  375,  375,  375,  375,  406,  407,  375,  406,  396,
      375,  375,  375,  377,  375,  375,  406,  406,  406,  406,
      406,  406,  406,  406,  406,  406,  406,  406,  406,  406,

      406,  406,  406,  406,  406,  406,  406,  406,  406,  375,
      406,  375,  375,  406,  406,  375,  375,  375,  406,  382,
      418,  418,  418,  418,  418,  418,  418,  418,  408,  418,
      418,  418,  418,  383,  418,  418,  408,  408,  408,  408,
      408,  408,  408,  408,  408,  408,  408,  408,  408,  408,
      408,  408,  408,  408,  408,  408,  408,  408,  408,  418,
      408,  418,  418,  408,  408,  418,  418,  418,  408,  381,
      381,  381,  381,  381,  381,  381,  381,  381,  381,  382,
      381,  381,  381,  381,  381,  412,  413,  381,  412,  399,
      381,  381,  381,  383,  381,  381,  412,  412,  412,  412,

      412,  412,  412,  412,  412,  412,  412,  412,  412,  412,
      412,  412,  412,  412,  412,  412,  412,  412,  412,  381,
      412,  381,  381,  412,  412,  381,  381,  381,  412,  414,
      415,  418,  414,  418,  418,  418,  418,  418,  418,  418,
      414,  414,  414,  414,  414,  414,  414,  414,  414,  414,
      414,  414,  414,  414,  414,  414,  414,  414,  414,  414,
      414,  414,  414,  418,  414,  418,  418,  414,  414,  418,
      418,  418,  414,  416,  417,  418,  416,  418,  418,  418,
      418,  418,  418,  418,  416,  416,  416,  416,  416,  416,
      416,  416,  416,  416,  416,  416,  416,  416,  416,  416,

      416,  416,  416,  416,  416,  416,  416,  418,  416,  418,
      418,  416,  416,  418,  418,  418,  416,   73,   73,   73,
       73,   73,   73,   73,   73,   73,   73,   73,   73,   75,
       75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
       75,   80,  418,   80,   80,   80,   80,   80,   80,   80,
       80,   80,   80,   83,   83,   83,   83,   83,   83,   83,
       83,   83,   83,   83,   83,   87,  418,   87,   87,   87,
       87,   87,   87,   87,   87,   87,   87,   98,  418,  418,
       98,  418,  418,   98,   98,  106,  106,  106,  106,  418,
      106,  106,  140,  418,  418,  140,  140,  142,  418,  418,

      142,  142,  144,  144,  144,  144,  418,  144,  144,  147,
      147,  147,  147,  147,  147,  147,  147,  147,  147,  147,
      147,  150,  150,  150,  150,  150,  150,  150,  150,  150,
      150,  150,  150,  162,  162,  162,  162,  162,  162,  162,
      162,  162,  162,  162,  162,  169,  169,  169,  169,  418,
      418,  169,  169,  171,  171,  171,  171,  171,  171,  171,
      171,  171,  171,  171,  171,  210,  418,  418,  210,  210,
      255,  255,  255,  418,  418,  255,  255,  259,  418,  259,
      418,  418,  259,  418,  259,  262,  262,  262,  262,  263,
      418,  263,  418,  418,  263,  418,  263,  266,  266,  266,

      266,  301,  418,  418,  301,  301,  302,  302,  418,  302,
      302,  302,  302,  302,  418,  302,  302,  302,  304,  304,
      304,  304,  418,  304,  304,  306,  418,  418,  306,  306,
      307,  307,  418,  307,  307,  307,  307,  307,  418,  307,
      307,  307,  309,  309,  309,  309,  418,  309,  309,  334,
      334,  334,  418,  418,  334,  334,  336,  336,  336,  336,
      336,  336,  336,  336,  336,  336,  336,  336,  338,  338,
      338,  418,  418,  338,  338,  340,  340,  340,  340,  340,
      340,  340,  340,  340,  340,  340,  340,  354,  354,  354,
      354,  354,  354,  354,  354,  354,  354,  354,  354,  360,

      360,  360,  360,  360,  360,  360,  360,  360,  360,  360,
      360,  375,  375,  375,  375,  375,  375,  375,  375,  375,
      375,  375,  375,  381,  381,  381,  381,  381,  381,  381,
      381,  381,  381,  381,  381,  403,  403,  403,  403,  403,
      403,  403,  403,  403,  403,  403,  403,  409,  409,  409,
      409,  409,  409,  409,  409,  409,  409,  409,  409,   13,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,

      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418
    } ;

static yyconst flex_int16_t yy_chk[2321] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,

        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,

        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
        7,    7,    7,    7,    7,    7,    7,    7,    7,    7,
       15,   19,   23,   15,   20,   20,   27,   29,   27,   29,
       31,   32,  153,   32,   39,   31,   41,   39,   45,   41,
       46,   45,  436,   46,   52,   32,   67,   52,   56,   67,
       70,   56,   72,   70,   77,   72,   98,   77,   52,  153,
       41,   39,   98,   23,   45,   56,   19,   35,   35,   35,
       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,

       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
       35,   35,   35,   35,   35,   35,   35,   35,   35,   35,
       35,   35,   35,   35,   35,   35,   35,   40,   42,   43,
       40,   42,   43,   83,   83,   94,   94,   40,   42,   80,
       47,  435,   42,   47,   44,   49,   42,   44,   49,   50,
      413,   40,   50,   51,   44,   49,   51,   87,   48,   40,
       43,   48,   44,   47,   50,   40,   42,   47,   48,   54,
       44,  407,   54,   81,   50,   50,   48,   53,   55,   51,

       53,   55,   44,   49,   80,   60,   88,   53,   60,  211,
       91,   53,   91,   81,   92,   54,   48,   95,   87,  162,
      162,   55,   88,  102,   91,   53,   92,  104,   96,   95,
       96,  104,   60,   96,  106,   53,  102,  106,  107,  109,
       81,  107,  109,  110,  111,  112,  110,  111,  112,   88,
      114,  109,  113,  114,  383,  113,  211,  116,  115,  109,
      116,  115,  117,  129,  120,  117,  129,  120,  118,  119,
      110,  118,  119,  111,  122,  113,  129,  122,  114,  115,
      214,  113,  214,  121,  116,  115,  121,  117,  120,  118,
      119,  123,  124,  121,  123,  124,  125,  126,  377,  125,

      126,  122,  123,  128,  165,  364,  128,  121,  127,  123,
      130,  127,  123,  130,  131,  124,  165,  131,  125,  126,
      123,  121,  132,  127,  130,  132,  133,  131,  157,  133,
      131,  128,  134,  135,  136,  134,  135,  136,  141,  137,
      143,  141,  137,  143,  132,  144,  145,  133,  144,  145,
      358,  169,  136,  137,  161,  157,  161,  169,  134,  161,
      340,  166,  135,  166,  170,  175,  166,  339,  175,  176,
      170,  174,  176,  257,  206,  190,  174,  206,  190,  174,
      174,  174,  174,  174,  174,  174,  174,  174,  174,  174,
      174,  174,  174,  174,  174,  174,  174,  174,  174,  174,

      174,  174,  177,  174,  190,  177,  174,  174,  338,  178,
      179,  174,  178,  179,  181,  180,  177,  181,  180,  182,
      257,  336,  182,  183,  181,  184,  183,  185,  184,  335,
      185,  186,  178,  182,  186,  183,  187,  179,  180,  187,
      188,  189,  191,  188,  189,  191,  192,  193,  185,  192,
      193,  194,  181,  184,  194,  216,  191,  216,  186,  334,
      195,  308,  188,  195,  187,  196,  189,  192,  196,  194,
      307,  197,  198,  193,  197,  198,  195,  199,  200,  201,
      199,  200,  201,  196,  202,  197,  203,  202,  204,  203,
      205,  204,  200,  205,  201,  199,  212,  306,  207,  198,

      203,  207,  204,  208,  205,  209,  208,  223,  209,  303,
      223,  224,  207,  202,  224,  230,  232,  302,  230,  232,
      233,  301,  234,  233,  224,  234,  248,  208,  269,  248,
      232,  209,  252,  230,  233,  252,  268,  265,  248,  212,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,

      225,  226,  227,  225,  226,  227,  228,  229,  231,  228,
      229,  231,  236,  237,  235,  236,  237,  235,  231,  263,
      239,  240,  238,  239,  240,  238,  261,  259,  225,  226,
      227,  235,  238,  229,  228,  256,  255,  236,  239,  237,
      241,  242,  243,  241,  242,  243,  231,  244,  245,  240,
      244,  245,  258,  246,  249,  243,  246,  249,  354,  220,
      238,  244,  241,  247,  250,  251,  247,  250,  251,  242,
      253,  262,  245,  253,  262,  254,  354,  251,  254,  246,
      266,  247,  219,  266,  270,  249,  218,  270,  271,  254,
      217,  271,  250,  253,  272,  258,  273,  272,  274,  273,

      275,  274,  276,  275,  277,  276,  278,  277,  279,  278,
      280,  279,  274,  280,  271,  215,  281,  282,  275,  281,
      282,  283,  277,  284,  283,  276,  284,  285,  273,  286,
      285,  213,  286,  287,  279,  288,  287,  289,  288,  286,
      289,  285,  355,  290,  283,  282,  290,  291,  292,  293,
      291,  292,  293,  294,  295,  296,  294,  295,  296,  297,
      355,  298,  297,  293,  298,  289,  290,  286,  295,  304,
      305,  309,  304,  305,  309,  310,  210,  313,  310,  292,
      313,  360,  314,  296,  299,  314,  356,  317,  318,  315,
      317,  318,  315,  314,  322,  360,  173,  322,  299,  311,

      299,  315,  311,  172,  356,  299,  299,  299,  299,  299,
      299,  299,  299,  299,  299,  299,  299,  299,  299,  299,
      299,  299,  299,  299,  299,  299,  299,  299,  311,  299,
      171,  316,  319,  299,  316,  319,  324,  299,  300,  324,
      325,  327,  346,  325,  327,  346,  347,  168,  300,  347,
      300,  167,  319,  325,  316,  300,  300,  300,  300,  300,
      300,  300,  300,  300,  300,  300,  300,  300,  300,  300,
      300,  300,  300,  300,  300,  300,  300,  300,  312,  300,
      164,  312,  320,  300,  375,  320,  321,  300,  323,  321,
      326,  323,  329,  326,  329,  376,  160,  342,  323,  332,

      342,  343,  375,  312,  343,  332,  156,  152,  320,  342,
      329,  329,  329,  376,  321,  343,  326,  332,  332,  332,
      344,  349,  351,  344,  349,  351,  323,  328,  361,  366,
      362,  151,  366,  349,  344,  348,  367,  150,  348,  367,
      328,  149,  361,  345,  362,  348,  345,  148,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  328,  328,  328,  328,  328,  328,  328,  328,  328,
      328,  345,  328,  348,  368,  328,  328,  368,  147,  108,
      328,  330,  330,  330,  330,  330,  330,  330,  330,  330,
      330,  330,  330,  330,  330,  330,  330,  330,  330,  330,

      330,  330,  330,  330,  330,  330,  330,  330,  330,  330,
      330,  330,  330,  330,  330,  330,  330,  330,  330,  330,
      330,  330,  330,  330,  330,  330,  330,  330,  330,  330,
      330,  330,  330,  330,  330,  330,  330,  330,  330,  330,
      330,  331,  371,  372,  385,  371,  372,  385,  386,  393,
      331,  386,  393,  365,  103,   99,  365,   90,  331,  331,
      331,  331,  331,  331,  331,  331,  331,  331,  331,  331,
      331,  331,  331,  331,  331,  331,  331,  331,  331,  331,
      331,  365,  331,   85,   76,  331,  331,   75,   74,   73,
      331,  333,  333,  333,  333,  333,  333,  333,  333,  333,

      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  350,  352,  378,  350,  352,  369,   62,  390,  369,
       59,  390,  370,   37,   33,  370,  381,  382,  384,  389,
      387,  378,  350,  387,  352,  353,  353,  369,  353,  370,
      381,  382,  384,  389,  387,  390,  353,  353,  353,  353,
      353,  353,  353,  353,  353,  353,  353,  353,  353,  353,

      353,  353,  353,  353,  353,  353,  353,  353,  353,  388,
      353,  403,  389,  353,  353,   30,   22,   18,  353,  359,
      359,   17,  359,   13,   12,   11,   10,  388,    9,  403,
      359,  359,  359,  359,  359,  359,  359,  359,  359,  359,
      359,  359,  359,  359,  359,  359,  359,  359,  359,  359,
      359,  359,  359,  391,  359,  392,  388,  359,  359,  397,
      409,  397,  359,  404,  400,    0,  410,  405,    0,  392,
      400,  391,  411,    0,  409,    0,    0,  397,  397,  397,
      410,  404,  400,  400,  400,  405,  411,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,  392,    0,

      391,  394,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,  394,    0,  394,    0,  394,
        0,    0,  394,  394,  394,  394,  394,  394,  394,  394,
      394,  394,  394,  394,  394,  394,  394,  394,  394,  394,
      394,  394,  394,  394,  394,    0,  394,    0,    0,    0,
      394,    0,    0,    0,  394,  395,    0,    0,    0,    0,
        0,    0,    0,    0,    0,  395,    0,  395,    0,  395,
        0,    0,  395,  395,  395,  395,  395,  395,  395,  395,
      395,  395,  395,  395,  395,  395,  395,  395,  395,  395,
      395,  395,  395,  395,  395,    0,  395,    0,    0,    0,

      395,    0,    0,    0,  395,  396,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,  396,    0,
        0,    0,    0,  396,    0,    0,  396,  396,  396,  396,
      396,  396,  396,  396,  396,  396,  396,  396,  396,  396,
      396,  396,  396,  396,  396,  396,  396,  396,  396,    0,
      396,    0,    0,  396,  396,    0,    0,    0,  396,  398,
      398,  398,  398,  398,  398,  398,  398,  398,  398,  398,
      398,  398,  398,  398,  398,  398,  398,  398,  398,  398,
      398,  398,  398,  398,  398,  398,  398,  398,  398,  398,
      398,  398,  398,  398,  398,  398,  398,  398,  398,  398,

      398,  398,  398,  398,  398,  398,  398,  398,  398,  398,
      398,  398,  398,  398,  398,  398,  398,  398,  398,  399,
        0,    0,    0,    0,    0,    0,    0,    0,  399,    0,
        0,    0,    0,  399,    0,    0,  399,  399,  399,  399,
      399,  399,  399,  399,  399,  399,  399,  399,  399,  399,
      399,  399,  399,  399,  399,  399,  399,  399,  399,    0,
      399,    0,    0,  399,  399,    0,    0,    0,  399,  401,
      401,  401,  401,  401,  401,  401,  401,  401,  401,  401,
      401,  401,  401,  401,  401,  401,  401,  401,  401,  401,
      401,  401,  401,  401,  401,  401,  401,  401,  401,  401,

      401,  401,  401,  401,  401,  401,  401,  401,  401,  401,
      401,  401,  401,  401,  401,  401,  401,  401,  401,  401,
      401,  401,  401,  401,  401,  401,  401,  401,  401,  402,
      402,    0,  402,    0,    0,    0,    0,    0,    0,    0,
      402,  402,  402,  402,  402,  402,  402,  402,  402,  402,
      402,  402,  402,  402,  402,  402,  402,  402,  402,  402,
      402,  402,  402,    0,  402,    0,    0,  402,  402,    0,
        0,    0,  402,  408,  408,    0,  408,    0,    0,    0,
        0,    0,    0,    0,  408,  408,  408,  408,  408,  408,
      408,  408,  408,  408,  408,  408,  408,  408,  408,  408,

      408,  408,  408,  408,  408,  408,  408,    0,  408,    0,
        0,  408,  408,    0,    0,    0,  408,  419,  419,  419,
      419,  419,  419,  419,  419,  419,  419,  419,  419,  420,
      420,  420,  420,  420,  420,  420,  420,  420,  420,  420,
      420,  421,    0,  421,  421,  421,  421,  421,  421,  421,
      421,  421,  421,  422,  422,  422,  422,  422,  422,  422,
      422,  422,  422,  422,  422,  423,    0,  423,  423,  423,
      423,  423,  423,  423,  423,  423,  423,  424,    0,    0,
      424,    0,    0,  424,  424,  425,  425,  425,  425,    0,
      425,  425,  426,    0,    0,  426,  426,  427,    0,    0,

      427,  427,  428,  428,  428,  428,    0,  428,  428,  429,
      429,  429,  429,  429,  429,  429,  429,  429,  429,  429,
      429,  430,  430,  430,  430,  430,  430,  430,  430,  430,
      430,  430,  430,  431,  431,  431,  431,  431,  431,  431,
      431,  431,  431,  431,  431,  432,  432,  432,  432,    0,
        0,  432,  432,  433,  433,  433,  433,  433,  433,  433,
      433,  433,  433,  433,  433,  434,    0,    0,  434,  434,
      437,  437,  437,    0,    0,  437,  437,  438,    0,  438,
        0,    0,  438,    0,  438,  439,  439,  439,  439,  440,
        0,  440,    0,    0,  440,    0,  440,  441,  441,  441,

      441,  442,    0,    0,  442,  442,  443,  443,    0,  443,
      443,  443,  443,  443,    0,  443,  443,  443,  444,  444,
      444,  444,    0,  444,  444,  445,    0,    0,  445,  445,
      446,  446,    0,  446,  446,  446,  446,  446,    0,  446,
      446,  446,  447,  447,  447,  447,    0,  447,  447,  448,
      448,  448,    0,    0,  448,  448,  449,  449,  449,  449,
      449,  449,  449,  449,  449,  449,  449,  449,  450,  450,
      450,    0,    0,  450,  450,  451,  451,  451,  451,  451,
      451,  451,  451,  451,  451,  451,  451,  452,  452,  452,
      452,  452,  452,  452,  452,  452,  452,  452,  452,  453,

      453,  453,  453,  453,  453,  453,  453,  453,  453,  453,
      453,  454,  454,  454,  454,  454,  454,  454,  454,  454,
      454,  454,  454,  455,  455,  455,  455,  455,  455,  455,
      455,  455,  455,  455,  455,  456,  456,  456,  456,  456,
      456,  456,  456,  456,  456,  456,  456,  457,  457,  457,
      457,  457,  457,  457,  457,  457,  457,  457,  457,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,

      418,  418,  418,  418,  418,  418,  418,  418,  418,  418,
      418,  418,  418,  418,  418,  418,  418,  418,  418,  418
    } ;

/* The intent behind this definition is that it'll catch
 * any uses of REJECT which flex missed.
 */
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
#line 1 "./sparql_lexer.l"
/* -*- Mode: c; c-basic-offset: 2 -*-
 *
 * sparql_lexer.l - Rasqal SPARQL lexer - making tokens for sparql grammar generator
 *
 * Copyright (C) 2004-2008, David Beckett http://www.dajobe.org/
 * Copyright (C) 2004-2005, University of Bristol, UK http://www.bristol.ac.uk/
 * 
 * This package is Free Software and part of Redland http://librdf.org/
 * 
 * It is licensed under the following three licenses as alternatives:
 *   1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
 *   2. GNU General Public License (GPL) V2 or any newer version
 *   3. Apache License, V2.0 or any newer version
 * 
 * You may not use this file except in compliance with at least one of
 * the above three licenses.
 * 
 * See LICENSE.html or LICENSE.txt at the top of this package for the
 * complete terms and further detail along with the license texts for
 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
 * 
 * To generate the C files from this source, rather than use the
 * shipped sparql_lexer.c/.h needs a patched version of flex 2.5.31 such
 * as the one available in Debian GNU/Linux.   Details below
 * near the %option descriptions.
 *
 * SPARQL defined in http://www.w3.org/TR/rdf-sparql-query/
 *   http://www.w3.org/TR/2005/WD-rdf-sparql-query-20050419/
 *
 * Editor's draft of above http://www.w3.org/2001/sw/DataAccess/rq23/
 */
/* recognise 8-bits */
/* all symbols prefixed by this */
/* This is not needed, flex is invoked -osparql_lexer.c */
/* Emit a C header file for prototypes
 * Only available in flex 2.5.13 or newer.
 * It was renamed to header-file in flex 2.5.19
 */
/* Do not emit #include <unistd.h>
 * Only available in flex 2.5.7 or newer.
 * Broken in flex 2.5.31 without patches.
 */
#define YY_NO_UNISTD_H 1
/* Never interactive */
/*  No isatty() check */
/* Batch scanner */
/* Never use yyunput */
/* Supply our own alloc/realloc/free functions */
/* Re-entrant scanner */

/* definitions */
#line 78 "./sparql_lexer.l"

/* NOTE: These headers are NOT included here. They are inserted by fix-flex
 * since otherwise it appears far too late in the generated C
 */

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

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

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#ifdef HAVE_SETJMP_H
#include <setjmp.h>
#endif

#include <rasqal.h>
#include <rasqal_internal.h>
#undef DELETE
#include <sparql_parser.h>

#include <sparql_common.h>



static int sparql_skip_c_comment(rasqal_query *rq);

/*
 * Extra checks beyond valid Namespaces in XML 1.1 name
 *
 * SPARQL_NAME_CHECK_VARNAME (token VARNAME)
 *   No '.' allowed.
 *   No '-' allowed.
 *
 * SPARQL_NAME_CHECK_PREFIX (token NCNAME_PREFIX)
 *   No '_' allowed as the first character.
 *   No '.' allowed as the last character.
 *
 * SPARQL_NAME_CHECK_NCNAME (token NCNAME)
 *  [0-9] allowed as the first character
 *   No '.' allowed as the first character.
 *   No '.' allowed as the last character.
 *
*/
typedef enum {
  SPARQL_NAME_CHECK_NO_UL_FIRST  = 1,
  SPARQL_NAME_CHECK_NO_DOT_LAST  = 2,
  SPARQL_NAME_CHECK_NO_DOT_MINUS = 4,
  SPARQL_NAME_CHECK_ALLOW_09_FIRST = 8,

  SPARQL_NAME_CHECK_VARNAME = SPARQL_NAME_CHECK_NO_DOT_MINUS,
  SPARQL_NAME_CHECK_PREFIX  = SPARQL_NAME_CHECK_NO_UL_FIRST | SPARQL_NAME_CHECK_NO_DOT_LAST,
  SPARQL_NAME_CHECK_NCNAME  = SPARQL_NAME_CHECK_NO_DOT_LAST | SPARQL_NAME_CHECK_ALLOW_09_FIRST
} sparql_name_check_flags;


static int rasqal_sparql_name_check(unsigned char *string, size_t length, sparql_name_check_flags check_flags);
static unsigned char *sparql_copy_name(rasqal_query *rq, const unsigned char *text, size_t len, sparql_name_check_flags check_flags);
static raptor_uri* sparql_copy_qname(rasqal_query *rq, const unsigned char *text, size_t len);
static int sparql_copy_string_token(rasqal_query *rq, YYSTYPE* lval, const unsigned char *text, size_t len, int delim);

#ifdef RASQAL_DEBUG
const char * sparql_token_print(int token, YYSTYPE *lval);
#endif

int sparql_lexer_lex (YYSTYPE *sparql_parser_lval, yyscan_t yyscanner);
#define YY_DECL int sparql_lexer_lex (YYSTYPE *sparql_parser_lval, yyscan_t yyscanner)

#ifdef __cplusplus
#define INPUT_FN yyinput
#else
#define INPUT_FN input
#endif

/* Remove the re-fill function since it should never be called */
#define YY_INPUT(buf,result,max_size) { return YY_NULL; }


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

static void sparql_lexer_cleanup(yyscan_t yyscanner);

#ifdef HAVE_SETJMP
static jmp_buf sparql_lexer_fatal_error_longjmp_env;

/* fatal error handler declaration */
#define YY_FATAL_ERROR(msg) do {		\
    sparql_lexer_fatal_error(msg, yyscanner);   \
    longjmp(sparql_lexer_fatal_error_longjmp_env, 1);        \
} while(0)
#else
#define YY_FATAL_ERROR(msg) do {		\
    sparql_lexer_fatal_error(msg, yyscanner);   \
    abort();                                    \
} while(0)
#endif
 
static void sparql_lexer_fatal_error(yyconst char *msg, yyscan_t yyscanner);

/* Fatal error handler that returns EOF instead of abort()/longjmp()
 * so that parser can clean up properly */
#define YY_FATAL_ERROR_EOF(msg) do { \
    sparql_lexer_fatal_error(msg, yyscanner); \
    yyterminate(); \
} while(0)
/*
 * rq23 is http://www.w3.org/2001/sw/DataAccess/rq23/
 * CVS ID 1.420 2005/07/12 15:38:40
 */
/* [85] NCCHAR1p ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] |
 *   [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] |
 *   [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] |
 *   [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] |
 *   [#x10000-#xEFFFF]
 *
 * This is an XML 1.1 NameStartChar
 *   http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-NameStartChar
 * except
 *   No '_' allowed.
 */
/* [86] NCCHAR1 ::= NCCHAR1p | '_'
 * This is an XML 1.1 NameStartChar
 *   http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-NameStartChar
 */
/* [87]  VARNAME ::= ( NCCHAR1 | _ ) 
 *   ( NCCHAR1 | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*
 *
 * This is an Namespaces in XML 1.1 Name except:
 *   No '.' allowed.
 *   No '-' allowed.
 */
/* [88]  NCCHAR ::= 
 *   NCCHAR1 | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
 *
 * This is XML 1.1 NameChar
 *   http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-NameChar
 * except:
 *   No '.' allowed.
 */
/* [89]  NCNAME_PREFIX ::= NCCHAR1p ((NCCHAR|".")* NCCHAR)?
 *
 * This is an Namespaces in XML 1.1 Name except:
 *   No '_' allowed as the first character.
 *   No '.' allowed as the last character.
 */
/* [90]  NCNAME ::= NCCHAR1 ((NCCHAR|".")* NCCHAR)?
 *
 * This is an Namespaces in XML 1.1 Name except:
 *   No '.' allowed as the last character.
 */
/* SPARQL allows [0-9] after a : in the 
 * W3C Candidate Recommendation 14 June 2007 
 * as an at risk feature that may be removed.
 */
/* rq23 [67] QNAME_NS ::= NCNAME_PREFIX? ':'
 * Inlined into in rule <PREF>{NCNAME_PREFIX}":" below 
 */
/* rq23 [68] QNAME ::= NCNAME_PREFIX? ':' NCNAME? */
/* rq23 [69] BNODE_LABEL (renamed to BNAME) ::= '_:' NCNAME */
/* a blank node name written inside a URI - this is an illegal
 * URI form and for convienence 
 */
/* The initial char conditions are to ensure this doesn't grab < or <= 
 * as operators.  starting with <_: is caught by BNAME2 above.
 **/
#line 1319 "sparql_lexer.c"

#define INITIAL 0
#define ID 1
#define SPID 2
#define PREF 3
#define LITERAL 4
#define LITERAL2 5

#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
 * down here because we want the user's section 1 to have been scanned first.
 * The user has a chance to override it with an option.
 */
#ifndef YY_NO_UNISTD_H
#include <unistd.h>
#endif
#endif

#ifndef YY_EXTRA_TYPE
#define YY_EXTRA_TYPE void *
#endif

/* Holds the entire state of the reentrant scanner. */
struct yyguts_t
    {

    /* User-defined. Not touched by flex. */
    YY_EXTRA_TYPE yyextra_r;

    /* The rest are the same as the globals declared in the non-reentrant scanner. */
    FILE *yyin_r, *yyout_r;
    size_t yy_buffer_stack_top; /**< index of top of stack. */
    size_t yy_buffer_stack_max; /**< capacity of stack. */
    YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
    char yy_hold_char;
    int yy_n_chars;
    int yyleng_r;
    char *yy_c_buf_p;
    int yy_init;
    int yy_start;
    int yy_did_buffer_switch_on_eof;
    int yy_start_stack_ptr;
    int yy_start_stack_depth;
    int *yy_start_stack;
    yy_state_type yy_last_accepting_state;
    char* yy_last_accepting_cpos;

    int yylineno_r;
    int yy_flex_debug_r;

    char *yytext_r;
    int yy_more_flag;
    int yy_more_len;

    }; /* end struct yyguts_t */

static int yy_init_globals (yyscan_t yyscanner );

int sparql_lexer_lex_init (yyscan_t* scanner);

int sparql_lexer_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);

/* Accessor methods to globals.
   These are made visible to non-reentrant scanners for convenience. */

int sparql_lexer_lex_destroy (yyscan_t yyscanner );

int sparql_lexer_get_debug (yyscan_t yyscanner );

void sparql_lexer_set_debug (int debug_flag ,yyscan_t yyscanner );

YY_EXTRA_TYPE sparql_lexer_get_extra (yyscan_t yyscanner );

void sparql_lexer_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );

FILE *sparql_lexer_get_in (yyscan_t yyscanner );

void sparql_lexer_set_in  (FILE * in_str ,yyscan_t yyscanner );

FILE *sparql_lexer_get_out (yyscan_t yyscanner );

void sparql_lexer_set_out  (FILE * out_str ,yyscan_t yyscanner );

int sparql_lexer_get_leng (yyscan_t yyscanner );

char *sparql_lexer_get_text (yyscan_t yyscanner );

int sparql_lexer_get_lineno (yyscan_t yyscanner );

void sparql_lexer_set_lineno (int line_number ,yyscan_t yyscanner );

/* Macros after this point can all be overridden by user definitions in
 * section 1.
 */

#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int sparql_lexer_wrap (yyscan_t yyscanner );
#else
extern int sparql_lexer_wrap (yyscan_t yyscanner );
#endif
#endif

#ifndef yytext_ptr
static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
#endif

#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
#endif

#ifndef YY_NO_INPUT

#ifdef __cplusplus
static int yyinput (yyscan_t yyscanner );
#else
static int input (yyscan_t yyscanner );
#endif

#endif

/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif

/* Copy whatever the last rule matched to the standard output. */
#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
 * we now use fwrite().
 */
#define ECHO fwrite( yytext, yyleng, 1, yyout )
#endif

/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
		{ \
		int c = '*'; \
		size_t n; \
		for ( n = 0; n < max_size && \
			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
			buf[n] = (char) c; \
		if ( c == '\n' ) \
			buf[n++] = (char) c; \
		if ( c == EOF && ferror( yyin ) ) \
			YY_FATAL_ERROR( "input in flex scanner failed" ); \
		result = n; \
		} \
	else \
		{ \
		errno=0; \
		while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
			{ \
			if( errno != EINTR) \
				{ \
				YY_FATAL_ERROR( "input in flex scanner failed" ); \
				break; \
				} \
			errno=0; \
			clearerr(yyin); \
			} \
		}\
\

#endif

/* No semi-colon after return; correct usage is to write "yyterminate();" -
 * we don't want an extra ';' after the "return" because that will cause
 * some compilers to complain about unreachable statements.
 */
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif

/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif

/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
#endif

/* end tables serialization structures and prototypes */

/* Default declaration of generated scanner - a define so the user can
 * easily add parameters.
 */
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1

extern int sparql_lexer_lex (yyscan_t yyscanner);

#define YY_DECL int sparql_lexer_lex (yyscan_t yyscanner)
#endif /* !YY_DECL */

/* Code executed at the beginning of each rule, after yytext and yyleng
 * have been set up.
 */
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif

/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK break;
#endif

#define YY_RULE_SETUP \
	YY_USER_ACTION

/** The main scanner function which does all the work.
 */
YY_DECL
{
	register yy_state_type yy_current_state;
	register char *yy_cp, *yy_bp;
	register int yy_act;
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

#line 290 "./sparql_lexer.l"

  /* rules */



  int c;
  rasqal_query *rq=(rasqal_query*)yyextra;
  rasqal_sparql_query_engine *rqe=(rasqal_sparql_query_engine*)rq->context;

#ifdef HAVE_SETJMP
  if(setjmp(sparql_lexer_fatal_error_longjmp_env))
    return 1;
#endif
  


#line 1562 "sparql_lexer.c"

	if ( !yyg->yy_init )
		{
		yyg->yy_init = 1;

#ifdef YY_USER_INIT
		YY_USER_INIT;
#endif

		if ( ! yyg->yy_start )
			yyg->yy_start = 1;	/* first start state */

		if ( ! yyin )
			yyin = stdin;

		if ( ! yyout )
			yyout = stdout;

		if ( ! YY_CURRENT_BUFFER ) {
			sparql_lexer_ensure_buffer_stack (yyscanner);
			YY_CURRENT_BUFFER_LVALUE =
				sparql_lexer__create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
		}

		sparql_lexer__load_buffer_state(yyscanner );
		}

	while ( 1 )		/* loops until end-of-file is reached */
		{
		yy_cp = yyg->yy_c_buf_p;

		/* Support of yytext. */
		*yy_cp = yyg->yy_hold_char;

		/* yy_bp points to the position in yy_ch_buf of the start of
		 * the current run.
		 */
		yy_bp = yy_cp;

		yy_current_state = yyg->yy_start;
yy_match:
		do
			{
			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
			if ( yy_accept[yy_current_state] )
				{
				yyg->yy_last_accepting_state = yy_current_state;
				yyg->yy_last_accepting_cpos = yy_cp;
				}
			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
				{
				yy_current_state = (int) yy_def[yy_current_state];
				if ( yy_current_state >= 419 )
					yy_c = yy_meta[(unsigned int) yy_c];
				}
			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
			++yy_cp;
			}
		while ( yy_current_state != 418 );
		yy_cp = yyg->yy_last_accepting_cpos;
		yy_current_state = yyg->yy_last_accepting_state;

yy_find_action:
		yy_act = yy_accept[yy_current_state];

		YY_DO_BEFORE_ACTION;

do_action:	/* This label is used only to access EOF actions. */

		switch ( yy_act )
	{ /* beginning of action switch */
			case 0: /* must back up */
			/* undo the effects of YY_DO_BEFORE_ACTION */
			*yy_cp = yyg->yy_hold_char;
			yy_cp = yyg->yy_last_accepting_cpos;
			yy_current_state = yyg->yy_last_accepting_state;
			goto yy_find_action;

case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
#line 306 "./sparql_lexer.l"
{ /* C++ comment */
        rqe->lineno++;
}
	YY_BREAK
case 2:
YY_RULE_SETUP
#line 310 "./sparql_lexer.l"
{ int lines=sparql_skip_c_comment(rq);
          if(lines < 0)
            yyterminate();
          rqe->lineno += lines;
        }
	YY_BREAK
case 3:
/* rule 3 can match eol */
YY_RULE_SETUP
#line 316 "./sparql_lexer.l"
{ rqe->lineno++; }
	YY_BREAK
case 4:
YY_RULE_SETUP
#line 318 "./sparql_lexer.l"
{ /* eat up other whitespace */
	;
}
	YY_BREAK
case 5:
YY_RULE_SETUP
#line 322 "./sparql_lexer.l"
{ return SELECT; }
	YY_BREAK
case 6:
YY_RULE_SETUP
#line 323 "./sparql_lexer.l"
{ return FROM; }
	YY_BREAK
case 7:
YY_RULE_SETUP
#line 324 "./sparql_lexer.l"
{ return WHERE; }
	YY_BREAK
case 8:
YY_RULE_SETUP
#line 325 "./sparql_lexer.l"
{ BEGIN(PREF);
		return PREFIX; }
	YY_BREAK
case 9:
YY_RULE_SETUP
#line 327 "./sparql_lexer.l"
{ return DESCRIBE; }
	YY_BREAK
case 10:
YY_RULE_SETUP
#line 328 "./sparql_lexer.l"
{ return CONSTRUCT; }
	YY_BREAK
case 11:
YY_RULE_SETUP
#line 329 "./sparql_lexer.l"
{ return ASK; }
	YY_BREAK
case 12:
YY_RULE_SETUP
#line 330 "./sparql_lexer.l"
{ return DISTINCT; }
	YY_BREAK
case 13:
YY_RULE_SETUP
#line 331 "./sparql_lexer.l"
{ return REDUCED; }
	YY_BREAK
case 14:
YY_RULE_SETUP
#line 332 "./sparql_lexer.l"
{ return LIMIT; }
	YY_BREAK
case 15:
YY_RULE_SETUP
#line 333 "./sparql_lexer.l"
{ return UNION; }
	YY_BREAK
case 16:
YY_RULE_SETUP
#line 334 "./sparql_lexer.l"
{ return OPTIONAL; }
	YY_BREAK
case 17:
YY_RULE_SETUP
#line 335 "./sparql_lexer.l"
{ return BASE; }
	YY_BREAK
case 18:
YY_RULE_SETUP
#line 336 "./sparql_lexer.l"
{ return BOUND; }
	YY_BREAK
case 19:
YY_RULE_SETUP
#line 337 "./sparql_lexer.l"
{ return STR; }
	YY_BREAK
case 20:
YY_RULE_SETUP
#line 338 "./sparql_lexer.l"
{ return LANG; }
	YY_BREAK
case 21:
YY_RULE_SETUP
#line 339 "./sparql_lexer.l"
{ return DATATYPE; }
	YY_BREAK
case 22:
YY_RULE_SETUP
#line 340 "./sparql_lexer.l"
{ return ISURI; } /* isURI and isIRI */
	YY_BREAK
case 23:
YY_RULE_SETUP
#line 341 "./sparql_lexer.l"
{ return ISBLANK; }
	YY_BREAK
case 24:
YY_RULE_SETUP
#line 342 "./sparql_lexer.l"
{ return ISLITERAL; }
	YY_BREAK
case 25:
YY_RULE_SETUP
#line 343 "./sparql_lexer.l"
{ return GRAPH; }
	YY_BREAK
case 26:
YY_RULE_SETUP
#line 344 "./sparql_lexer.l"
{ return NAMED; }
	YY_BREAK
case 27:
YY_RULE_SETUP
#line 345 "./sparql_lexer.l"
{ return FILTER; }
	YY_BREAK
case 28:
YY_RULE_SETUP
#line 346 "./sparql_lexer.l"
{ return OFFSET; }
	YY_BREAK
case 29:
YY_RULE_SETUP
#line 347 "./sparql_lexer.l"
{ return ORDER; }
	YY_BREAK
case 30:
YY_RULE_SETUP
#line 348 "./sparql_lexer.l"
{ return BY; }
	YY_BREAK
case 31:
YY_RULE_SETUP
#line 349 "./sparql_lexer.l"
{ return REGEX; }
	YY_BREAK
case 32:
YY_RULE_SETUP
#line 350 "./sparql_lexer.l"
{ return ASC; }
	YY_BREAK
case 33:
YY_RULE_SETUP
#line 351 "./sparql_lexer.l"
{ return DESC; } 
	YY_BREAK
case 34:
YY_RULE_SETUP
#line 352 "./sparql_lexer.l"
{ return LANGMATCHES; } 
	YY_BREAK
case 35:
YY_RULE_SETUP
#line 353 "./sparql_lexer.l"
{ return EXPLAIN; }
	YY_BREAK
case 36:
YY_RULE_SETUP
#line 354 "./sparql_lexer.l"
{ return GROUP; }
	YY_BREAK
case 37:
YY_RULE_SETUP
#line 355 "./sparql_lexer.l"
{ return COUNT; }
	YY_BREAK
case 38:
YY_RULE_SETUP
#line 356 "./sparql_lexer.l"
{ BEGIN(SPID); return AS; }
	YY_BREAK
case 39:
YY_RULE_SETUP
#line 357 "./sparql_lexer.l"
{ return DELETE; }
	YY_BREAK
case 40:
YY_RULE_SETUP
#line 358 "./sparql_lexer.l"
{ return INSERT; }
	YY_BREAK
case 41:
YY_RULE_SETUP
#line 359 "./sparql_lexer.l"
{ return SAMETERM; }
	YY_BREAK
case 42:
YY_RULE_SETUP
#line 361 "./sparql_lexer.l"
{ return A; }
	YY_BREAK
case 43:
YY_RULE_SETUP
#line 363 "./sparql_lexer.l"
{ return ','; } 
	YY_BREAK
case 44:
YY_RULE_SETUP
#line 364 "./sparql_lexer.l"
{ return '('; } 
	YY_BREAK
case 45:
YY_RULE_SETUP
#line 365 "./sparql_lexer.l"
{ return ')'; } 
	YY_BREAK
case 46:
YY_RULE_SETUP
#line 366 "./sparql_lexer.l"
{ return '['; }
	YY_BREAK
case 47:
YY_RULE_SETUP
#line 367 "./sparql_lexer.l"
{ return ']'; }
	YY_BREAK
case 48:
YY_RULE_SETUP
#line 368 "./sparql_lexer.l"
{ BEGIN(ID); return '?'; }
	YY_BREAK
case 49:
YY_RULE_SETUP
#line 369 "./sparql_lexer.l"
{ BEGIN(ID); return '$'; }
	YY_BREAK
case 50:
YY_RULE_SETUP
#line 370 "./sparql_lexer.l"
{ return '{'; } 
	YY_BREAK
case 51:
YY_RULE_SETUP
#line 371 "./sparql_lexer.l"
{ return '}'; } 
	YY_BREAK
case 52:
YY_RULE_SETUP
#line 372 "./sparql_lexer.l"
{ return '.'; } 
	YY_BREAK
case 53:
YY_RULE_SETUP
#line 373 "./sparql_lexer.l"
{ return ';'; } 
	YY_BREAK
case 54:
YY_RULE_SETUP
#line 375 "./sparql_lexer.l"
{ return SC_OR; }
	YY_BREAK
case 55:
YY_RULE_SETUP
#line 376 "./sparql_lexer.l"
{ return SC_AND; }
	YY_BREAK
case 56:
YY_RULE_SETUP
#line 378 "./sparql_lexer.l"
{ return EQ; }
	YY_BREAK
case 57:
YY_RULE_SETUP
#line 379 "./sparql_lexer.l"
{ return NEQ; }
	YY_BREAK
case 58:
/* rule 58 can match eol */
*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */
yyg->yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
#line 380 "./sparql_lexer.l"
{ return LT; }
	YY_BREAK
case 59:
YY_RULE_SETUP
#line 381 "./sparql_lexer.l"
{ return GT; }
	YY_BREAK
case 60:
YY_RULE_SETUP
#line 382 "./sparql_lexer.l"
{ return LE; }
	YY_BREAK
case 61:
YY_RULE_SETUP
#line 383 "./sparql_lexer.l"
{ return GE; }
	YY_BREAK
case 62:
YY_RULE_SETUP
#line 385 "./sparql_lexer.l"
{ return '*'; }
	YY_BREAK
case 63:
YY_RULE_SETUP
#line 386 "./sparql_lexer.l"
{ return '/'; }
	YY_BREAK
case 64:
YY_RULE_SETUP
#line 387 "./sparql_lexer.l"
{ return '!'; }
	YY_BREAK
case 65:
YY_RULE_SETUP
#line 390 "./sparql_lexer.l"
{ c=*yytext;
                  sparql_parser_lval->literal=rasqal_new_typed_literal(rq->world, RASQAL_LITERAL_INTEGER, (const unsigned char*)yytext);
                  if(!sparql_parser_lval->literal)
                    YY_FATAL_ERROR_EOF("rasqal_new_typed_literal failed");
 		  return (c=='+' ? INTEGER_POSITIVE_LITERAL : (c == '-' ? INTEGER_NEGATIVE_LITERAL : INTEGER_LITERAL));
}
	YY_BREAK
case 66:
YY_RULE_SETUP
#line 397 "./sparql_lexer.l"
{ 
                        c=*yytext;
                        
                        if(!rasqal_xsd_datatype_check(RASQAL_LITERAL_DECIMAL, (const unsigned char*)yytext, 0)) {
                          sparql_syntax_error(rq, "SPARQL syntax error - Illegal decimal constant %s", yytext);
                          yyterminate();
                        }
                        sparql_parser_lval->literal=rasqal_new_decimal_literal(rq->world, (const unsigned char*)yytext);
                        if(!sparql_parser_lval->literal)
                          YY_FATAL_ERROR_EOF("rasqal_new_decimal_literal failed");
                        return (c=='+' ? DECIMAL_POSITIVE_LITERAL : (c == '-' ? DECIMAL_NEGATIVE_LITERAL : DECIMAL_LITERAL));
}
	YY_BREAK
case 67:
YY_RULE_SETUP
#line 410 "./sparql_lexer.l"
{
                        c=*yytext;
                        if(!rasqal_xsd_datatype_check(RASQAL_LITERAL_DOUBLE, (const unsigned char*)yytext, 0)) {
                          sparql_syntax_error(rq, "SPARQL syntax error - Illegal double constant %s", yytext);
                          yyterminate();
                        }
                        sparql_parser_lval->literal=rasqal_new_typed_literal(rq->world, RASQAL_LITERAL_DOUBLE, (const unsigned char*)yytext);
                        if(!sparql_parser_lval->literal)
                          YY_FATAL_ERROR_EOF("rasqal_new_typed_literal failed");
                        return (c=='+' ? DOUBLE_POSITIVE_LITERAL : (c == '-' ? DOUBLE_NEGATIVE_LITERAL : DOUBLE_LITERAL));
}
	YY_BREAK
case 68:
YY_RULE_SETUP
#line 422 "./sparql_lexer.l"
{ return '+'; }
	YY_BREAK
case 69:
YY_RULE_SETUP
#line 423 "./sparql_lexer.l"
{ return '-'; }
	YY_BREAK
case 70:
/* rule 70 can match eol */
YY_RULE_SETUP
#line 425 "./sparql_lexer.l"
{ /*' */
                        if(sparql_copy_string_token(rq, sparql_parser_lval,
                           (const unsigned char*)yytext+1, yyleng-1, '\''))
                          YY_FATAL_ERROR_EOF("sparql_copy_string_token failed");
                        return STRING_LITERAL; }
	YY_BREAK
case 71:
/* rule 71 can match eol */
YY_RULE_SETUP
#line 431 "./sparql_lexer.l"
{ /* " */
                        if(sparql_copy_string_token(rq, sparql_parser_lval,
                           (const unsigned char*)yytext+1, yyleng-1, '"'))
                          YY_FATAL_ERROR_EOF("sparql_copy_string_token failed");
                        return STRING_LITERAL; }
	YY_BREAK
case 72:
YY_RULE_SETUP
#line 437 "./sparql_lexer.l"
{ BEGIN(LITERAL); }
	YY_BREAK
case 73:
/* rule 73 can match eol */
YY_RULE_SETUP
#line 439 "./sparql_lexer.l"
{ if(sparql_copy_string_token(rq, sparql_parser_lval, 
                            (unsigned char*)yytext, yyleng, '"')) /* ' */
                            YY_FATAL_ERROR_EOF("sparql_copy_string_token failed");
                          BEGIN(INITIAL);
                          return STRING_LITERAL; }
	YY_BREAK
case 74:
/* rule 74 can match eol */
YY_RULE_SETUP
#line 445 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  if (!*yytext)
                    return EOF;

                  sparql_syntax_error(rq, "syntax error at %c - \"\"\"string was not terminated", *yytext);
                  yyterminate();  }
	YY_BREAK
case 75:
YY_RULE_SETUP
#line 453 "./sparql_lexer.l"
{ BEGIN(LITERAL2); }
	YY_BREAK
case 76:
/* rule 76 can match eol */
YY_RULE_SETUP
#line 455 "./sparql_lexer.l"
{ if(sparql_copy_string_token(rq, sparql_parser_lval, 
                            (unsigned char*)yytext, yyleng, '\''))
                            YY_FATAL_ERROR_EOF("sparql_copy_string_token failed");
                          BEGIN(INITIAL);
                          return STRING_LITERAL; }
	YY_BREAK
case 77:
/* rule 77 can match eol */
YY_RULE_SETUP
#line 461 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  if (!*yytext)
                    return EOF;

                  sparql_syntax_error(rq, "syntax error at %c - '''string was not terminated", *yytext);
                  yyterminate();  }
	YY_BREAK
case 78:
YY_RULE_SETUP
#line 469 "./sparql_lexer.l"
{ sparql_parser_lval->literal=rasqal_new_boolean_literal(rq->world, 1);
                    if(!sparql_parser_lval->literal)
                      YY_FATAL_ERROR_EOF("rasqal_new_boolean_literal failed");
                  return BOOLEAN_LITERAL; }
	YY_BREAK
case 79:
YY_RULE_SETUP
#line 474 "./sparql_lexer.l"
{ sparql_parser_lval->literal=rasqal_new_boolean_literal(rq->world, 0);
                        if(!sparql_parser_lval->literal)
                          YY_FATAL_ERROR_EOF("rasqal_new_boolean_literal failed");
                  return BOOLEAN_LITERAL; }
	YY_BREAK
case 80:
YY_RULE_SETUP
#line 479 "./sparql_lexer.l"
{ sparql_parser_lval->name=sparql_copy_name(rq, (const unsigned char*)yytext, yyleng, SPARQL_NAME_CHECK_VARNAME);
		  if(!sparql_parser_lval->name)
                    YY_FATAL_ERROR_EOF("sparql_copy_name failed");
                          BEGIN(INITIAL);
                          return IDENTIFIER; }
	YY_BREAK
case 81:
/* rule 81 can match eol */
YY_RULE_SETUP
#line 484 "./sparql_lexer.l"
{	BEGIN(INITIAL);
		sparql_syntax_error(rq, "SPARQL syntax error - missing variable name after ?");
                yyterminate();
}
	YY_BREAK
case 82:
YY_RULE_SETUP
#line 489 "./sparql_lexer.l"
{ /* eat up leading whitespace */
	;
}
	YY_BREAK
case 83:
YY_RULE_SETUP
#line 492 "./sparql_lexer.l"
{ sparql_parser_lval->name=sparql_copy_name(rq, (const unsigned char*)yytext, yyleng, SPARQL_NAME_CHECK_VARNAME);
		  if(!sparql_parser_lval->name)
                    YY_FATAL_ERROR_EOF("sparql_copy_name failed");
                          BEGIN(INITIAL);
                          return IDENTIFIER; }
	YY_BREAK
case 84:
/* rule 84 can match eol */
YY_RULE_SETUP
#line 498 "./sparql_lexer.l"
{	BEGIN(INITIAL);
		sparql_syntax_error(rq, "SPARQL syntax error - missing variable name after ?");
                yyterminate();
}
	YY_BREAK
case 85:
YY_RULE_SETUP
#line 503 "./sparql_lexer.l"
{ /* eat up leading whitespace */ }
	YY_BREAK
case 86:
YY_RULE_SETUP
#line 504 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  	  sparql_parser_lval->name=sparql_copy_name(rq, (const unsigned char*)yytext, yyleng-1, SPARQL_NAME_CHECK_PREFIX);
			  if(!sparql_parser_lval->name)
			    YY_FATAL_ERROR_EOF("sparql_copy_name failed");
                          return IDENTIFIER; }
	YY_BREAK
case 87:
YY_RULE_SETUP
#line 509 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  sparql_parser_lval->name=NULL;
                  return IDENTIFIER; }
	YY_BREAK
case 88:
/* rule 88 can match eol */
YY_RULE_SETUP
#line 513 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  if (!*yytext)
                    return EOF;

                  sparql_syntax_error(rq, "SPARQL syntax error at '%c'", *yytext);
                  yyterminate();
}
	YY_BREAK
case 89:
YY_RULE_SETUP
#line 521 "./sparql_lexer.l"
{
		int have_brace=(yytext[yyleng-1]=='(');
		if(have_brace)
			yyleng--;
		sparql_parser_lval->uri=sparql_copy_qname(rq, (const unsigned char*)yytext, yyleng);
		if(!sparql_parser_lval->uri)
		  YY_FATAL_ERROR_EOF("sparql_copy_qname failed");
 		return have_brace ? URI_LITERAL_BRACE : URI_LITERAL;
}
	YY_BREAK
case 90:
YY_RULE_SETUP
#line 531 "./sparql_lexer.l"
{	sparql_parser_lval->name=sparql_copy_name(rq, (unsigned char*)yytext+2, yyleng-2, SPARQL_NAME_CHECK_NCNAME);
		return BLANK_LITERAL;
}
	YY_BREAK
case 91:
YY_RULE_SETUP
#line 535 "./sparql_lexer.l"
{	sparql_parser_lval->name=sparql_copy_name(rq, (unsigned char*)yytext+3, yyleng-4, SPARQL_NAME_CHECK_NCNAME);
		return BLANK_LITERAL;
}
	YY_BREAK
case 92:
/* rule 92 can match eol */
YY_RULE_SETUP
#line 539 "./sparql_lexer.l"
{ 
		int have_brace=(yytext[yyleng-1]=='(');
		if(have_brace)
			yyleng--;
		if(yyleng == 2) 
                  sparql_parser_lval->uri=raptor_uri_copy(rq->base_uri);
                else {
                  unsigned char* uri_string;

                  yytext[yyleng-1]='\0';
                  uri_string=rasqal_escaped_name_to_utf8_string((unsigned char*)yytext+1,
                                                                yyleng-1,
                                                                NULL,
                                                                (raptor_simple_message_handler)sparql_syntax_error, rq);
                  if(!uri_string)
                    YY_FATAL_ERROR_EOF("rasqal_escaped_name_to_utf8_string failed");

                  sparql_parser_lval->uri=raptor_new_uri_relative_to_base(rq->base_uri, uri_string);
                  RASQAL_FREE(cstring, uri_string);
                  if(!sparql_parser_lval->uri)
                    YY_FATAL_ERROR_EOF("raptor_new_uri_relative_to_base failed");
                 }
                 return have_brace ? URI_LITERAL_BRACE : URI_LITERAL; }
	YY_BREAK
case 93:
/* rule 93 can match eol */
YY_RULE_SETUP
#line 563 "./sparql_lexer.l"
{ /* # comment */
        	rqe->lineno++;
                }
	YY_BREAK
case 94:
YY_RULE_SETUP
#line 567 "./sparql_lexer.l"
{ if (!*yytext)
                    return EOF;

                  sparql_syntax_error(rq, "SPARQL syntax error at '%c'", *yytext);
                  yyterminate();
		}
	YY_BREAK
case 95:
YY_RULE_SETUP
#line 574 "./sparql_lexer.l"
YY_FATAL_ERROR( "flex scanner jammed" );
	YY_BREAK
#line 2269 "sparql_lexer.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(ID):
case YY_STATE_EOF(SPID):
case YY_STATE_EOF(PREF):
case YY_STATE_EOF(LITERAL):
case YY_STATE_EOF(LITERAL2):
	yyterminate();

	case YY_END_OF_BUFFER:
		{
		/* Amount of text matched not including the EOB char. */
		int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;

		/* Undo the effects of YY_DO_BEFORE_ACTION. */
		*yy_cp = yyg->yy_hold_char;
		YY_RESTORE_YY_MORE_OFFSET

		if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
			{
			/* We're scanning a new file or input source.  It's
			 * possible that this happened because the user
			 * just pointed yyin at a new source and called
			 * sparql_lexer_lex().  If so, then we have to assure
			 * consistency between YY_CURRENT_BUFFER and our
			 * globals.  Here is the right place to do so, because
			 * this is the first action (other than possibly a
			 * back-up) that will match for the new input source.
			 */
			yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
			YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
			YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
			}

		/* Note that here we test for yy_c_buf_p "<=" to the position
		 * of the first EOB in the buffer, since yy_c_buf_p will
		 * already have been incremented past the NUL character
		 * (since all states make transitions on EOB to the
		 * end-of-buffer state).  Contrast this with the test
		 * in input().
		 */
		if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
			{ /* This was really a NUL. */
			yy_state_type yy_next_state;

			yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;

			yy_current_state = yy_get_previous_state( yyscanner );

			/* Okay, we're now positioned to make the NUL
			 * transition.  We couldn't have
			 * yy_get_previous_state() go ahead and do it
			 * for us because it doesn't know how to deal
			 * with the possibility of jamming (and we don't
			 * want to build jamming into it because then it
			 * will run more slowly).
			 */

			yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);

			yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;

			if ( yy_next_state )
				{
				/* Consume the NUL. */
				yy_cp = ++yyg->yy_c_buf_p;
				yy_current_state = yy_next_state;
				goto yy_match;
				}

			else
				{
				yy_cp = yyg->yy_last_accepting_cpos;
				yy_current_state = yyg->yy_last_accepting_state;
				goto yy_find_action;
				}
			}

		else switch ( yy_get_next_buffer( yyscanner ) )
			{
			case EOB_ACT_END_OF_FILE:
				{
				yyg->yy_did_buffer_switch_on_eof = 0;

				if ( sparql_lexer_wrap(yyscanner ) )
					{
					/* Note: because we've taken care in
					 * yy_get_next_buffer() to have set up
					 * yytext, we can now set up
					 * yy_c_buf_p so that if some total
					 * hoser (like flex itself) wants to
					 * call the scanner after we return the
					 * YY_NULL, it'll still work - another
					 * YY_NULL will get returned.
					 */
					yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;

					yy_act = YY_STATE_EOF(YY_START);
					goto do_action;
					}

				else
					{
					if ( ! yyg->yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
					}
				break;
				}

			case EOB_ACT_CONTINUE_SCAN:
				yyg->yy_c_buf_p =
					yyg->yytext_ptr + yy_amount_of_matched_text;

				yy_current_state = yy_get_previous_state( yyscanner );

				yy_cp = yyg->yy_c_buf_p;
				yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
				goto yy_match;

			case EOB_ACT_LAST_MATCH:
				yyg->yy_c_buf_p =
				&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];

				yy_current_state = yy_get_previous_state( yyscanner );

				yy_cp = yyg->yy_c_buf_p;
				yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
				goto yy_find_action;
			}
		break;
		}

	default:
		YY_FATAL_ERROR(
			"fatal flex scanner internal error--no action found" );
	} /* end of action switch */
		} /* end of scanning one token */
} /* end of sparql_lexer_lex */

/* yy_get_next_buffer - try to read in a new buffer
 *
 * Returns a code representing an action:
 *	EOB_ACT_LAST_MATCH -
 *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
 *	EOB_ACT_END_OF_FILE - end of file
 */
static int yy_get_next_buffer (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
	register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
	register char *source = yyg->yytext_ptr;
	register int number_to_move, i;
	int ret_val;

	if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
		YY_FATAL_ERROR(
		"fatal flex scanner internal error--end of buffer missed" );

	if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
		{ /* Don't try to fill the buffer, so this is an EOF. */
		if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
			{
			/* We matched a single character, the EOB, so
			 * treat this as a final EOF.
			 */
			return EOB_ACT_END_OF_FILE;
			}

		else
			{
			/* We matched some text prior to the EOB, first
			 * process it.
			 */
			return EOB_ACT_LAST_MATCH;
			}
		}

	/* Try to read more data. */

	/* First move last chars to start of buffer. */
	number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;

	for ( i = 0; i < number_to_move; ++i )
		*(dest++) = *(source++);

	if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
		/* don't do the read, it's not guaranteed to return an EOF,
		 * just force an EOF
		 */
		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;

	else
		{
			int num_to_read =
			YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;

		while ( num_to_read <= 0 )
			{ /* Not enough room in the buffer - grow it. */

			/* just a shorter name for the current buffer */
			YY_BUFFER_STATE b = YY_CURRENT_BUFFER;

			int yy_c_buf_p_offset =
				(int) (yyg->yy_c_buf_p - b->yy_ch_buf);

			if ( b->yy_is_our_buffer )
				{
				int new_size = b->yy_buf_size * 2;

				if ( new_size <= 0 )
					b->yy_buf_size += b->yy_buf_size / 8;
				else
					b->yy_buf_size *= 2;

				b->yy_ch_buf = (char *)
					/* Include room in for 2 EOB chars. */
					sparql_lexer_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
				}
			else
				/* Can't grow it, we don't own it. */
				b->yy_ch_buf = 0;

			if ( ! b->yy_ch_buf )
				YY_FATAL_ERROR(
				"fatal error - scanner input buffer overflow" );

			yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];

			num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
						number_to_move - 1;

			}

		if ( num_to_read > YY_READ_BUF_SIZE )
			num_to_read = YY_READ_BUF_SIZE;

		/* Read in more data. */
		YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
			yyg->yy_n_chars, (size_t) num_to_read );

		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
		}

	if ( yyg->yy_n_chars == 0 )
		{
		if ( number_to_move == YY_MORE_ADJ )
			{
			ret_val = EOB_ACT_END_OF_FILE;
			sparql_lexer_restart(yyin  ,yyscanner);
			}

		else
			{
			ret_val = EOB_ACT_LAST_MATCH;
			YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
				YY_BUFFER_EOF_PENDING;
			}
		}

	else
		ret_val = EOB_ACT_CONTINUE_SCAN;

	if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
		/* Extend the array by 50%, plus the number we really need. */
		yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
		YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) sparql_lexer_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
		if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
			YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
	}

	yyg->yy_n_chars += number_to_move;
	YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
	YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;

	yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];

	return ret_val;
}

/* yy_get_previous_state - get the state just before the EOB char was reached */

    static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
{
	register yy_state_type yy_current_state;
	register char *yy_cp;
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	yy_current_state = yyg->yy_start;

	for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
		{
		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
		if ( yy_accept[yy_current_state] )
			{
			yyg->yy_last_accepting_state = yy_current_state;
			yyg->yy_last_accepting_cpos = yy_cp;
			}
		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
			{
			yy_current_state = (int) yy_def[yy_current_state];
			if ( yy_current_state >= 419 )
				yy_c = yy_meta[(unsigned int) yy_c];
			}
		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
		}

	return yy_current_state;
}

/* yy_try_NUL_trans - try to make a transition on the NUL character
 *
 * synopsis
 *	next_state = yy_try_NUL_trans( current_state );
 */
    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state , yyscan_t yyscanner)
{
	register int yy_is_jam;
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
	register char *yy_cp = yyg->yy_c_buf_p;

	register YY_CHAR yy_c = 1;
	if ( yy_accept[yy_current_state] )
		{
		yyg->yy_last_accepting_state = yy_current_state;
		yyg->yy_last_accepting_cpos = yy_cp;
		}
	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
		{
		yy_current_state = (int) yy_def[yy_current_state];
		if ( yy_current_state >= 419 )
			yy_c = yy_meta[(unsigned int) yy_c];
		}
	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
	yy_is_jam = (yy_current_state == 418);

	return yy_is_jam ? 0 : yy_current_state;
}

#ifndef YY_NO_INPUT
#ifdef __cplusplus
    static int yyinput (yyscan_t yyscanner)
#else
    static int input  (yyscan_t yyscanner)
#endif

{
	int c;
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	*yyg->yy_c_buf_p = yyg->yy_hold_char;

	if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
		{
		/* yy_c_buf_p now points to the character we want to return.
		 * If this occurs *before* the EOB characters, then it's a
		 * valid NUL; if not, then we've hit the end of the buffer.
		 */
		if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
			/* This was really a NUL. */
			*yyg->yy_c_buf_p = '\0';

		else
			{ /* need more input */
			int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
			++yyg->yy_c_buf_p;

			switch ( yy_get_next_buffer( yyscanner ) )
				{
				case EOB_ACT_LAST_MATCH:
					/* This happens because yy_g_n_b()
					 * sees that we've accumulated a
					 * token and flags that we need to
					 * try matching the token before
					 * proceeding.  But for input(),
					 * there's no matching to consider.
					 * So convert the EOB_ACT_LAST_MATCH
					 * to EOB_ACT_END_OF_FILE.
					 */

					/* Reset buffer status. */
					sparql_lexer_restart(yyin ,yyscanner);

					/*FALLTHROUGH*/

				case EOB_ACT_END_OF_FILE:
					{
					if ( sparql_lexer_wrap(yyscanner ) )
						return EOF;

					if ( ! yyg->yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
#ifdef __cplusplus
					return yyinput(yyscanner);
#else
					return input(yyscanner);
#endif
					}

				case EOB_ACT_CONTINUE_SCAN:
					yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
					break;
				}
			}
		}

	c = *(unsigned char *) yyg->yy_c_buf_p;	/* cast for 8-bit char's */
	*yyg->yy_c_buf_p = '\0';	/* preserve yytext */
	yyg->yy_hold_char = *++yyg->yy_c_buf_p;

	return c;
}
#endif	/* ifndef YY_NO_INPUT */

/** Immediately switch to a different input stream.
 * @param input_file A readable stream.
 * @param yyscanner The scanner object.
 * @note This function does not reset the start condition to @c INITIAL .
 */
    void sparql_lexer_restart  (FILE * input_file , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	if ( ! YY_CURRENT_BUFFER ){
        sparql_lexer_ensure_buffer_stack (yyscanner);
		YY_CURRENT_BUFFER_LVALUE =
            sparql_lexer__create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
	}

	sparql_lexer__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
	sparql_lexer__load_buffer_state(yyscanner );
}

/** Switch to a different input buffer.
 * @param new_buffer The new input buffer.
 * @param yyscanner The scanner object.
 */
    void sparql_lexer__switch_to_buffer  (YY_BUFFER_STATE  new_buffer , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	/* TODO. We should be able to replace this entire function body
	 * with
	 *		sparql_lexer_pop_buffer_state();
	 *		sparql_lexer_push_buffer_state(new_buffer);
     */
	sparql_lexer_ensure_buffer_stack (yyscanner);
	if ( YY_CURRENT_BUFFER == new_buffer )
		return;

	if ( YY_CURRENT_BUFFER )
		{
		/* Flush out information for old buffer. */
		*yyg->yy_c_buf_p = yyg->yy_hold_char;
		YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
		}

	YY_CURRENT_BUFFER_LVALUE = new_buffer;
	sparql_lexer__load_buffer_state(yyscanner );

	/* We don't actually know whether we did this switch during
	 * EOF (sparql_lexer_wrap()) processing, but the only time this flag
	 * is looked at is after sparql_lexer_wrap() is called, so it's safe
	 * to go ahead and always set it.
	 */
	yyg->yy_did_buffer_switch_on_eof = 1;
}

static void sparql_lexer__load_buffer_state  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
	yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
	yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
	yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
	yyg->yy_hold_char = *yyg->yy_c_buf_p;
}

/** Allocate and initialize an input buffer state.
 * @param file A readable stream.
 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
 * @param yyscanner The scanner object.
 * @return the allocated buffer state.
 */
    YY_BUFFER_STATE sparql_lexer__create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
{
	YY_BUFFER_STATE b;
    
	b = (YY_BUFFER_STATE) sparql_lexer_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in sparql_lexer__create_buffer()" );

	b->yy_buf_size = size;

	/* yy_ch_buf has to be 2 characters longer than the size given because
	 * we need to put in 2 end-of-buffer characters.
	 */
	b->yy_ch_buf = (char *) sparql_lexer_alloc(b->yy_buf_size + 2 ,yyscanner );
	if ( ! b->yy_ch_buf )
		YY_FATAL_ERROR( "out of dynamic memory in sparql_lexer__create_buffer()" );

	b->yy_is_our_buffer = 1;

	sparql_lexer__init_buffer(b,file ,yyscanner);

	return b;
}

/** Destroy the buffer.
 * @param b a buffer created with sparql_lexer__create_buffer()
 * @param yyscanner The scanner object.
 */
    void sparql_lexer__delete_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	if ( ! b )
		return;

	if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
		YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;

	if ( b->yy_is_our_buffer )
		sparql_lexer_free((void *) b->yy_ch_buf ,yyscanner );

	sparql_lexer_free((void *) b ,yyscanner );
}

/* Initializes or reinitializes a buffer.
 * This function is sometimes called more than once on the same buffer,
 * such as during a sparql_lexer_restart() or at EOF.
 */
    static void sparql_lexer__init_buffer  (YY_BUFFER_STATE  b, FILE * file , yyscan_t yyscanner)

{
	int oerrno = errno;
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	sparql_lexer__flush_buffer(b ,yyscanner);

	b->yy_input_file = file;
	b->yy_fill_buffer = 1;

    /* If b is the current buffer, then sparql_lexer__init_buffer was _probably_
     * called from sparql_lexer_restart() or through yy_get_next_buffer.
     * In that case, we don't want to reset the lineno or column.
     */
    if (b != YY_CURRENT_BUFFER){
        b->yy_bs_lineno = 1;
        b->yy_bs_column = 0;
    }

        b->yy_is_interactive = 0;
    
	errno = oerrno;
}

/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
 * @param yyscanner The scanner object.
 */
    void sparql_lexer__flush_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
	if ( ! b )
		return;

	b->yy_n_chars = 0;

	/* We always need two end-of-buffer characters.  The first causes
	 * a transition to the end-of-buffer state.  The second causes
	 * a jam in that state.
	 */
	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;

	b->yy_buf_pos = &b->yy_ch_buf[0];

	b->yy_at_bol = 1;
	b->yy_buffer_status = YY_BUFFER_NEW;

	if ( b == YY_CURRENT_BUFFER )
		sparql_lexer__load_buffer_state(yyscanner );
}

/** Pushes the new state onto the stack. The new state becomes
 *  the current state. This function will allocate the stack
 *  if necessary.
 *  @param new_buffer The new state.
 *  @param yyscanner The scanner object.
 */
void sparql_lexer_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
	if (new_buffer == NULL)
		return;

	sparql_lexer_ensure_buffer_stack(yyscanner);

	/* This block is copied from sparql_lexer__switch_to_buffer. */
	if ( YY_CURRENT_BUFFER )
		{
		/* Flush out information for old buffer. */
		*yyg->yy_c_buf_p = yyg->yy_hold_char;
		YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
		}

	/* Only push if top exists. Otherwise, replace top. */
	if (YY_CURRENT_BUFFER)
		yyg->yy_buffer_stack_top++;
	YY_CURRENT_BUFFER_LVALUE = new_buffer;

	/* copied from sparql_lexer__switch_to_buffer. */
	sparql_lexer__load_buffer_state(yyscanner );
	yyg->yy_did_buffer_switch_on_eof = 1;
}

/** Removes and deletes the top of the stack, if present.
 *  The next element becomes the new top.
 *  @param yyscanner The scanner object.
 */
void sparql_lexer_pop_buffer_state (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
	if (!YY_CURRENT_BUFFER)
		return;

	sparql_lexer__delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
	YY_CURRENT_BUFFER_LVALUE = NULL;
	if (yyg->yy_buffer_stack_top > 0)
		--yyg->yy_buffer_stack_top;

	if (YY_CURRENT_BUFFER) {
		sparql_lexer__load_buffer_state(yyscanner );
		yyg->yy_did_buffer_switch_on_eof = 1;
	}
}

/* Allocates the stack if it does not exist.
 *  Guarantees space for at least one push.
 */
static void sparql_lexer_ensure_buffer_stack (yyscan_t yyscanner)
{
	int num_to_alloc;
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

	if (!yyg->yy_buffer_stack) {

		/* First allocation is just for 2 elements, since we don't know if this
		 * scanner will even need a stack. We use 2 instead of 1 to avoid an
		 * immediate realloc on the next call.
         */
		num_to_alloc = 1;
		yyg->yy_buffer_stack = (struct yy_buffer_state**)sparql_lexer_alloc
								(num_to_alloc * sizeof(struct yy_buffer_state*)
								, yyscanner);
		if ( ! yyg->yy_buffer_stack )
			YY_FATAL_ERROR( "out of dynamic memory in sparql_lexer_ensure_buffer_stack()" );
								  
		if(!yyg->yy_buffer_stack)
		  YY_FATAL_ERROR("ouf of memory - lexer yy_buffer_stack");

		memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
				
		yyg->yy_buffer_stack_max = num_to_alloc;
		yyg->yy_buffer_stack_top = 0;
		return;
	}

	if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){

		/* Increase the buffer to prepare for a possible push. */
		int grow_size = 8 /* arbitrary grow size */;

		num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
		yyg->yy_buffer_stack = (struct yy_buffer_state**)sparql_lexer_realloc
								(yyg->yy_buffer_stack,
								num_to_alloc * sizeof(struct yy_buffer_state*)
								, yyscanner);
		if ( ! yyg->yy_buffer_stack )
			YY_FATAL_ERROR( "out of dynamic memory in sparql_lexer_ensure_buffer_stack()" );

		/* zero only the new slots.*/
		if(!yyg->yy_buffer_stack)
		  YY_FATAL_ERROR("ouf of memory - lexer yy_buffer_stack");

		memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
		yyg->yy_buffer_stack_max = num_to_alloc;
	}
}

/** Setup the input buffer state to scan directly from a user-specified character buffer.
 * @param base the character buffer
 * @param size the size in bytes of the character buffer
 * @param yyscanner The scanner object.
 * @return the newly allocated buffer state object. 
 */
YY_BUFFER_STATE sparql_lexer__scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
{
	YY_BUFFER_STATE b;
    
	if ( size < 2 ||
	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
	     base[size-1] != YY_END_OF_BUFFER_CHAR )
		/* They forgot to leave room for the EOB's. */
		return 0;

	b = (YY_BUFFER_STATE) sparql_lexer_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in sparql_lexer__scan_buffer()" );

	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
	b->yy_buf_pos = b->yy_ch_buf = base;
	b->yy_is_our_buffer = 0;
	b->yy_input_file = 0;
	b->yy_n_chars = b->yy_buf_size;
	b->yy_is_interactive = 0;
	b->yy_at_bol = 1;
	b->yy_fill_buffer = 0;
	b->yy_buffer_status = YY_BUFFER_NEW;

	sparql_lexer__switch_to_buffer(b ,yyscanner );

	return b;
}

/** Setup the input buffer state to scan a string. The next call to sparql_lexer_lex() will
 * scan from a @e copy of @a str.
 * @param yystr a NUL-terminated string to scan
 * @param yyscanner The scanner object.
 * @return the newly allocated buffer state object.
 * @note If you want to scan bytes that may contain NUL values, then use
 *       sparql_lexer__scan_bytes() instead.
 */
YY_BUFFER_STATE sparql_lexer__scan_string (yyconst char * yystr , yyscan_t yyscanner)
{
    
	return sparql_lexer__scan_bytes(yystr,strlen(yystr) ,yyscanner);
}

/** Setup the input buffer state to scan the given bytes. The next call to sparql_lexer_lex() will
 * scan from a @e copy of @a bytes.
 * @param bytes the byte buffer to scan
 * @param len the number of bytes in the buffer pointed to by @a bytes.
 * @param yyscanner The scanner object.
 * @return the newly allocated buffer state object.
 */
YY_BUFFER_STATE sparql_lexer__scan_bytes  (yyconst char * yybytes, int  _yybytes_len , yyscan_t yyscanner)
{
	YY_BUFFER_STATE b;
	char *buf;
	yy_size_t n;
	int i;
    
	/* Get memory for full buffer, including space for trailing EOB's. */
	n = _yybytes_len + 2;
	buf = (char *) sparql_lexer_alloc(n ,yyscanner );
	if ( ! buf )
		YY_FATAL_ERROR( "out of dynamic memory in sparql_lexer__scan_bytes()" );

	for ( i = 0; i < _yybytes_len; ++i )
		buf[i] = yybytes[i];

	buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;

	b = sparql_lexer__scan_buffer(buf,n ,yyscanner);
	if ( ! b )
		YY_FATAL_ERROR( "bad buffer in sparql_lexer__scan_bytes()" );

	/* It's okay to grow etc. this buffer, and we should throw it
	 * away when we're done.
	 */
	b->yy_is_our_buffer = 1;

	return b;
}

#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif


/* Redefine yyless() so it works in section 3 code. */

#undef yyless
#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
        int yyless_macro_arg = (n); \
        YY_LESS_LINENO(yyless_macro_arg);\
		yytext[yyleng] = yyg->yy_hold_char; \
		yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
		yyg->yy_hold_char = *yyg->yy_c_buf_p; \
		*yyg->yy_c_buf_p = '\0'; \
		yyleng = yyless_macro_arg; \
		} \
	while ( 0 )

/* Accessor  methods (get/set functions) to struct members. */

/** Get the user-defined data for this scanner.
 * @param yyscanner The scanner object.
 */
YY_EXTRA_TYPE sparql_lexer_get_extra  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yyextra;
}

/** Get the current line number.
 * @param yyscanner The scanner object.
 */
int sparql_lexer_get_lineno  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    
        if (! YY_CURRENT_BUFFER)
            return 0;
    
    return yylineno;
}

/** Get the current column number.
 * @param yyscanner The scanner object.
 */
int sparql_lexer_get_column  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    
        if (! YY_CURRENT_BUFFER)
            return 0;
    
    return yycolumn;
}

/** Get the input stream.
 * @param yyscanner The scanner object.
 */
FILE *sparql_lexer_get_in  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yyin;
}

/** Get the output stream.
 * @param yyscanner The scanner object.
 */
FILE *sparql_lexer_get_out  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yyout;
}

/** Get the length of the current token.
 * @param yyscanner The scanner object.
 */
int sparql_lexer_get_leng  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yyleng;
}

/** Get the current token.
 * @param yyscanner The scanner object.
 */

char *sparql_lexer_get_text  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yytext;
}

/** Set the user-defined data. This data is never touched by the scanner.
 * @param user_defined The data to be associated with this scanner.
 * @param yyscanner The scanner object.
 */
void sparql_lexer_set_extra (YY_EXTRA_TYPE  user_defined , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    yyextra = user_defined ;
}

/** Set the current line number.
 * @param line_number
 * @param yyscanner The scanner object.
 */
void sparql_lexer_set_lineno (int  line_number , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

        /* lineno is only valid if an input buffer exists. */
        if (! YY_CURRENT_BUFFER )
           YY_FATAL_ERROR("sparql_lexer_set_lineno called with no buffer"); 
    
    yylineno = line_number;
}

/** Set the current column.
 * @param line_number
 * @param yyscanner The scanner object.
 */
void sparql_lexer_set_column (int  column_no , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

        /* column is only valid if an input buffer exists. */
        if (! YY_CURRENT_BUFFER )
           YY_FATAL_ERROR("sparql_lexer_set_column called with no buffer"); 
    
    yycolumn = column_no;
}

/** Set the input stream. This does not discard the current
 * input buffer.
 * @param in_str A readable stream.
 * @param yyscanner The scanner object.
 * @see sparql_lexer__switch_to_buffer
 */
void sparql_lexer_set_in (FILE *  in_str , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    yyin = in_str ;
}

void sparql_lexer_set_out (FILE *  out_str , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    yyout = out_str ;
}

int sparql_lexer_get_debug  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yy_flex_debug;
}

void sparql_lexer_set_debug (int  bdebug , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    yy_flex_debug = bdebug ;
}

/* Accessor methods for yylval and yylloc */

/* User-visible API */

/* sparql_lexer_lex_init is special because it creates the scanner itself, so it is
 * the ONLY reentrant function that doesn't take the scanner as the last argument.
 * That's why we explicitly handle the declaration, instead of using our macros.
 */

int sparql_lexer_lex_init(yyscan_t* ptr_yy_globals)

{
    if (ptr_yy_globals == NULL){
        errno = EINVAL;
        return 1;
    }

    *ptr_yy_globals = (yyscan_t) sparql_lexer_alloc ( sizeof( struct yyguts_t ), NULL );

    if (*ptr_yy_globals == NULL){
        errno = ENOMEM;
        return 1;
    }

    /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));

    return yy_init_globals ( *ptr_yy_globals );
}

/* sparql_lexer_lex_init_extra has the same functionality as sparql_lexer_lex_init, but follows the
 * convention of taking the scanner as the last argument. Note however, that
 * this is a *pointer* to a scanner, as it will be allocated by this call (and
 * is the reason, too, why this function also must handle its own declaration).
 * The user defined value in the first argument will be available to sparql_lexer_alloc in
 * the yyextra field.
 */

int sparql_lexer_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )

{
    struct yyguts_t dummy_yyguts;

    sparql_lexer_set_extra (yy_user_defined, &dummy_yyguts);

    if (ptr_yy_globals == NULL){
        errno = EINVAL;
        return 1;
    }
	
    *ptr_yy_globals = (yyscan_t) sparql_lexer_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
	
    if (*ptr_yy_globals == NULL){
        errno = ENOMEM;
        return 1;
    }
    
    /* By setting to 0xAA, we expose bugs in
    yy_init_globals. Leave at 0x00 for releases. */
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
    
    sparql_lexer_set_extra (yy_user_defined, *ptr_yy_globals);
    
    return yy_init_globals ( *ptr_yy_globals );
}

static int yy_init_globals (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    /* Initialization is the same as for the non-reentrant scanner.
     * This function is called from sparql_lexer_lex_destroy(), so don't allocate here.
     */

    yyg->yy_buffer_stack = 0;
    yyg->yy_buffer_stack_top = 0;
    yyg->yy_buffer_stack_max = 0;
    yyg->yy_c_buf_p = (char *) 0;
    yyg->yy_init = 0;
    yyg->yy_start = 0;

    yyg->yy_start_stack_ptr = 0;
    yyg->yy_start_stack_depth = 0;
    yyg->yy_start_stack =  NULL;

/* Defined in main.c */
#ifdef YY_STDINIT
    yyin = stdin;
    yyout = stdout;
#else
    yyin = (FILE *) 0;
    yyout = (FILE *) 0;
#endif

    /* For future reference: Set errno on error, since we are called by
     * sparql_lexer_lex_init()
     */
    return 0;
}

/* sparql_lexer_lex_destroy is for both reentrant and non-reentrant scanners. */
int sparql_lexer_lex_destroy  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;

    /* Pop the buffer stack, destroying each element. */
	while(YY_CURRENT_BUFFER){
		sparql_lexer__delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
		YY_CURRENT_BUFFER_LVALUE = NULL;
		sparql_lexer_pop_buffer_state(yyscanner);
	}

	/* Destroy the stack itself. */
	sparql_lexer_free(yyg->yy_buffer_stack ,yyscanner);
	yyg->yy_buffer_stack = NULL;

    /* Destroy the start condition stack. */
        sparql_lexer_free(yyg->yy_start_stack ,yyscanner );
        yyg->yy_start_stack = NULL;

    /* Reset the globals. This is important in a non-reentrant scanner so the next time
     * sparql_lexer_lex() is called, initialization will occur. */
    yy_init_globals( yyscanner);

    /* Destroy the main struct (reentrant only). */
    /* clean up leaks if any before freeing yyscanner */
    sparql_lexer_cleanup(yyscanner);
    sparql_lexer_free ( yyscanner , yyscanner );
    yyscanner = NULL;
    return 0;
}

/*
 * Internal utility routines.
 */

#ifndef yytext_ptr
static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
{
	register int i;
	for ( i = 0; i < n; ++i )
		s1[i] = s2[i];
}
#endif

#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
{
	register int n;
	for ( n = 0; s[n]; ++n )
		;

	return n;
}
#endif

#define YYTABLES_NAME "yytables"

#line 574 "./sparql_lexer.l"


  /* user code */

int
sparql_lexer_wrap (yyscan_t yyscanner) {
  return 1;
}


static int
rasqal_sparql_name_check(unsigned char *string, size_t length,
                         sparql_name_check_flags check_flags)
{
  int rc=0;
  int c= -1;
#if RASQAL_DEBUG > 2
  RASQAL_DEBUG1("Checking name '");
  if(length)
     fwrite(string, length, sizeof(unsigned char), stderr);
  fprintf(stderr, "' (length %d), flags %d\n", (int)length, (int)check_flags);
#endif

  if(!length)
    return 1;

  if(check_flags && SPARQL_NAME_CHECK_ALLOW_09_FIRST &&
     (*string >= '0' && *string <= '9')) {
    c=*string;
    *string='X';
  }

  if(!raptor_xml_name_check(string, length, 11)) /* 11 = XML 1.1 */
    goto done;
  
  if((check_flags & SPARQL_NAME_CHECK_NO_UL_FIRST) && *string == '_')
    goto done;

  if((check_flags & SPARQL_NAME_CHECK_NO_DOT_LAST) && string[length-1] == '.')
    goto done;

  if(check_flags & SPARQL_NAME_CHECK_NO_DOT_MINUS) {
    int i;
    for(i=0; i < (int)length; i++)
      if(string[i] == '.' || string[i] == '-')
        goto done;
  }
  rc=1;

  done:
  if(c >=0)
    *string=c;
  return rc;
}


static unsigned char *
sparql_copy_name(rasqal_query *rq, const unsigned char *text, size_t len,
                 sparql_name_check_flags check_flags) {
  size_t dest_len=0;
  unsigned char *s;

  s=rasqal_escaped_name_to_utf8_string((unsigned char*)text, len,
                                       &dest_len,
                                       (raptor_simple_message_handler)sparql_syntax_error, rq);
  if(!s)
    return s;

  if(!rasqal_sparql_name_check(s, dest_len, check_flags))
    sparql_syntax_error(rq, "Invalid SPARQL name \"%s\"", s);

  return s;
}


static raptor_uri*
sparql_copy_qname(rasqal_query *rq, const unsigned char *text, size_t len) {
  unsigned char *p;
  size_t dest_len=0;
  unsigned char *s;
  raptor_uri* uri=NULL;
  
  s=rasqal_escaped_name_to_utf8_string((unsigned char*)text, len,
                                       &dest_len,
                                       (raptor_simple_message_handler)sparql_syntax_error, rq);
  if(!s)
    return NULL;

  p=(unsigned char*)strchr((const char*)s, ':');
  if(!rasqal_sparql_name_check(s, p-s, SPARQL_NAME_CHECK_PREFIX))
    sparql_syntax_error(rq, "Invalid SPARQL prefix name \"%s\"", s);
  if(!rasqal_sparql_name_check(p+1, dest_len-((p+1)-s), SPARQL_NAME_CHECK_NCNAME))
    sparql_syntax_error(rq, "Invalid SPARQL local name \"%s\"", p+1);

#ifdef STANDALONE
  /* lexer test cannot declare namespaces - so just ignore expansion */
  uri=raptor_new_uri_relative_to_base(rq->base_uri, s);
#else
  if(!rq->namespaces) {
    sparql_syntax_error(rq, "SPARQL syntax error - no namespaces declared");
    return NULL;
  }
  
  uri=raptor_qname_string_to_uri(rq->namespaces,
                                 s, dest_len,
                                 (raptor_simple_message_handler)rasqal_query_simple_error, rq);
#endif
  RASQAL_FREE(cstring, s);
  
  return uri;
}


static int
sparql_copy_string_token(rasqal_query* rq, YYSTYPE* lval,
                         const unsigned char *text, size_t len, int delim) {
  unsigned int i;
  const unsigned char *s;
  unsigned char *d;
  unsigned char *string;
  char *language=NULL;
  unsigned char *dt=NULL;
  raptor_uri *dt_uri=NULL;
  unsigned char *dt_qname=NULL;

  string=(unsigned char *)RASQAL_MALLOC(cstring, len+1);
  if(!string)
    return 1;

  for(s=text, d=string, i=0; i<len; s++, i++) {
    unsigned char c=*s;

    if(c == '\\' ) {
      s++; i++;
      c=*s;
      if(c == 'n')
        *d++= '\n';
      else if(c == 'r')
        *d++= '\r';
      else if(c == 't')
        *d++= '\t';
      else if(c == '\\' || c == delim)
        *d++=c;
      else if (c == 'u' || c == 'U') {
        int ulen=(c == 'u') ? 4 : 8;
        unsigned long unichar=0;
        int n;
        
        s++; i++;
        if(i+ulen > len) {
          printf("\\%c over end of line", c);
          RASQAL_FREE(cstring, string);
          return 1;
        }
        
        n=sscanf((const char*)s, ((ulen == 4) ? "%04lx" : "%08lx"), &unichar);
        if(n != 1) {
          sparql_syntax_error(rq, "SPARQL syntax error - Illegal Uncode escape '%c%s...'", c, s);
          RASQAL_FREE(cstring, string);
          return 1;
        }

        s+= ulen-1;
        i+= ulen-1;
        
        if(unichar > 0x10ffff) {
          sparql_syntax_error(rq, "SPARQL syntax error - Illegal Unicode character with code point #x%lX.", unichar);
          RASQAL_FREE(cstring, string);
          return 1;
        }
          
        d+=raptor_unicode_char_to_utf8(unichar, d);
      } else {
        /* Ignore \x where x isn't the one of: \n \r \t \\ (delim) \u \U */
        sparql_syntax_warning(rq, "Unknown SPARQL string escape \\%c in \"%s\"", c, text);
        *d++=c;
      }
    } else if(c== delim) {
      *d++='\0';

      /* skip delims (', ", ''' or """) */
      while(c == delim) {
        c=*s++; i++;
      }
      
      if(c=='@') {
        language=(char*)d;
        while(i<=len) {
          c=*s++; i++;
          if(!isalpha(c) && !isdigit(c) && c!= '-')
            break;
          *d++=c;
        }
        *d++='\0';
      }
      if(c=='^') {
        /* skip second char of ^^ */
        s++; i++;

        dt=d;
        while(i++<=len)
          *d++=*s++;
        /* *d='\0' below */
      } else if (language)
        *d='\0';
      
      break;
   } else
    *d++=c;
  } /* end of for */

  *d='\0';

  if(language) {
    char *new_language=(char *)RASQAL_MALLOC(cstring, strlen((const char*)language)+1);
    if(!new_language) {
      RASQAL_FREE(cstring, string);
      return 1;
    }
    strcpy(new_language, language);
    language=new_language;
  }
  
  if(dt) {
    /* dt can be a URI or qname */
    if(*dt == '<') {
      dt[strlen((const char*)dt)-1]='\0';
      dt_uri=raptor_new_uri(dt+1);
      if(!dt_uri) {
        if(language)
          RASQAL_FREE(cstring, language);
        RASQAL_FREE(cstring, string);
        return 1;
      }
    } else {
      unsigned char *dt_p;
      size_t dest_len=0;
      unsigned char *dt_s;
      
      dt_s=rasqal_escaped_name_to_utf8_string(dt,
                                              strlen((const char*)dt),
                                              &dest_len,
                                              (raptor_simple_message_handler)sparql_syntax_error, rq);
      if(!dt_s) {
        if(language)
          RASQAL_FREE(cstring, language);
        RASQAL_FREE(cstring, string);
        return 1;
      }

      dt_p=(unsigned char*)strchr((const char*)dt_s, ':');
      if(!rasqal_sparql_name_check(dt_s, dt_p-dt_s, SPARQL_NAME_CHECK_PREFIX))
        sparql_syntax_error(rq, "Invalid SPARQL prefix name \"%s\"", dt_s);
      if(!rasqal_sparql_name_check(dt_p+1, dest_len-((dt_p+1)-dt_s), 
                                   SPARQL_NAME_CHECK_NCNAME))
        sparql_syntax_error(rq, "Invalid SPARQL local name \"%s\"", dt_p+1);

#ifdef STANDALONE
      /* lexer test cannot declare namespaces - so just ignore expansion */
      dt_qname=dt_s;
#else
      if(!rq->namespaces) {
        sparql_syntax_error(rq, "SPARQL syntax error - no namespaces declared");
        RASQAL_FREE(cstring, dt_s);
        if(language)
          RASQAL_FREE(cstring, language);
        RASQAL_FREE(cstring, string);
        return 1;
      }
  
      dt_uri=raptor_qname_string_to_uri(rq->namespaces,
                                        dt_s, dest_len,
                                        (raptor_simple_message_handler)rasqal_query_simple_error, rq);
      RASQAL_FREE(cstring, dt_s);

      if(!dt_uri) {
        if(language)
          RASQAL_FREE(cstring, language);
        RASQAL_FREE(cstring, string);
        return 1;
      }
#endif
    }
  }

#if RASQAL_DEBUG >3
  fprintf(stderr, "string='%s', language='%s'\n", 
          string, (language ? language : ""));
  fprintf(stderr, "datatype uri='%s'\n",
          (dt_uri ? (const char*)raptor_uri_as_string(dt_uri) : ""));
#endif

  lval->literal=rasqal_new_string_literal(rq->world, string, language, dt_uri, dt_qname);
  if(!lval->literal)
    return 1;

  return 0;
}


static int
sparql_skip_c_comment(rasqal_query *rq) {
  rasqal_sparql_query_engine *rqe=(rasqal_sparql_query_engine*)rq->context;
  yyscan_t yyscanner=rqe->scanner;
  int lines=0;
  int c;
  int lastc= -1;
  
  while(1) {
    while ((c=INPUT_FN(yyscanner)) != '*' && c!= EOF) {
      if(c == '\r' || (c == '\n' && lastc != '\r'))
        lines++;
      lastc= c;
    }
    if( c == '*') {
      while ((c=INPUT_FN(yyscanner)) == '*') {
        if(c == '\r' || (c == '\n' && lastc != '\r'))
          lines++;
        lastc= c;
      }

      if(c == '/')
        break;
    }
    if (c == EOF) {
      sparql_syntax_error(rq, "SPARQL syntax error - EOF in comment");
      lines= -1;
      break;
    }
    lastc= c;
  }
  return lines;
}


/*
 * sparql_lexer_fatal_error:
 * @msg:
 * @yyscanner:
 *
 * INTERNAL - replacement for the generated error handler.
 * Uses rasqal_query_fatal_error() when possible.
 */
static void sparql_lexer_fatal_error(yyconst char *msg, yyscan_t yyscanner)
{
  rasqal_query *rq=NULL;

  if(yyscanner)
    rq=(rasqal_query *)sparql_lexer_get_extra(yyscanner);

  if(rq) {
    /* avoid "format not a string literal and no format arguments" warning with %s */
    rq->failed=1;
    rasqal_log_error_simple(rq->world, RAPTOR_LOG_LEVEL_FATAL,
                            &rq->locator, "%s", msg); 
  } else {
    fputs(msg, stderr);
    fputc('\n', stderr);
  }
}


/* Define LEXER_ALLOC_TRACKING to enable allocated memory tracking
 * - fixes lexer memory leak when ensure_buffer_stack fails
 */

#ifdef LEXER_ALLOC_TRACKING
typedef struct {
  /* Number of void* slots allocated */
  int lexer_allocs_size;
  /* Allocted void* slots follow in memory after this header */
} lexer_alloc_tracker_header;

/* Initial alloc tracker slot array size - 2 seems to be enough for almost all cases */
static const int initial_lexer_allocs_size=2;
#endif

/*
 * sparql_lexer_cleanup:
 * @yyscanner:
 *
 * INTERNAL - Clean up unfreed lexer allocs if LEXER_ALLOC_TRACKING is enabled.
 */
static void sparql_lexer_cleanup(yyscan_t yyscanner)
{
#ifdef LEXER_ALLOC_TRACKING
  rasqal_query *rq;
  lexer_alloc_tracker_header *tracker;
  void **lexer_allocs;
  int i;

  if(!yyscanner)
    return;

  rq=(rasqal_query *)sparql_lexer_get_extra(yyscanner);
  if(!rq)
    return;

  tracker=(lexer_alloc_tracker_header *)rq->lexer_user_data;
  if(!tracker)
    return;
  lexer_allocs=(void**)&tracker[1];

  for(i=0; i<tracker->lexer_allocs_size; ++i) {
    if(lexer_allocs[i])
      free(lexer_allocs[i]);
    lexer_allocs[i]=NULL;
  }
  free(rq->lexer_user_data);
  rq->lexer_user_data=NULL;
#endif
}


/*
 * sparql_lexer_alloc:
 * @size
 * @yyscanner
 *
 * INTERNAL - alloc replacement.
 * Tracks allocated cells if LEXER_ALLOC_TRACKING is enabled.
 */
void *sparql_lexer_alloc(yy_size_t size, yyscan_t yyscanner)
{
#ifdef LEXER_ALLOC_TRACKING
  rasqal_query *rq;
  lexer_alloc_tracker_header *tracker;
  void **lexer_allocs;
  int i;
  void *ptr;

  /* yyscanner not initialized -> probably initializing yyscanner itself
   * -> just malloc without tracking
   */
  if(!yyscanner)
    return malloc(size);

  rq=(rasqal_query *)sparql_lexer_get_extra(yyscanner);
  if(!rq)
    YY_FATAL_ERROR("lexer_alloc: yyscanner extra not initialized");

  /* try to allocate tracker if it does not exist */
  tracker=(lexer_alloc_tracker_header *)rq->lexer_user_data;
  if(!tracker) {
    /* allocate tracker header + array of void* slots */
    tracker=calloc(1, sizeof(lexer_alloc_tracker_header)+initial_lexer_allocs_size*sizeof(void*));
    if(!tracker)
      YY_FATAL_ERROR("lexer_alloc: cannot allocate tracker");
    tracker->lexer_allocs_size=initial_lexer_allocs_size;
    rq->lexer_user_data=(void *)tracker;
  }
  lexer_allocs=(void**)&tracker[1];

  /* allocate memory */
  ptr=malloc(size);
  
  /* find a free slot for ptr */
  for(i=0; i<tracker->lexer_allocs_size; ++i) {
    if(!lexer_allocs[i]) {
      lexer_allocs[i]=ptr;
      break;
    }
  }

  /* no free slots -> grow tracker slot array */
  if(i>=tracker->lexer_allocs_size) {
    int j;
    void **dest;
    tracker=calloc(1, sizeof(lexer_alloc_tracker_header)+i*2*sizeof(void*));
    if(!tracker) {
      if(ptr)
        free(ptr);
      YY_FATAL_ERROR("lexer_alloc: cannot grow tracker");
    }
    tracker->lexer_allocs_size=i*2;
    
    /* copy data from old tracker */
    dest=(void**)&tracker[1];
    for(j=0; j<i; ++j) {
      dest[j]=lexer_allocs[j];
    }
    
    /* set new item to first free slot */
    dest[j]=ptr;

    /* free old tracker and replace with new one */
    free(rq->lexer_user_data);
    rq->lexer_user_data=tracker;
  }

  return ptr;
#else
  return malloc(size);
#endif
}


/*
 * sparql_lexer_realloc:
 *
 * INTERNAL - realloc replacement
 * Tracks allocated cells if LEXER_ALLOC_TRACKING is enabled.
 */
void *sparql_lexer_realloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
{
#ifdef LEXER_ALLOC_TRACKING
  rasqal_query *rq;
  lexer_alloc_tracker_header *tracker;
  void **lexer_allocs;
  int i;
  void *newptr;

  if(!yyscanner)
    YY_FATAL_ERROR("lexer_realloc: yyscanner not initialized");

  rq=(rasqal_query *)sparql_lexer_get_extra(yyscanner);
  if(!rq)
    YY_FATAL_ERROR("lexer_realloc: yyscanner extra not initialized");

  tracker=(lexer_alloc_tracker_header *)rq->lexer_user_data;
  if(!tracker)
    YY_FATAL_ERROR("lexer_realloc: no alloc tracker");
  lexer_allocs=(void**)&tracker[1];

  /* find the old slot for ptr */
  for(i=0; i<tracker->lexer_allocs_size; ++i) {
    if(lexer_allocs[i]==ptr)
      break;
  }

  /* no old slot -> error */  
  if(i>=tracker->lexer_allocs_size)
    YY_FATAL_ERROR("lexer_realloc: cell not in tracker");

  /* realloc */
  newptr=realloc((char*)ptr, size);

  /* replace entry in tracker */
  lexer_allocs[i]=newptr;

  return newptr;
#else
  return realloc((char*)ptr, size);
#endif
}


/*
 * sparql_lexer_free:
 *
 * INTERNAL - free replacement.
 * Checks for NULL pointer to be freed unlike the default lexer free function.
 * Tracks allocated cells if LEXER_ALLOC_TRACKING is enabled.
 */
void sparql_lexer_free(void *ptr, yyscan_t yyscanner)
{
#ifdef LEXER_ALLOC_TRACKING
  rasqal_query *rq;
  lexer_alloc_tracker_header *tracker;
  void **lexer_allocs;
  int i;

  /* do not free NULL */
  if(!ptr)
    return;

  /* free ptr even if we would encounter an error */
  free(ptr);

  /* yyscanner is allocated with sparql_lexer_alloc() but it's never stored in the tracker
   * - we need yyscanner to access the tracker */
  if(!yyscanner || ptr==yyscanner)
    return;

  rq=(rasqal_query *)sparql_lexer_get_extra(yyscanner);
  if(!rq)
    return;

  tracker=(lexer_alloc_tracker_header *)rq->lexer_user_data;
  if(!tracker)
    return;
  lexer_allocs=(void**)&tracker[1];

  /* find the slot for ptr */
  for(i=0; i<tracker->lexer_allocs_size; ++i) {
    if(lexer_allocs[i]==ptr)
      break;
  }

  /* no slot -> error */  
  if(i>=tracker->lexer_allocs_size)
    YY_FATAL_ERROR("lexer_free: cell not in tracker");

  /* remove entry from tracker */
  lexer_allocs[i]=NULL;
#else
  if(ptr)
    free(ptr);
#endif
}


#ifdef RASQAL_DEBUG

const char *
sparql_token_print(int token, YYSTYPE *lval)
{
  static char buffer[2048];

  if(!token)
    return "<<EOF>>";
  
  switch(token) {
    case SELECT:
      return "SELECT";

    case FROM:
      return "FROM";

    case WHERE:
      return "WHERE";

    case PREFIX:
      return "PREFIX";

    case DESCRIBE:
      return "DESCRIBE";

    case CONSTRUCT:
      return "CONSTRUCT";

    case ASK:
      return "ASK";

    case DISTINCT:
      return "DISTINCT";

    case LIMIT:
      return "LIMIT";

    case UNION:
      return "UNION";

    case OPTIONAL:
      return "OPTIONAL";

    case BASE:
      return "BASE";

    case BOUND:
      return "BOUND";

    case STR:
      return "STR";
      
    case LANG:
      return "LANG";
      
    case DATATYPE:
      return "DATATYPE";
      
    case ISURI:
      return "ISURI";
      
    case ISBLANK:
      return "ISBLANK";
      
    case ISLITERAL:
      return "ISLITERAL";
      
    case GRAPH:
      return "GRAPH";
      
    case NAMED:
      return "NAMED";
      
    case FILTER:
      return "FILTER";

    case OFFSET:
      return "OFFSET";
      
    case A:
      return "a";
      
    case ORDER:
      return "ORDER";
      
    case BY:
      return "BY";
      
    case REGEX:
      return "REGEX";
      
    case ASC:
      return "ASC[";
      
    case DESC:
      return "DESC[";
      
    case LANGMATCHES:
      return "LANGMATCHES";
      
    case ',':
      return ",";

    case '(':
      return "(";

    case ')':
      return ")";

    case '[':
      return "[";

    case ']':
      return "]";

    case '{':
      return "{";

    case '}':
      return "}";

    case '.':
      return ".";

    case ';':
      return ";";

    case '?':
      return "?";

    case '$':
      return "$";

    case SC_AND:
      return "SC_AND";

    case SC_OR:
      return "SC_OR";

    case GE:
      return "GE";

    case LE:
      return "LE";

    case GT:
      return "GT";

    case LT:
      return "LT";

    case NEQ:
      return "NEQ";

    case EQ:
      return "EQ";

    case '/':
      return "/";

    case '*':
      return "*";

    case '-':
      return "-";

    case '+':
      return "+";

    case '!':
      return "!";

    case EXPLAIN:
      return "EXPLAIN";

    case GROUP:
      return "GROUP";

    case COUNT:
      return "COUNT";

    case AS:
      return "AS";

    case INTEGER_LITERAL:
    case INTEGER_POSITIVE_LITERAL:
    case INTEGER_NEGATIVE_LITERAL:
      sprintf(buffer, "INTEGER_LITERAL(%d)", lval->literal->value.integer);
      return buffer;

    case DOUBLE_LITERAL:
    case DOUBLE_POSITIVE_LITERAL:
    case DOUBLE_NEGATIVE_LITERAL:
      sprintf(buffer, "DOUBLE_LITERAL(%g)", lval->floating);
      return buffer;

    case STRING_LITERAL:
      if(lval->literal->language) {
        if(lval->literal->datatype)
          sprintf(buffer, "STRING_LITERAL(\"%s\"@%s^^%s)",
                  lval->literal->string, lval->literal->language,
                  raptor_uri_as_string(lval->literal->datatype));
        else
          sprintf(buffer, "STRING_LITERAL(\"%s\"@%s)",
                  lval->literal->string, lval->literal->language);
      } else {
        if(lval->literal->datatype)
          sprintf(buffer, "STRING_LITERAL(\"%s\"^^%s)", 
                  lval->literal->string,
                  raptor_uri_as_string(lval->literal->datatype));
        else
          sprintf(buffer, "STRING_LITERAL(\"%s\")", lval->literal->string);
      }
      return buffer;

    case BOOLEAN_LITERAL:
      return (lval->literal->value.integer ? "BOOLEAN_LITERAL(true)" : "BOOLEAN_LITERAL(false)");

    case URI_LITERAL:
      sprintf(buffer, "URI_LITERAL(%s)", raptor_uri_as_string(lval->uri));
      return buffer;

    case QNAME_LITERAL:
      sprintf(buffer, "QNAME_LITERAL(%s)", lval->name);
      return buffer;

    case URI_LITERAL_BRACE:
      sprintf(buffer, "URI_LITERAL_BRACE(%s)", raptor_uri_as_string(lval->uri));
      return buffer;

    case QNAME_LITERAL_BRACE:
      sprintf(buffer, "QNAME_LITERAL_BRACE(%s)", lval->name);
      return buffer;

    case IDENTIFIER:
      sprintf(buffer, "IDENTIFIER(%s)", lval->name);
      return buffer;

    case BLANK_LITERAL:
      sprintf(buffer, "BLANK_LITERAL(%s)", lval->name);
      return buffer;

    case DECIMAL_LITERAL:
    case DECIMAL_POSITIVE_LITERAL:
    case DECIMAL_NEGATIVE_LITERAL:
      sprintf(buffer, "DECIMAL_LITERAL(%s)", lval->literal->string);
      return buffer;

   default:
     RASQAL_DEBUG2("UNKNOWN token %d - add a new case\n", token);
     abort();
  }
}
#endif



#ifdef STANDALONE
static void
sparql_token_free(int token, YYSTYPE *lval)
{
  if(!token)
    return;
  
  switch(token) {
    case STRING_LITERAL:
      rasqal_free_literal(lval->literal);
      break;
    case URI_LITERAL:
      raptor_free_uri(lval->uri);
      break;
    case IDENTIFIER:
    case BLANK_LITERAL:
      RASQAL_FREE(cstring, lval->name);
      break;
    case QNAME_LITERAL:
      if(lval->name)
        RASQAL_FREE(cstring, lval->name);
      break;
    default:
      break;
  }
}


#define FILE_READ_BUF_SIZE 2048

int
main(int argc, char *argv[]) 
{
  const char *program=rasqal_basename(argv[0]);
  char *query_string=NULL;
  rasqal_query rq;
  rasqal_sparql_query_engine sparql;
  yyscan_t scanner;
  int token=EOF;
  YYSTYPE lval;
  const unsigned char *uri_string;
  const char *filename=NULL;
  char *buf=NULL;
  size_t len;
  void *buffer;
  rasqal_world *world;

  world=rasqal_new_world();
  
  if(argc > 1) {
    FILE *fh;
    query_string=(char*)RASQAL_CALLOC(cstring, FILE_READ_BUF_SIZE, 1);
    filename=argv[1];
    fh=fopen(filename, "r");
    if(fh) {
      fread(query_string, FILE_READ_BUF_SIZE, 1, fh);
      fclose(fh);
    } else {
      fprintf(stderr, "%s: Cannot open file %s - %s\n", program, filename,
              strerror(errno));
      exit(1);
    }
  } else {
    filename="<stdin>";
    query_string=(char*)RASQAL_CALLOC(cstring, FILE_READ_BUF_SIZE, 1);
    fread(query_string, FILE_READ_BUF_SIZE, 1, stdin);
  }

  memset(&rq, 0, sizeof(rasqal_query));
  rq.world=world;
  memset(&sparql, 0, sizeof(rasqal_sparql_query_engine));

  sparql_lexer_lex_init(&sparql.scanner);
  scanner=sparql.scanner;

  len= strlen((const char*)query_string);
  buf= (char *)RASQAL_MALLOC(cstring, len+3);
  strncpy(buf, query_string, len);
  buf[len]= ' ';
  buf[len+1]= buf[len+2]='\0'; /* YY_END_OF_BUFFER_CHAR; */
  buffer= sparql_lexer__scan_buffer(buf, len+3, scanner);

  sparql_lexer_set_extra(&rq, scanner);

  /* Initialise enough of the rasqal_query and locator to get error messages */
  rq.context=&sparql;
  sparql.lineno=1;
  rq.locator.file=filename;
  rq.locator.column= -1;

  uri_string=raptor_uri_filename_to_uri_string(filename);
  rq.base_uri=raptor_new_uri(uri_string);
  raptor_free_memory((void*)uri_string);

  while(1) {
    memset(&lval, 0, sizeof(YYSTYPE));
    if(sparql_lexer_get_text(scanner) != NULL)
      printf("yyinput '%s'\n", sparql_lexer_get_text(scanner));
    token=sparql_lexer_lex(&lval,scanner);
#ifdef RASQAL_DEBUG
    printf("token %s\n", sparql_token_print(token, &lval));
#else
    printf("token %d\n", token);
#endif
    sparql_token_free(token, &lval);
    if(!token || token == EOF)
      break;
  }

  if(buf)
    RASQAL_FREE(cstring, buf);
  
  sparql_lexer_lex_destroy(scanner);

  raptor_free_uri(rq.base_uri);

  RASQAL_FREE(cstring, query_string);

  rasqal_free_world(world);

  if(rq.failed)
    return 1;
 
  return 0;
}
#endif

