#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
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
 * Ditto for the __ia64__ case accordingly.
 */
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#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 178
#define YY_END_OF_BUFFER 179
/* 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[626] =
    {   0,
        0,    0,    0,    0,    0,    0,    0,    0,  153,  153,
      157,  157,  179,  177,    4,    3,    3,  140,  177,  177,
      125,  177,  177,  120,  121,  138,  147,  119,  148,  128,
      139,  144,  172,  129,  177,  132,  135,  124,  177,  177,
      177,  177,  177,  177,  177,  177,  177,  177,  177,  177,
      177,  177,  177,  177,  177,  177,  177,  177,  177,  177,
      177,  122,  123,  177,  177,  118,  177,  177,  126,  177,
      127,  162,  161,  167,  163,  165,  166,  164,  171,  168,
      170,  171,  153,  153,  153,  154,  157,  157,  157,  158,
        4,    3,  133,    0,  150,    0,    0,  176,  176,  131,

        0,  149,    0,    0,  144,  145,    2,    0,  145,    0,
      172,  172,  141,  134,  134,  136,  175,    0,  134,  137,
      142,    0,    0,  172,    0,    0,    0,   45,    0,    0,
        0,    0,    0,   32,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,   59,   65,    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,   95,    0,  100,    0,    0,    0,    0,    0,    0,
        0,    0,  143,    0,  130,  161,  163,  166,  168,    0,

        0,  169,  153,  153,    0,    0,  157,  157,    0,    0,
      150,  151,  149,  155,    0,    0,    1,    1,  145,    0,
        0,  146,  172,    0,    0,  175,    0,  142,  102,   96,
       99,   34,   11,   42,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,   77,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,   60,    0,    0,    0,    0,
        0,    0,   49,    0,    0,   44,  106,   43,    0,    0,
        0,   64,   83,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,   21,

        0,   41,    0,    0,    0,    0,    0,    0,   61,    0,
        0,    0,    0,    0,  173,  152,  156,    0,  146,    0,
      146,    0,   17,   68,    0,    0,  104,    0,    0,    0,
        0,    0,   98,    0,    0,    0,   55,    0,    0,   35,
        0,   56,    0,    0,    0,    0,    0,    6,    0,    0,
        0,    0,    0,   58,    0,    0,    0,    0,   22,    0,
        0,   57,    0,    0,   97,    0,    0,    0,    0,    0,
      101,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,  107,    0,    0,    0,    0,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,  159,    0,    0,    0,

      115,    0,    0,   51,   75,  173,    0,    0,    0,  174,
        0,   62,   18,   52,    0,    0,    0,    0,   40,    0,
        0,    0,    0,    0,    0,    0,    0,    0,  160,    0,
      105,    0,   27,   38,    0,   78,    0,    0,   24,    0,
        0,    0,   90,   14,   72,    0,   76,   28,    0,    0,
       31,    0,    0,   33,    0,  103,    0,    0,    0,    0,
        0,    0,    0,    0,    0,    0,    0,    0,    0,   20,
        0,    0,    0,    0,    0,    0,    0,    0,   89,   70,
       15,    0,    7,    0,    0,   86,    0,    0,   53,    0,
        0,    0,   46,    0,    0,    0,    0,   29,    0,    0,

       39,   47,    0,    0,    0,    0,    0,   30,    0,    8,
        0,    0,    0,   74,    0,    5,    0,    0,  108,  109,
      110,  111,   54,    0,    0,    0,    0,   87,    0,    0,
       88,    0,    0,  117,    0,    0,    0,    0,    0,    0,
       63,    0,    0,    0,   37,    0,    0,   25,    0,    0,
        0,   79,    0,   13,  114,    0,   80,    0,   71,    0,
        0,   92,   19,    0,  116,    0,    0,   69,   50,    0,
       93,    0,   23,    9,   12,    0,    0,    0,    0,    0,
        0,   16,   48,    0,  113,    0,    0,   81,    0,   10,
        0,    0,    0,    0,   26,   73,    0,   67,  112,   91,

        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
        0,   36,   85,    0,    0,    0,   66,    0,    0,   84,
        0,   94,    0,   82,    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,   21,   22,
       23,   24,   25,   26,   20,   27,   20,   28,   29,   30,
       31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
       41,   42,   43,   44,   45,   46,   47,   48,   49,   50,
       44,   51,   52,   53,   54,   55,   56,   57,   58,   59,
       60,   61,   62,   63,   64,    1,   65,   36,   37,   38,

       39,   40,   41,   42,   43,   44,   45,   46,   47,   48,
       49,   50,   44,   66,   52,   53,   67,   55,   56,   57,
       58,   59,   68,   69,   70,    1,    1,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,

       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71,   71,   71,   71,   71,   71,
       71,   71,   71,   71,   71
    } ;

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

static yyconst flex_int16_t yy_base[645] =
    {   0,
        0,    0,   71,    0,  142,    0,  213,    0,  282,  283,
      284,  285,  810, 2645,  289, 2645,  796,  766,  286,  294,
     2645,  751,  281, 2645, 2645, 2645,  281, 2645,  291,  299,
      313,  313,  298, 2645,  352, 2645,  728, 2645,    0,  406,
      408,  421,  420,  417,  461,  450,  464,  466,  323,  502,
      493,  475,  515,  472,  529,  534,  531,  561,  412,  528,
      463, 2645, 2645,  695,  713,  567,  565,  589, 2645,  658,
     2645, 2645,    0, 2645,  423, 2645,    0, 2645, 2645,  427,
     2645,  409,  447,  461,  713,  473,  492,  502,  688,  430,
      570, 2645, 2645,  541,  690,    0,  345, 2645,  693, 2645,

      289,  683,    0,  624,  637,  645, 2645,  450,  665,  685,
     2645,  497, 2645,  646, 2645, 2645,  661,  574,  522, 2645,
        0,  507,  516,  579,  568,  614,  590,  685,  593,  665,
      605,  696,  697,  607,  611,  698,  700,  701,  705,  716,
      703,  714,  729,  735,  718,  734,  742,  755,  757,  758,
      759,  761,  763,  764,  766,  783,  772,  777,  780,  785,
      806,  807,  818,  812,  820,  826,  821,  827,  829,  834,
      841,  833,  838,  835,  865,  867,  866,  868,  869,  872,
      881,  887,  888,  893,  904,  906,  909,  918,  912,  920,
      925,  929, 2645,    0, 2645,    0,  636,    0,  672,  932,

      938, 2645,  621,  637,  672,  554,  677,  678,  581,  549,
     2645, 2645, 2645, 2645,  950,  494, 2645,  516,  959,  980,
      988,  996,  683,  784,  451, 2645, 1023,    0,  971, 1077,
     1078, 1079, 1080, 1081, 1082, 1084, 1085, 1083, 1086, 1098,
     1097, 1099, 1100, 1101, 1102, 1106, 1120, 1117, 1126, 1132,
     1128, 1141, 1146, 1148, 1152, 1150, 1155, 1161, 1159, 1164,
     1172, 1175, 1177, 1181, 1183, 1189, 1194, 1195, 1201, 1197,
     1206, 1203, 1209, 1217, 1220, 1224, 1231, 1235, 1238, 1239,
     1244, 1247, 1251, 1252, 1253, 1256, 1258, 1259, 1264, 1272,
     1275, 1281, 1287, 1289, 1288, 1295, 1292, 1318, 1294, 1343,

     1296, 1307, 1314, 1316, 1327, 1334, 1336, 1331, 1339, 1356,
     1345, 1340, 1359, 1370,  451, 2645, 2645, 1393, 1402, 1417,
     1425, 1452, 1372, 1506, 1507, 1509, 1374, 1508, 1511, 1510,
     1512, 1513, 1375, 1514, 1515, 1533, 1526, 1534, 1538, 1542,
     1553, 1535, 1559, 1555, 1564, 1566, 1558, 1567, 1571, 1582,
     1586, 1584, 1588, 1589, 1593, 1597, 1609, 1601, 1605, 1617,
     1623, 1625, 1629, 1631, 1632, 1637, 1646, 1643, 1649, 1650,
     1651, 1652, 1666, 1668, 1669, 1673, 1670, 1677, 1681, 1684,
     1686, 1692, 1699, 1704, 1716, 1710, 1712, 1718, 1721, 1723,
     1725, 1727, 1738, 1741, 1744, 1745, 1747, 1749, 1758, 1761,

     1750, 1763, 1767, 1769, 1782,  444,  428,    0,  399,  318,
     1783, 1786, 1789, 1790, 1794, 1795, 1798, 1797, 1801, 1802,
     1806, 1809, 1810, 1814, 1815, 1817, 1829, 1832, 1833, 1834,
     1841, 1845, 1848, 1852, 1853, 1854, 1856, 1859, 1860, 1865,
     1874, 1861, 1873, 1877, 1880, 1892, 1893, 1896, 1897, 1899,
     1900, 1901, 1904, 1905, 1912, 1916, 1917, 1918, 1923, 1920,
     1924, 1935, 1936, 1948, 1947, 1959, 1950, 1951, 1952, 1965,
     1967, 1966, 1968, 1972, 1970, 1973, 1981, 1984, 1990, 1992,
     1993, 1997, 2001, 2004, 2005, 2008, 2010, 2013, 2016, 2022,
     2028, 2029, 2025, 2030, 2034, 2037, 2041, 2042, 2045, 2058,

     2056, 2062, 2063, 2069, 2070, 2074, 2076, 2078, 2081, 2082,
     2085, 2087, 2089, 2094, 2096, 2101, 2113, 2114, 2115, 2116,
     2119, 2121, 2132, 2133, 2134, 2136, 2139, 2140, 2141, 2147,
     2145, 2153, 2156, 2158, 2159, 2161, 2175, 2176, 2177, 2178,
     2180, 2181, 2196, 2197, 2198, 2201, 2203, 2204, 2205, 2217,
     2218, 2220, 2225, 2229, 2233, 2236, 2238, 2240, 2241, 2244,
     2245, 2247, 2249, 2256, 2258, 2260, 2262, 2263, 2264, 2269,
     2275, 2276, 2280, 2284, 2288, 2289, 2295, 2300, 2301, 2302,
     2303, 2306, 2307, 2308, 2309, 2314, 2315, 2322, 2323, 2326,
     2328, 2337, 2342, 2340, 2343, 2344, 2351, 2355, 2357, 2358,

     2363, 2364, 2366, 2369, 2371, 2380, 2383, 2386, 2387, 2391,
     2395, 2398, 2400, 2403, 2406, 2411, 2409, 2415, 2417, 2424,
     2431, 2433, 2435, 2437, 2645, 2478, 2490, 2502, 2514, 2526,
     2534,  317, 2541, 2546, 2551, 2558, 2570, 2582, 2594, 2602,
     2614, 2621, 2625, 2632
    } ;

static yyconst flex_int16_t yy_def[645] =
    {   0,
      625,    1,  625,    3,  625,    5,  625,    7,  626,  626,
      627,  627,  625,  625,  625,  625,  625,  625,  628,  629,
      625,  625,  630,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  631,  625,  625,  625,  625,  625,  632,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  625,  625,  625,  625,  633,  633,  633,  625,  625,
      625,  625,  634,  625,  625,  625,  635,  625,  625,  625,
      625,  636,  637,  637,  625,  637,  638,  638,  625,  638,
      625,  625,  625,  628,  625,  628,  629,  625,  625,  625,

      630,  625,  630,  625,  625,  625,  625,  639,  625,  625,
      625,  640,  625,  641,  625,  625,  625,  641,  641,  625,
      642,  633,  633,  631,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  625,  643,  625,  634,  625,  635,  625,  636,

      636,  625,  637,  637,  637,  625,  638,  638,  638,  625,
      625,  625,  625,  625,  625,  639,  625,  625,  625,  625,
      625,  625,  640,  640,  641,  625,  625,  642,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,

      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  644,  625,  625,  625,  625,  625,
      625,  625,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,

      633,  633,  633,  633,  633,  644,  644,  322,  322,  625,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,

      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,

      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,  633,  633,  633,  633,  633,  633,
      633,  633,  633,  633,    0,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625
    } ;

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

       72,   72,   72,   72,   72,   73,   73,   73,   73,   73,
       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
       73,   73,   73,   73,   73,   73,   73,   73,   73,   73,
       72,   73,   72,   72,   73,   73,   73,   73,   72,   72,
       72,   73,   74,   75,   74,   74,   75,   74,   74,   74,
       76,   74,   74,   74,   74,   74,   74,   74,   74,   74,
       74,   77,   77,   77,   77,   77,   77,   77,   77,   74,
       74,   74,   74,   74,   78,   74,   77,   77,   77,   77,
       77,   77,   77,   77,   77,   77,   77,   77,   77,   77,
       77,   77,   77,   77,   77,   77,   77,   77,   77,   77,

       77,   74,   77,   74,   74,   77,   77,   77,   77,   74,
       74,   74,   77,   79,   80,   79,   79,   80,   79,   79,
       79,   79,   79,   79,   79,   79,   79,   79,   79,   79,
       79,   79,   79,   79,   79,   79,   79,   79,   79,   79,
       81,   79,   79,   79,   79,   79,   79,   82,   82,   82,
       82,   82,   82,   82,   82,   82,   82,   82,   82,   82,
       82,   82,   82,   82,   82,   82,   82,   82,   82,   82,
       82,   82,   79,   82,   79,   79,   79,   82,   82,   82,
       79,   79,   79,   82,   84,   84,   88,   88,   85,   85,
       91,  102,   95,   91,   89,   89,   98,   99,  104,  213,

      105,  105,  105,  105,  105,  105,  105,  105,  104,  111,
      105,  105,  105,  105,  105,  105,  105,  105,  106,  106,
      106,  106,  106,  106,  106,  106,  107,  121,  113,  226,
      109,  108,  105,  105,  105,  105,  105,  105,  105,  105,
      123,  103,   86,   86,   90,   90,   96,   98,   99,  103,
      124,  110,  114,  114,  114,  114,  115,  114,  114,  114,
      114,  114,  114,  114,  114,  114,  114,  114,  114,  114,
      114,  114,  114,  114,  114,  114,  114,  114,  114,  114,
      114,  115,  116,  117,  114,  114,  118,  118,  118,  118,
      118,  118,  118,  118,  118,  118,  118,  118,  118,  118,

      118,  118,  118,  118,  118,  118,  118,  118,  118,  118,
      118,  114,  114,  114,  114,  119,  118,  118,  118,  114,
      114,  114,  114,  123,  197,  123,  201,  197,  199,  123,
      117,  199,  625,  124,  123,  124,  202,  123,  123,  124,
      207,  125,  130,  126,  124,  407,  189,  124,  124,  204,
      131,  127,  217,  218,  140,  132,  133,  128,  141,  135,
      129,  407,  142,  204,  144,  134,  136,  123,  407,  137,
      143,  138,  130,  145,  139,  625,  189,  124,  123,  203,
      123,  123,  117,  123,  140,  143,  138,  139,  124,  123,
      124,  124,  123,  124,  208,  146,  217,  218,  151,  124,

      150,  192,  124,  147,  208,  153,  148,  205,  111,  166,
      123,  149,  152,  154,  224,  150,  155,  156,  217,  123,
      124,  205,  171,  167,  123,  146,  149,  162,  151,  124,
      163,  155,  123,  123,  124,  164,  157,  171,  158,  166,
      159,  165,  124,  625,  160,  123,  123,  211,  123,  227,
      161,  123,  209,  117,  168,  124,  124,  162,  124,  317,
      316,  124,  209,  172,  169,  170,  157,  173,  175,  190,
      191,   91,  176,  181,   91,  177,  178,  174,  123,  182,
      170,  183,  123,  625,  123,  123,  179,  180,  124,  184,
      111,  207,  124,  172,  124,  124,  183,  185,  175,  172,

      180,   96,  125,  173,  126,  117,  123,  123,  186,  625,
      123,  187,  127,  174,  188,  187,  124,  124,  128,  229,
      124,  129,  123,  204,  123,  185,  187,  188,  123,  172,
      187,  123,  124,  234,  124,  231,  186,  197,  124,  204,
      197,  124,  188,  106,  106,  106,  106,  106,  106,  106,
      106,  230,  236,  239,  109,  188,  105,  105,  105,  105,
      105,  105,  105,  105,  106,  106,  106,  106,  106,  106,
      106,  106,  226,  199,  625,  110,  199,  117,  203,  208,
      208,  205,  123,  215,  219,  219,  219,  219,  219,  219,
      219,  219,  124,  214,  111,   98,  212,  205,  210,  221,

      224,  221,  123,  220,  222,  222,  222,  222,  222,  222,
      222,  222,  124,  123,  123,  123,  235,  123,  123,  206,
      123,  232,  123,  124,  124,  124,  195,  124,  124,  233,
      124,  123,  124,  123,  241,  123,  240,  209,  209,  245,
      194,  124,  249,  124,  237,  124,  123,  242,  250,  243,
      238,  123,  123,  244,  251,  246,  124,  193,  120,  123,
      100,  124,  124,  238,  241,  252,  244,  255,  247,  124,
      246,  254,  123,  248,  123,  123,  123,  253,  123,  256,
      123,  123,  124,  123,  124,  124,  124,  257,  124,  123,
      124,  124,  260,  124,  123,  625,   93,  123,   92,  124,

      123,  224,  123,  258,  124,  259,  261,  124,  266,  625,
      124,  272,  124,  262,  263,  264,  265,  625,  267,  271,
      625,  625,  260,  123,  123,  268,  625,  263,  269,  123,
      270,  274,  273,  124,  124,  123,  268,  123,  123,  124,
      275,  272,  277,  123,  123,  124,  123,  124,  124,  268,
      123,  123,  123,  124,  124,  123,  124,  625,  123,  278,
      124,  124,  124,  276,  625,  124,  284,  279,  124,  625,
      275,  286,  281,  282,  280,  289,  283,  625,  290,  287,
      288,  285,  123,  123,  123,  123,  123,  291,  292,  123,
      625,  625,  124,  124,  124,  124,  124,  625,  123,  124,

      298,  292,  625,  294,  123,  123,  625,  301,  124,  625,
      123,  293,  295,  299,  124,  124,  296,  297,  302,  300,
      124,  123,  625,  123,  625,  625,  123,  303,  625,  123,
      298,  124,  297,  124,  300,  123,  124,  123,  306,  124,
      625,  305,  123,  307,  625,  124,  123,  124,  308,  201,
      304,  309,  124,  625,  305,  201,  124,  311,  312,  202,
      310,  625,  625,  314,  318,  625,  318,  625,  306,  319,
      319,  319,  319,  319,  319,  319,  319,  313,  219,  219,
      219,  219,  219,  219,  219,  219,  625,  625,  123,  625,
      625,  625,  625,  314,  320,  625,  320,  220,  124,  321,

      321,  321,  321,  321,  321,  321,  321,  222,  222,  222,
      222,  222,  222,  222,  222,  222,  222,  222,  222,  222,
      222,  222,  222,  225,  225,  225,  225,  225,  225,  225,
      225,  225,  225,  225,  225,  225,  225,  225,  225,  225,
      225,  225,  322,  322,  322,  322,  322,  322,  322,  322,
      225,  225,  225,  225,  117,  225,  225,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  225,  322,  225,  225,  322,  322,  322,  322,
      225,  225,  225,  322,  123,  123,  123,  123,  123,  123,

      123,  123,  123,  123,  124,  124,  124,  124,  124,  124,
      124,  124,  124,  124,  123,  123,  123,  123,  123,  123,
      323,  324,  325,  123,  124,  124,  124,  124,  124,  124,
      326,  327,  328,  124,  123,  330,  335,  123,  625,  625,
      625,  625,  329,  123,  124,  123,  625,  124,  334,  123,
      331,  332,  625,  124,  337,  124,  336,  333,  123,  124,
      338,  625,  328,  123,  340,  123,  335,  123,  124,  123,
      339,  336,  123,  124,  625,  124,  123,  124,  123,  124,
      625,  123,  124,  625,  337,  625,  124,  625,  124,  123,
      338,  124,  123,  341,  123,  342,  343,  344,  123,  124,

      123,  345,  124,  625,  124,  348,  123,  346,  124,  347,
      124,  123,  123,  349,  123,  625,  124,  351,  123,  353,
      123,  124,  124,  123,  124,  350,  123,  352,  124,  625,
      124,  354,  625,  124,  123,  625,  124,  123,  350,  355,
      625,  123,  352,  357,  124,  356,  359,  124,  123,  625,
      358,  124,  123,  625,  360,  123,  123,  362,  124,  361,
      356,  123,  124,  358,  123,  124,  124,  625,  123,  123,
      123,  124,  625,  123,  124,  123,  123,  365,  124,  124,
      124,  123,  366,  124,  625,  124,  124,  625,  363,  123,
      364,  124,  123,  625,  369,  368,  371,  370,  123,  124,

      625,  363,  124,  367,  123,  123,  123,  625,  124,  123,
      373,  123,  123,  123,  124,  124,  124,  372,  625,  124,
      374,  124,  124,  124,  123,  376,  379,  625,  375,  380,
      372,  123,  386,  123,  124,  123,  377,  378,  382,  383,
      384,  124,  385,  124,  123,  124,  381,  394,  123,  625,
      625,  123,  395,  123,  124,  625,  123,  123,  124,  380,
      123,  124,  123,  124,  625,  397,  124,  124,  625,  396,
      124,  625,  124,  123,  399,  625,  123,  387,  388,  400,
      389,  390,  396,  124,  625,  398,  124,  123,  391,  123,
      403,  123,  123,  401,  392,  625,  393,  124,  402,  124,

      404,  124,  124,  625,  625,  403,  625,  387,  625,  393,
      625,  402,  319,  319,  319,  319,  319,  319,  319,  319,
      405,  319,  319,  319,  319,  319,  319,  319,  319,  625,
      625,  625,  625,  625,  625,  405,  321,  321,  321,  321,
      321,  321,  321,  321,  321,  321,  321,  321,  321,  321,
      321,  321,  225,  225,  225,  225,  225,  225,  225,  225,
      225,  225,  225,  225,  225,  225,  225,  225,  408,  409,
      225,  408,  408,  408,  408,  408,  408,  408,  408,  225,
      225,  225,  225,  410,  225,  225,  408,  408,  408,  408,
      408,  408,  408,  408,  408,  408,  408,  408,  408,  408,

      408,  408,  408,  408,  408,  408,  408,  408,  408,  408,
      408,  225,  408,  225,  225,  408,  408,  408,  408,  225,
      225,  225,  408,  123,  123,  123,  123,  123,  123,  123,
      123,  123,  123,  124,  124,  124,  124,  124,  124,  124,
      124,  124,  124,  123,  416,  412,  413,  418,  411,  415,
      123,  123,  123,  124,  625,  123,  625,  625,  414,  123,
      124,  124,  124,  625,  417,  124,  419,  420,  625,  124,
      123,  421,  123,  414,  416,  123,  123,  418,  422,  625,
      124,  123,  124,  123,  123,  124,  124,  423,  123,  428,
      424,  124,  425,  124,  124,  426,  427,  625,  124,  123,

      423,  123,  429,  123,  430,  123,  123,  425,  431,  124,
      123,  124,  433,  124,  123,  124,  124,  625,  123,  428,
      124,  625,  123,  431,  124,  625,  123,  438,  124,  625,
      432,  434,  124,  435,  123,  436,  124,  625,  437,  439,
      123,  625,  123,  625,  124,  625,  123,  441,  123,  123,
      124,  442,  124,  437,  123,  443,  124,  438,  124,  124,
      123,  440,  625,  123,  124,  625,  123,  123,  123,  123,
      124,  625,  447,  124,  448,  444,  124,  124,  124,  124,
      445,  446,  625,  123,  449,  123,  123,  123,  453,  625,
      123,  450,  452,  124,  123,  124,  124,  124,  123,  451,

      124,  123,  455,  123,  124,  625,  456,  625,  124,  123,
      625,  124,  625,  124,  451,  458,  123,  460,  625,  124,
      463,  123,  454,  464,  459,  457,  124,  123,  462,  123,
      465,  124,  455,  123,  461,  123,  466,  124,  123,  124,
      123,  625,  123,  124,  123,  124,  625,  625,  124,  461,
      124,  468,  124,  625,  124,  123,  469,  467,  123,  472,
      625,  123,  123,  473,  123,  124,  123,  123,  124,  625,
      471,  124,  124,  470,  124,  123,  124,  124,  123,  474,
      123,  625,  625,  625,  123,  124,  123,  479,  124,  472,
      124,  475,  478,  476,  124,  625,  124,  480,  625,  123,

      123,  482,  477,  123,  475,  483,  123,  123,  481,  124,
      124,  123,  123,  124,  123,  123,  124,  124,  123,  123,
      625,  124,  124,  123,  124,  124,  123,  123,  124,  124,
      484,  123,  123,  124,  123,  625,  124,  124,  625,  488,
      489,  124,  124,  625,  124,  485,  123,  486,  487,  123,
      123,  123,  493,  490,  625,  492,  124,  494,  123,  124,
      124,  124,  123,  487,  495,  123,  491,  496,  124,  123,
      123,  123,  124,  123,  497,  124,  123,  123,  123,  124,
      124,  124,  123,  124,  498,  625,  124,  124,  124,  625,
      123,  123,  124,  501,  123,  506,  625,  123,  499,  498,

      124,  124,  625,  504,  124,  625,  503,  124,  502,  123,
      123,  499,  505,  123,  123,  500,  123,  123,  123,  124,
      124,  123,  123,  124,  124,  506,  124,  124,  124,  123,
      507,  124,  124,  123,  123,  123,  625,  123,  625,  124,
      123,  123,  511,  124,  124,  124,  509,  124,  512,  508,
      124,  124,  123,  123,  625,  513,  514,  510,  517,  519,
      515,  625,  124,  124,  123,  123,  625,  123,  123,  123,
      521,  518,  516,  520,  124,  124,  123,  124,  124,  124,
      522,  625,  123,  123,  123,  123,  124,  123,  517,  123,
      123,  525,  124,  124,  124,  124,  625,  124,  123,  124,

      124,  123,  523,  524,  526,  625,  529,  123,  124,  123,
      123,  124,  530,  527,  123,  528,  625,  124,  123,  124,
      124,  123,  123,  531,  124,  123,  533,  123,  124,  532,
      123,  124,  124,  123,  625,  124,  529,  124,  531,  123,
      124,  536,  123,  124,  535,  123,  123,  123,  534,  124,
      625,  123,  124,  625,  123,  124,  124,  124,  123,  123,
      538,  124,  123,  537,  124,  542,  625,  625,  124,  124,
      543,  625,  124,  123,  539,  123,  537,  540,  625,  123,
      123,  541,  625,  124,  625,  124,  123,  123,  545,  124,
      124,  123,  546,  123,  547,  123,  124,  124,  123,  123,

      544,  124,  123,  124,  123,  124,  123,  548,  124,  124,
      625,  123,  124,  123,  124,  553,  124,  625,  123,  549,
      550,  124,  554,  124,  625,  555,  551,  552,  124,  625,
      123,  123,  123,  123,  549,  550,  123,  625,  123,  556,
      124,  124,  124,  124,  625,  553,  124,  557,  124,  123,
      123,  123,  559,  123,  556,  625,  123,  123,  123,  124,
      124,  124,  123,  124,  123,  558,  124,  124,  124,  625,
      123,  560,  124,  123,  124,  123,  123,  625,  123,  563,
      124,  625,  561,  124,  565,  124,  124,  562,  124,  625,
      625,  564,  123,  123,  123,  123,  625,  123,  123,  569,

      566,  625,  124,  124,  124,  124,  564,  124,  124,  625,
      568,  570,  567,  123,  123,  123,  573,  625,  123,  574,
      123,  123,  123,  124,  124,  124,  625,  571,  124,  625,
      124,  124,  124,  625,  123,  123,  576,  123,  625,  579,
      572,  625,  123,  577,  124,  124,  123,  124,  575,  625,
      123,  578,  124,  123,  581,  123,  124,  123,  123,  580,
      124,  123,  123,  124,  123,  124,  123,  124,  124,  579,
      582,  124,  124,  123,  124,  123,  124,  123,  625,  123,
      123,  123,  583,  124,  625,  124,  123,  124,  584,  124,
      124,  124,  123,  123,  585,  586,  124,  123,  588,  625,

      625,  123,  124,  124,  625,  123,  123,  124,  587,  585,
      586,  124,  123,  591,  589,  124,  124,  123,  123,  123,
      123,  590,  124,  123,  123,  123,  123,  124,  124,  124,
      124,  123,  123,  124,  124,  124,  124,  592,  596,  123,
      123,  124,  124,  123,  597,  123,  595,  594,  625,  124,
      124,  593,  599,  124,  123,  124,  625,  123,  598,  123,
      123,  123,  602,  625,  124,  601,  600,  124,  123,  124,
      124,  124,  123,  598,  123,  123,  605,  625,  124,  625,
      123,  123,  124,  123,  124,  124,  123,  603,  123,  606,
      124,  124,  602,  124,  604,  625,  124,  123,  124,  625,

      123,  625,  603,  123,  123,  611,  625,  124,  123,  607,
      124,  610,  123,  124,  124,  123,  608,  123,  124,  625,
      123,  613,  124,  123,  614,  124,  123,  124,  123,  609,
      124,  612,  123,  124,  123,  611,  124,  616,  124,  625,
      615,  123,  124,  625,  124,  625,  625,  617,  123,  620,
      123,  124,  123,  615,  123,  618,  619,  621,  124,  622,
      124,  625,  124,  625,  124,  625,  625,  625,  625,  625,
      625,  619,  625,  624,  625,  625,  625,  623,   83,   83,
       83,   83,   83,   83,   83,   83,   83,   83,   83,   83,
       87,   87,   87,   87,   87,   87,   87,   87,   87,   87,

       87,   87,   94,  625,   94,   94,   94,   94,   94,   94,
       94,   94,   94,   94,   97,   97,   97,   97,   97,   97,
       97,   97,   97,   97,   97,   97,  101,  625,  101,  101,
      101,  101,  101,  101,  101,  101,  101,  101,  112,  625,
      625,  112,  625,  112,  112,  112,  122,  122,  122,  122,
      625,  122,  122,  196,  625,  625,  196,  196,  198,  625,
      625,  198,  198,  200,  200,  200,  200,  625,  200,  200,
      203,  203,  625,  203,  203,  203,  203,  203,  203,  203,
      203,  203,  207,  207,  207,  625,  207,  207,  207,  207,
      207,  207,  207,  207,  216,  216,  216,  216,  216,  216,

      216,  216,  216,  216,  216,  216,  223,  223,  223,  223,
      625,  625,  223,  223,  225,  225,  225,  225,  225,  225,
      225,  225,  225,  225,  225,  225,  228,  625,  228,  625,
      625,  228,  315,  625,  625,  315,  315,  406,  406,  406,
      625,  625,  406,  406,   13,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,

      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625
    } ;

static yyconst flex_int16_t yy_chk[2717] =
    {   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,
        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,    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,    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,    7,    7,    7,    7,    7,    7,    7,
        7,    7,    7,    7,    9,   10,   11,   12,    9,   10,
       15,   23,   19,   15,   11,   12,   20,   20,   27,  101,

       27,   27,   27,   27,   27,   27,   27,   27,   29,   33,
       29,   29,   29,   29,   29,   29,   29,   29,   30,   30,
       30,   30,   30,   30,   30,   30,   31,  632,   33,  410,
       32,   31,   32,   32,   32,   32,   32,   32,   32,   32,
       49,   23,    9,   10,   11,   12,   19,   97,   97,  101,
       49,   32,   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,   35,   35,   35,   35,   35,   35,   35,   35,
       35,   35,   35,   40,   75,   41,   82,   75,   80,   59,
      409,   80,   90,   40,   44,   41,   82,   43,   42,   59,
       90,   40,   41,   40,   44,  407,   59,   43,   42,   83,
       41,   40,  108,  108,   43,   41,   41,   40,   43,   42,
       40,  406,   43,   84,   44,   41,   42,   46,  315,   42,
       43,   42,   41,   44,   42,   86,   59,   46,   45,   86,
       61,   47,  225,   48,   43,   43,   42,   42,   45,   54,
       61,   47,   52,   48,   87,   45,  216,  216,   47,   54,

       46,   61,   52,   45,   88,   48,   45,   83,  112,   52,
       51,   45,   47,   48,  112,   46,   48,   48,  218,   50,
       51,   84,   54,   52,  122,   45,   45,   51,   47,   50,
       51,   48,   53,  123,  122,   51,   50,   54,   50,   52,
       50,   51,   53,  123,   50,   60,   55,   94,   57,  119,
       50,   56,   87,  119,   53,   60,   55,   51,   57,  210,
      206,   56,   88,   55,   53,   53,   50,   55,   56,   60,
       60,   91,   56,   57,   91,   56,   56,   55,   58,   57,
       53,   57,   67,  209,   66,  125,   56,   56,   58,   57,
      124,  209,   67,   55,   66,  125,   57,   58,   56,   67,

       56,   94,   66,   67,   66,  118,   68,  127,   58,  124,
      129,   58,   66,   67,   58,   67,   68,  127,   66,  125,
      129,   66,  131,  203,  134,   68,   58,   58,  135,   67,
       67,  126,  131,  129,  134,  127,   68,  197,  135,  204,
      197,  126,   68,  104,  104,  104,  104,  104,  104,  104,
      104,  126,  131,  135,  105,   68,  105,  105,  105,  105,
      105,  105,  105,  105,  106,  106,  106,  106,  106,  106,
      106,  106,  117,  199,  205,  105,  199,  114,  205,  207,
      208,  203,  130,  106,  109,  109,  109,  109,  109,  109,
      109,  109,  130,  102,  223,   99,   95,  204,   89,  110,

      223,  110,  128,  109,  110,  110,  110,  110,  110,  110,
      110,  110,  128,  132,  133,  136,  130,  137,  138,   85,
      141,  128,  139,  132,  133,  136,   70,  137,  138,  128,
      141,  142,  139,  140,  137,  145,  136,  207,  208,  138,
       65,  142,  141,  140,  132,  145,  143,  137,  141,  137,
      133,  146,  144,  137,  141,  139,  143,   64,   37,  147,
       22,  146,  144,  133,  137,  142,  137,  145,  140,  147,
      139,  144,  148,  140,  149,  150,  151,  143,  152,  146,
      153,  154,  148,  155,  149,  150,  151,  147,  152,  157,
      153,  154,  150,  155,  158,  224,   18,  159,   17,  157,

      156,  224,  160,  148,  158,  149,  150,  159,  155,   13,
      156,  158,  160,  151,  152,  154,  154,    0,  156,  157,
        0,    0,  150,  161,  162,  156,    0,  152,  156,  164,
      156,  160,  159,  161,  162,  163,  156,  165,  167,  164,
      161,  158,  163,  166,  168,  163,  169,  165,  167,  156,
      172,  170,  174,  166,  168,  173,  169,    0,  171,  164,
      172,  170,  174,  162,    0,  173,  168,  165,  171,    0,
      161,  170,  166,  167,  165,  173,  167,    0,  173,  171,
      172,  169,  175,  177,  176,  178,  179,  173,  174,  180,
        0,    0,  175,  177,  176,  178,  179,    0,  181,  180,

      177,  174,    0,  176,  182,  183,    0,  180,  181,    0,
      184,  175,  176,  178,  182,  183,  176,  176,  180,  179,
      184,  185,    0,  186,    0,    0,  187,  181,    0,  189,
      177,  185,  176,  186,  179,  188,  187,  190,  185,  189,
        0,  183,  191,  186,    0,  188,  192,  190,  186,  200,
      182,  187,  191,    0,  183,  201,  192,  189,  190,  200,
      188,    0,    0,  192,  215,  201,  215,    0,  185,  215,
      215,  215,  215,  215,  215,  215,  215,  191,  219,  219,
      219,  219,  219,  219,  219,  219,    0,    0,  229,    0,
        0,    0,    0,  192,  220,    0,  220,  219,  229,  220,

      220,  220,  220,  220,  220,  220,  220,  221,  221,  221,
      221,  221,  221,  221,  221,  222,  222,  222,  222,  222,
      222,  222,  222,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  227,  227,  227,  227,  227,  227,
      227,  227,  227,  227,  230,  231,  232,  233,  234,  235,

      238,  236,  237,  239,  230,  231,  232,  233,  234,  235,
      238,  236,  237,  239,  241,  240,  242,  243,  244,  245,
      235,  236,  237,  246,  241,  240,  242,  243,  244,  245,
      238,  239,  240,  246,  248,  242,  245,  247,    0,    0,
        0,    0,  241,  249,  248,  251,    0,  247,  244,  250,
      242,  242,    0,  249,  247,  251,  246,  243,  252,  250,
      249,    0,  240,  253,  251,  254,  245,  256,  252,  255,
      250,  246,  257,  253,    0,  254,  259,  256,  258,  255,
        0,  260,  257,    0,  247,    0,  259,    0,  258,  261,
      249,  260,  262,  252,  263,  253,  254,  255,  264,  261,

      265,  256,  262,    0,  263,  259,  266,  257,  264,  258,
      265,  267,  268,  260,  270,    0,  266,  262,  269,  264,
      272,  267,  268,  271,  270,  261,  273,  263,  269,    0,
      272,  265,    0,  271,  274,    0,  273,  275,  261,  267,
        0,  276,  263,  269,  274,  268,  271,  275,  277,    0,
      270,  276,  278,    0,  272,  279,  280,  275,  277,  274,
      268,  281,  278,  270,  282,  279,  280,    0,  283,  284,
      285,  281,    0,  286,  282,  287,  288,  280,  283,  284,
      285,  289,  281,  286,    0,  287,  288,    0,  278,  290,
      279,  289,  291,    0,  286,  285,  288,  287,  292,  290,

        0,  278,  291,  284,  293,  295,  294,    0,  292,  297,
      290,  299,  296,  301,  293,  295,  294,  289,    0,  297,
      291,  299,  296,  301,  302,  293,  295,    0,  292,  296,
      289,  303,  299,  304,  302,  298,  293,  294,  298,  298,
      298,  303,  298,  304,  305,  298,  297,  301,  308,    0,
        0,  306,  303,  307,  305,    0,  309,  312,  308,  296,
      300,  306,  311,  307,    0,  305,  309,  312,    0,  304,
      300,    0,  311,  310,  307,    0,  313,  300,  300,  308,
      300,  300,  304,  310,    0,  306,  313,  314,  300,  323,
      312,  327,  333,  310,  300,    0,  300,  314,  311,  323,

      313,  327,  333,    0,    0,  312,    0,  300,    0,  300,
        0,  311,  318,  318,  318,  318,  318,  318,  318,  318,
      314,  319,  319,  319,  319,  319,  319,  319,  319,    0,
        0,    0,    0,    0,    0,  314,  320,  320,  320,  320,
      320,  320,  320,  320,  321,  321,  321,  321,  321,  321,
      321,  321,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,

      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  322,  322,  322,  322,  322,  322,  322,
      322,  322,  322,  324,  325,  328,  326,  330,  329,  331,
      332,  334,  335,  324,  325,  328,  326,  330,  329,  331,
      332,  334,  335,  337,  330,  325,  326,  332,  324,  329,
      336,  338,  342,  337,    0,  339,    0,    0,  328,  340,
      336,  338,  342,    0,  331,  339,  334,  335,    0,  340,
      341,  336,  344,  328,  330,  347,  343,  332,  337,    0,
      341,  345,  344,  346,  348,  347,  343,  338,  349,  344,
      339,  345,  340,  346,  348,  341,  343,    0,  349,  350,

      338,  352,  345,  351,  346,  353,  354,  340,  347,  350,
      355,  352,  349,  351,  356,  353,  354,    0,  358,  344,
      355,    0,  359,  347,  356,    0,  357,  355,  358,    0,
      348,  350,  359,  351,  360,  352,  357,    0,  353,  356,
      361,    0,  362,    0,  360,    0,  363,  358,  364,  365,
      361,  359,  362,  353,  366,  360,  363,  355,  364,  365,
      368,  357,    0,  367,  366,    0,  369,  370,  371,  372,
      368,    0,  364,  367,  366,  361,  369,  370,  371,  372,
      363,  363,    0,  373,  367,  374,  375,  377,  372,    0,
      376,  368,  370,  373,  378,  374,  375,  377,  379,  369,

      376,  380,  374,  381,  378,    0,  375,    0,  379,  382,
        0,  380,    0,  381,  369,  377,  383,  379,    0,  382,
      383,  384,  373,  383,  378,  376,  383,  386,  381,  387,
      384,  384,  374,  385,  380,  388,  385,  386,  389,  387,
      390,    0,  391,  385,  392,  388,    0,    0,  389,  380,
      390,  387,  391,    0,  392,  393,  388,  386,  394,  391,
        0,  395,  396,  391,  397,  393,  398,  401,  394,    0,
      390,  395,  396,  389,  397,  399,  398,  401,  400,  392,
      402,    0,    0,    0,  403,  399,  404,  398,  400,  391,
      402,  393,  396,  394,  403,    0,  404,  399,    0,  405,

      411,  402,  395,  412,  393,  403,  413,  414,  400,  405,
      411,  415,  416,  412,  418,  417,  413,  414,  419,  420,
        0,  415,  416,  421,  418,  417,  422,  423,  419,  420,
      411,  424,  425,  421,  426,    0,  422,  423,    0,  418,
      420,  424,  425,    0,  426,  415,  427,  416,  417,  428,
      429,  430,  424,  421,    0,  423,  427,  425,  431,  428,
      429,  430,  432,  417,  426,  433,  422,  427,  431,  434,
      435,  436,  432,  437,  428,  433,  438,  439,  442,  434,
      435,  436,  440,  437,  430,    0,  438,  439,  442,    0,
      443,  441,  440,  435,  444,  442,    0,  445,  432,  430,

      443,  441,    0,  440,  444,    0,  438,  445,  437,  446,
      447,  432,  441,  448,  449,  434,  450,  451,  452,  446,
      447,  453,  454,  448,  449,  442,  450,  451,  452,  455,
      446,  453,  454,  456,  457,  458,    0,  460,    0,  455,
      459,  461,  453,  456,  457,  458,  450,  460,  455,  449,
      459,  461,  462,  463,    0,  457,  458,  452,  461,  463,
      459,    0,  462,  463,  465,  464,    0,  467,  468,  469,
      465,  462,  460,  464,  465,  464,  466,  467,  468,  469,
      466,    0,  470,  472,  471,  473,  466,  475,  461,  474,
      476,  469,  470,  472,  471,  473,    0,  475,  477,  474,

      476,  478,  467,  468,  471,    0,  474,  479,  477,  480,
      481,  478,  475,  472,  482,  473,    0,  479,  483,  480,
      481,  484,  485,  476,  482,  486,  478,  487,  483,  477,
      488,  484,  485,  489,    0,  486,  474,  487,  476,  490,
      488,  485,  493,  489,  484,  491,  492,  494,  482,  490,
        0,  495,  493,    0,  496,  491,  492,  494,  497,  498,
      488,  495,  499,  487,  496,  494,    0,    0,  497,  498,
      495,    0,  499,  501,  490,  500,  487,  491,    0,  502,
      503,  492,    0,  501,    0,  500,  504,  505,  497,  502,
      503,  506,  499,  507,  500,  508,  504,  505,  509,  510,

      496,  506,  511,  507,  512,  508,  513,  503,  509,  510,
        0,  514,  511,  515,  512,  509,  513,    0,  516,  504,
      505,  514,  511,  515,    0,  512,  506,  507,  516,    0,
      517,  518,  519,  520,  504,  505,  521,    0,  522,  513,
      517,  518,  519,  520,    0,  509,  521,  515,  522,  523,
      524,  525,  518,  526,  513,    0,  527,  528,  529,  523,
      524,  525,  531,  526,  530,  517,  527,  528,  529,    0,
      532,  524,  531,  533,  530,  534,  535,    0,  536,  527,
      532,    0,  525,  533,  530,  534,  535,  526,  536,    0,
        0,  529,  537,  538,  539,  540,    0,  541,  542,  536,

      532,    0,  537,  538,  539,  540,  529,  541,  542,    0,
      535,  537,  533,  543,  544,  545,  540,    0,  546,  542,
      547,  548,  549,  543,  544,  545,    0,  538,  546,    0,
      547,  548,  549,    0,  550,  551,  544,  552,    0,  549,
      539,    0,  553,  546,  550,  551,  554,  552,  543,    0,
      555,  547,  553,  556,  551,  557,  554,  558,  559,  550,
      555,  560,  561,  556,  562,  557,  563,  558,  559,  549,
      553,  560,  561,  564,  562,  565,  563,  566,    0,  567,
      568,  569,  556,  564,    0,  565,  570,  566,  558,  567,
      568,  569,  571,  572,  560,  561,  570,  573,  566,    0,

        0,  574,  571,  572,    0,  575,  576,  573,  564,  560,
      561,  574,  577,  572,  567,  575,  576,  578,  579,  580,
      581,  570,  577,  582,  583,  584,  585,  578,  579,  580,
      581,  586,  587,  582,  583,  584,  585,  576,  580,  588,
      589,  586,  587,  590,  581,  591,  579,  578,    0,  588,
      589,  577,  586,  590,  592,  591,    0,  594,  584,  593,
      595,  596,  591,    0,  592,  589,  587,  594,  597,  593,
      595,  596,  598,  584,  599,  600,  594,    0,  597,    0,
      601,  602,  598,  603,  599,  600,  604,  592,  605,  597,
      601,  602,  591,  603,  593,    0,  604,  606,  605,    0,

      607,    0,  592,  608,  609,  605,    0,  606,  610,  601,
      607,  604,  611,  608,  609,  612,  602,  613,  610,    0,
      614,  607,  611,  615,  608,  612,  617,  613,  616,  603,
      614,  606,  618,  615,  619,  605,  617,  610,  616,    0,
      609,  620,  618,    0,  619,    0,    0,  611,  621,  616,
      622,  620,  623,  609,  624,  614,  615,  618,  621,  619,
      622,    0,  623,    0,  624,    0,    0,    0,    0,    0,
        0,  615,    0,  623,    0,    0,    0,  621,  626,  626,
      626,  626,  626,  626,  626,  626,  626,  626,  626,  626,
      627,  627,  627,  627,  627,  627,  627,  627,  627,  627,

      627,  627,  628,    0,  628,  628,  628,  628,  628,  628,
      628,  628,  628,  628,  629,  629,  629,  629,  629,  629,
      629,  629,  629,  629,  629,  629,  630,    0,  630,  630,
      630,  630,  630,  630,  630,  630,  630,  630,  631,    0,
        0,  631,    0,  631,  631,  631,  633,  633,  633,  633,
        0,  633,  633,  634,    0,    0,  634,  634,  635,    0,
        0,  635,  635,  636,  636,  636,  636,    0,  636,  636,
      637,  637,    0,  637,  637,  637,  637,  637,  637,  637,
      637,  637,  638,  638,  638,    0,  638,  638,  638,  638,
      638,  638,  638,  638,  639,  639,  639,  639,  639,  639,

      639,  639,  639,  639,  639,  639,  640,  640,  640,  640,
        0,    0,  640,  640,  641,  641,  641,  641,  641,  641,
      641,  641,  641,  641,  641,  641,  642,    0,  642,    0,
        0,  642,  643,    0,    0,  643,  643,  644,  644,  644,
        0,    0,  644,  644,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,

      625,  625,  625,  625,  625,  625,  625,  625,  625,  625,
      625,  625,  625,  625,  625,  625
    } ;

/* 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-2014, 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 */
/* Makes sparql_lexer_get_lval() sparql_lexer_set_lval() functions
 * and yylval macro appear 
 */
/* Makes yyget_lloc() yyset_lloc() and yylloc appear */
/* %option bison-locations */

/* definitions */
#line 87 "./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>

#include <sparql_parser.h>
#include <sparql_common.h>


/* Set RASQAL_DEBUG to 2 for verbose lexing (when building this as
 * sparql_lexer_test) and 3 for super verbose
 */
#if 0
#undef RASQAL_DEBUG
#define RASQAL_DEBUG 3
#endif

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 unsigned char *sparql_copy_string_token(rasqal_query* rq, unsigned char *text, size_t len, int delim);
static int sparql_stringbuffer_append_sparql_string(rasqal_query* rq, raptor_stringbuffer* stringbuffer, const unsigned char *text, size_t len, int delim);

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

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

#if FLEX_VERSION_DECIMAL < 20536
/* debian flex 2.5.35-10.1 added these column header prototypes in
 * re-entrant mode.  standard flex omits them
 */
void sparql_lexer_set_column(int column_no, yyscan_t yyscanner);
int sparql_lexer_get_column(yyscan_t yyscanner);
#endif

static void sparql_lexer_cleanup(yyscan_t yyscanner);

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

/* Log error handler wrapper */
static void sparql_lexer_log_error(yyconst char *msg, raptor_log_level level, yyscan_t yyscanner);


/* fatal error handler declaration 
 * If we have a setjmp / longjmp then report an ERROR and do not abort.
 *
 * Flex's use of this macro makes doing a return impossible since some
 * uses require a return NULL, some an int and some no value :(
 */
#ifdef HAVE_SETJMP
static jmp_buf sparql_lexer_log_error_longjmp_env;
#define YY_FATAL_ERROR(msg) do {		\
    sparql_lexer_log_error(msg, RAPTOR_LOG_LEVEL_ERROR, yyscanner);      \
    longjmp(sparql_lexer_log_error_longjmp_env, 1);        \
} while(0)
#else
#define YY_FATAL_ERROR(msg) do {		\
    sparql_lexer_log_error(msg, RAPTOR_LOG_LEVEL_FATAL, yyscanner);   \
    abort();                                    \
} while(0)
#endif
 
/* Error handler that returns EOF instead of abort() / longjmp()
 * so that parser can clean up properly */
#define YY_REPORT_ERROR_EOF(msg) do { \
    sparql_lexer_log_error(msg, RAPTOR_LOG_LEVEL_ERROR, 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 1501 "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

#define YY_EXTRA_TYPE rasqal_query*

/* 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;

    YYSTYPE * yylval_r;

    }; /* end struct yyguts_t */

static int yy_init_globals (yyscan_t yyscanner );

    /* This must go here because YYSTYPE and YYLTYPE are included
     * from bison output in section 1.*/
    #    define yylval yyg->yylval_r
    
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 );

int sparql_lexer_get_column  (yyscan_t yyscanner );

void sparql_lexer_set_column (int column_no ,yyscan_t yyscanner );

YYSTYPE * sparql_lexer_get_lval (yyscan_t yyscanner );

void sparql_lexer_set_lval (YYSTYPE * yylval_param ,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
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#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 do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
#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 \
               (YYSTYPE * yylval_param ,yyscan_t yyscanner);

#define YY_DECL int sparql_lexer_lex \
               (YYSTYPE * yylval_param , 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 313 "./sparql_lexer.l"

  /* rules */



  int c;
  rasqal_query *rq;
  rasqal_sparql_query_language *rqe;

  rq = (rasqal_query*)yyextra;
  rqe = (rasqal_sparql_query_language*)rq->context;

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


#line 1766 "sparql_lexer.c"

    yylval = yylval_param;

	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 >= 626 )
					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 != 625 );
		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 332 "./sparql_lexer.l"
{ /* C++ comment */
        rqe->lineno++;
}
	YY_BREAK
case 2:
YY_RULE_SETUP
#line 336 "./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 342 "./sparql_lexer.l"
{ rqe->lineno++; }
	YY_BREAK
case 4:
YY_RULE_SETUP
#line 344 "./sparql_lexer.l"
{ /* eat up other whitespace */
	;
}
	YY_BREAK
case 5:
YY_RULE_SETUP
#line 348 "./sparql_lexer.l"
{ return SELECT; }
	YY_BREAK
case 6:
YY_RULE_SETUP
#line 349 "./sparql_lexer.l"
{ return FROM; }
	YY_BREAK
case 7:
YY_RULE_SETUP
#line 350 "./sparql_lexer.l"
{ return WHERE; }
	YY_BREAK
case 8:
YY_RULE_SETUP
#line 351 "./sparql_lexer.l"
{ BEGIN(PREF);
		return PREFIX; }
	YY_BREAK
case 9:
YY_RULE_SETUP
#line 353 "./sparql_lexer.l"
{ return DESCRIBE; }
	YY_BREAK
case 10:
YY_RULE_SETUP
#line 354 "./sparql_lexer.l"
{ return CONSTRUCT; }
	YY_BREAK
case 11:
YY_RULE_SETUP
#line 355 "./sparql_lexer.l"
{ return ASK; }
	YY_BREAK
case 12:
YY_RULE_SETUP
#line 356 "./sparql_lexer.l"
{ return DISTINCT; }
	YY_BREAK
case 13:
YY_RULE_SETUP
#line 357 "./sparql_lexer.l"
{ return REDUCED; }
	YY_BREAK
case 14:
YY_RULE_SETUP
#line 358 "./sparql_lexer.l"
{ return LIMIT; }
	YY_BREAK
case 15:
YY_RULE_SETUP
#line 359 "./sparql_lexer.l"
{ return UNION; }
	YY_BREAK
case 16:
YY_RULE_SETUP
#line 360 "./sparql_lexer.l"
{ return OPTIONAL; }
	YY_BREAK
case 17:
YY_RULE_SETUP
#line 361 "./sparql_lexer.l"
{ return BASE; }
	YY_BREAK
case 18:
YY_RULE_SETUP
#line 362 "./sparql_lexer.l"
{ return BOUND; }
	YY_BREAK
case 19:
YY_RULE_SETUP
#line 363 "./sparql_lexer.l"
{ return STRLANG; }
	YY_BREAK
case 20:
YY_RULE_SETUP
#line 364 "./sparql_lexer.l"
{ return STRDT; }
	YY_BREAK
case 21:
YY_RULE_SETUP
#line 365 "./sparql_lexer.l"
{ return STR; }
	YY_BREAK
case 22:
YY_RULE_SETUP
#line 366 "./sparql_lexer.l"
{ return LANG; }
	YY_BREAK
case 23:
YY_RULE_SETUP
#line 367 "./sparql_lexer.l"
{ return DATATYPE; }
	YY_BREAK
case 24:
YY_RULE_SETUP
#line 368 "./sparql_lexer.l"
{ return ISURI; } /* isURI and isIRI */
	YY_BREAK
case 25:
YY_RULE_SETUP
#line 369 "./sparql_lexer.l"
{ return ISBLANK; }
	YY_BREAK
case 26:
YY_RULE_SETUP
#line 370 "./sparql_lexer.l"
{ return ISLITERAL; }
	YY_BREAK
case 27:
YY_RULE_SETUP
#line 371 "./sparql_lexer.l"
{ return GRAPH; }
	YY_BREAK
case 28:
YY_RULE_SETUP
#line 372 "./sparql_lexer.l"
{ return NAMED; }
	YY_BREAK
case 29:
YY_RULE_SETUP
#line 373 "./sparql_lexer.l"
{ return FILTER; }
	YY_BREAK
case 30:
YY_RULE_SETUP
#line 374 "./sparql_lexer.l"
{ return OFFSET; }
	YY_BREAK
case 31:
YY_RULE_SETUP
#line 375 "./sparql_lexer.l"
{ return ORDER; }
	YY_BREAK
case 32:
YY_RULE_SETUP
#line 376 "./sparql_lexer.l"
{ return BY; }
	YY_BREAK
case 33:
YY_RULE_SETUP
#line 377 "./sparql_lexer.l"
{ return REGEX; }
	YY_BREAK
case 34:
YY_RULE_SETUP
#line 378 "./sparql_lexer.l"
{ return ASC; }
	YY_BREAK
case 35:
YY_RULE_SETUP
#line 379 "./sparql_lexer.l"
{ return DESC; } 
	YY_BREAK
case 36:
YY_RULE_SETUP
#line 380 "./sparql_lexer.l"
{ return LANGMATCHES; } 
	YY_BREAK
case 37:
YY_RULE_SETUP
#line 381 "./sparql_lexer.l"
{ return EXPLAIN; }
	YY_BREAK
case 38:
YY_RULE_SETUP
#line 382 "./sparql_lexer.l"
{ return GROUP; }
	YY_BREAK
case 39:
YY_RULE_SETUP
#line 383 "./sparql_lexer.l"
{ return HAVING; }
	YY_BREAK
case 40:
YY_RULE_SETUP
#line 384 "./sparql_lexer.l"
{ return COUNT; }
	YY_BREAK
case 41:
YY_RULE_SETUP
#line 385 "./sparql_lexer.l"
{ return SUM; }
	YY_BREAK
case 42:
YY_RULE_SETUP
#line 386 "./sparql_lexer.l"
{ return AVG; }
	YY_BREAK
case 43:
YY_RULE_SETUP
#line 387 "./sparql_lexer.l"
{ return MIN; }
	YY_BREAK
case 44:
YY_RULE_SETUP
#line 388 "./sparql_lexer.l"
{ return MAX; }
	YY_BREAK
case 45:
YY_RULE_SETUP
#line 389 "./sparql_lexer.l"
{ BEGIN(SPID); return AS; }
	YY_BREAK
case 46:
YY_RULE_SETUP
#line 390 "./sparql_lexer.l"
{ return DELETE; }
	YY_BREAK
case 47:
YY_RULE_SETUP
#line 391 "./sparql_lexer.l"
{ return INSERT; }
	YY_BREAK
case 48:
YY_RULE_SETUP
#line 392 "./sparql_lexer.l"
{ return SAMETERM; }
	YY_BREAK
case 49:
YY_RULE_SETUP
#line 393 "./sparql_lexer.l"
{ return LET; }
	YY_BREAK
case 50:
YY_RULE_SETUP
#line 394 "./sparql_lexer.l"
{ return COALESCE; }
	YY_BREAK
case 51:
YY_RULE_SETUP
#line 395 "./sparql_lexer.l"
{ return WITH; }
	YY_BREAK
case 52:
YY_RULE_SETUP
#line 396 "./sparql_lexer.l"
{ return CLEAR; }
	YY_BREAK
case 53:
YY_RULE_SETUP
#line 397 "./sparql_lexer.l"
{ return CREATE; }
	YY_BREAK
case 54:
YY_RULE_SETUP
#line 398 "./sparql_lexer.l"
{ return SILENT; }
	YY_BREAK
case 55:
YY_RULE_SETUP
#line 399 "./sparql_lexer.l"
{ return DATA; }
	YY_BREAK
case 56:
YY_RULE_SETUP
#line 400 "./sparql_lexer.l"
{ return DROP; }
	YY_BREAK
case 57:
YY_RULE_SETUP
#line 401 "./sparql_lexer.l"
{ return LOAD; }
	YY_BREAK
case 58:
YY_RULE_SETUP
#line 402 "./sparql_lexer.l"
{ return INTO; }
	YY_BREAK
case 59:
YY_RULE_SETUP
#line 403 "./sparql_lexer.l"
{ return IF; }
	YY_BREAK
case 60:
YY_RULE_SETUP
#line 404 "./sparql_lexer.l"
{ return IRI; }
	YY_BREAK
case 61:
YY_RULE_SETUP
#line 405 "./sparql_lexer.l"
{ return URI; }
	YY_BREAK
case 62:
YY_RULE_SETUP
#line 406 "./sparql_lexer.l"
{ return BNODE; }
	YY_BREAK
case 63:
YY_RULE_SETUP
#line 407 "./sparql_lexer.l"
{ return DEFAULT; }
	YY_BREAK
case 64:
YY_RULE_SETUP
#line 408 "./sparql_lexer.l"
{ return NOT; }
	YY_BREAK
case 65:
YY_RULE_SETUP
#line 409 "./sparql_lexer.l"
{ return IN; }
	YY_BREAK
case 66:
YY_RULE_SETUP
#line 410 "./sparql_lexer.l"
{ return GROUP_CONCAT; }
	YY_BREAK
case 67:
YY_RULE_SETUP
#line 411 "./sparql_lexer.l"
{ return SEPARATOR; }
	YY_BREAK
case 68:
YY_RULE_SETUP
#line 412 "./sparql_lexer.l"
{ return BIND; }
	YY_BREAK
case 69:
YY_RULE_SETUP
#line 413 "./sparql_lexer.l"
{ return BINDINGS; }
	YY_BREAK
case 70:
YY_RULE_SETUP
#line 414 "./sparql_lexer.l"
{ return UNDEF; }
	YY_BREAK
case 71:
YY_RULE_SETUP
#line 415 "./sparql_lexer.l"
{ return SERVICE; }
	YY_BREAK
case 72:
YY_RULE_SETUP
#line 416 "./sparql_lexer.l"
{ return MINUS; }
	YY_BREAK
case 73:
YY_RULE_SETUP
#line 417 "./sparql_lexer.l"
{ return ISNUMERIC; }
	YY_BREAK
case 74:
YY_RULE_SETUP
#line 418 "./sparql_lexer.l"
{ return SAMPLE; }
	YY_BREAK
case 75:
YY_RULE_SETUP
#line 419 "./sparql_lexer.l"
{ return YEAR; }
	YY_BREAK
case 76:
YY_RULE_SETUP
#line 420 "./sparql_lexer.l"
{ return MONTH; }
	YY_BREAK
case 77:
YY_RULE_SETUP
#line 421 "./sparql_lexer.l"
{ return DAY; }
	YY_BREAK
case 78:
YY_RULE_SETUP
#line 422 "./sparql_lexer.l"
{ return HOURS; }
	YY_BREAK
case 79:
YY_RULE_SETUP
#line 423 "./sparql_lexer.l"
{ return MINUTES; }
	YY_BREAK
case 80:
YY_RULE_SETUP
#line 424 "./sparql_lexer.l"
{ return SECONDS; }
	YY_BREAK
case 81:
YY_RULE_SETUP
#line 425 "./sparql_lexer.l"
{ return TIMEZONE; }
	YY_BREAK
case 82:
YY_RULE_SETUP
#line 426 "./sparql_lexer.l"
{ return CURRENT_DATETIME; }
	YY_BREAK
case 83:
YY_RULE_SETUP
#line 427 "./sparql_lexer.l"
{ return NOW; }
	YY_BREAK
case 84:
YY_RULE_SETUP
#line 428 "./sparql_lexer.l"
{ return FROM_UNIXTIME; }
	YY_BREAK
case 85:
YY_RULE_SETUP
#line 429 "./sparql_lexer.l"
{ return TO_UNIXTIME; }
	YY_BREAK
case 86:
YY_RULE_SETUP
#line 430 "./sparql_lexer.l"
{ return CONCAT; }
	YY_BREAK
case 87:
YY_RULE_SETUP
#line 431 "./sparql_lexer.l"
{ return STRLEN; }
	YY_BREAK
case 88:
YY_RULE_SETUP
#line 432 "./sparql_lexer.l"
{ return SUBSTR; }
	YY_BREAK
case 89:
YY_RULE_SETUP
#line 433 "./sparql_lexer.l"
{ return UCASE; }
	YY_BREAK
case 90:
YY_RULE_SETUP
#line 434 "./sparql_lexer.l"
{ return LCASE; }
	YY_BREAK
case 91:
YY_RULE_SETUP
#line 435 "./sparql_lexer.l"
{ return STRSTARTS; }
	YY_BREAK
case 92:
YY_RULE_SETUP
#line 436 "./sparql_lexer.l"
{ return STRENDS; }
	YY_BREAK
case 93:
YY_RULE_SETUP
#line 437 "./sparql_lexer.l"
{ return CONTAINS; }
	YY_BREAK
case 94:
YY_RULE_SETUP
#line 438 "./sparql_lexer.l"
{ return ENCODE_FOR_URI; }
	YY_BREAK
case 95:
YY_RULE_SETUP
#line 439 "./sparql_lexer.l"
{ return TO; }
	YY_BREAK
case 96:
YY_RULE_SETUP
#line 440 "./sparql_lexer.l"
{ return ADD; }
	YY_BREAK
case 97:
YY_RULE_SETUP
#line 441 "./sparql_lexer.l"
{ return MOVE; }
	YY_BREAK
case 98:
YY_RULE_SETUP
#line 442 "./sparql_lexer.l"
{ return COPY; }
	YY_BREAK
case 99:
YY_RULE_SETUP
#line 443 "./sparql_lexer.l"
{ return ALL; }
	YY_BREAK
case 100:
YY_RULE_SETUP
#line 444 "./sparql_lexer.l"
{ return TZ; }
	YY_BREAK
case 101:
YY_RULE_SETUP
#line 445 "./sparql_lexer.l"
{ return RAND; }
	YY_BREAK
case 102:
YY_RULE_SETUP
#line 446 "./sparql_lexer.l"
{ return ABS; }
	YY_BREAK
case 103:
YY_RULE_SETUP
#line 447 "./sparql_lexer.l"
{ return ROUND; }
	YY_BREAK
case 104:
YY_RULE_SETUP
#line 448 "./sparql_lexer.l"
{ return CEIL; }
	YY_BREAK
case 105:
YY_RULE_SETUP
#line 449 "./sparql_lexer.l"
{ return FLOOR; }
	YY_BREAK
case 106:
YY_RULE_SETUP
#line 450 "./sparql_lexer.l"
{ return MD5; }
	YY_BREAK
case 107:
YY_RULE_SETUP
#line 451 "./sparql_lexer.l"
{ return SHA1; }
	YY_BREAK
case 108:
YY_RULE_SETUP
#line 452 "./sparql_lexer.l"
{ return SHA224; }
	YY_BREAK
case 109:
YY_RULE_SETUP
#line 453 "./sparql_lexer.l"
{ return SHA256; }
	YY_BREAK
case 110:
YY_RULE_SETUP
#line 454 "./sparql_lexer.l"
{ return SHA384; }
	YY_BREAK
case 111:
YY_RULE_SETUP
#line 455 "./sparql_lexer.l"
{ return SHA512; }
	YY_BREAK
case 112:
YY_RULE_SETUP
#line 456 "./sparql_lexer.l"
{ return STRBEFORE; }
	YY_BREAK
case 113:
YY_RULE_SETUP
#line 457 "./sparql_lexer.l"
{ return STRAFTER; }
	YY_BREAK
case 114:
YY_RULE_SETUP
#line 458 "./sparql_lexer.l"
{ return REPLACE; }
	YY_BREAK
case 115:
YY_RULE_SETUP
#line 459 "./sparql_lexer.l"
{ return UUID; }
	YY_BREAK
case 116:
YY_RULE_SETUP
#line 460 "./sparql_lexer.l"
{ return STRUUID; }
	YY_BREAK
case 117:
YY_RULE_SETUP
#line 461 "./sparql_lexer.l"
{ return VALUES; }
	YY_BREAK
case 118:
YY_RULE_SETUP
#line 463 "./sparql_lexer.l"
{ return A; }
	YY_BREAK
case 119:
YY_RULE_SETUP
#line 465 "./sparql_lexer.l"
{ return ','; } 
	YY_BREAK
case 120:
YY_RULE_SETUP
#line 466 "./sparql_lexer.l"
{ return '('; } 
	YY_BREAK
case 121:
YY_RULE_SETUP
#line 467 "./sparql_lexer.l"
{ return ')'; } 
	YY_BREAK
case 122:
YY_RULE_SETUP
#line 468 "./sparql_lexer.l"
{ return '['; }
	YY_BREAK
case 123:
YY_RULE_SETUP
#line 469 "./sparql_lexer.l"
{ return ']'; }
	YY_BREAK
case 124:
YY_RULE_SETUP
#line 470 "./sparql_lexer.l"
{ BEGIN(ID); return '?'; }
	YY_BREAK
case 125:
YY_RULE_SETUP
#line 471 "./sparql_lexer.l"
{ BEGIN(ID); return '$'; }
	YY_BREAK
case 126:
YY_RULE_SETUP
#line 472 "./sparql_lexer.l"
{ return '{'; } 
	YY_BREAK
case 127:
YY_RULE_SETUP
#line 473 "./sparql_lexer.l"
{ return '}'; } 
	YY_BREAK
case 128:
YY_RULE_SETUP
#line 474 "./sparql_lexer.l"
{ return '.'; } 
	YY_BREAK
case 129:
YY_RULE_SETUP
#line 475 "./sparql_lexer.l"
{ return ';'; } 
	YY_BREAK
case 130:
YY_RULE_SETUP
#line 477 "./sparql_lexer.l"
{ return SC_OR; }
	YY_BREAK
case 131:
YY_RULE_SETUP
#line 478 "./sparql_lexer.l"
{ return SC_AND; }
	YY_BREAK
case 132:
YY_RULE_SETUP
#line 480 "./sparql_lexer.l"
{ return EQ; }
	YY_BREAK
case 133:
YY_RULE_SETUP
#line 481 "./sparql_lexer.l"
{ return NEQ; }
	YY_BREAK
case 134:
/* rule 134 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 482 "./sparql_lexer.l"
{ return LT; }
	YY_BREAK
case 135:
YY_RULE_SETUP
#line 483 "./sparql_lexer.l"
{ return GT; }
	YY_BREAK
case 136:
YY_RULE_SETUP
#line 484 "./sparql_lexer.l"
{ return LE; }
	YY_BREAK
case 137:
YY_RULE_SETUP
#line 485 "./sparql_lexer.l"
{ return GE; }
	YY_BREAK
case 138:
YY_RULE_SETUP
#line 487 "./sparql_lexer.l"
{ return '*'; }
	YY_BREAK
case 139:
YY_RULE_SETUP
#line 488 "./sparql_lexer.l"
{ return '/'; }
	YY_BREAK
case 140:
YY_RULE_SETUP
#line 489 "./sparql_lexer.l"
{ return '!'; }
	YY_BREAK
case 141:
YY_RULE_SETUP
#line 491 "./sparql_lexer.l"
{ return ASSIGN; }
	YY_BREAK
case 142:
YY_RULE_SETUP
#line 493 "./sparql_lexer.l"
{
			yylval->name = RASQAL_MALLOC(unsigned char*, yyleng);
                        if(!yylval->name)
                          YY_REPORT_ERROR_EOF("Out of memory");

                        memcpy(yylval->name, yytext + 1, yyleng - 1);
                        yylval->name[yyleng - 1] = '\0';
                  return LANGTAG;
		}
	YY_BREAK
case 143:
YY_RULE_SETUP
#line 503 "./sparql_lexer.l"
{ return HATHAT; }
	YY_BREAK
case 144:
YY_RULE_SETUP
#line 506 "./sparql_lexer.l"
{ c = *yytext;
                  yylval->literal = rasqal_new_typed_literal(rq->world, RASQAL_LITERAL_INTEGER, RASQAL_GOOD_CAST(const unsigned char*, yytext));
                  if(!yylval->literal)
                    YY_REPORT_ERROR_EOF("rasqal_new_typed_literal failed");
 		  return (c=='+' ? INTEGER_POSITIVE_LITERAL : (c == '-' ? INTEGER_NEGATIVE_LITERAL : INTEGER_LITERAL));
}
	YY_BREAK
case 145:
YY_RULE_SETUP
#line 513 "./sparql_lexer.l"
{ 
                        c = *yytext;
                        
                        if(!rasqal_xsd_datatype_check(RASQAL_LITERAL_DECIMAL, RASQAL_GOOD_CAST(const unsigned char*, yytext), 0)) {
                          sparql_syntax_error(rq, "SPARQL syntax error - Illegal decimal constant %s", yytext);
                          yyterminate();
                        }
                        yylval->literal = rasqal_new_decimal_literal(rq->world, RASQAL_GOOD_CAST(const unsigned char*, yytext));
                        if(!yylval->literal)
                          YY_REPORT_ERROR_EOF("rasqal_new_decimal_literal failed");
                        return (c=='+' ? DECIMAL_POSITIVE_LITERAL : (c == '-' ? DECIMAL_NEGATIVE_LITERAL : DECIMAL_LITERAL));
}
	YY_BREAK
case 146:
YY_RULE_SETUP
#line 526 "./sparql_lexer.l"
{
                        c = *yytext;
                        if(!rasqal_xsd_datatype_check(RASQAL_LITERAL_DOUBLE, RASQAL_GOOD_CAST(const unsigned char*, yytext), 0)) {
                          sparql_syntax_error(rq, "SPARQL syntax error - Illegal double constant %s", yytext);
                          yyterminate();
                        }
                        yylval->literal = rasqal_new_typed_literal(rq->world, RASQAL_LITERAL_DOUBLE, RASQAL_GOOD_CAST(const unsigned char*, yytext));
                        if(!yylval->literal)
                          YY_REPORT_ERROR_EOF("rasqal_new_typed_literal failed");
                        return (c=='+' ? DOUBLE_POSITIVE_LITERAL : (c == '-' ? DOUBLE_NEGATIVE_LITERAL : DOUBLE_LITERAL));
}
	YY_BREAK
case 147:
YY_RULE_SETUP
#line 538 "./sparql_lexer.l"
{ return '+'; }
	YY_BREAK
case 148:
YY_RULE_SETUP
#line 539 "./sparql_lexer.l"
{ return '-'; }
	YY_BREAK
case 149:
YY_RULE_SETUP
#line 541 "./sparql_lexer.l"
{ /*' */
                        yylval->name = sparql_copy_string_token(rq, RASQAL_GOOD_CAST(unsigned char*, yytext) + 1, yyleng - 2, '\'');
                        if(!yylval->name)
                          YY_REPORT_ERROR_EOF("sparql_copy_string_token failed");
                        return STRING; }
	YY_BREAK
case 150:
YY_RULE_SETUP
#line 547 "./sparql_lexer.l"
{ /* " */
                        yylval->name = sparql_copy_string_token(rq, RASQAL_GOOD_CAST(unsigned char*, yytext) + 1, yyleng - 2, '"');
                        if(!yylval->name)
                          YY_REPORT_ERROR_EOF("sparql_copy_string_token failed");
                        return STRING; }
	YY_BREAK
case 151:
YY_RULE_SETUP
#line 553 "./sparql_lexer.l"
{ BEGIN(LITERAL); 
                                  rqe->sb = raptor_new_stringbuffer();
                                  if(!rqe->sb)
                                    YY_REPORT_ERROR_EOF("raptor_new_stringbuffer failed");
                          }
	YY_BREAK
case 152:
YY_RULE_SETUP
#line 559 "./sparql_lexer.l"
{
		  size_t len;
     
		  BEGIN(INITIAL);
                  len = raptor_stringbuffer_length(rqe->sb);
                  yylval->name = RASQAL_MALLOC(unsigned char*, len + 1);
                  if(!yylval->name)
                    YY_REPORT_ERROR_EOF("Out of memory");

                  raptor_stringbuffer_copy_to_string(rqe->sb,
                                                     RASQAL_GOOD_CAST(unsigned char*, yylval->name), len);
                  yylval->name[len] = '\0';

                  raptor_free_stringbuffer(rqe->sb);
                  rqe->sb = NULL;
                  return STRING; }
	YY_BREAK
case 153:
/* rule 153 can match eol */
YY_RULE_SETUP
#line 576 "./sparql_lexer.l"
{
		  char *p;

		  if(*yytext == EOF) {
                    BEGIN(INITIAL);
                    sparql_syntax_error(rq, "End of file in middle of literal");
                    raptor_free_stringbuffer(rqe->sb);
                    rqe->sb = NULL;
                    return EOF;
                  }

		  for(p = yytext; *p; p++) {
                    if(*p == '\n')
                      rqe->lineno++;
                  }

                  if(sparql_stringbuffer_append_sparql_string(rq, rqe->sb, RASQAL_GOOD_CAST(unsigned char*, yytext), yyleng, '"')) { /* " */
                    BEGIN(INITIAL);
                    raptor_free_stringbuffer(rqe->sb);
                    rqe->sb = NULL;
                    YY_REPORT_ERROR_EOF("sparql_stringbuffer_append_sparql_string failed");
                  }
                  
   }
	YY_BREAK
case 154:
YY_RULE_SETUP
#line 601 "./sparql_lexer.l"
{
     		/* this should only happen if \ is at the end of the file so the Turtle doc is illegal anyway */
                sparql_syntax_error(rq, "End of file in middle of literal");
}
	YY_BREAK
case 155:
YY_RULE_SETUP
#line 606 "./sparql_lexer.l"
{ BEGIN(LITERAL2); 
                                  rqe->sb = raptor_new_stringbuffer();
                                  if(!rqe->sb) {
                                    BEGIN(INITIAL);
                                    YY_REPORT_ERROR_EOF("raptor_new_stringbuffer failed");
                                  }
                          }
	YY_BREAK
case 156:
YY_RULE_SETUP
#line 614 "./sparql_lexer.l"
{
		  size_t len;
     
		  BEGIN(INITIAL);
                  len = raptor_stringbuffer_length(rqe->sb);
                  yylval->name = RASQAL_MALLOC(unsigned char*, len + 1);
                  if(!yylval->name)
                    YY_REPORT_ERROR_EOF("Out of memory");

                  raptor_stringbuffer_copy_to_string(rqe->sb, RASQAL_GOOD_CAST(unsigned char*, yylval->name), len);
                  yylval->name[len] = '\0';

                  raptor_free_stringbuffer(rqe->sb);
                  rqe->sb = NULL;
                  return STRING; }
	YY_BREAK
case 157:
/* rule 157 can match eol */
YY_RULE_SETUP
#line 630 "./sparql_lexer.l"
{
		  char *p;

		  if(*yytext == EOF) {
                    BEGIN(INITIAL);
                    sparql_syntax_error(rq, "End of file in middle of \"\"\" literal");
                    raptor_free_stringbuffer(rqe->sb);
                    rqe->sb = NULL;
                    return EOF;
                  }

		  for(p = yytext; *p; p++) {
                    if(*p == '\n')
                      rqe->lineno++;
                  }

                  if(sparql_stringbuffer_append_sparql_string(rq, rqe->sb, RASQAL_GOOD_CAST(unsigned char*, yytext), yyleng, '\'')) {
                    BEGIN(INITIAL);
                    raptor_free_stringbuffer(rqe->sb);
                    rqe->sb = NULL;
                    YY_REPORT_ERROR_EOF("sparql_stringbuffer_append_sparql_string failed");
                  }
                  
   }
	YY_BREAK
case 158:
YY_RULE_SETUP
#line 655 "./sparql_lexer.l"
{
     		/* this should only happen if \ is at the end of the file so the Turtle doc is illegal anyway */
                sparql_syntax_error(rq, "End of file in middle of ''' literal");
}
	YY_BREAK
case 159:
YY_RULE_SETUP
#line 662 "./sparql_lexer.l"
{ yylval->literal = rasqal_new_boolean_literal(rq->world, 1);
                    if(!yylval->literal)
                      YY_REPORT_ERROR_EOF("rasqal_new_boolean_literal failed");
                  return BOOLEAN_LITERAL; }
	YY_BREAK
case 160:
YY_RULE_SETUP
#line 667 "./sparql_lexer.l"
{ yylval->literal = rasqal_new_boolean_literal(rq->world, 0);
                        if(!yylval->literal)
                          YY_REPORT_ERROR_EOF("rasqal_new_boolean_literal failed");
                  return BOOLEAN_LITERAL; }
	YY_BREAK
case 161:
YY_RULE_SETUP
#line 672 "./sparql_lexer.l"
{ yylval->name = sparql_copy_name(rq, RASQAL_GOOD_CAST(const unsigned char*, yytext), yyleng, SPARQL_NAME_CHECK_VARNAME);
		  if(!yylval->name)
                    yyterminate();

                          BEGIN(INITIAL);
                          return IDENTIFIER; }
	YY_BREAK
case 162:
/* rule 162 can match eol */
YY_RULE_SETUP
#line 678 "./sparql_lexer.l"
{	BEGIN(INITIAL);
		sparql_syntax_error(rq, "SPARQL syntax error - missing variable name after ?");
                yyterminate();
}
	YY_BREAK
case 163:
YY_RULE_SETUP
#line 683 "./sparql_lexer.l"
{ /* eat up leading whitespace */
	;
}
	YY_BREAK
case 164:
YY_RULE_SETUP
#line 687 "./sparql_lexer.l"
{
	return '?';
}
	YY_BREAK
case 165:
YY_RULE_SETUP
#line 691 "./sparql_lexer.l"
{
	return '$';
}
	YY_BREAK
case 166:
YY_RULE_SETUP
#line 695 "./sparql_lexer.l"
{ yylval->name = sparql_copy_name(rq, RASQAL_GOOD_CAST(const unsigned char*, yytext), yyleng, SPARQL_NAME_CHECK_VARNAME);
		  if(!yylval->name)
                    yyterminate();

                          BEGIN(INITIAL);
                          return IDENTIFIER; }
	YY_BREAK
case 167:
/* rule 167 can match eol */
YY_RULE_SETUP
#line 702 "./sparql_lexer.l"
{	BEGIN(INITIAL);
		sparql_syntax_error(rq, "SPARQL syntax error - missing variable name after ?");
                yyterminate();
}
	YY_BREAK
case 168:
YY_RULE_SETUP
#line 707 "./sparql_lexer.l"
{ /* eat up leading whitespace */ }
	YY_BREAK
case 169:
YY_RULE_SETUP
#line 708 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  	  yylval->name = sparql_copy_name(rq, RASQAL_GOOD_CAST(const unsigned char*, yytext), yyleng - 1, SPARQL_NAME_CHECK_PREFIX);
			  if(!yylval->name)
			    yyterminate();

                          return IDENTIFIER; }
	YY_BREAK
case 170:
YY_RULE_SETUP
#line 714 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  yylval->name = NULL;
                  return IDENTIFIER; }
	YY_BREAK
case 171:
/* rule 171 can match eol */
YY_RULE_SETUP
#line 718 "./sparql_lexer.l"
{ BEGIN(INITIAL);
		  if(!*yytext)
                    return EOF;

                  sparql_syntax_error(rq, "SPARQL syntax error at '%c'", *yytext);
                  yyterminate();
}
	YY_BREAK
case 172:
YY_RULE_SETUP
#line 726 "./sparql_lexer.l"
{
		int have_brace = (yytext[yyleng-1]=='(');
		if(have_brace)
			yyleng--;
		yylval->uri = sparql_copy_qname(rq, RASQAL_GOOD_CAST(const unsigned char*, yytext), yyleng);
		if(!yylval->uri)
		  yyterminate();

 		return have_brace ? URI_LITERAL_BRACE : URI_LITERAL;
}
	YY_BREAK
case 173:
YY_RULE_SETUP
#line 737 "./sparql_lexer.l"
{	yylval->name = sparql_copy_name(rq, RASQAL_GOOD_CAST(unsigned char*, yytext) + 2, yyleng - 2, SPARQL_NAME_CHECK_NCNAME);
		if(!yylval->name)
		  yyterminate();

		return BLANK_LITERAL;
}
	YY_BREAK
case 174:
YY_RULE_SETUP
#line 744 "./sparql_lexer.l"
{	yylval->name = sparql_copy_name(rq, RASQAL_GOOD_CAST(unsigned char*, yytext) + 3, yyleng - 4, SPARQL_NAME_CHECK_NCNAME);
		if(!yylval->name)
		  yyterminate();

		return BLANK_LITERAL;
}
	YY_BREAK
case 175:
/* rule 175 can match eol */
YY_RULE_SETUP
#line 751 "./sparql_lexer.l"
{ 
		int have_brace = (yytext[yyleng-1]=='(');
		if(have_brace)
			yyleng--;
		if(yyleng == 2) 
                  yylval->uri = raptor_uri_copy(rq->base_uri);
                else {
                  unsigned char* uri_string;

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

                  yylval->uri = raptor_new_uri_relative_to_base(rq->world->raptor_world_ptr, rq->base_uri, uri_string);
                  RASQAL_FREE(char*, uri_string);
                  if(!yylval->uri)
                    YY_REPORT_ERROR_EOF("raptor_new_uri_relative_to_base failed");
                 }
                 return have_brace ? URI_LITERAL_BRACE : URI_LITERAL; }
	YY_BREAK
case 176:
/* rule 176 can match eol */
YY_RULE_SETUP
#line 775 "./sparql_lexer.l"
{ /* # comment */
        	rqe->lineno++;
                }
	YY_BREAK
case 177:
YY_RULE_SETUP
#line 779 "./sparql_lexer.l"
{ if(!*yytext)
                    return EOF;

                  sparql_syntax_error(rq, "SPARQL syntax error at '%c'", *yytext);
                  yyterminate();
		}
	YY_BREAK
case 178:
YY_RULE_SETUP
#line 786 "./sparql_lexer.l"
YY_FATAL_ERROR( "flex scanner jammed" );
	YY_BREAK
#line 2981 "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, num_to_read );


		}

	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 >= 626 )
				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 >= 626 )
			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 == 625);

	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 ( ! yyg->yy_buffer_stack ){
        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_LVALUE,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_LVALUE == new_buffer )
		return;

	if ( YY_CURRENT_BUFFER_LVALUE )
		{
		/* 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_LVALUE )
		{
		/* 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_LVALUE)
		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_LVALUE) {
		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()" );
								  
		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.*/
		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 yybytes the byte buffer to scan
 * @param _yybytes_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;
	yy_size_t 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 */

YYSTYPE * sparql_lexer_get_lval  (yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    return yylval;
}

void sparql_lexer_set_lval (YYSTYPE *  yylval_param , yyscan_t yyscanner)
{
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
    yylval = yylval_param;
}

/* 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 786 "./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 defined(RASQAL_DEBUG) && RASQAL_DEBUG > 2
  RASQAL_DEBUG1("Checking name '");
  if(length)
     fwrite(string, length, sizeof(unsigned char), stderr);
  fprintf(stderr, "' (length %d), flags %d\n", RASQAL_BAD_CAST(int, length), RASQAL_GOOD_CAST(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) {
    size_t i;
    for(i = 0; i < 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(RASQAL_GOOD_CAST(unsigned char*, text),
                                         len, &dest_len,
                                         sparql_syntax_error, rq);
  if(!s) {
    sparql_syntax_error(rq, "Failed to decode SPARQL string \"%s\"", text);
    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(RASQAL_GOOD_CAST(unsigned char*, text),
                                         len, &dest_len,
                                         sparql_syntax_error, rq);
  if(!s) {
    sparql_syntax_error(rq, "Failed to decode SPARQL ID \"%s\"", text);
    return NULL;
  }

  p = RASQAL_GOOD_CAST(unsigned char*, strchr(RASQAL_GOOD_CAST(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->world->raptor_world_ptr, rq->base_uri, s);
#else /* not */
  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);
#endif /* STANDALONE */
  RASQAL_FREE(char*, s);
  
  return uri;
}


static unsigned char*
sparql_copy_string_token(rasqal_query* rq,
                         unsigned char *string, size_t len, int delim)
{
  raptor_stringbuffer* sb = NULL;
  int rc;
  
  if(len) {
    sb = raptor_new_stringbuffer();
    if(!sb)
      return NULL;
    
    rc = sparql_stringbuffer_append_sparql_string(rq, sb, string, len, delim);
    if(rc) {
      raptor_free_stringbuffer(sb);
      return NULL;
    }

    len = raptor_stringbuffer_length(sb);
  }
  
  string = RASQAL_MALLOC(unsigned char*, len + 1);
  if(string) {
    if(sb) 
      raptor_stringbuffer_copy_to_string(sb, string, len + 1);
    string[len]='\0';
  }

  if(sb)
    raptor_free_stringbuffer(sb);
  
  return string;
}


static int
sparql_skip_c_comment(rasqal_query *rq)
{
  rasqal_sparql_query_language *rqe;
  yyscan_t yyscanner;
  int lines = 0;
  int lastc = -1;
  
  rqe = (rasqal_sparql_query_language*)rq->context;
  yyscanner = rqe->scanner;

  while(1) {
    int c = INPUT_FN(yyscanner);
    
    if(c == EOF) {
      /* EOF */
      sparql_syntax_error(rq, "SPARQL syntax error - EOF in comment");
      lines = -1;
      break;
    }

    if(c == '\r' || (c == '\n' && lastc != '\r'))
      lines++;

    if(lastc == '*' && c == '/')
      break;

    lastc =  c;
  }
  return lines;
}


/**
 * sparql_stringbuffer_append_sparql_string:
 * @rq: rasqal query
 * @stringbuffer: String buffer to add to
 * @text: turtle string to decode
 * @len: length of string
 * @delim: terminating delimiter for string - only ', " or &gt; are allowed
 *
 * INTERNAL - Append to a stringbuffer a SPARQL-escaped string.
 *
 * The passed in string is handled according to the SPARQL string
 * escape rules giving a UTF-8 encoded output of the Unicode codepoints.
 *
 * The SPARQL escapes are \n \r \f \b \t \\
 * \uXXXX \UXXXXXXXX where X is [A-F0-9]
 * and \ followed by the @delim char
 * 
 * Return value: non-0 on failure
 **/
static int
sparql_stringbuffer_append_sparql_string(rasqal_query* rq,
                                         raptor_stringbuffer* stringbuffer,
                                         const unsigned char *text,
                                         size_t len, int delim)
{
  size_t i;
  const unsigned char *s;
  unsigned char *d;
  unsigned char *string;

  string = RASQAL_MALLOC(unsigned char*, 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 == 'f')
        *d++ = '\f';
      else if(c == 'b')
        *d++ = '\b';
      else if(c == 't')
        *d++ = '\t';
      else if(c == '\\' || c == delim)
        *d++ = c;
      else if(c == 'u' || c == 'U') {
        size_t ulen = (c == 'u') ? 4 : 8;
        unsigned long unichar = 0;
        int n;
        
        s++; i++;
        if(i + ulen > len) {
          sparql_syntax_error(rq, "SPARQL string \\%c over end of line", c);
          RASQAL_FREE(char*, string);
          return 1;
        }
        
        n = sscanf(RASQAL_GOOD_CAST(const char*, s), ((ulen == 4) ? "%04lx" : "%08lx"), &unichar);
        if(n != 1) {
          sparql_syntax_error(rq, "Bad SPARQL string Uncode escape '%c%s...'",
                              c, s);
          RASQAL_FREE(char*, string);
          return 1;
        }

        s += ulen - 1;
        i += ulen - 1;
        
        if(unichar > rasqal_unicode_max_codepoint) {
          sparql_syntax_error(rq,
                              "Bad SPARQL string Unicode character with code point #x%lX (max #x%lX).", 
                              unichar, rasqal_unicode_max_codepoint);
          RASQAL_FREE(char*, string);
          return 1;
        }
          
        d += raptor_unicode_utf8_string_put_char(unichar, d, len - (d - string));

      } 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
      *d++ = c;
  }
  *d='\0';

  /* calculate output string size */
  len = d-string;
  
  /* string gets owned by the stringbuffer after this */
  return raptor_stringbuffer_append_counted_string(stringbuffer, 
                                                   string, len, 0);

}


/*
 * sparql_lexer_log_error:
 * @msg: message string
 * @level: log level
 * @yyscanner: scanner context
 *
 * INTERNAL - replacement for the generated error handler.
 * Uses rasqal_log_error_simple() when possible.
 */
static void sparql_lexer_log_error(yyconst char *msg,
                                   raptor_log_level level,
                                   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, level, &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 = (lexer_alloc_tracker_header*)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 = (lexer_alloc_tracker_header*)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(RASQAL_GOOD_CAST(char*, ptr), size);

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

  return newptr;
#else
  return realloc(RASQAL_GOOD_CAST(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(rasqal_world* world, 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 STRLANG:
      return "STRLANG";
      
    case STRDT:
      return "STRDT";
      
    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 HAVING:
      return "HAVING";

    case COUNT:
      return "COUNT";

    case SUM:
      return "SUM";

    case AVG:
      return "AVG";

    case MIN:
      return "MIN";

    case MAX:
      return "MAX";

    case DELETE:
      return "DELETE";

    case INSERT:
      return "INSERT";

    case WITH:
      return "WITH";

    case CLEAR:
      return "CLEAR";

    case CREATE:
      return "CREATE";

    case SILENT:
      return "SILENT";

    case DATA:
      return "DATA";
      
    case DROP:
      return "DROP";
      
    case LOAD:
      return "LOAD";
      
    case INTO:
      return "INTO";
      
    case IF:
      return "IF";

    case LET:
      return "LET";

    case AS:
      return "AS";

    case ASSIGN:
      return ":=";

    case COALESCE:
      return "COALESCE";

    case IRI:
      return "IRI";

    case URI:
      return "URI";

    case BNODE:
      return "BNODE";

    case SAMPLE:
      return "SAMPLE";

    case DEFAULT:
      return "DEFAULT";

    case NOT:
      return "NOT";

    case IN:
      return "IN";

    case GROUP_CONCAT:
      return "GROUP_CONCAT";

    case SEPARATOR:
      return "SEPARATOR";

    case BINDINGS:
      return "BINDINGS";

    case UNDEF:
      return "UNDEF";

    case SERVICE:
      return "SERVICE";

    case MINUS:
      return "MINUS";

    case ISNUMERIC:
      return "isNUMERIC";

    case YEAR:
      return "YEAR";

    case MONTH:
      return "MONTH";

    case DAY:
      return "DAY";

    case HOURS:
      return "HOURS";

    case MINUTES:
      return "MINUTES";

    case SECONDS:
      return "SECONDS";

    case TIMEZONE:
      return "TIMEZONE";

    case CURRENT_DATETIME:
      return "CURRENT_DATETIME";

    case NOW:
      return "NOW";

    case FROM_UNIXTIME:
      return "FROM_UNIXTIME";

    case TO_UNIXTIME:
      return "TO_UNIXTIME";

    case CONCAT:
      return "CONCAT";

    case STRLEN:
      return "STRLEN";

    case SUBSTR:
      return "SUBSTR";

    case UCASE:
      return "UCASE";

    case LCASE:
      return "LCASE";

    case STRSTARTS:
      return "STRSTARTS";

    case STRENDS:
      return "STRENDS";

    case CONTAINS:
      return "CONTAINS";

    case ENCODE_FOR_URI:
      return "ENCODE_FOR_URI";

    case TO:
      return "TO";

    case ADD:
      return "ADD";

    case MOVE:
      return "MOVE";

    case COPY:
      return "COPY";

    case ALL:
      return "ALL";

    case TZ:
      return "TZ";

    case RAND:
      return "RAND";

    case BIND:
      return "BIND";

    case ABS:
      return "ABS";

    case ROUND:
      return "ROUND";

    case CEIL:
      return "CEIL";

    case FLOOR:
      return "FLOOR";

    case MD5:
      return "MD5";

    case SHA1:
      return "SHA1";

    case SHA224:
      return "SHA224";

    case SHA256:
      return "SHA256";

    case SHA384:
      return "SHA384";

    case SHA512:
      return "SHA512";

    case STRBEFORE:
      return "STRBEFORE";

    case STRAFTER:
      return "STRAFTER";

    case REPLACE:
      return "REPLACE";

    case UUID:
      return "UUID";

    case STRUUID:
      return "STRUUID";

    case VALUES:
      return "VALUES";

    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:
      sprintf(buffer, "STRING(\"%s\")", lval->name);
      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;

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

    case HATHAT:
      return "HATHAT";

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



#ifdef STANDALONE
static void
sparql_token_free(rasqal_world* world, int token, YYSTYPE *lval)
{
  if(!token)
    return;
  
  switch(token) {
    case INTEGER_LITERAL:
    case INTEGER_POSITIVE_LITERAL:
    case INTEGER_NEGATIVE_LITERAL:
    case DOUBLE_LITERAL:
    case DOUBLE_POSITIVE_LITERAL:
    case DOUBLE_NEGATIVE_LITERAL:
    case DECIMAL_POSITIVE_LITERAL:
    case DECIMAL_NEGATIVE_LITERAL:
    case DECIMAL_LITERAL:
    case BOOLEAN_LITERAL:
      rasqal_free_literal(lval->literal);
      break;
    case URI_LITERAL:
    case URI_LITERAL_BRACE:
      raptor_free_uri(lval->uri);
      break;
    case STRING:
    case IDENTIFIER:
    case BLANK_LITERAL:
    case PREFIX:
      RASQAL_FREE(char*, lval->name);
      break;
    case QNAME_LITERAL:
      if(lval->name)
        RASQAL_FREE(char*, lval->name);
      break;
    default:
      break;
  }
}


#define FILE_READ_BUF_SIZE 4096

int
main(int argc, char *argv[]) 
{
  const char *program = rasqal_basename(argv[0]);
  char *query_string = NULL;
  rasqal_query rq;
  rasqal_sparql_query_language sparql;
  yyscan_t scanner;
  int token = EOF;
  YYSTYPE lval;
  const unsigned char *uri_string;
  const char *filename = NULL;
  char *buf = NULL;
  size_t len;
  rasqal_world *world;
  FILE *fh;
  
  world = rasqal_new_world();
  if(!world || rasqal_world_open(world))
    exit(1);
  
  filename = getenv("SPARQL_QUERY_FILE");
  if(!filename) {
    if(argc != 2) {
      fprintf(stderr, "%s: Too many arguments.\n", program);
      fprintf(stderr, "SPARQL lexer test for Rasqal %s\n", 
              rasqal_version_string);
      fprintf(stderr, "USAGE: %s SPARQL-QUERY-FILE\n", program);
      exit(1);
    }
    
    filename = argv[1];
  }
  
  query_string = RASQAL_CALLOC(char*, FILE_READ_BUF_SIZE, 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);
  }

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

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

  len =  strlen(RASQAL_GOOD_CAST(const char*, query_string));
  buf =  RASQAL_MALLOC(char*, len + 3);
  memcpy(buf, query_string, len);
  buf[len] =  ' ';
  buf[len+1] =  buf[len+2] = '\0'; /* YY_END_OF_BUFFER_CHAR; */
  (void)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(world->raptor_world_ptr, uri_string);
  raptor_free_memory((void*)uri_string);

  while(1) {
    memset(&lval, 0, sizeof(lval));
    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(world, token, &lval));
#else
    printf("token %d\n", token);
#endif
    sparql_token_free(world, token, &lval);
    if(!token || token == EOF)
      break;
  }

  if(buf)
    RASQAL_FREE(char*, buf);
  
  sparql_lexer_lex_destroy(scanner);

  raptor_free_uri(rq.base_uri);

  RASQAL_FREE(char*, query_string);

  rasqal_free_world(world);

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

