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

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

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

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

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

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

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

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

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

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

/* Pure parsers.  */
#define YYPURE 0

/* Using locations.  */
#define YYLSP_NEEDED 0

/* If NAME_PREFIX is specified substitute the variables and functions
   names.  */
#define yyparse slparse
#define yylex   sllex
#define yyerror slerror
#define yylval  sllval
#define yychar  slchar
#define yydebug sldebug
#define yynerrs slnerrs


/* Tokens.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
   /* Put the tokens into the symbol table, so that GDB and other debuggers
      know about them.  */
   enum yytokentype {
     SCRL_PARAMETERS = 258,
     SCRL_VARIABLES = 259,
     SCRL_OUTPUT = 260,
     SCRL_VARYING = 261,
     SCRL_VERTEX = 262,
     SCRL_UNIFORM = 263,
     SCRL_BOOLEAN = 264,
     SCRL_FLOAT = 265,
     SCRL_COLOR = 266,
     SCRL_VECTOR = 267,
     SCRL_NORMAL = 268,
     SCRL_POINT = 269,
     SCRL_MATRIX = 270,
     SCRL_STRING = 271,
     SCRL_SURFACE = 272,
     SCRL_DISPLACEMENT = 273,
     SCRL_IMAGER = 274,
     SCRL_LIGHTSOURCE = 275,
     SCRL_VOLUME = 276,
     SCRL_GENERIC = 277,
     SCRL_DSO = 278,
     SCRL_INIT = 279,
     SCRL_CODE = 280,
     SCRL_DOT = 281,
     SCRL_COLON = 282,
     SCRL_EQUAL = 283,
     SCRL_OPEN_PARANTHESIS = 284,
     SCRL_CLOSE_PARANTHESIS = 285,
     SCRL_OPEN_SQR_PARANTHESIS = 286,
     SCRL_CLOSE_SQR_PARANTHESIS = 287,
     SCRL_COMMA = 288,
     SCRL_NL = 289,
     SCRL_TEXT_VALUE = 290,
     SCRL_IDENTIFIER_VALUE = 291,
     SCRL_LABEL_VALUE = 292,
     SCRL_FLOAT_VALUE = 293
   };
#endif
#define SCRL_PARAMETERS 258
#define SCRL_VARIABLES 259
#define SCRL_OUTPUT 260
#define SCRL_VARYING 261
#define SCRL_VERTEX 262
#define SCRL_UNIFORM 263
#define SCRL_BOOLEAN 264
#define SCRL_FLOAT 265
#define SCRL_COLOR 266
#define SCRL_VECTOR 267
#define SCRL_NORMAL 268
#define SCRL_POINT 269
#define SCRL_MATRIX 270
#define SCRL_STRING 271
#define SCRL_SURFACE 272
#define SCRL_DISPLACEMENT 273
#define SCRL_IMAGER 274
#define SCRL_LIGHTSOURCE 275
#define SCRL_VOLUME 276
#define SCRL_GENERIC 277
#define SCRL_DSO 278
#define SCRL_INIT 279
#define SCRL_CODE 280
#define SCRL_DOT 281
#define SCRL_COLON 282
#define SCRL_EQUAL 283
#define SCRL_OPEN_PARANTHESIS 284
#define SCRL_CLOSE_PARANTHESIS 285
#define SCRL_OPEN_SQR_PARANTHESIS 286
#define SCRL_CLOSE_SQR_PARANTHESIS 287
#define SCRL_COMMA 288
#define SCRL_NL 289
#define SCRL_TEXT_VALUE 290
#define SCRL_IDENTIFIER_VALUE 291
#define SCRL_LABEL_VALUE 292
#define SCRL_FLOAT_VALUE 293




/* Copy the first part of user declarations.  */
#line 1 "sdr.y"

//////////////////////////////////////////////////////////////////////
//
//                             Pixie
//
// Copyright © 1999 - 2003, Okan Arikan
//
// Contact: okan@cs.berkeley.edu
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//
//  File				:	sl.y
//  Classes				:	-
//  Description			:	This is the parser file for CShader
//
////////////////////////////////////////////////////////////////////////
#undef alloca
#include <math.h>
#include <string.h>

#include "common/global.h"
#include "common/containers.h"
#include "shader.h"
#include "slcode.h"
#include "renderer.h"
#include "error.h"

/////////////////////////////////////////////////////////////////////////////////////
//   First some temporary data structures used during the script parsing


// Some forward definitions
		void							slerror(char *);			// Forward definition for stupid yacc
		int								sllex(void );				// Forward definition for stupid yacc

		static	char					*initLabel	=	"#!Init";	// The label for the init
		static	char					*codeLabel	=	"#!Code";	// The label for the code

typedef struct TSlVariable {
	char			name[64];
	int				index;
	int				multiplicity;
	EVariableType	type;
	EVariableClass	container;
	int				uniform;
	CVariable		*global;
	TSlVariable		*next;
} TSlVariable;

typedef struct TSlLabel {
	char			name[64];
	int				index;
	TSlLabel		*next;
} TSlLabel;

typedef struct {
	ESlCode			entryPoint;
	char			*name;
	int				nargs;
	unsigned int	usedParameters;
} TSlOpcode;

typedef struct {
	ESlCode			entryPoint;
	char			*name;
	char			*prototype;
	unsigned int	usedParameters;
} TSlFunction;

#define	DEFOPCODE(name,text,nargs,expr_pre,expr,expr_update,expr_post,params)			{OPCODE_##name,text,nargs,params},
#define	DEFSHORTOPCODE(name,text,nargs,expr_pre,expr,expr_update,expr_post,params)		{OPCODE_##name,text,nargs,params},
#define	DEFLINKOPCODE(name,text,nargs)													{OPCODE_##name,text,nargs,0},
#define	DEFFUNC(name,text,prototype,expr_pre,expr,expr_update,expr_post,par)
#define	DEFLIGHTFUNC(name,text,prototype,expr_pre,expr,expr_update,expr_post,par)
#define	DESHORTFFUNC(name,text,prototype,expr_pre,expr,expr_update,expr_post,par)
#define	DEFLINKFUNC(name,text,prototype,par)

static	TSlOpcode	opcodes[]	=	{
#include "scriptOpcodes.h"
{	OPCODE_NOP	,	NULL	,	0	}
};

#undef DEFOPCODE
#undef DEFSHORTOPCODE
#undef DEFLINKOPCODE
#undef DEFFUNC
#undef DEFLIGHTFUNC
#undef DEFSHORTFUNC
#undef DEFLINKFUNC

#define	DEFOPCODE(name,text,nargs,expr_pre,expr,expr_update,expr_post)
#define	DEFSHORTOPCODE(name,text,nargs,expr_pre,expr,expr_update,expr_post)
#define DEFLINKOPCODE(name,text,nargs)
#define	DEFFUNC(name,text,prototype,expr_pre,expr,expr_update,expr_post,par)			{FUNCTION_##name,text,prototype,par},
#define	DEFLIGHTFUNC(name,text,prototype,expr_pre,expr,expr_update,expr_post,par)		{FUNCTION_##name,text,prototype,par},
#define	DEFSHORTFUNC(name,text,prototype,expr_pre,expr,expr_update,expr_post,par)		{FUNCTION_##name,text,prototype,par},
#define	DEFLINKFUNC(name,text,prototype,par)											{FUNCTION_##name,text,prototype,par},
static	TSlFunction		functions[]	=	{
#include "scriptFunctions.h"
{	OPCODE_NOP	,	NULL	,	NULL	}
};


#undef DEFOPCODE
#undef DEFSHORTOPCODE
#undef DEFLINKOPCODE
#undef DEFFUNC
#undef DEFSHORTFUNC
#undef DEFLINKFUNC


		////////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	This structure holds the compiling context
		//
		//
		typedef struct {
				const char				*name;					// Name of the file being parsed
				int						passNumber;				// Current pass number (we make 2 passes)
				int						parsingInit;			// TRUE if we're parsing the init code
				int						numErrors;				// Number of errors encountered during parse

				// Pass 1
				int						numCode;				// The number of code blocks
				int						numConstants;			// The number of constants
				int						numVariables;			// The number of variable variables
				int						numUniforms;			// The number of uniform variables
				int						numParameters;			// The number of parameters
				int						numStrings;				// The number of strings

				int						constantSize;			// Total size required by the constants
				int						parameterSize;			// Total size required by the parameters
				int						varyingSize;			// Total size required by the varying variables
				int						uniformSize;			// Total size required by the uniform variables

				int						shaderType;				// Type of the shader

				int						uniform;				// TRUE if the current expression is uniform
				int						opcodeUniform;			// TRUE if the opcode/function is uniform

				// Pass 2
				EVariableType			currentParameterType;	// The type of the current parameter
				int						currentParameterGlobal;	// TRUE if the current parameter is also global
				EVariableClass			currentParameterClass;	// The container class of the current parameter
				int						currentCode;			// Current xXx
				int						currentConstant;
				int						currentVariable;
				int						currentUniform;
				int						currentParameter;
				int						currentString;
				int						currentPL;				// The current parameter list

				int						currentParameterSize;
				int						currentConstantSize;
				int						currentVaryingSize;
				int						currentUniformSize;

				TCode					*currentArray;			// Array items go here as we read them
				int						numArrayItemsRemaining;	// Number of array items we're still expecting to read
				
				char					currentOpcode[32];		// Holds the opcode being parsed
				char					currentPrototype[32];	// Holds the prototype being parsed
				int						currentArgument;		// The current argument number
				unsigned int			usedParameters;			// Used parameters by this shader
				TCode					*currentOpcodePlace;	// Points to the code that should holds the opcode

				int						codeEntryPoint;			// Indices in the code array for corresponding entry points
				int						initEntryPoint;
				

				TCode					*memory;				// The memory base for the area that's allocated
				TCode					*code;					// Code blocks
				TCode					*constants;				// Constants blocks
				TCode					*parameters;			// Parameter blocks
				int						*varyingSizes;			// Holds the size of each varying in codes
				int						*uniformSizes;			// Holds the size of each uniform in codes
				char					**strings;				// Strings defined
				TCode					**parameterEntries;
				int						*parameterDisplacements;
				TCode					**constantEntries;

				TSlVariable				*definedVariables;		// List of defined variables
				TSlVariable				*definedParameters;		// List of defined parameters
				TSlLabel				*labelReferences;		// List of label references
				TSlLabel				*labelDefinitions;		// List of label definitions
		} TShaderData;

		TShaderData						currentData;

											///////////////////////////////////////////////////////////////////////
											// Function				:	numComponents
											// Description			:	Returns the number of codes that a particular type takes
											// Return Value			:	Size in codes
											// Comments				:
											// Date last edited		:	8/8/2001
			static	int					numComponents(EVariableType type) {
											switch(type) {
											case TYPE_FLOAT:
												return	1;
												break;
											case TYPE_COLOR:
												return	3;
												break;
											case TYPE_VECTOR:
												return	3;
												break;
											case TYPE_NORMAL:
												return	3;
												break;
											case TYPE_POINT:
												return	3;
												break;
											case TYPE_MATRIX:
												return	16;
												break;
											case TYPE_QUAD:
												return	4;
												break;
											case TYPE_DOUBLE:
												return	2;
												break;
											case TYPE_STRING:
												return	1;
												break;
											case TYPE_INTEGER:
											case TYPE_BOOLEAN:
												return	1;
												break;
											default:
												slerror("Unknown type (bug)");
												break;
											}

											return 0;
										}

										///////////////////////////////////////////////////////////////////////
										// Function				:	makeGlobal
										// Description			:	Make a variable global
										// Return Value			:	-
										// Comments				:
										// Date last edited		:	2/2/2005
		static	void					makeGlobal(TSlVariable *cVariable) {
											char tmp[512];

											sprintf(tmp,"global ");

											switch(cVariable->container) {
												case CONTAINER_UNIFORM:
													strcat(tmp,"uniform ");
													break;
												case CONTAINER_VERTEX:
													strcat(tmp,"vertex ");
													break;
												case CONTAINER_VARYING:
													strcat(tmp,"varying ");
													break;
												default:
													slerror("Unexpected container class for shader variable.\n");
													break;
											}


											switch(cVariable->type) {
												case TYPE_FLOAT:
													strcat(tmp,"float");
													break;
												case TYPE_COLOR:
													strcat(tmp,"color");
													break;
												case TYPE_VECTOR:
													strcat(tmp,"vector");
													break;
												case TYPE_NORMAL:
													strcat(tmp,"normal");
													break;
												case TYPE_POINT:
													strcat(tmp,"point");
													break;
												case TYPE_MATRIX:
													strcat(tmp,"matrix");
													break;
												case TYPE_QUAD:
													strcat(tmp,"qtpoint");
													break;
												case TYPE_DOUBLE:
													slerror("Unexpected container class for shader variable.\n");
													break;
												case TYPE_STRING:
													strcat(tmp,"string");
													break;
												case TYPE_INTEGER:
													slerror("Unexpected container class for shader variable.\n");
													break;
												case TYPE_BOOLEAN:
													slerror("Unexpected container class for shader variable.\n");
													break;
												default:
													break;
											}

											if ( cVariable->multiplicity != 1 ) {
												sprintf(tmp+strlen(tmp),"[%d]",cVariable->multiplicity);
											}
											
											cVariable->global	=	currentRenderer->declareVariable(cVariable->name,tmp);
										}

										///////////////////////////////////////////////////////////////////////
										// Function				:	newVariable
										// Description			:	Add a new variable/parameter
										// Return Value			:	The default area if available
										// Comments				:
										// Date last edited		:	8/8/2001
		static	TCode					*newVariable(char *name,EVariableType type,int numItems,int parameter) {
										TCode			*result			=	NULL;
										int				numComp			=	numComponents(type);


										switch(currentData.passNumber) {
										case 1:
											if (parameter) {
												currentData.numParameters++;
												currentData.parameterSize	+=	numItems*numComp;
											} else {
												if (currentData.uniform) {
													currentData.numUniforms++;
													currentData.uniformSize		+=	numItems*numComp;
												} else {
													currentData.numVariables++;
													currentData.varyingSize		+=	numItems*numComp;
												}
											}
											result	=	NULL;
											break;
										case 2:
											{
												TSlVariable	*cVariable	=	new TSlVariable;

												strcpy(cVariable->name,name);
												cVariable->multiplicity	=	numItems;
												cVariable->type			=	type;
												cVariable->container	=	currentData.currentParameterClass;
												cVariable->uniform		=	currentData.uniform;
												cVariable->global		=	NULL;

												if (parameter) {
													result	=	currentData.parameterEntries[currentData.currentParameter]	=	&currentData.parameters[currentData.currentParameterSize];
													currentData.parameterDisplacements[currentData.currentParameter]		=	currentData.currentParameterSize;
													cVariable->index				=	currentData.currentParameter;
													currentData.currentParameter++;
													currentData.currentParameterSize+=	numItems*numComp;

													cVariable->next					=	currentData.definedParameters;
													currentData.definedParameters	=	cVariable;

													if (currentData.currentParameterGlobal == TRUE) {
														makeGlobal(cVariable);
													}
												} else {
													result							=	NULL;

													if (cVariable->uniform) {
														cVariable->index										=	currentData.currentUniform;
														currentData.uniformSizes[currentData.currentUniform]	=	numItems*numComp;
														currentData.currentUniform++;
														currentData.currentUniformSize	+=	numItems*numComp;
													} else {
														cVariable->index										=	currentData.currentVariable;
														currentData.varyingSizes[currentData.currentVariable]	=	numItems*numComp;
														currentData.currentVariable++;
														currentData.currentVaryingSize	+=	numItems*numComp;
													}

													cVariable->next					=	currentData.definedVariables;
													currentData.definedVariables	=	cVariable;
												}
											}
											break;
										default:
											break;
										}

										return result;
									}

									///////////////////////////////////////////////////////////////////////
									// Function				:	addStringReference
									// Description			:	Add a reference to a string
									// Return Value			:	-
									// Comments				:
									// Date last edited		:	8/8/2001
		static	void				addStringReference(char **items,int numItems) {
										switch(currentData.passNumber) {
										case 1:
											currentData.numCode			+=	1;
											currentData.numConstants	+=	1;
											currentData.numStrings		+=	numItems;
											currentData.constantSize	+=	numItems;
											break;
										case 2:
											currentData.code[currentData.currentCode].reference.numItems	=	0;
											currentData.code[currentData.currentCode].reference.index		=	currentData.currentConstant;
											currentData.code[currentData.currentCode].reference.accessor	=	SL_IMMEDIATE_OPERAND;
											currentData.constantEntries[currentData.currentConstant]		=	&currentData.constants[currentData.currentConstantSize];
											currentData.currentCode++;
											currentData.currentConstant++;

											{
												int	i;

												for (i=0;i<numItems;i++)
													currentData.constants[currentData.currentConstantSize++].string		=	currentData.strings[currentData.currentString++]	=	strdup(items[i]);
											}

											currentData.currentArgument++;
											break;
										default:
											break;
										}
									}


									///////////////////////////////////////////////////////////////////////
									// Function				:	addFloatReference
									// Description			:	Add a reference to a float
									// Return Value			:	-
									// Comments				:
									// Date last edited		:	8/8/2001
		static	void				addFloatReference(float *items,int numItems) {
									switch(currentData.passNumber) {
										case 1:
											currentData.numCode			+=	1;
											currentData.numConstants	+=	1;
											currentData.constantSize	+=	numItems;
											break;
										case 2:
											{
												int	i;

												currentData.code[currentData.currentCode].reference.numItems	=	0;
												currentData.code[currentData.currentCode].reference.index		=	currentData.currentConstant;
												currentData.code[currentData.currentCode].reference.accessor	=	SL_IMMEDIATE_OPERAND;
												currentData.constantEntries[currentData.currentConstant]		=	&currentData.constants[currentData.currentConstantSize];
												currentData.currentCode++;
												currentData.currentConstant++;

												for (i=0;i<numItems;i++)
													currentData.constants[currentData.currentConstantSize++].real	=	items[i];

												currentData.currentArgument++;
											}
											break;
										default:
											break;
										}
									}

									///////////////////////////////////////////////////////////////////////
									// Function				:	addVariableReference
									// Description			:	Add a reference to a variable/parameter
									// Return Value			:	-
									// Comments				:
									// Date last edited		:	8/8/2001
		static	void				addVariableReference(char *name) {
									CVariable		*var;
									TSlVariable		*cVariable;

									switch(currentData.passNumber) {
									case 1:
										currentData.numCode	+=	1;
										break;
									case 2:
										currentData.currentArgument++;

										// Search the parameters
										for (cVariable=currentData.definedParameters;cVariable!=NULL;cVariable=cVariable->next) {
											if (strcmp(cVariable->name,name) == 0) {
												if ((cVariable->global == NULL) || (currentData.parsingInit == TRUE)) {
													currentData.code[currentData.currentCode].reference.index			=	cVariable->index;
													currentData.code[currentData.currentCode].reference.accessor		=	SL_PARAMETER_OPERAND;
													if (cVariable->uniform) {
														currentData.code[currentData.currentCode].reference.numItems	=	0;
													} else {
														currentData.code[currentData.currentCode].reference.numItems	=	numComponents(cVariable->type)*cVariable->multiplicity;
														currentData.opcodeUniform										=	FALSE;
													}
													currentData.currentCode++;
													return;
												}
											}
										}

										for (cVariable=currentData.definedVariables;cVariable!=NULL;cVariable=cVariable->next) {
											if (strcmp(cVariable->name,name) == 0) {
												currentData.code[currentData.currentCode].reference.index		=	cVariable->index;
												if (cVariable->uniform) {
													currentData.code[currentData.currentCode].reference.accessor	=	SL_UNIFORM_OPERAND;
													currentData.code[currentData.currentCode].reference.numItems	=	0;
												} else {
													currentData.code[currentData.currentCode].reference.numItems	=	cVariable->multiplicity*numComponents(cVariable->type);
													currentData.code[currentData.currentCode].reference.accessor	=	SL_VARYING_OPERAND;
													currentData.opcodeUniform										=	FALSE;
												}

												currentData.currentCode++;
												return;
											}
										}

										var	=	currentRenderer->retrieveVariable(name);

										if (var != NULL) {
											int	step;

											if (var->global == FALSE)	currentRenderer->makeGlobalVariable(var);

											if ((var->container == CONTAINER_UNIFORM) || (var->container == CONTAINER_CONSTANT)) {
												step						=	0;
											} else {
												step						=	var->numFloats;
												currentData.opcodeUniform	=	FALSE;
											}

											currentData.usedParameters										|=	var->usageMarker;

											currentData.code[currentData.currentCode].reference.index		=	var->entry;
											currentData.code[currentData.currentCode].reference.numItems	=	step;
											currentData.code[currentData.currentCode].reference.accessor	=	SL_GLOBAL_OPERAND;
											currentData.currentCode++;

											return;
										}

										slerror("Unknown variable");

										break;
									default:
										break;
									}

									}

									///////////////////////////////////////////////////////////////////////
									// Function				:	setOpcode
									// Description			:	Find/Set an opcode/function
									// Return Value			:	-
									// Comments				:
									// Date last edited		:	8/8/2001
		static	void				setOpcode() {
										switch(currentData.passNumber) {
										case 1:
											break;
										case 2:
											// Is this an opcode or function
											if (currentData.currentPrototype[0] == '~') {
												ESlCode	opcode;
												int		i;

												for(i=0;opcodes[i].name != NULL;i++) {
													if (strcmp(opcodes[i].name,currentData.currentOpcode) == 0) 
														if (opcodes[i].nargs == currentData.currentArgument) {
															opcode	=	opcodes[i].entryPoint;
															break;
														}
												}

												if (opcodes[i].name == NULL)
													slerror("Unknown opcode");
												else {
													// Save the opcode
													currentData.usedParameters									|=	opcodes[i].usedParameters;
													currentData.currentOpcodePlace[0].integer					=	(int) opcode;
													currentData.currentOpcodePlace[1].arguments.numCodes		=	currentData.currentArgument+2;
													currentData.currentOpcodePlace[1].arguments.numArguments	=	currentData.currentArgument;
													currentData.currentOpcodePlace[1].arguments.uniform			=	currentData.opcodeUniform;
												}
											} else {
												int			i;
												ESlCode		opcode;

												for(i=0;functions[i].name != NULL;i++) {
													if (strcmp(functions[i].name,currentData.currentOpcode) == 0) {
														if (strcmp(functions[i].prototype,currentData.currentPrototype) == 0) {
															currentData.usedParameters	|=	functions[i].usedParameters;
															opcode						=	functions[i].entryPoint;
															break;
														} else {
															// Do a pattern match
			

															// The return types must match exactly
															if (functions[i].prototype[0] != currentData.currentPrototype[0]) continue;

															{
																int		j,k,t;

																t	=	FALSE;

																for (j=2,k=2;(currentData.currentPrototype[j] != '\0') && (functions[i].prototype[k] != '\0');j++,k++) {
																	// Do the current parameters match
																	if (currentData.currentPrototype[j] == functions[i].prototype[k]) continue;
																	// Does the function match any parameter ?
																	else if (functions[i].prototype[k] == '.') continue;
																	// Is the current parameter a * or + ?
																	else if ((functions[i].prototype[k] == '+') || (functions[i].prototype[k] == '*')) {
																		k-=2;
																		j--;
																		continue;
																	// Is the current parameter a parameter list ?
																	} else if (functions[i].prototype[k] == '!') {
																		if ((currentData.currentPrototype[j] == 's') || (currentData.currentPrototype[j] == 'S')) {
																			j++;
																			k--;
																		} else {
																			t	=	TRUE;
																			break;
																		}
																	} else {
																		t	=	TRUE;
																		break;
																	}
																}


																if (t == FALSE) {
																	if (
																			((functions[i].prototype[k] == '\0') && (currentData.currentPrototype[j] == '\0')) ||
																			((functions[i].prototype[k] == '+') || (functions[i].prototype[k] == '*')) || 
																			(functions[i].prototype[k] == '!') ||
																			(functions[i].prototype[k+1] == '*')) {
																		// We found our function/opcode
																		currentData.usedParameters	|=	functions[i].usedParameters;
																		opcode	=	functions[i].entryPoint;
																		break;
																	} else {
																		continue;
																	}
																}
															}
														}
													}
												}	

												// Save the opcode
												if (functions[i].name != NULL) {
													currentData.currentOpcodePlace[0].integer						=	(int) opcode;
													currentData.currentOpcodePlace[1].arguments.numCodes			=	currentData.currentArgument+2;
													currentData.currentOpcodePlace[1].arguments.plNumber			=	currentData.currentPL;
													currentData.currentOpcodePlace[1].arguments.numArguments		=	currentData.currentArgument;
													currentData.currentOpcodePlace[1].arguments.uniform				=	currentData.opcodeUniform;
													if (strchr(functions[i].prototype,'!') != NULL)	currentData.currentPL++;
												} else {
													// Allright, we could not find the function, check the DSO shaders
													void			*handle;
													dsoExecFunction	exec;

													if (currentRenderer->getDSO(currentData.currentOpcode,currentData.currentPrototype,handle,exec) == TRUE) {
														// We have the DSO
													} else {
														slerror("Unknown function");
													}
												}
											}
											break;
										default:
											break;
										}
									}


									///////////////////////////////////////////////////////////////////////
									// Function				:	newLabel
									// Description			:	Create a new label definition/reference
									// Return Value			:	-
									// Comments				:
									// Date last edited		:	8/8/2001
		static	void				newLabel(char *name,int reference) {
										switch(currentData.passNumber) {
										case 1:
											if (reference)
												currentData.numCode++;
											break;
										case 2:
											{
												TSlLabel	*cLabel	=	new TSlLabel;

												strcpy(cLabel->name,name);
												cLabel->index	=	currentData.currentCode;

												if (reference) {
													cLabel->next					=	currentData.labelReferences;
													currentData.labelReferences		=	cLabel;
													currentData.currentCode++;
													currentData.currentArgument++;
												} else {
													TSlLabel	*tLabel;

													for (tLabel=currentData.labelDefinitions;tLabel!=NULL;tLabel=tLabel->next) {
														if (strcmp(tLabel->name,cLabel->name) == 0) {
															slerror("Duplicate label definition\n");
														}
													}

													cLabel->next					=	currentData.labelDefinitions;
													currentData.labelDefinitions	=	cLabel;
												}
											}
											break;
										default:
											break;
										}
									}

									// Some forward references
		void						reset();
		void						alloc();
		CShader						*shaderCreate(const char *);
		int							getVariable(char *);
		int							getOpcode(char *,int);
		int							getFunction(char *,char *,int *ps = NULL);
		void						*newVariable(char *,int,int,int,int m=1);
		TSlLabel					*newLabelDef(char *,int);
		TSlLabel					*newLabelRef(char *,int);
		void						processEscapes(char *);


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

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

#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 742 "sdr.y"
typedef union slval {
	float	real;
	char	string[64];
	matrix	m;
	vector	v;
} YYSTYPE;
/* Line 191 of yacc.c.  */
#line 910 "sl.cpp"
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif



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


/* Line 214 of yacc.c.  */
#line 922 "sl.cpp"

#if ! defined (yyoverflow) || YYERROR_VERBOSE

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

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

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

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


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

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

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

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

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

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

#endif

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

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

/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS  39
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS  62
/* YYNRULES -- Number of rules. */
#define YYNRULES  141
/* YYNRULES -- Number of states. */
#define YYNSTATES  320

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

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

/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
static const unsigned char yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
      35,    36,    37,    38
};

#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
   YYRHS.  */
static const unsigned short int yyprhs[] =
{
       0,     0,     3,    10,    11,    14,    18,    26,    29,    36,
      37,    39,    41,    43,    44,    47,    50,    53,    56,    59,
      64,    68,    69,    71,    73,    75,    78,    81,    84,    86,
      87,    90,    92,    94,    96,    98,   100,   102,   104,   109,
     112,   113,   122,   128,   132,   135,   136,   139,   144,   145,
     154,   160,   164,   167,   168,   169,   174,   175,   184,   190,
     191,   196,   197,   206,   212,   213,   218,   219,   228,   234,
     235,   240,   241,   250,   256,   259,   266,   268,   274,   278,
     281,   282,   304,   309,   312,   313,   322,   328,   332,   352,
     355,   356,   361,   365,   366,   369,   372,   375,   378,   381,
     384,   387,   390,   393,   399,   402,   408,   411,   417,   420,
     426,   429,   435,   438,   444,   447,   453,   456,   462,   463,
     468,   469,   474,   478,   482,   486,   487,   488,   496,   498,
     500,   502,   505,   506,   509,   512,   514,   516,   518,   520,
     528,   562
};

/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yysigned_char yyrhs[] =
{
      40,     0,    -1,    45,    46,    78,    89,    91,    41,    -1,
      -1,    34,    41,    -1,    28,    35,    38,    -1,    28,    35,
      31,    38,    38,    38,    32,    -1,    28,    38,    -1,    28,
      31,    38,    38,    38,    32,    -1,    -1,    42,    -1,     8,
      -1,     6,    -1,    -1,    17,    34,    -1,    18,    34,    -1,
      20,    34,    -1,    21,    34,    -1,    19,    34,    -1,     3,
      27,    34,    47,    -1,    47,    49,    34,    -1,    -1,     8,
      -1,     6,    -1,     7,    -1,     5,     8,    -1,     5,     6,
      -1,     5,     7,    -1,     5,    -1,    -1,    48,    50,    -1,
      51,    -1,    55,    -1,    59,    -1,    62,    -1,    65,    -1,
      68,    -1,    74,    -1,    10,    36,    28,    38,    -1,    10,
      36,    -1,    -1,    10,    36,    31,    38,    32,    28,    52,
      53,    -1,    10,    36,    31,    38,    32,    -1,    31,    54,
      32,    -1,    54,    38,    -1,    -1,    16,    36,    -1,    16,
      36,    28,    35,    -1,    -1,    16,    36,    31,    38,    32,
      28,    56,    57,    -1,    16,    36,    31,    38,    32,    -1,
      31,    58,    32,    -1,    58,    35,    -1,    -1,    -1,    11,
      36,    60,    43,    -1,    -1,    11,    36,    31,    38,    32,
      28,    61,    72,    -1,    11,    36,    31,    38,    32,    -1,
      -1,    12,    36,    63,    43,    -1,    -1,    12,    36,    31,
      38,    32,    28,    64,    72,    -1,    12,    36,    31,    38,
      32,    -1,    -1,    13,    36,    66,    43,    -1,    -1,    13,
      36,    31,    38,    32,    28,    67,    72,    -1,    13,    36,
      31,    38,    32,    -1,    -1,    14,    36,    69,    43,    -1,
      -1,    14,    36,    31,    38,    32,    28,    70,    72,    -1,
      14,    36,    31,    38,    32,    -1,    35,    38,    -1,    35,
      31,    38,    38,    38,    32,    -1,    38,    -1,    31,    38,
      38,    38,    32,    -1,    31,    73,    32,    -1,    73,    71,
      -1,    -1,    15,    36,    28,    31,    38,    38,    38,    38,
      38,    38,    38,    38,    38,    38,    38,    38,    38,    38,
      38,    38,    32,    -1,    15,    36,    28,    38,    -1,    15,
      36,    -1,    -1,    15,    36,    31,    38,    32,    28,    75,
      76,    -1,    15,    36,    31,    38,    32,    -1,    31,    77,
      32,    -1,    77,    31,    38,    38,    38,    38,    38,    38,
      38,    38,    38,    38,    38,    38,    38,    38,    38,    38,
      32,    -1,    77,    38,    -1,    -1,     4,    27,    34,    79,
      -1,    79,    80,    34,    -1,    -1,    44,    81,    -1,    44,
      82,    -1,    44,    83,    -1,    44,    85,    -1,    44,    84,
      -1,    44,    86,    -1,    44,    87,    -1,    44,    88,    -1,
       9,    36,    -1,     9,    36,    31,    38,    32,    -1,    10,
      36,    -1,    10,    36,    31,    38,    32,    -1,    16,    36,
      -1,    16,    36,    31,    38,    32,    -1,    12,    36,    -1,
      12,    36,    31,    38,    32,    -1,    11,    36,    -1,    11,
      36,    31,    38,    32,    -1,    13,    36,    -1,    13,    36,
      31,    38,    32,    -1,    14,    36,    -1,    14,    36,    31,
      38,    32,    -1,    15,    36,    -1,    15,    36,    31,    38,
      32,    -1,    -1,    24,    34,    90,    93,    -1,    -1,    25,
      34,    92,    93,    -1,    93,    98,    34,    -1,    93,    99,
      34,    -1,    93,    94,    34,    -1,    -1,    -1,    23,    36,
      95,    29,    35,    30,    97,    -1,    36,    -1,    17,    -1,
      18,    -1,   100,    97,    -1,    -1,    96,    97,    -1,    37,
      27,    -1,    35,    -1,    37,    -1,    36,    -1,    38,    -1,
      29,    38,    33,    38,    33,    38,    30,    -1,    29,    38,
      33,    38,    33,    38,    33,    38,    33,    38,    33,    38,
      33,    38,    33,    38,    33,    38,    33,    38,    33,    38,
      33,    38,    33,    38,    33,    38,    33,    38,    33,    38,
      30,    -1,    29,    35,    30,    -1
};

/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
static const unsigned short int yyrline[] =
{
       0,   796,   796,   804,   806,   810,   819,   832,   840,   852,
     859,   867,   872,   877,   883,   889,   895,   901,   907,   915,
     922,   925,   929,   936,   943,   950,   958,   966,   974,   981,
     990,   996,   998,  1000,  1002,  1004,  1006,  1008,  1013,  1025,
    1041,  1035,  1057,  1076,  1087,  1100,  1105,  1124,  1151,  1145,
    1176,  1193,  1204,  1218,  1225,  1223,  1248,  1242,  1257,  1270,
    1268,  1293,  1287,  1304,  1317,  1315,  1340,  1334,  1351,  1364,
    1362,  1387,  1381,  1398,  1408,  1416,  1428,  1435,  1449,  1460,
    1478,  1483,  1527,  1554,  1585,  1579,  1600,  1619,  1630,  1678,
    1708,  1713,  1720,  1723,  1727,  1730,  1733,  1736,  1739,  1742,
    1745,  1748,  1753,  1759,  1771,  1777,  1788,  1794,  1805,  1811,
    1822,  1828,  1839,  1845,  1856,  1862,  1873,  1879,  1891,  1889,
    1900,  1898,  1908,  1912,  1916,  1919,  1925,  1923,  1977,  1996,
    2015,  2036,  2041,  2046,  2054,  2062,  2069,  2074,  2079,  2084,
    2101,  2157
};
#endif

#if YYDEBUG || YYERROR_VERBOSE
/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
  "$end", "error", "$undefined", "SCRL_PARAMETERS", "SCRL_VARIABLES",
  "SCRL_OUTPUT", "SCRL_VARYING", "SCRL_VERTEX", "SCRL_UNIFORM",
  "SCRL_BOOLEAN", "SCRL_FLOAT", "SCRL_COLOR", "SCRL_VECTOR", "SCRL_NORMAL",
  "SCRL_POINT", "SCRL_MATRIX", "SCRL_STRING", "SCRL_SURFACE",
  "SCRL_DISPLACEMENT", "SCRL_IMAGER", "SCRL_LIGHTSOURCE", "SCRL_VOLUME",
  "SCRL_GENERIC", "SCRL_DSO", "SCRL_INIT", "SCRL_CODE", "SCRL_DOT",
  "SCRL_COLON", "SCRL_EQUAL", "SCRL_OPEN_PARANTHESIS",
  "SCRL_CLOSE_PARANTHESIS", "SCRL_OPEN_SQR_PARANTHESIS",
  "SCRL_CLOSE_SQR_PARANTHESIS", "SCRL_COMMA", "SCRL_NL", "SCRL_TEXT_VALUE",
  "SCRL_IDENTIFIER_VALUE", "SCRL_LABEL_VALUE", "SCRL_FLOAT_VALUE",
  "$accept", "start", "slEmptySpace", "slVectorIn", "slVector",
  "slContainer", "slType", "slParameterDefinitions", "slParameters",
  "slParameterContainer", "slParameter", "slAParameter",
  "slFloatParameter", "@1", "slFloatArrayInitializer",
  "slFloatArrayInitializerItems", "slStringParameter", "@2",
  "slStringArrayInitializer", "slStringArrayInitializerItems",
  "slColorParameter", "@3", "@4", "slVectorParameter", "@5", "@6",
  "slNormalParameter", "@7", "@8", "slPointParameter", "@9", "@10",
  "slVectorValue", "slVectorArrayInitializer",
  "slVectorArrayInitializerItems", "slMatrixParameter", "@11",
  "slMatrixArrayInitializer", "slMatrixArrayInitializerItems",
  "slVariableDefinitions", "slVariables", "slVariable",
  "slBooleanVariable", "slFloatVariable", "slStringVariable",
  "slVectorVariable", "slColorVariable", "slNormalVariable",
  "slPointVariable", "slMatrixVariable", "slInit", "@12", "slCode", "@13",
  "slShaderLine", "slDSO", "@14", "slOpcode", "slOperandList",
  "slStatement", "slLabelDefinition", "slOperand", 0
};
#endif

# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
   token YYLEX-NUM.  */
static const unsigned short int yytoknum[] =
{
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
     285,   286,   287,   288,   289,   290,   291,   292,   293
};
# endif

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
static const unsigned char yyr1[] =
{
       0,    39,    40,    41,    41,    42,    42,    42,    42,    42,
      43,    44,    44,    44,    45,    45,    45,    45,    45,    46,
      47,    47,    48,    48,    48,    48,    48,    48,    48,    48,
      49,    50,    50,    50,    50,    50,    50,    50,    51,    51,
      52,    51,    51,    53,    54,    54,    55,    55,    56,    55,
      55,    57,    58,    58,    60,    59,    61,    59,    59,    63,
      62,    64,    62,    62,    66,    65,    67,    65,    65,    69,
      68,    70,    68,    68,    71,    71,    71,    71,    72,    73,
      73,    74,    74,    74,    75,    74,    74,    76,    77,    77,
      77,    78,    79,    79,    80,    80,    80,    80,    80,    80,
      80,    80,    81,    81,    82,    82,    83,    83,    84,    84,
      85,    85,    86,    86,    87,    87,    88,    88,    90,    89,
      92,    91,    93,    93,    93,    93,    95,    94,    96,    96,
      96,    97,    97,    98,    99,   100,   100,   100,   100,   100,
     100,   100
};

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

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

/* YYDEFGOTO[NTERM-NUM]. */
static const short int yydefgoto[] =
{
      -1,     6,    38,   137,   138,    60,     7,    15,    23,    32,
      33,    49,    50,   205,   218,   233,    51,   214,   230,   239,
      52,   102,   206,    53,   104,   209,    54,   106,   210,    55,
     108,   211,   248,   220,   234,    56,   213,   228,   238,    18,
      34,    61,    80,    81,    82,    83,    84,    85,    86,    87,
      22,    35,    27,    63,    62,    94,   158,    95,   129,    96,
      97,   130
};

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
#define YYPACT_NINF -131
static const short int yypact[] =
{
      40,   -29,   -17,    11,    22,    52,    34,    64,  -131,  -131,
    -131,  -131,  -131,  -131,    49,    83,    54,    62,    66,  -131,
      57,    59,    67,    58,  -131,  -131,    60,    61,    73,  -131,
    -131,  -131,    39,    63,    -2,  -131,  -131,    61,  -131,  -131,
    -131,  -131,    65,    68,    69,    70,    71,    72,    74,  -131,
    -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,
      14,    75,   -16,  -131,  -131,    16,    80,    81,    82,    84,
      41,    42,    78,    85,    86,    87,    88,    89,    90,    91,
    -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,
    -131,    92,  -131,    76,    95,   -26,    96,    97,   -16,    79,
      94,    98,   105,    99,   105,   100,   105,   101,   105,   -23,
     102,   106,   104,   103,   112,   113,   114,   115,   116,   117,
     118,  -131,  -131,  -131,    33,  -131,  -131,  -131,  -131,  -131,
     -26,  -131,  -131,  -131,   119,   120,     2,  -131,  -131,   121,
    -131,   122,  -131,   123,  -131,   124,  -131,   125,  -131,   126,
     127,   128,   129,   130,   131,   132,   133,   134,   135,   143,
     141,  -131,   107,   147,   138,     5,  -131,   149,   150,   151,
     142,   153,   154,   152,   155,   156,   157,   158,   159,   160,
     161,   148,  -131,   162,  -131,  -131,   163,   164,  -131,  -131,
    -131,  -131,   165,  -131,  -131,  -131,  -131,  -131,  -131,  -131,
    -131,  -131,  -131,   166,   171,   167,   168,   169,   170,   168,
     168,   168,   172,   174,   175,   -26,   173,  -131,  -131,  -131,
    -131,   177,   176,  -131,  -131,  -131,   178,  -131,  -131,  -131,
    -131,  -131,    44,   -19,     0,  -131,   180,   179,    10,    43,
    -131,   181,  -131,  -131,   182,  -131,     8,  -131,  -131,  -131,
     183,   184,  -131,  -131,  -131,  -131,   185,   186,   187,  -131,
     188,   189,   190,   191,   192,   193,   194,   200,   202,   197,
     198,   199,   201,  -131,   206,   203,   204,   207,  -131,   205,
     208,   209,   210,   211,   212,   213,   214,   215,   216,   217,
     223,   219,   220,   221,   218,   222,   228,  -131,   224,   225,
     226,   232,   229,   230,   231,   233,   234,   235,   238,   241,
    -131,   237,   243,   239,   245,   242,   246,   244,   251,  -131
};

/* YYPGOTO[NTERM-NUM].  */
static const short int yypgoto[] =
{
    -131,  -131,   247,  -131,   -90,  -131,  -131,  -131,  -131,  -131,
    -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,
    -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,
    -131,  -131,  -131,  -127,  -131,  -131,  -131,  -131,  -131,  -131,
    -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,  -131,
    -131,  -131,  -131,  -131,    35,  -131,  -131,  -131,  -130,  -131,
    -131,  -131
};

/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
   positive, shift that token.  If negative, reduce the rule which
   number is the opposite.  If zero, do what YYDEFACT says.
   If YYTABLE_NINF, syntax error.  */
#define YYTABLE_NINF -92
static const short int yytable[] =
{
     161,    89,    90,   124,    58,     8,    59,    91,   145,   125,
     126,   127,   128,   242,   140,   146,   142,     9,   144,   243,
      92,    93,   -91,    72,    73,    74,    75,    76,    77,    78,
      79,   244,   245,   164,    13,   246,   187,   165,   247,   258,
     166,   251,   252,   188,    99,    10,   259,   100,   253,    42,
      43,    44,    45,    46,    47,    48,    11,     1,     2,     3,
       4,     5,   -19,    28,    29,    30,    31,    14,   159,   109,
     111,   160,   110,   112,   240,   254,    16,   241,   255,    39,
      40,    41,   223,   224,   225,   231,    12,    17,    19,    20,
      21,    24,    26,    25,    36,    37,     0,    57,    98,     0,
       0,    65,     0,   122,    66,    67,    68,    69,    70,    88,
      71,   101,   103,   105,   113,   107,     0,   133,     0,     0,
       0,   114,   115,   116,   117,   118,   119,   120,   121,   123,
     131,   132,   134,   136,   150,   184,   135,   139,   141,   143,
     147,   148,   149,   151,   152,   153,   154,   155,   156,   157,
       0,   162,   163,   167,   168,   169,     0,   171,   172,     0,
       0,     0,   170,     0,   181,   173,   174,   175,   176,   177,
     178,   179,   180,   182,   183,   185,   186,   189,   190,   191,
     192,   193,   194,   203,   195,     0,     0,   196,   197,   198,
     199,   200,   201,   202,     0,     0,   215,     0,   217,   219,
     204,   207,   208,   212,   216,   227,   229,   221,   222,   235,
     226,   232,   249,     0,   236,     0,   237,   250,   262,   256,
     257,   260,   261,     0,   263,   264,   265,   266,   267,   268,
     269,   270,   271,   272,   273,   274,   275,   276,   278,   277,
     281,   279,   280,   282,     0,   287,   283,   284,   285,   286,
     297,   288,   289,   290,   291,   292,   293,   294,   295,   296,
     298,   299,   300,   301,   302,   303,   307,   304,   305,   306,
     310,     0,   308,   309,   311,   312,   313,   314,   315,   317,
     316,   319,   318,     0,    64
};

static const short int yycheck[] =
{
     130,    17,    18,    29,     6,    34,     8,    23,    31,    35,
      36,    37,    38,    32,   104,    38,   106,    34,   108,    38,
      36,    37,    24,     9,    10,    11,    12,    13,    14,    15,
      16,    31,    32,    31,     0,    35,    31,    35,    38,    31,
      38,    31,    32,    38,    28,    34,    38,    31,    38,    10,
      11,    12,    13,    14,    15,    16,    34,    17,    18,    19,
      20,    21,     4,     5,     6,     7,     8,     3,    35,    28,
      28,    38,    31,    31,    30,    32,    27,    33,    35,     6,
       7,     8,   209,   210,   211,   215,    34,     4,    34,    27,
      24,    34,    25,    34,    34,    34,    -1,    34,    63,    -1,
      -1,    36,    -1,    27,    36,    36,    36,    36,    36,    34,
      36,    31,    31,    31,    36,    31,    -1,    38,    -1,    -1,
      -1,    36,    36,    36,    36,    36,    36,    36,    36,    34,
      34,    34,    38,    28,    31,    28,    38,    38,    38,    38,
      38,    35,    38,    31,    31,    31,    31,    31,    31,    31,
      -1,    32,    32,    32,    32,    32,    -1,    32,    32,    -1,
      -1,    -1,    38,    -1,    29,    38,    38,    38,    38,    38,
      38,    38,    38,    30,    33,    28,    38,    28,    28,    28,
      38,    28,    28,    35,    32,    -1,    -1,    32,    32,    32,
      32,    32,    32,    32,    -1,    -1,    30,    -1,    31,    31,
      38,    38,    38,    38,    33,    31,    31,    38,    38,    32,
      38,    38,    32,    -1,    38,    -1,    38,    38,    33,    38,
      38,    38,    38,    -1,    38,    38,    38,    38,    38,    38,
      38,    38,    38,    33,    32,    38,    38,    38,    32,    38,
      33,    38,    38,    38,    -1,    33,    38,    38,    38,    38,
      32,    38,    38,    38,    38,    38,    33,    38,    38,    38,
      38,    33,    38,    38,    38,    33,    33,    38,    38,    38,
      32,    -1,    38,    38,    33,    38,    33,    38,    33,    33,
      38,    30,    38,    -1,    37
};

/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
   symbol of state STATE-NUM.  */
static const unsigned char yystos[] =
{
       0,    17,    18,    19,    20,    21,    40,    45,    34,    34,
      34,    34,    34,     0,     3,    46,    27,     4,    78,    34,
      27,    24,    89,    47,    34,    34,    25,    91,     5,     6,
       7,     8,    48,    49,    79,    90,    34,    34,    41,     6,
       7,     8,    10,    11,    12,    13,    14,    15,    16,    50,
      51,    55,    59,    62,    65,    68,    74,    34,     6,     8,
      44,    80,    93,    92,    41,    36,    36,    36,    36,    36,
      36,    36,     9,    10,    11,    12,    13,    14,    15,    16,
      81,    82,    83,    84,    85,    86,    87,    88,    34,    17,
      18,    23,    36,    37,    94,    96,    98,    99,    93,    28,
      31,    31,    60,    31,    63,    31,    66,    31,    69,    28,
      31,    28,    31,    36,    36,    36,    36,    36,    36,    36,
      36,    36,    27,    34,    29,    35,    36,    37,    38,    97,
     100,    34,    34,    38,    38,    38,    28,    42,    43,    38,
      43,    38,    43,    38,    43,    31,    38,    38,    35,    38,
      31,    31,    31,    31,    31,    31,    31,    31,    95,    35,
      38,    97,    32,    32,    31,    35,    38,    32,    32,    32,
      38,    32,    32,    38,    38,    38,    38,    38,    38,    38,
      38,    29,    30,    33,    28,    28,    38,    31,    38,    28,
      28,    28,    38,    28,    28,    32,    32,    32,    32,    32,
      32,    32,    32,    35,    38,    52,    61,    38,    38,    64,
      67,    70,    38,    75,    56,    30,    33,    31,    53,    31,
      72,    38,    38,    72,    72,    72,    38,    31,    76,    31,
      57,    97,    38,    54,    73,    32,    38,    38,    77,    58,
      30,    33,    32,    38,    31,    32,    35,    38,    71,    32,
      38,    31,    32,    38,    32,    35,    38,    38,    31,    38,
      38,    38,    33,    38,    38,    38,    38,    38,    38,    38,
      38,    38,    33,    32,    38,    38,    38,    38,    32,    38,
      38,    33,    38,    38,    38,    38,    38,    33,    38,    38,
      38,    38,    38,    33,    38,    38,    38,    32,    38,    33,
      38,    38,    38,    33,    38,    38,    38,    33,    38,    38,
      32,    33,    38,    33,    38,    33,    38,    33,    38,    30
};

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

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

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


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

#define YYFAIL		goto yyerrlab

#define YYRECOVERING()  (!!yyerrstatus)

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

#define YYTERROR	1
#define YYERRCODE	256

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

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

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

#ifdef YYLEX_PARAM
# define YYLEX yylex (YYLEX_PARAM)
#else
# define YYLEX yylex ()
#endif

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

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

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

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

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

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

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

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


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

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

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

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


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

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

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

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

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif



#if YYERROR_VERBOSE

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

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

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

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

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

  return yyd - 1;
}
#  endif
# endif

#endif /* !YYERROR_VERBOSE */



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

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

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

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

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

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

  switch (yytype)
    {

      default:
        break;
    }
}


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

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



/* The lookahead symbol.  */
int yychar;

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

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



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

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

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

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

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

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

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



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

  YYSIZE_T yystacksize = YYINITDEPTH;

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


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

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

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

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

  yyssp = yyss;
  yyvsp = yyvs;


  goto yysetstate;

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

 yysetstate:
  *yyssp = yystate;

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

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


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

		    &yystacksize);

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

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

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

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


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

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

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

  goto yybackup;

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

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

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

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

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

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

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

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

  if (yyn == YYFINAL)
    YYACCEPT;

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

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

  *++yyvsp = yylval;


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

  yystate = yyn;
  goto yynewstate;


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


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

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

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


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
        case 5:
#line 813 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[0].real;
					yyval.v[1]	=	yyvsp[0].real;
					yyval.v[2]	=	yyvsp[0].real;
				;}
    break;

  case 6:
#line 826 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[-3].real;
					yyval.v[1]	=	yyvsp[-2].real;
					yyval.v[2]	=	yyvsp[-1].real;
				;}
    break;

  case 7:
#line 834 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[0].real;
					yyval.v[1]	=	yyvsp[0].real;
					yyval.v[2]	=	yyvsp[0].real;
				;}
    break;

  case 8:
#line 846 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[-3].real;
					yyval.v[1]	=	yyvsp[-2].real;
					yyval.v[2]	=	yyvsp[-1].real;
				;}
    break;

  case 9:
#line 852 "sdr.y"
    {
					yyval.v[0]	=	0;
					yyval.v[1]	=	0;
					yyval.v[2]	=	0;
				;}
    break;

  case 10:
#line 860 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[0].v[0];
					yyval.v[1]	=	yyvsp[0].v[1];
					yyval.v[2]	=	yyvsp[0].v[2];
				;}
    break;

  case 11:
#line 868 "sdr.y"
    {
					currentData.uniform	=	TRUE;
				;}
    break;

  case 12:
#line 873 "sdr.y"
    {
					currentData.uniform	=	FALSE;
				;}
    break;

  case 13:
#line 877 "sdr.y"
    {
					currentData.uniform	=	FALSE;
				;}
    break;

  case 14:
#line 885 "sdr.y"
    {
					currentData.shaderType	=	SL_SURFACE;
				;}
    break;

  case 15:
#line 891 "sdr.y"
    {
					currentData.shaderType	=	SL_DISPLACEMENT;
				;}
    break;

  case 16:
#line 897 "sdr.y"
    {
					currentData.shaderType	=	SL_LIGHTSOURCE;
				;}
    break;

  case 17:
#line 903 "sdr.y"
    {
					currentData.shaderType	=	SL_ATMOSPHERE;
				;}
    break;

  case 18:
#line 909 "sdr.y"
    {
					currentData.shaderType	=	SL_IMAGER;
				;}
    break;

  case 22:
#line 930 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_UNIFORM;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	TRUE;
				;}
    break;

  case 23:
#line 937 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_VARYING;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	FALSE;
				;}
    break;

  case 24:
#line 944 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_VERTEX;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	FALSE;
				;}
    break;

  case 25:
#line 952 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_UNIFORM;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	TRUE;
				;}
    break;

  case 26:
#line 960 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_VARYING;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	FALSE;
				;}
    break;

  case 27:
#line 968 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_VERTEX;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	FALSE;
				;}
    break;

  case 28:
#line 975 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_UNIFORM;
					currentData.currentParameterGlobal	=	TRUE;
					currentData.uniform					=	TRUE;
				;}
    break;

  case 29:
#line 981 "sdr.y"
    {
					currentData.currentParameterClass	=	CONTAINER_UNIFORM;
					currentData.currentParameterGlobal	=	FALSE;
					currentData.uniform					=	TRUE;
				;}
    break;

  case 38:
#line 1017 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,TYPE_FLOAT,1,TRUE);

					if (def != NULL) {
						def->real	=	yyvsp[0].real;
					}
				;}
    break;

  case 39:
#line 1027 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[0].string,TYPE_FLOAT,1,TRUE);

					if (def != NULL) {
						def->real	=	0;
					}
				;}
    break;

  case 40:
#line 1041 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_FLOAT,(int) yyvsp[-2].real,TRUE);
					
					if (def != NULL) {
						int	i;

						for (i=0;i<(int) yyvsp[-2].real;i++)
							def[i].real	=	0;
						
						currentData.currentArray = def;
					}
					
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 42:
#line 1062 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_FLOAT,(int) yyvsp[-1].real,TRUE);

					if (def != NULL) {
						int	i;

						for (i=0;i<(int) yyvsp[-1].real;i++)
							def[i].real	=	0;
					}
				;}
    break;

  case 43:
#line 1079 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining){
						slerror("Wrong number of items in array initializer\n");
					}
				;}
    break;

  case 44:
#line 1089 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining > 0){
						if(currentData.currentArray){
							currentData.currentArray->real = yyvsp[0].real;
							currentData.currentArray++;
						}
						currentData.numArrayItemsRemaining--;
					} else{
						slerror("Wrong number of items in array initializer\n");
					}
				;}
    break;

  case 46:
#line 1107 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[0].string,TYPE_STRING,1,TRUE);

					switch(currentData.passNumber) {
					case 1:
						currentData.numStrings++;
						break;
					case 2:
						if (def != NULL) {
							def->string	=	currentData.strings[currentData.currentString++]	=	strdup("*");
						}
						break;
					default:
						break;
					}
				;}
    break;

  case 47:
#line 1128 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,TYPE_STRING,1,TRUE);

					switch(currentData.passNumber) {
					case 1:
						currentData.numStrings++;
						break;
					case 2:
						if (def != NULL) {
							def->string	=	currentData.strings[currentData.currentString++]	=	strdup(yyvsp[0].string);
						}
						break;
					default:
						break;
					}
				;}
    break;

  case 48:
#line 1151 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_STRING,(int) yyvsp[-2].real,TRUE);
					
					switch(currentData.passNumber) {
					case 1:
						currentData.numStrings += (int) yyvsp[-2].real;
						break;
					case 2:
						if (def != NULL) {
							int	i;

							for (i=0;i<(int) yyvsp[-2].real;i++)
								def[i].string	=	NULL;
							
							currentData.currentArray = def;
						}
						break;
					default:
						break;
					}
					
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 50:
#line 1181 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_STRING,(int) yyvsp[-1].real,TRUE);

					if (def != NULL) {
						int	i;

						for (i=0;i<(int) yyvsp[-1].real;i++)
							def[i].string	=	NULL;
					}
				;}
    break;

  case 51:
#line 1196 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining){
						slerror("Wrong number of items in array initializer\n");
					}
				;}
    break;

  case 52:
#line 1206 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining > 0){
						if(currentData.currentArray){
							currentData.currentArray->string	=	currentData.strings[currentData.currentString++]	=	strdup(yyvsp[0].string);
							currentData.currentArray++;
						}
						currentData.numArrayItemsRemaining--;
					}
					else{
						slerror("Wrong number of items in array initializer\n");
					}
				;}
    break;

  case 54:
#line 1225 "sdr.y"
    {
					currentData.currentParameterType	=	TYPE_COLOR;
				;}
    break;

  case 55:
#line 1229 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,currentData.currentParameterType,1,TRUE);
					float	*v;

					if (def != NULL) {
						v	=	yyvsp[0].v;

						def[0].real	=	v[0];
						def[1].real	=	v[1];
						def[2].real	=	v[2];
					}
				;}
    break;

  case 56:
#line 1248 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_COLOR,(int) yyvsp[-2].real,TRUE);
					
					if(def != NULL)
						currentData.currentArray = def;
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 58:
#line 1262 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_COLOR,(int) yyvsp[-1].real,TRUE);
				;}
    break;

  case 59:
#line 1270 "sdr.y"
    {
					currentData.currentParameterType	=	TYPE_VECTOR;
				;}
    break;

  case 60:
#line 1274 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,currentData.currentParameterType,1,TRUE);
					float	*v;

					if (def != NULL) {
						v	=	yyvsp[0].v;

						def[0].real	=	v[0];
						def[1].real	=	v[1];
						def[2].real	=	v[2];
					}
				;}
    break;

  case 61:
#line 1293 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_VECTOR,(int) yyvsp[-2].real,TRUE);
					
					if(def != NULL) {
						currentData.currentArray = def;
					}
					
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 63:
#line 1309 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_VECTOR,(int) yyvsp[-1].real,TRUE);
				;}
    break;

  case 64:
#line 1317 "sdr.y"
    {
					currentData.currentParameterType	=	TYPE_NORMAL;
				;}
    break;

  case 65:
#line 1321 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,currentData.currentParameterType,1,TRUE);
					float	*v;

					if (def != NULL) {
						v	=	yyvsp[0].v;

						def[0].real	=	v[0];
						def[1].real	=	v[1];
						def[2].real	=	v[2];
					}
				;}
    break;

  case 66:
#line 1340 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_NORMAL,(int) yyvsp[-2].real,TRUE);
					
					if(def != NULL) {
						currentData.currentArray = def;
					}
					
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 68:
#line 1356 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_NORMAL,(int) yyvsp[-1].real,TRUE);
				;}
    break;

  case 69:
#line 1364 "sdr.y"
    {
					currentData.currentParameterType	=	TYPE_POINT;
				;}
    break;

  case 70:
#line 1368 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,currentData.currentParameterType,1,TRUE);
					float	*v;

					if (def != NULL) {
						v	=	yyvsp[0].v;

						def[0].real	=	v[0];
						def[1].real	=	v[1];
						def[2].real	=	v[2];
					}
				;}
    break;

  case 71:
#line 1387 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_POINT,(int) yyvsp[-2].real,TRUE);
					
					if(def != NULL) {
						currentData.currentArray = def;
					}
					
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 73:
#line 1403 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_POINT,(int) yyvsp[-1].real,TRUE);
				;}
    break;

  case 74:
#line 1410 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[0].real;
					yyval.v[1]	=	yyvsp[0].real;
					yyval.v[2]	=	yyvsp[0].real;
				;}
    break;

  case 75:
#line 1422 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[-3].real;
					yyval.v[1]	=	yyvsp[-2].real;
					yyval.v[2]	=	yyvsp[-1].real;
				;}
    break;

  case 76:
#line 1429 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[0].real;
					yyval.v[1]	=	yyvsp[0].real;
					yyval.v[2]	=	yyvsp[0].real;
				;}
    break;

  case 77:
#line 1440 "sdr.y"
    {
					yyval.v[0]	=	yyvsp[-3].real;
					yyval.v[1]	=	yyvsp[-2].real;
					yyval.v[2]	=	yyvsp[-1].real;
				;}
    break;

  case 78:
#line 1452 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining){
						slerror("Wrong number of items in array initializer\n");
					}
				;}
    break;

  case 79:
#line 1462 "sdr.y"
    {
					float *v;
					
					if(currentData.numArrayItemsRemaining > 0){
						if(currentData.currentArray){
							v = yyvsp[0].v;
							currentData.currentArray[0].real = v[0];
							currentData.currentArray[1].real = v[1];
							currentData.currentArray[2].real = v[2];
							currentData.currentArray += 3;
						}
						currentData.numArrayItemsRemaining--;
					} else{
						slerror("Wrong number of items in array initializer\n");
					}
				;}
    break;

  case 81:
#line 1504 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-19].string,TYPE_MATRIX,1,TRUE);

					if (def != NULL) {
						def[0].real		=	yyvsp[-16].real;
						def[1].real		=	yyvsp[-15].real;
						def[2].real		=	yyvsp[-14].real;
						def[3].real		=	yyvsp[-13].real;
						def[4].real		=	yyvsp[-12].real;
						def[5].real		=	yyvsp[-11].real;
						def[6].real		=	yyvsp[-10].real;
						def[7].real		=	yyvsp[-9].real;
						def[8].real		=	yyvsp[-8].real;
						def[9].real		=	yyvsp[-7].real;
						def[10].real	=	yyvsp[-6].real;
						def[11].real	=	yyvsp[-5].real;
						def[12].real	=	yyvsp[-4].real;
						def[13].real	=	yyvsp[-3].real;
						def[14].real	=	yyvsp[-2].real;
						def[15].real	=	yyvsp[-1].real;
					}
				;}
    break;

  case 82:
#line 1531 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-2].string,TYPE_MATRIX,1,TRUE);

					if (def != NULL) {
						def[0].real		=	yyvsp[0].real;
						def[1].real		=	0;
						def[2].real		=	0;
						def[3].real		=	0;
						def[4].real		=	0;
						def[5].real		=	yyvsp[0].real;
						def[6].real		=	0;
						def[7].real		=	0;
						def[8].real		=	0;
						def[9].real		=	0;
						def[10].real	=	yyvsp[0].real;
						def[11].real	=	0;
						def[12].real	=	0;
						def[13].real	=	0;
						def[14].real	=	0;
						def[15].real	=	1;
					}
				;}
    break;

  case 83:
#line 1556 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[0].string,TYPE_MATRIX,1,TRUE);

					if (def != NULL) {
						def[0].real		=	1;
						def[1].real		=	0;
						def[2].real		=	0;
						def[3].real		=	0;
						def[4].real		=	0;
						def[5].real		=	1;
						def[6].real		=	0;
						def[7].real		=	0;
						def[8].real		=	0;
						def[9].real		=	0;
						def[10].real	=	1;
						def[11].real	=	0;
						def[12].real	=	0;
						def[13].real	=	0;
						def[14].real	=	0;
						def[15].real	=	1;
					}
				;}
    break;

  case 84:
#line 1585 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-4].string,TYPE_MATRIX,(int) yyvsp[-2].real,TRUE);
					
					if (def != NULL) {
						int	i;

						for (i=0;i<((int) yyvsp[-2].real)*16;i++)
							def[i].real	=	0;
						currentData.currentArray = def;
					}
					
					currentData.numArrayItemsRemaining = (int) yyvsp[-2].real;
				;}
    break;

  case 86:
#line 1605 "sdr.y"
    {
					TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_MATRIX,(int) yyvsp[-1].real,TRUE);

					if (def != NULL) {
						int	i;

						for (i=0;i<((int) yyvsp[-1].real)*16;i++)
							def[i].real	=	0;
					}
				;}
    break;

  case 87:
#line 1622 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining){
						slerror("wrong number of items in array initializer\n");
					}
				;}
    break;

  case 88:
#line 1649 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining > 0){
						if(currentData.currentArray){
							currentData.currentArray[0].real = yyvsp[-16].real;
							currentData.currentArray[1].real = yyvsp[-15].real;
							currentData.currentArray[2].real = yyvsp[-14].real;
							currentData.currentArray[3].real = yyvsp[-13].real;
							currentData.currentArray[4].real = yyvsp[-12].real;
							currentData.currentArray[5].real = yyvsp[-11].real;
							currentData.currentArray[6].real = yyvsp[-10].real;
							currentData.currentArray[7].real = yyvsp[-9].real;
							currentData.currentArray[8].real = yyvsp[-8].real;
							currentData.currentArray[9].real = yyvsp[-7].real;
							currentData.currentArray[10].real = yyvsp[-6].real;
							currentData.currentArray[11].real = yyvsp[-5].real;
							currentData.currentArray[12].real = yyvsp[-4].real;
							currentData.currentArray[13].real = yyvsp[-3].real;
							currentData.currentArray[14].real = yyvsp[-2].real;
							currentData.currentArray[15].real = yyvsp[-1].real;
							
							currentData.currentArray += 16;
						}
						currentData.numArrayItemsRemaining--;
					}
					else{
						slerror("wrong number of items in array initializer\n");
					}
				;}
    break;

  case 89:
#line 1680 "sdr.y"
    {
					if(currentData.numArrayItemsRemaining > 0){
						if(currentData.currentArray){
							currentData.currentArray[0].real = yyvsp[0].real;
							currentData.currentArray[1].real = 0;
							currentData.currentArray[2].real = 0;
							currentData.currentArray[3].real = 0;
							currentData.currentArray[4].real = 0;
							currentData.currentArray[5].real = yyvsp[0].real;
							currentData.currentArray[6].real = 0;
							currentData.currentArray[7].real = 0;
							currentData.currentArray[8].real = 0;
							currentData.currentArray[9].real = 0;
							currentData.currentArray[10].real = yyvsp[0].real;
							currentData.currentArray[11].real = 0;
							currentData.currentArray[12].real = 0;
							currentData.currentArray[13].real = 0;
							currentData.currentArray[14].real = 0;
							currentData.currentArray[15].real = 1;
							
							currentData.currentArray += 16;
						}
						currentData.numArrayItemsRemaining--;
					}
					else{
						slerror("wrong number of items in array initializer\n");
					}
				;}
    break;

  case 102:
#line 1755 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_BOOLEAN,1,FALSE);
				;}
    break;

  case 103:
#line 1764 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_BOOLEAN,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 104:
#line 1773 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_FLOAT,1,FALSE);
				;}
    break;

  case 105:
#line 1782 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_FLOAT,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 106:
#line 1790 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_STRING,1,FALSE);
				;}
    break;

  case 107:
#line 1799 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_STRING,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 108:
#line 1807 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_VECTOR,1,FALSE);
				;}
    break;

  case 109:
#line 1816 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_VECTOR,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 110:
#line 1824 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_COLOR,1,FALSE);
				;}
    break;

  case 111:
#line 1833 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_COLOR,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 112:
#line 1841 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_NORMAL,1,FALSE);
				;}
    break;

  case 113:
#line 1850 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_NORMAL,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 114:
#line 1858 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_POINT,1,FALSE);
				;}
    break;

  case 115:
#line 1867 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_POINT,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 116:
#line 1875 "sdr.y"
    {
					newVariable(yyvsp[0].string,TYPE_MATRIX,1,FALSE);
				;}
    break;

  case 117:
#line 1884 "sdr.y"
    {
					newVariable(yyvsp[-3].string,TYPE_MATRIX,(int) yyvsp[-1].real,FALSE);
				;}
    break;

  case 118:
#line 1891 "sdr.y"
    {
					currentData.parsingInit	=	TRUE;
					newLabel(initLabel,FALSE);
				;}
    break;

  case 120:
#line 1900 "sdr.y"
    {
					currentData.parsingInit	=	FALSE;
					newLabel(codeLabel,FALSE);
				;}
    break;

  case 126:
#line 1925 "sdr.y"
    {
					switch(currentData.passNumber) {
					case 1:
						currentData.numCode					+=	4;		// opcode
						break;
					case 2:
						strcpy(currentData.currentOpcode,yyvsp[0].string);
						currentData.currentArgument			=	0;
						currentData.currentOpcodePlace		=	&currentData.code[currentData.currentCode];
						currentData.currentCode				+=	4;
						currentData.currentPrototype[0]		=	'~';
						currentData.opcodeUniform			=	TRUE;
						break;
					default:
						break;
					}
				;}
    break;

  case 127:
#line 1946 "sdr.y"
    {
					switch(currentData.passNumber) {
					case 1:
						break;
					case 2:
						// Set the opcode here
						void			*handle;
						dsoExecFunction	exec;

						if (currentRenderer->getDSO(yyvsp[-5].string,yyvsp[-2].string,handle,exec) == TRUE) {
							if (yyvsp[-2].string[0] == 'o')
								currentData.currentOpcodePlace[0].integer	=	FUNCTION_DSO_VOID;
							else
								currentData.currentOpcodePlace[0].integer	=	FUNCTION_DSO;

							currentData.currentOpcodePlace[1].arguments.numCodes			=	currentData.currentArgument+4;
							currentData.currentOpcodePlace[1].arguments.numArguments		=	currentData.currentArgument;
							currentData.currentOpcodePlace[1].arguments.uniform				=	currentData.opcodeUniform;
							currentData.currentOpcodePlace[2].integer						=	(int) handle;
							currentData.currentOpcodePlace[3].integer						=	(int) exec;
						} else {
							slerror("Unable to locate DSO function\n");
						}
						break;
					default:
						break;
					}
				;}
    break;

  case 128:
#line 1978 "sdr.y"
    {
					switch(currentData.passNumber) {
					case 1:
						currentData.numCode					+=	2;		// opcode
						break;
					case 2:
						strcpy(currentData.currentOpcode,yyvsp[0].string);
						currentData.currentArgument			=	0;
						currentData.currentOpcodePlace		=	&currentData.code[currentData.currentCode];
						currentData.currentCode				+=	2;
						currentData.currentPrototype[0]		=	'~';
						currentData.opcodeUniform			=	TRUE;
						break;
					default:
						break;
					}
				;}
    break;

  case 129:
#line 1997 "sdr.y"
    {
					switch(currentData.passNumber) {
					case 1:
						currentData.numCode					+=	2;		// opcode
						break;
					case 2:
						strcpy(currentData.currentOpcode,"surface");
						currentData.currentArgument			=	0;
						currentData.currentOpcodePlace		=	&currentData.code[currentData.currentCode];
						currentData.currentCode				+=	2;
						currentData.currentPrototype[0]		=	'~';
						currentData.opcodeUniform			=	TRUE;
						break;
					default:
						break;
					}
				;}
    break;

  case 130:
#line 2016 "sdr.y"
    {
					switch(currentData.passNumber) {
					case 1:
						currentData.numCode					+=	2;		// opcode
						break;
					case 2:
						strcpy(currentData.currentOpcode,"displacement");
						currentData.currentArgument			=	0;
						currentData.currentOpcodePlace		=	&currentData.code[currentData.currentCode];
						currentData.currentCode				+=	2;
						currentData.currentPrototype[0]		=	'~';
						currentData.opcodeUniform			=	TRUE;
						break;
					default:
						break;
					}
				;}
    break;

  case 131:
#line 2038 "sdr.y"
    {
				;}
    break;

  case 132:
#line 2041 "sdr.y"
    {
				;}
    break;

  case 133:
#line 2048 "sdr.y"
    {
					setOpcode();
				;}
    break;

  case 134:
#line 2056 "sdr.y"
    {
					newLabel(yyvsp[-1].string,FALSE);
				;}
    break;

  case 135:
#line 2063 "sdr.y"
    {
					char	*str	=	yyvsp[0].string;

					addStringReference(&str,1);
				;}
    break;

  case 136:
#line 2070 "sdr.y"
    {
					newLabel(yyvsp[0].string,TRUE);
				;}
    break;

  case 137:
#line 2075 "sdr.y"
    {
					addVariableReference(yyvsp[0].string);
				;}
    break;

  case 138:
#line 2080 "sdr.y"
    {
					addFloatReference(&yyvsp[0].real,1);
				;}
    break;

  case 139:
#line 2091 "sdr.y"
    {
					vector	tmp;

					tmp[0]	=	yyvsp[-5].real;
					tmp[1]	=	yyvsp[-3].real;
					tmp[2]	=	yyvsp[-1].real;

					addFloatReference(tmp,3);
				;}
    break;

  case 140:
#line 2134 "sdr.y"
    {
					matrix	tmp;

					tmp[element(0,0)]	=	yyvsp[-31].real;
					tmp[element(0,1)]	=	yyvsp[-29].real;
					tmp[element(0,2)]	=	yyvsp[-27].real;
					tmp[element(0,3)]	=	yyvsp[-25].real;
					tmp[element(1,0)]	=	yyvsp[-23].real;
					tmp[element(1,1)]	=	yyvsp[-21].real;
					tmp[element(1,2)]	=	yyvsp[-19].real;
					tmp[element(1,3)]	=	yyvsp[-17].real;
					tmp[element(2,0)]	=	yyvsp[-15].real;
					tmp[element(2,1)]	=	yyvsp[-13].real;
					tmp[element(2,2)]	=	yyvsp[-11].real;
					tmp[element(2,3)]	=	yyvsp[-9].real;
					tmp[element(3,0)]	=	yyvsp[-7].real;
					tmp[element(3,1)]	=	yyvsp[-5].real;
					tmp[element(3,2)]	=	yyvsp[-3].real;
					tmp[element(3,3)]	=	yyvsp[-1].real;

					addFloatReference(tmp,16);
				;}
    break;

  case 141:
#line 2160 "sdr.y"
    {
					strcpy(currentData.currentPrototype,yyvsp[-1].string);
				;}
    break;


    }

/* Line 1010 of yacc.c.  */
#line 3225 "sl.cpp"

  yyvsp -= yylen;
  yyssp -= yylen;


  YY_STACK_PRINT (yyss, yyssp);

  *++yyvsp = yyval;


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

  yyn = yyr1[yyn];

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

  goto yynewstate;


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

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

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

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

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

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



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

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

	}
    }

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


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

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

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


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

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

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

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

  if (yyn == YYFINAL)
    YYACCEPT;

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

  *++yyvsp = yylval;


  yystate = yyn;
  goto yynewstate;


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

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

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

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


#line 2165 "sdr.y"

#include "lex.sl.cpp"

int	slLineno	=	0;

///////////////////////////////////////////////////////////////////////
// Function				:	slerror
// Description			:	Parser error function
// Return Value			:
// Comments				:
// Date last edited		:	8/8/2001
void	slerror(char *s) {
	warning(CODE_BADFILE,"Error in shader \"%s\" (%d) (\"%s\") (v%d.%d.%d)\n",currentData.name,slLineno,s,VERSION_RELEASE,VERSION_BETA,VERSION_ALPHA);
	currentData.numErrors++;
}


///////////////////////////////////////////////////////////////////////
// Function				:	parseShader
// Description			:	Parse a shader
// Return Value			:	Parsed shader if successful
// Comments				:
// Date last edited		:	8/8/2001
CShader	*parseShader(const char *shaderName,const char *name) {
	YY_BUFFER_STATE	oldState;

	FILE	*fin;

	fin						=	fopen(name,"r");
	
	if (fin == NULL) return NULL;

	oldState				=	YY_CURRENT_BUFFER;
	yy_switch_to_buffer(yy_create_buffer( fin, YY_BUF_SIZE ) );

	slLineno				=	0;

	slin					=	fin;

	reset();
	currentData.name					=	name;
	currentData.passNumber				=	1;
	slparse();

	if (currentData.numErrors != 0) {
		fclose(fin);
		return NULL;
	}

	slLineno				=	0;

	fseek(fin,0,SEEK_SET);
	alloc();
	currentData.passNumber				=	2;
	
	slparse();
	if (currentData.numErrors != 0) {
		reset();
		yy_delete_buffer( YY_CURRENT_BUFFER );
		fclose(fin);
		yy_switch_to_buffer( oldState );
		return NULL;
	} else {
		CShader	*cShader	=	shaderCreate(shaderName);
		reset();
		yy_delete_buffer( YY_CURRENT_BUFFER );
		fclose(fin);
		yy_switch_to_buffer( oldState );
		return cShader;
	}
}

///////////////////////////////////////////////////////////////////////
// Function				:	reset
// Description			:	Deallocate any previously allocated memory for the shader
// Return Value			:	-
// Comments				:
// Date last edited		:	8/8/2001
void	reset() {
	if (currentData.strings != NULL) {
		int	i;

		for (i=0;i<currentData.numStrings;i++)
			if (currentData.strings[i] != NULL)
				free(currentData.strings[i]);
	}


	if (currentData.definedVariables != NULL) {
		TSlVariable	*cVar,*nVar;

		for (cVar=currentData.definedVariables;cVar != NULL;) {
			nVar	=	cVar->next;
			delete cVar;
			cVar	=	nVar;
		}
	}

	if (currentData.definedParameters != NULL) {
		TSlVariable	*cVar,*nVar;

		for (cVar=currentData.definedParameters;cVar != NULL;) {
			nVar	=	cVar->next;
			delete cVar;
			cVar	=	nVar;
		}
	}

	if (currentData.labelDefinitions != NULL) {
		TSlLabel	*cLabel,*nLabel;

		for (cLabel=currentData.labelDefinitions;cLabel != NULL;) {
			nLabel	=	cLabel->next;
			delete cLabel;
			cLabel	=	nLabel;
		}
	}

	if (currentData.labelReferences != NULL) {
		TSlLabel	*cLabel,*nLabel;

		for (cLabel=currentData.labelReferences;cLabel != NULL;) {
			nLabel	=	cLabel->next;
			delete cLabel;
			cLabel	=	nLabel;
		}
	}


	if (currentData.memory != NULL)		delete [] currentData.memory;


	currentData.name					=	NULL;
	currentData.passNumber				=	0;
	currentData.parsingInit				=	FALSE;
	currentData.numErrors				=	0;

				// Pass 1
	currentData.numCode					=	0;
	currentData.numConstants			=	0;
	currentData.numVariables			=	0;
	currentData.numUniforms				=	0;
	currentData.numParameters			=	0;
	currentData.numStrings				=	0;
	currentData.constantSize			=	0;
	currentData.parameterSize			=	0;
	currentData.varyingSize				=	0;
	currentData.uniformSize				=	0;
	currentData.shaderType				=	SL_SURFACE;
	currentData.uniform					=	FALSE;
	currentData.opcodeUniform			=	FALSE;

				// Pass 2
	currentData.currentCode				=	0;
	currentData.currentConstant			=	0;
	currentData.currentVariable			=	0;
	currentData.currentUniform			=	0;
	currentData.currentParameter		=	0;
	currentData.currentString			=	0;
	currentData.currentPL				=	0;
	currentData.currentParameterSize	=	0;
	currentData.currentConstantSize		=	0;
	currentData.currentVaryingSize		=	0;
	currentData.currentUniformSize		=	0;
	strcpy(currentData.currentOpcode,"");
	strcpy(currentData.currentPrototype,"");
	currentData.currentArgument			=	0;
	currentData.usedParameters			=	0;
	currentData.currentOpcodePlace		=	NULL;
	currentData.codeEntryPoint			=	-1;
	currentData.initEntryPoint			=	-1;
				
	currentData.memory					=	NULL;
	currentData.code					=	NULL;
	currentData.constants				=	NULL;
	currentData.parameters				=	NULL;
	currentData.varyingSizes			=	NULL;
	currentData.uniformSizes			=	NULL;
	currentData.strings					=	NULL;
	currentData.parameterEntries		=	NULL;
	currentData.parameterDisplacements	=	NULL;
	currentData.constantEntries			=	NULL;
	currentData.definedVariables		=	NULL;
	currentData.definedParameters		=	NULL;
	currentData.labelReferences			=	NULL;
	currentData.labelDefinitions		=	NULL;
}

///////////////////////////////////////////////////////////////////////
// Function				:	alloc
// Description			:	Allocate required space for the shader
// Return Value			:
// Comments				:
// Date last edited		:	8/8/2001
void	alloc() {
	TCode	*mem;

	currentData.memory	=	new TCode[	currentData.numCode	+
										currentData.parameterSize +
										currentData.constantSize +
										currentData.numParameters + 
										currentData.numParameters + 
										currentData.numConstants + 
										currentData.numVariables + 
										currentData.numUniforms + 
										currentData.numStrings];

	mem		=	currentData.memory;

	if (currentData.numCode != 0) {
		currentData.code						=	mem;
		mem										+=	currentData.numCode;
	}

	if (currentData.parameterSize != 0) {
		currentData.parameters					=	mem;
		mem										+=	currentData.parameterSize;
	}

	if (currentData.constantSize != 0) {
		currentData.constants					=	mem;
		mem										+=	currentData.constantSize;
	}

	if (currentData.numParameters != 0) {
		currentData.parameterEntries			=	(TCode **) mem;
		mem										+=	currentData.numParameters;
		currentData.parameterDisplacements		=	(int *) mem;
		mem										+=	currentData.numParameters;
	}

	if (currentData.numConstants != 0) {
		currentData.constantEntries				=	(TCode **) mem;
		mem										+=	currentData.numConstants;
	}

	if (currentData.numVariables != 0) {
		currentData.varyingSizes				=	(int *) mem;
		mem										+=	currentData.numVariables;
	}

	if (currentData.numUniforms != 0) {
		currentData.uniformSizes				=	(int *) mem;
		mem										+=	currentData.numUniforms;
	}

	if (currentData.numStrings != 0) {
		int	i;

		currentData.strings						=	(char **) mem;
		mem										+=	currentData.numStrings;

		for (i=0;i<currentData.numStrings;i++) {
			currentData.strings[i]				=	NULL;
		}
	}
}

///////////////////////////////////////////////////////////////////////
// Function				:	shaderCreate
// Description			:	Parse successful, allocate the shader
// Return Value			:
// Comments				:
// Date last edited		:	8/8/2001
CShader	*shaderCreate(const char *shaderName) {
	CShader	*cShader;


	assert(currentData.numParameters	==	currentData.currentParameter);
	assert(currentData.numConstants		==	currentData.currentConstant);
	assert(currentData.numVariables		==	currentData.currentVariable);
	assert(currentData.numUniforms		==	currentData.currentUniform);
	assert(currentData.numStrings		==	currentData.currentString);
	assert(currentData.parameterSize	==	currentData.currentParameterSize);
	assert(currentData.constantSize		==	currentData.currentConstantSize);
	assert(currentData.varyingSize		==	currentData.currentVaryingSize);
	assert(currentData.uniformSize		==	currentData.currentUniformSize);


	// Fix the labels
	{
		TSlLabel	*cLabel,*nLabel;

		for (cLabel = currentData.labelReferences;cLabel != NULL;cLabel = cLabel->next) {
			for (nLabel = currentData.labelDefinitions;nLabel != NULL;nLabel = nLabel->next) {
				if (strcmp(cLabel->name,nLabel->name) == 0) {
					currentData.code[cLabel->index].integer	=	nLabel->index;
					break;
				}
			}

			if (nLabel == NULL) {
				slerror("Label not found");
				return NULL;
			}
		}

		for (cLabel = currentData.labelDefinitions;cLabel != NULL;cLabel = cLabel->next) {
			if (strcmp(cLabel->name,codeLabel) == 0) {
				currentData.codeEntryPoint	=	cLabel->index;
			}

			if (strcmp(cLabel->name,initLabel) == 0) {
				currentData.initEntryPoint	=	cLabel->index;
			}
		}
	}

	cShader								=	new CShader(shaderName);

	cShader->memory						=	currentData.memory;

	cShader->codeArea					=	currentData.code;
	cShader->parametersArea				=	currentData.parameters;
	cShader->constantsArea				=	currentData.constants;

	cShader->totalParameterSize			=	currentData.parameterSize;

	cShader->parameterEntries			=	currentData.parameterEntries;
	cShader->parameterDisplacements		=	currentData.parameterDisplacements;
	cShader->constantEntries			=	currentData.constantEntries;
	cShader->varyingSizes				=	currentData.varyingSizes;
	cShader->totalVaryingSize			=	currentData.varyingSize;
	cShader->uniformSizes				=	currentData.uniformSizes;
	cShader->totalUniformSize			=	currentData.uniformSize;

	cShader->strings					=	currentData.strings;

	cShader->numStrings					=	currentData.numStrings;
	cShader->numParameters				=	currentData.numParameters;
	cShader->numVariables				=	currentData.numVariables;
	cShader->numUniforms				=	currentData.numUniforms;
	cShader->numPLs						=	currentData.currentPL;

	cShader->codeEntryPoint				=	currentData.codeEntryPoint;
	cShader->initEntryPoint				=	currentData.initEntryPoint;

	cShader->usedParameters				=	currentData.usedParameters;

	cShader->type						=	currentData.shaderType;

	cShader->parameters					=	new CShader::TShaderParameter[currentData.numParameters];
	{
		TSlVariable	*cVar;
		int			i,numGlobals=0;

		for (cVar = currentData.definedParameters,i=0;cVar != NULL;cVar = cVar->next,i++) {
			int	j	=	currentData.numParameters - 1 - i;
			cShader->parameters[j].name	=	strdup(cVar->name);
			cShader->parameters[j].type	=	cVar->type;
			if (cShader->parameters[j].type == TYPE_STRING) {
				cShader->parameters[j].defaultValue	=	cShader->parameterEntries[j][0].string;
			} else {
				cShader->parameters[j].defaultValue	=	NULL;
			}
			cShader->parameters[j].uniform	=	cVar->uniform;
			cShader->parameters[j].numItems	=	cVar->multiplicity;
			cShader->parameters[j].global	=	cVar->global;
			if (cShader->parameters[j].global != NULL) {
				numGlobals++;
			}
		}
		cShader->numGlobals	=	numGlobals;
	}

	currentData.memory					=	NULL;
	currentData.code					=	NULL;
	currentData.constants				=	NULL;
	currentData.parameters				=	NULL;
	currentData.varyingSizes			=	NULL;
	currentData.uniformSizes			=	NULL;
	currentData.strings					=	NULL;
	currentData.parameterEntries		=	NULL;
	currentData.parameterDisplacements	=	NULL;
	currentData.constantEntries			=	NULL;


	return cShader;
}

///////////////////////////////////////////////////////////////////////
// Function				:
// Description			:
// Return Value			:
// Comments				:
// Date last edited		:
void	processEscapes(char *str) {
	int		i,n,j;

	n	=	strlen(str);
	for (i=0;i<n;i++) {
		if (str[i] == '\\') {
			switch(str[i+1]) {
			case 'n':
				str[i]	=	'\n';
				break;
			case 't':
				str[i]	=	'\t';
				break;
			case 'r':
				str[i]	=	'\r';
				break;
			case '\\':
				str[i]	=	'\\';
				break;
			default:
				break;
			}

			j	=	i+2;
			do {
				str[j-1]	=	str[j];
				j++;
			} while(str[j] != '\0');
			n--;
			i++;
		}
	}
	str[i]	=	'\0';
}

extern	void		convertColorFrom(float *out,const float *in,ECoordinateSystem s);




