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

/* Skeleton parser for Yacc-like parsing with Bison,
   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 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_DOT = 279,
     SCRL_COLON = 280,
     SCRL_EQUAL = 281,
     SCRL_OPEN_PARANTHESIS = 282,
     SCRL_CLOSE_PARANTHESIS = 283,
     SCRL_OPEN_SQR_PARANTHESIS = 284,
     SCRL_CLOSE_SQR_PARANTHESIS = 285,
     SCRL_COMMA = 286,
     SCRL_NL = 287,
     SCRL_TEXT_VALUE = 288,
     SCRL_IDENTIFIER_VALUE = 289,
     SCRL_LABEL_VALUE = 290,
     SCRL_FLOAT_VALUE = 291
   };
#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_DOT 279
#define SCRL_COLON 280
#define SCRL_EQUAL 281
#define SCRL_OPEN_PARANTHESIS 282
#define SCRL_CLOSE_PARANTHESIS 283
#define SCRL_OPEN_SQR_PARANTHESIS 284
#define SCRL_CLOSE_SQR_PARANTHESIS 285
#define SCRL_COMMA 286
#define SCRL_NL 287
#define SCRL_TEXT_VALUE 288
#define SCRL_IDENTIFIER_VALUE 289
#define SCRL_LABEL_VALUE 290
#define SCRL_FLOAT_VALUE 291




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

typedef struct TSlVariable {
	char			name[64];
	int				index;
	int				multiplicity;
	EVariableType	type;
	int				uniform;
	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	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 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	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						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;
				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;

				
				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				:	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->uniform		=	currentData.uniform;

												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;
												} 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.strings[currentData.currentString++]	=	currentData.constants[currentData.currentConstantSize++].string	=	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) {
												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 650 "sdr.y"
typedef union slval {
	float	real;
	char	string[64];
	matrix	m;
	vector	v;
} YYSTYPE;
/* Line 191 of yacc.c.  */
#line 813 "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 825 "sl.cpp"

#if ! defined (yyoverflow) || YYERROR_VERBOSE

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

# if YYSTACK_USE_ALLOCA
#  define YYSTACK_ALLOC alloca
# else
#  ifndef YYSTACK_USE_ALLOCA
#   if defined (alloca) || defined (_ALLOCA_H)
#    define YYSTACK_ALLOC alloca
#   else
#    ifdef __GNUC__
#     define YYSTACK_ALLOC __builtin_alloca
#    endif
#   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 malloc
#  define YYSTACK_FREE free
# endif
#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */


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

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

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

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

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

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

#endif

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

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

/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS  37
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS  47
/* YYNRULES -- Number of rules. */
#define YYNRULES  119
/* YYNRULES -- Number of states. */
#define YYNSTATES  264

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

#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
};

#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
   YYRHS.  */
static const unsigned short yyprhs[] =
{
       0,     0,     3,     9,    10,    13,    17,    25,    28,    35,
      36,    38,    40,    42,    43,    46,    49,    52,    55,    58,
      63,    67,    68,    70,    71,    74,    76,    78,    80,    82,
      84,    86,    88,    89,    95,    98,   101,   108,   109,   111,
     113,   115,   117,   119,   121,   123,   125,   127,   129,   132,
     135,   138,   140,   145,   148,   154,   159,   165,   166,   171,
     177,   178,   183,   189,   190,   195,   201,   202,   207,   213,
     235,   240,   243,   249,   254,   258,   259,   262,   265,   268,
     271,   274,   277,   280,   283,   286,   292,   295,   301,   304,
     310,   313,   319,   322,   328,   331,   337,   340,   346,   349,
     355,   359,   363,   367,   368,   369,   377,   379,   381,   383,
     386,   387,   390,   393,   395,   397,   399,   401,   409,   443
};

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

/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
static const unsigned short yyrline[] =
{
       0,   702,   702,   709,   711,   715,   724,   737,   745,   757,
     764,   772,   777,   782,   788,   794,   800,   806,   812,   820,
     827,   830,   834,   836,   836,   843,   845,   847,   849,   851,
     853,   855,   862,   859,   878,   883,   888,   897,   902,   907,
     912,   917,   922,   927,   932,   939,   944,   949,   954,   960,
     966,   972,   979,   991,  1001,  1019,  1040,  1060,  1058,  1077,
    1090,  1088,  1107,  1120,  1118,  1137,  1150,  1148,  1167,  1178,
    1222,  1249,  1274,  1292,  1299,  1302,  1306,  1309,  1312,  1315,
    1318,  1321,  1324,  1327,  1332,  1338,  1350,  1356,  1367,  1373,
    1384,  1390,  1401,  1407,  1418,  1424,  1435,  1441,  1452,  1458,
    1469,  1473,  1477,  1481,  1487,  1485,  1539,  1558,  1577,  1598,
    1603,  1608,  1616,  1624,  1631,  1636,  1641,  1646,  1663,  1719
};
#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_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", "slParameter", "@1", 
  "slRegularParameter", "slGlobalParameter", "@2", 
  "slGlobalParameterInit", "slGlobalParameterType", 
  "slGlobalParameterContainer", "slFloatParameter", "slStringParameter", 
  "slColorParameter", "@3", "slVectorParameter", "@4", 
  "slNormalParameter", "@5", "slPointParameter", "@6", 
  "slMatrixParameter", "slVariableDefinitions", "slVariables", 
  "slVariable", "slBooleanVariable", "slFloatVariable", 
  "slStringVariable", "slVectorVariable", "slColorVariable", 
  "slNormalVariable", "slPointVariable", "slMatrixVariable", "slCode", 
  "slDSO", "@7", "slOpcode", "slOperandList", "slStatement", 
  "slLabelDefinition", "slOperand", 0
};
#endif

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

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
static const unsigned char yyr1[] =
{
       0,    37,    38,    39,    39,    40,    40,    40,    40,    40,
      41,    42,    42,    42,    43,    43,    43,    43,    43,    44,
      45,    45,    46,    47,    46,    48,    48,    48,    48,    48,
      48,    48,    50,    49,    51,    51,    51,    51,    52,    52,
      52,    52,    52,    52,    52,    53,    53,    53,    53,    53,
      53,    53,    54,    54,    54,    55,    55,    57,    56,    56,
      59,    58,    58,    61,    60,    60,    63,    62,    62,    64,
      64,    64,    64,    65,    66,    66,    67,    67,    67,    67,
      67,    67,    67,    67,    68,    68,    69,    69,    70,    70,
      71,    71,    72,    72,    73,    73,    74,    74,    75,    75,
      76,    76,    76,    76,    78,    77,    79,    79,    79,    80,
      80,    81,    82,    83,    83,    83,    83,    83,    83,    83
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
static const unsigned char yyr2[] =
{
       0,     2,     5,     0,     2,     3,     7,     2,     6,     0,
       1,     1,     1,     0,     2,     2,     2,     2,     2,     4,
       3,     0,     1,     0,     2,     1,     1,     1,     1,     1,
       1,     1,     0,     5,     2,     2,     6,     0,     1,     1,
       1,     1,     1,     1,     1,     1,     1,     1,     2,     2,
       2,     1,     4,     2,     5,     4,     5,     0,     4,     5,
       0,     4,     5,     0,     4,     5,     0,     4,     5,    21,
       4,     2,     5,     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,
       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,   103,    21,
       0,     3,    23,    75,   107,   108,     0,     3,   106,     0,
       2,     0,   110,     0,     0,    51,    46,    47,    45,     0,
       0,    22,     0,    13,   104,     4,   112,   102,     0,   113,
     115,   114,   116,   111,   110,   100,   101,    49,    50,    48,
      20,     0,     0,     0,     0,     0,     0,     0,    24,    25,
      26,    27,    28,    29,    30,    31,    38,    41,    39,    40,
      42,    43,    44,     0,    12,    11,     0,     0,     0,     0,
       0,   109,    53,    57,    60,    63,    66,    71,     0,    32,
       0,     0,     0,     0,     0,     0,     0,     0,    76,    77,
      78,    80,    79,    81,    82,    83,    74,     0,   119,     0,
       0,     0,     0,     9,     0,     9,     0,     9,     0,     9,
       0,     0,     0,     0,    37,    84,    86,    92,    90,    94,
      96,    98,    88,     0,     0,    52,     0,     0,     0,    10,
      58,     0,    61,     0,    64,     0,    67,     0,    70,     0,
      55,     0,     0,    33,     0,     0,     0,     0,     0,     0,
       0,     0,   110,     0,    54,    59,     0,     0,     7,    62,
      65,    68,     0,    72,    56,     0,    35,    34,     0,     0,
       0,     0,     0,     0,     0,     0,   105,     0,     0,     0,
       5,     0,     0,    85,    87,    93,    91,    95,    97,    99,
      89,   117,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     8,     0,     0,    36,     0,     6,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,    69,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,   118
};

/* YYDEFGOTO[NTERM-NUM]. */
static const short yydefgoto[] =
{
      -1,     6,    30,   149,   150,    86,     7,    15,    22,    39,
      40,    68,    41,   134,   163,    83,    42,    69,    70,    71,
     123,    72,   125,    73,   127,    74,   129,    75,    18,    43,
      87,   108,   109,   110,   111,   112,   113,   114,   115,    21,
      31,    88,    32,    53,    33,    34,    54
};

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
#define YYPACT_NINF -55
static const short yypact[] =
{
      45,   -30,   -28,   -11,    29,    41,    40,    78,   -55,   -55,
     -55,   -55,   -55,   -55,    61,    83,    56,    64,   -55,   -55,
      58,   -12,    63,   -55,   -55,   -55,    57,    60,   -55,    68,
     -55,    62,   -19,    65,    66,    77,   -55,   -55,   -55,    67,
      37,   -55,    44,     1,   -55,   -55,   -55,   -55,   -23,   -55,
     -55,   -55,   -55,   -55,   -19,   -55,   -55,   -55,   -55,   -55,
     -55,    69,    70,    71,    72,    73,    74,    75,   -55,   -55,
     -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,
     -55,   -55,   -55,    76,   -55,   -55,    16,    79,    85,    86,
      82,   -55,    49,    87,    88,    90,    91,    51,    53,   -55,
      81,    89,    92,    93,    94,    95,    96,    97,   -55,   -55,
     -55,   -55,   -55,   -55,   -55,   -55,   -55,    99,   -55,    59,
      98,   100,   101,   107,   102,   107,   103,   107,   104,   107,
     -24,   105,   109,   108,   117,   106,   116,   118,   119,   120,
     121,   122,   123,   125,   115,   -55,   124,   126,     5,   -55,
     -55,   127,   -55,   128,   -55,   129,   -55,   130,   -55,   131,
     -55,   132,    10,   -55,   133,   134,   135,   136,   137,   138,
     139,   140,   -19,   141,   -55,   -55,   142,     8,   -55,   -55,
     -55,   -55,   143,   -55,   -55,   144,   -55,   -55,   151,   152,
     153,   154,   155,   156,   157,   158,   -55,    14,   159,   160,
     -55,   161,   162,   -55,   -55,   -55,   -55,   -55,   -55,   -55,
     -55,   -55,   163,   164,   165,   166,   167,   173,   175,   170,
     171,   178,   174,   -55,   179,   176,   -55,   180,   -55,   177,
     181,   182,   183,   184,   185,   186,   188,   187,   189,   190,
     193,   191,   192,   194,   198,   195,   196,   197,   203,   207,
     200,   -55,   206,   202,   208,   204,   210,   209,   211,   212,
     213,   214,   215,   -55
};

/* YYPGOTO[NTERM-NUM].  */
static const short yypgoto[] =
{
     -55,   -55,   219,   -55,   -53,   -55,   -55,   -55,   -55,   -55,
     -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,
     -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,
     -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,   -55,
     -55,   -55,   -55,   -54,   -55,   -55,   -55
};

/* 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 -74
static const short yytable[] =
{
      91,   -73,     8,   157,     9,    24,    25,    84,    48,    85,
      89,    26,   158,    90,    49,    50,    51,    52,   -73,   -73,
      27,    10,    28,    29,   -73,   100,   101,   102,   103,   104,
     105,   106,   107,   -73,   176,   -73,   -73,   199,   177,   185,
      13,   178,   211,   186,   200,   212,   187,    61,    62,    63,
      64,    65,    66,    67,    76,    77,    78,    79,    80,    81,
      82,    11,     1,     2,     3,     4,     5,   -19,    35,    36,
      37,    38,   152,    12,   154,   120,   156,   130,   121,   132,
     131,    14,   133,    57,    58,    59,    16,    17,    19,    20,
      23,    44,    27,    46,    47,   144,     0,    55,    56,    60,
       0,     0,     0,    92,    93,    94,    95,    96,    97,    98,
      99,   116,   117,   119,   118,   135,   122,   124,   196,   126,
     128,     0,     0,   136,     0,     0,   137,   138,   139,   140,
     141,   142,   143,   148,   145,   164,   146,   147,   151,   153,
     155,   159,   160,   162,   161,   165,   173,   166,   167,   168,
     169,   170,   171,   172,   174,     0,   175,   179,   180,   181,
       0,   183,   184,     0,     0,     0,   182,     0,     0,   188,
     189,   190,   191,   192,   193,   194,   195,   197,   198,   201,
     202,   203,   204,   205,   206,   207,   208,   209,   210,     0,
       0,     0,     0,     0,     0,   213,   214,   215,   216,   217,
     218,   219,   220,   221,   222,   223,   224,   225,   226,   228,
     227,   230,   229,   231,   234,     0,     0,   232,   233,   238,
     235,   236,   237,   239,   242,   240,   241,   243,   244,   246,
     245,   247,   248,   249,   250,   251,   252,   253,   254,   255,
     256,   257,   259,   263,   261,   258,    45,     0,   260,     0,
     262
};

static const short yycheck[] =
{
      54,     0,    32,    27,    32,    17,    18,     6,    27,     8,
      33,    23,    36,    36,    33,    34,    35,    36,    17,    18,
      32,    32,    34,    35,    23,     9,    10,    11,    12,    13,
      14,    15,    16,    32,    29,    34,    35,    29,    33,    29,
       0,    36,    28,    33,    36,    31,    36,    10,    11,    12,
      13,    14,    15,    16,    10,    11,    12,    13,    14,    15,
      16,    32,    17,    18,    19,    20,    21,     4,     5,     6,
       7,     8,   125,    32,   127,    26,   129,    26,    29,    26,
      29,     3,    29,     6,     7,     8,    25,     4,    32,    25,
      32,    34,    32,    25,    32,    36,    -1,    32,    32,    32,
      -1,    -1,    -1,    34,    34,    34,    34,    34,    34,    34,
      34,    32,    27,    31,    28,    34,    29,    29,   172,    29,
      29,    -1,    -1,    34,    -1,    -1,    34,    34,    34,    34,
      34,    34,    33,    26,    36,    29,    36,    36,    36,    36,
      36,    36,    33,    26,    36,    29,    31,    29,    29,    29,
      29,    29,    29,    28,    30,    -1,    30,    30,    30,    30,
      -1,    30,    30,    -1,    -1,    -1,    36,    -1,    -1,    36,
      36,    36,    36,    36,    36,    36,    36,    36,    36,    36,
      36,    30,    30,    30,    30,    30,    30,    30,    30,    -1,
      -1,    -1,    -1,    -1,    -1,    36,    36,    36,    36,    36,
      36,    36,    36,    36,    31,    30,    36,    36,    30,    30,
      36,    31,    36,    36,    31,    -1,    -1,    36,    36,    31,
      36,    36,    36,    36,    31,    36,    36,    36,    36,    31,
      36,    36,    36,    36,    31,    28,    36,    31,    36,    31,
      36,    31,    31,    28,    31,    36,    27,    -1,    36,    -1,
      36
};

/* 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,    38,    43,    32,    32,
      32,    32,    32,     0,     3,    44,    25,     4,    65,    32,
      25,    76,    45,    32,    17,    18,    23,    32,    34,    35,
      39,    77,    79,    81,    82,     5,     6,     7,     8,    46,
      47,    49,    53,    66,    34,    39,    25,    32,    27,    33,
      34,    35,    36,    80,    83,    32,    32,     6,     7,     8,
      32,    10,    11,    12,    13,    14,    15,    16,    48,    54,
      55,    56,    58,    60,    62,    64,    10,    11,    12,    13,
      14,    15,    16,    52,     6,     8,    42,    67,    78,    33,
      36,    80,    34,    34,    34,    34,    34,    34,    34,    34,
       9,    10,    11,    12,    13,    14,    15,    16,    68,    69,
      70,    71,    72,    73,    74,    75,    32,    27,    28,    31,
      26,    29,    29,    57,    29,    59,    29,    61,    29,    63,
      26,    29,    26,    29,    50,    34,    34,    34,    34,    34,
      34,    34,    34,    33,    36,    36,    36,    36,    26,    40,
      41,    36,    41,    36,    41,    36,    41,    27,    36,    36,
      33,    36,    26,    51,    29,    29,    29,    29,    29,    29,
      29,    29,    28,    31,    30,    30,    29,    33,    36,    30,
      30,    30,    36,    30,    30,    29,    33,    36,    36,    36,
      36,    36,    36,    36,    36,    36,    80,    36,    36,    29,
      36,    36,    36,    30,    30,    30,    30,    30,    30,    30,
      30,    28,    31,    36,    36,    36,    36,    36,    36,    36,
      36,    36,    31,    30,    36,    36,    30,    36,    30,    36,
      31,    36,    36,    36,    31,    36,    36,    36,    31,    36,
      36,    36,    31,    36,    36,    36,    31,    36,    36,    36,
      31,    28,    36,    31,    36,    31,    36,    31,    36,    31,
      36,    31,    36,    28
};

#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 yyerrlab1


/* 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 (cinluded).                                                   |
`------------------------------------------------------------------*/

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

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


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

#if defined (__STDC__) || defined (__cplusplus)
static void
yy_reduce_print (int yyrule)
#else
static void
yy_reduce_print (yyrule)
    int yyrule;
#endif
{
  int yyi;
  unsigned int yylineno = yyrline[yyrule];
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
             yyrule - 1, yylineno);
  /* 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 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	yyssa[YYINITDEPTH];
  short *yyss = yyssa;
  register short *yyssp;

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



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

  YYSIZE_T yystacksize = YYINITDEPTH;

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


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

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

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

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

  yyssp = yyss;
  yyvsp = yyvs;

  goto yysetstate;

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

 yysetstate:
  *yyssp = yystate;

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

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


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

		    &yystacksize);

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

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

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

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


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

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

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

  goto yybackup;

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

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

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

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

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

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

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

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

  if (yyn == YYFINAL)
    YYACCEPT;

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

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

  *++yyvsp = yylval;


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

  yystate = yyn;
  goto yynewstate;


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


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

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

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


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

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

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

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

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

  case 10:
#line 765 "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 773 "sdr.y"
    {
					currentData.uniform	=	TRUE;
				;}
    break;

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

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

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

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

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

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

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

  case 23:
#line 836 "sdr.y"
    {	// All regular parameters are uniform
			currentData.uniform	=	TRUE;
		;}
    break;

  case 32:
#line 862 "sdr.y"
    {
			if (currentData.passNumber == 2) {
				char tmp[256];

				sprintf(tmp,"global %s %s %s",yyvsp[-2].string,yyvsp[-1].string,yyvsp[0].string);

				currentRenderer->declareVariable(NULL,tmp);
			}
		;}
    break;

  case 33:
#line 872 "sdr.y"
    {
		;}
    break;

  case 34:
#line 880 "sdr.y"
    {
		;}
    break;

  case 35:
#line 885 "sdr.y"
    {
		;}
    break;

  case 36:
#line 894 "sdr.y"
    {
		;}
    break;

  case 37:
#line 897 "sdr.y"
    {
		;}
    break;

  case 38:
#line 903 "sdr.y"
    {
			strcpy(yyval.string,"float");
		;}
    break;

  case 39:
#line 908 "sdr.y"
    {
			strcpy(yyval.string,"vector");
		;}
    break;

  case 40:
#line 913 "sdr.y"
    {
			strcpy(yyval.string,"normal");
		;}
    break;

  case 41:
#line 918 "sdr.y"
    {
			strcpy(yyval.string,"color");
		;}
    break;

  case 42:
#line 923 "sdr.y"
    {
			strcpy(yyval.string,"point");
		;}
    break;

  case 43:
#line 928 "sdr.y"
    {
			strcpy(yyval.string,"matrix");
		;}
    break;

  case 44:
#line 933 "sdr.y"
    {
			strcpy(yyval.string,"string");
		;}
    break;

  case 45:
#line 940 "sdr.y"
    {
			strcpy(yyval.string,"uniform");
		;}
    break;

  case 46:
#line 945 "sdr.y"
    {
			strcpy(yyval.string,"varying");
		;}
    break;

  case 47:
#line 950 "sdr.y"
    {
			strcpy(yyval.string,"vertex");
		;}
    break;

  case 48:
#line 956 "sdr.y"
    {
			strcpy(yyval.string,"uniform");
		;}
    break;

  case 49:
#line 962 "sdr.y"
    {
			strcpy(yyval.string,"varying");
		;}
    break;

  case 50:
#line 968 "sdr.y"
    {
			strcpy(yyval.string,"vertex");
		;}
    break;

  case 51:
#line 973 "sdr.y"
    {
			strcpy(yyval.string,"uniform");
		;}
    break;

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

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

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

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

  case 54:
#line 1006 "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 55:
#line 1023 "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) {
					currentData.strings[currentData.currentString++]	=	def->string	=	strdup(yyvsp[0].string);
				}
				break;
			default:
				break;
			}
		;}
    break;

  case 56:
#line 1045 "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 57:
#line 1060 "sdr.y"
    {
			currentData.currentParameterType	=	TYPE_COLOR;
		;}
    break;

  case 58:
#line 1064 "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 59:
#line 1082 "sdr.y"
    {
			TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_COLOR,(int) yyvsp[-1].real,TRUE);
		;}
    break;

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

  case 61:
#line 1094 "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 62:
#line 1112 "sdr.y"
    {
			TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_VECTOR,(int) yyvsp[-1].real,TRUE);
		;}
    break;

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

  case 64:
#line 1124 "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 65:
#line 1142 "sdr.y"
    {
			TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_NORMAL,(int) yyvsp[-1].real,TRUE);
		;}
    break;

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

  case 67:
#line 1154 "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 68:
#line 1172 "sdr.y"
    {
			TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_POINT,(int) yyvsp[-1].real,TRUE);
		;}
    break;

  case 69:
#line 1199 "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 70:
#line 1226 "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 71:
#line 1251 "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 72:
#line 1279 "sdr.y"
    {
			TCode	*def	=	newVariable(yyvsp[-3].string,TYPE_POINT,(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 84:
#line 1334 "sdr.y"
    {
			newVariable(yyvsp[0].string,TYPE_BOOLEAN,1,FALSE);
		;}
    break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  case 104:
#line 1487 "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 105:
#line 1508 "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 106:
#line 1540 "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 107:
#line 1559 "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 108:
#line 1578 "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 109:
#line 1600 "sdr.y"
    {
		;}
    break;

  case 110:
#line 1603 "sdr.y"
    {
		;}
    break;

  case 111:
#line 1610 "sdr.y"
    {
			setOpcode();
		;}
    break;

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

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

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

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

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

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

  case 117:
#line 1653 "sdr.y"
    {
			vector	tmp;

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

			addFloatReference(tmp,3);
		;}
    break;

  case 118:
#line 1696 "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 119:
#line 1722 "sdr.y"
    {
			strcpy(currentData.currentPrototype,yyvsp[-1].string);
		;}
    break;


    }

/* Line 999 of yacc.c.  */
#line 2808 "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);
	  char *yymsg;
	  int yyx, yycount;

	  yycount = 0;
	  /* Start YYX at -YYN if negative to avoid negative indexes in
	     YYCHECK.  */
	  for (yyx = yyn < 0 ? -yyn : 0;
	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
	  yysize += yystrlen ("syntax error, unexpected ") + 1;
	  yysize += 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)
		{
		  yycount = 0;
		  for (yyx = yyn < 0 ? -yyn : 0;
		       yyx < (int) (sizeof (yytname) / sizeof (char *));
		       yyx++)
		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
		      {
			const char *yyq = ! yycount ? ", expecting " : " or ";
			yyp = yystpcpy (yyp, yyq);
			yyp = yystpcpy (yyp, yytname[yyx]);
			yycount++;
		      }
		}
	      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.  */

      /* Return failure if at end of input.  */
      if (yychar == YYEOF)
        {
	  /* Pop the error token.  */
          YYPOPSTACK;
	  /* Pop the rest of the stack.  */
	  while (yyss < yyssp)
	    {
	      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
	      yydestruct (yystos[*yyssp], yyvsp);
	      YYPOPSTACK;
	    }
	  YYABORT;
        }

      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;


/*----------------------------------------------------.
| yyerrlab1 -- error raised explicitly by an action.  |
`----------------------------------------------------*/
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);
      yyvsp--;
      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 1727 "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.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,"#!Code") == 0) {
				currentData.codeEntryPoint	=	cLabel->index;
			}

			if (strcmp(cLabel->name,"#!Init") == 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;

		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;
		}
	}

	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);



