⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc1.0_grammar.y

📁 使用stl技术,(还没看,是听说的)
💻 Y
📖 第 1 页 / 共 2 页
字号:
%start WholeEnchilada
%{
void yyerror(char* s);
int yylex ( void );

#ifdef _WIN32
# include <windows.h>
#endif

#include <stdio.h>
#include <stdlib.h>

#include "rc1.0_combiners.h"
#include "nvparse_errors.h"
#include "nvparse_externs.h"


%}
%union {
  int ival;
  float fval;
  RegisterEnum registerEnum;
  BiasScaleEnum biasScaleEnum;
  MappedRegisterStruct mappedRegisterStruct;
  ConstColorStruct constColorStruct;
  GeneralPortionStruct generalPortionStruct;
  GeneralFunctionStruct generalFunctionStruct;
  OpStruct opStruct;
  GeneralCombinerStruct generalCombinerStruct;
  GeneralCombinersStruct generalCombinersStruct;
  FinalProductStruct finalProductStruct;
  FinalRgbFunctionStruct finalRgbFunctionStruct;
  FinalAlphaFunctionStruct finalAlphaFunctionStruct;
  FinalCombinerStruct finalCombinerStruct;
  CombinersStruct combinersStruct;
}

%token <registerEnum> regVariable constVariable color_sum final_product
%token <ival> expandString halfBiasString unsignedString unsignedInvertString muxString sumString
%token <ival> rgb_portion alpha_portion
%token <ival> openParen closeParen openBracket closeBracket semicolon comma
%token <ival> dot times minus equals plus
%token <biasScaleEnum> bias_by_negative_one_half_scale_by_two bias_by_negative_one_half
%token <biasScaleEnum> scale_by_one_half scale_by_two scale_by_four

%token <ival> clamp_color_sum lerp
%token <ival> fragment_rgb fragment_alpha

%token <fval> floatValue

%type <combinersStruct> WholeEnchilada Combiners

%type <constColorStruct> ConstColor
%type <generalCombinerStruct> GeneralCombiner
%type <generalCombinersStruct> GeneralCombiners
%type <ival> PortionDesignator
%type <opStruct> Mux Sum Dot Mul
%type <generalPortionStruct> GeneralPortion
%type <generalFunctionStruct> GeneralFunction
%type <biasScaleEnum> BiasScale

%type <registerEnum> Register
%type <mappedRegisterStruct> GeneralMappedRegister FinalMappedRegister
%type <finalProductStruct> FinalProduct
%type <ival> ClampColorSum
%type <finalRgbFunctionStruct> FinalRgbFunction
%type <finalAlphaFunctionStruct> FinalAlphaFunction
%type <finalCombinerStruct> FinalCombiner

%%

WholeEnchilada	: Combiners
		{
			$1.Validate();
			$1.Invoke();
		}
		;

Combiners : ConstColor GeneralCombiners FinalCombiner
		{
			CombinersStruct combinersStruct;
			combinersStruct.Init($2, $3, $1);
			$$ = combinersStruct;
		}
		| ConstColor ConstColor GeneralCombiners FinalCombiner
		{
			CombinersStruct combinersStruct;
			combinersStruct.Init($3, $4, $1, $2);
			$$ = combinersStruct;
		}
		| GeneralCombiners FinalCombiner
		{
			CombinersStruct combinersStruct;
			combinersStruct.Init($1, $2);
			$$ = combinersStruct;
		}
		| ConstColor FinalCombiner
		{
			GeneralCombinersStruct generalCombinersStruct;
			generalCombinersStruct.Init();
			CombinersStruct combinersStruct;
			combinersStruct.Init(generalCombinersStruct, $2, $1);
			$$ = combinersStruct;
		}
		| ConstColor ConstColor FinalCombiner
		{
			GeneralCombinersStruct generalCombinersStruct;
			generalCombinersStruct.Init();
			CombinersStruct combinersStruct;
			combinersStruct.Init(generalCombinersStruct, $3, $1, $2);
			$$ = combinersStruct;
		}
		| FinalCombiner
		{
			GeneralCombinersStruct generalCombinersStruct;
			generalCombinersStruct.Init();
			CombinersStruct combinersStruct;
			combinersStruct.Init(generalCombinersStruct, $1);
			$$ = combinersStruct;
		}
		;
 
ConstColor : constVariable equals openParen floatValue comma floatValue comma floatValue comma floatValue closeParen semicolon
		{
			ConstColorStruct constColorStruct;
			constColorStruct.Init($1, $4, $6, $8, $10);
			$$ = constColorStruct;
		}
		;
 
 
GeneralCombiners	 : GeneralCombiners GeneralCombiner
		{
			$1 += $2;
			$$ = $1;
		}
		| GeneralCombiner
		{
			GeneralCombinersStruct generalCombinersStruct;
			generalCombinersStruct.Init($1);
			$$ = generalCombinersStruct;
		}
		;
 
GeneralCombiner : openBracket GeneralPortion GeneralPortion closeBracket
		{
			GeneralCombinerStruct generalCombinerStruct;
			generalCombinerStruct.Init($2, $3);
			$$ = generalCombinerStruct;
		}
		| openBracket ConstColor GeneralPortion GeneralPortion closeBracket
		{
			GeneralCombinerStruct generalCombinerStruct;
			generalCombinerStruct.Init($3, $4, $2);
			$$ = generalCombinerStruct;
		}
		| openBracket ConstColor ConstColor GeneralPortion GeneralPortion closeBracket
		{
			GeneralCombinerStruct generalCombinerStruct;
			generalCombinerStruct.Init($4, $5, $2, $3);
			$$ = generalCombinerStruct;
		}
		| openBracket GeneralPortion closeBracket
		{
			GeneralCombinerStruct generalCombinerStruct;
			generalCombinerStruct.Init($2);
			$$ = generalCombinerStruct;
		}
		| openBracket ConstColor GeneralPortion closeBracket
		{
			GeneralCombinerStruct generalCombinerStruct;
			generalCombinerStruct.Init($3, $2);
			$$ = generalCombinerStruct;
		}
		| openBracket ConstColor ConstColor GeneralPortion closeBracket
		{
			GeneralCombinerStruct generalCombinerStruct;
			generalCombinerStruct.Init($4, $2, $3);
			$$ = generalCombinerStruct;
		}
		;
 
GeneralPortion	: PortionDesignator openBracket GeneralFunction BiasScale closeBracket
		{
			GeneralPortionStruct generalPortionStruct;
			generalPortionStruct.Init($1, $3, $4);
			$$ = generalPortionStruct;
		}
		| PortionDesignator openBracket GeneralFunction closeBracket
		{
			BiasScaleEnum noScale;
			noScale.word = RCP_SCALE_BY_ONE;
			GeneralPortionStruct generalPortionStruct;
			generalPortionStruct.Init($1, $3, noScale);
			$$ = generalPortionStruct;
		}
		;
 
PortionDesignator	: rgb_portion
		{
			$$ = $1;
		}
		| alpha_portion
		{
			$$ = $1;
		}
		;

GeneralMappedRegister :     Register
		{
			MappedRegisterStruct reg;
			reg.Init($1, GL_SIGNED_IDENTITY_NV);
			$$ = reg;
		}
		| minus Register
		{
			MappedRegisterStruct reg;
			reg.Init($2, GL_SIGNED_NEGATE_NV);
			$$ = reg;
		}
		| expandString openParen Register closeParen
		{
			MappedRegisterStruct reg;
			reg.Init($3, GL_EXPAND_NORMAL_NV);
			$$ = reg;
		}
		| minus expandString openParen Register closeParen
		{
			MappedRegisterStruct reg;
			reg.Init($4, GL_EXPAND_NEGATE_NV);
			$$ = reg;
		}
		| halfBiasString openParen Register closeParen
		{
			MappedRegisterStruct reg;
			reg.Init($3, GL_HALF_BIAS_NORMAL_NV);
			$$ = reg;
		}
		| minus halfBiasString openParen Register closeParen
		{
			MappedRegisterStruct reg;
			reg.Init($4, GL_HALF_BIAS_NEGATE_NV);
			$$ = reg;
		}
		| unsignedString openParen Register closeParen
		{
			MappedRegisterStruct reg;
			reg.Init($3, GL_UNSIGNED_IDENTITY_NV);
			$$ = reg;
		}
		| unsignedInvertString openParen Register closeParen
		{
			MappedRegisterStruct reg;
			reg.Init($3, GL_UNSIGNED_INVERT_NV);
			$$ = reg;
		}
		;
  
GeneralFunction	: Dot Dot
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1, $2);
			$$ = generalFunction;
		}
		| Dot Mul
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1, $2);
			$$ = generalFunction;
		}
		| Mul Dot
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1, $2);
			$$ = generalFunction;
		}
		| Dot
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1);
			$$ = generalFunction;
		}
		| Mul Mul
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1, $2);
			$$ = generalFunction;
		}
		| Mul Mul Mux
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1, $2, $3);
			$$ = generalFunction;
		}
		| Mul Mul Sum
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1, $2, $3);
			$$ = generalFunction;
		}
		| Mul
		{
			GeneralFunctionStruct generalFunction;
			generalFunction.Init($1);
			$$ = generalFunction;
		}
		;
 
Dot : Register equals GeneralMappedRegister dot GeneralMappedRegister semicolon
		{
			OpStruct dotFunction;
			dotFunction.Init(RCP_DOT, $1, $3, $5);
			$$ = dotFunction;
		}
		;
 
Mul : Register equals GeneralMappedRegister times GeneralMappedRegister semicolon
		{
			OpStruct mulFunction;
			mulFunction.Init(RCP_MUL, $1, $3, $5);
			$$ = mulFunction;
		}
		| Register equals GeneralMappedRegister semicolon
		{
			RegisterEnum zero;
			zero.word = RCP_ZERO;
			MappedRegisterStruct one;
			one.Init(zero, GL_UNSIGNED_INVERT_NV);
			OpStruct mulFunction;
			mulFunction.Init(RCP_MUL, $1, $3, one);
			$$ = mulFunction;
		}
		;

Mux : Register equals muxString openParen closeParen semicolon
		{
			OpStruct muxFunction;
			muxFunction.Init(RCP_MUX, $1);
			$$ = muxFunction;
		}
		;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -