| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- %{
- #include "BsParserFX.h"
- #include "BsLexerFX.h"
- #define inline
- void yyerror(YYLTYPE *locp, ParseState* parse_state, yyscan_t scanner, const char *msg);
- %}
- %code requires{
- #include "BsMMAlloc.h"
- #include "BsASTFX.h"
- #include "BsIncludeHandler.h"
- #ifndef YY_TYPEDEF_YY_SCANNER_T
- #define YY_TYPEDEF_YY_SCANNER_T
- typedef void* yyscan_t;
- #endif
- typedef struct YYLTYPE {
- int first_line;
- int first_column;
- int last_line;
- int last_column;
- char *filename;
- } YYLTYPE;
- #define YYLTYPE_IS_DECLARED 1
- #define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- (Current).filename = YYRHSLOC (Rhs, 1).filename; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = YYRHSLOC (Rhs, 0).last_column; \
- (Current).filename = NULL; \
- } \
- while (0)
-
- }
- %output "BsParserFX.c"
- %defines "BsParserFX.h"
- %define api.pure
- %locations
- %lex-param { yyscan_t scanner }
- %parse-param { ParseState* parse_state }
- %parse-param { yyscan_t scanner }
- %glr-parser
- %union {
- int intValue;
- float floatValue;
- float matrixValue[16];
- int intVectorValue[4];
- const char* strValue;
- ASTFXNode* nodePtr;
- NodeOption nodeOption;
- }
- /* Value types */
- %token <intValue> TOKEN_INTEGER
- %token <floatValue> TOKEN_FLOAT
- %token <intValue> TOKEN_BOOLEAN
- %token <strValue> TOKEN_STRING
- %token <strValue> TOKEN_IDENTIFIER
- %token <intValue> TOKEN_FILLMODEVALUE
- %token <intValue> TOKEN_CULLMODEVALUE
- %token <intValue> TOKEN_COMPFUNCVALUE
- %token <intValue> TOKEN_OPVALUE
- %token <intValue> TOKEN_COLORMASK
- %token <intValue> TOKEN_BLENDOPVALUE
- %token <intValue> TOKEN_QUEUETYPE
- /* Qualifiers */
- %token TOKEN_BASE TOKEN_INHERITS
- /* Shader keywords */
- %token TOKEN_SEPARABLE TOKEN_SORT TOKEN_PRIORITY TOKEN_TRANSPARENT
- %token TOKEN_TECHNIQUE
- /* Technique keywords */
- %token TOKEN_RENDERER TOKEN_PASS TOKEN_TAGS
- /* Pass keywords */
- %token TOKEN_VERTEX TOKEN_FRAGMENT TOKEN_GEOMETRY TOKEN_HULL TOKEN_DOMAIN TOKEN_COMPUTE TOKEN_COMMON
- %token TOKEN_STENCILREF
- %token TOKEN_FILLMODE TOKEN_CULLMODE TOKEN_DEPTHBIAS TOKEN_SDEPTHBIAS
- %token TOKEN_DEPTHCLIP TOKEN_SCISSOR TOKEN_MULTISAMPLE TOKEN_AALINE
- %token TOKEN_DEPTHREAD TOKEN_DEPTHWRITE TOKEN_COMPAREFUNC TOKEN_STENCIL
- %token TOKEN_STENCILREADMASK TOKEN_STENCILWRITEMASK TOKEN_STENCILOPFRONT TOKEN_STENCILOPBACK
- %token TOKEN_FAIL TOKEN_ZFAIL
- %token TOKEN_ALPHATOCOVERAGE TOKEN_INDEPENDANTBLEND TOKEN_TARGET TOKEN_INDEX
- %token TOKEN_BLEND TOKEN_COLOR TOKEN_ALPHA TOKEN_WRITEMASK
- %token TOKEN_SOURCE TOKEN_DEST TOKEN_OP
- %type <nodePtr> shader;
- %type <nodeOption> shader_statement;
- %type <nodeOption> shader_option;
- %type <nodePtr> technique;
- %type <nodePtr> technique_header;
- %type <nodeOption> technique_statement;
- %type <nodeOption> technique_option;
- %type <nodePtr> tags;
- %type <nodePtr> tags_header;
- %type <nodePtr> pass;
- %type <nodePtr> pass_header;
- %type <nodeOption> pass_statement;
- %type <nodeOption> pass_option;
- %type <nodePtr> code;
- %type <nodePtr> code_header;
- %type <nodePtr> stencil_op_front_header;
- %type <nodePtr> stencil_op_back_header;
- %type <nodeOption> stencil_op_option;
- %type <nodePtr> target;
- %type <nodePtr> target_header;
- %type <nodeOption> target_statement;
- %type <nodeOption> target_option;
- %type <nodePtr> blend_color_header;
- %type <nodePtr> blend_alpha_header;
- %type <nodeOption> blenddef_option;
- %type <nodeOption> technique_qualifier
- %%
- /* Shader */
- shader
- : /* empty */ { }
- | shader_statement shader { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- shader_statement
- : shader_option
- | technique { $$.type = OT_Technique; $$.value.nodePtr = $1; }
- ;
- shader_option
- : TOKEN_SEPARABLE '=' TOKEN_BOOLEAN ';' { $$.type = OT_Separable; $$.value.intValue = $3; }
- | TOKEN_SORT '=' TOKEN_QUEUETYPE ';' { $$.type = OT_Sort; $$.value.intValue = $3; }
- | TOKEN_PRIORITY '=' TOKEN_INTEGER ';' { $$.type = OT_Priority; $$.value.intValue = $3; }
- | TOKEN_TRANSPARENT '=' TOKEN_BOOLEAN ';' { $$.type = OT_Transparent; $$.value.intValue = $3; }
- ;
- /* Technique */
- technique
- : technique_header technique_qualifier_list '=' '{' technique_body '}' ';' { nodePop(parse_state); $$ = $1; }
- ;
- technique_header
- : TOKEN_TECHNIQUE
- {
- $$ = nodeCreate(parse_state->memContext, NT_Technique);
- nodePush(parse_state, $$);
- }
- ;
- technique_body
- : /* empty */
- | technique_statement technique_body { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- technique_statement
- : technique_option
- | pass { $$.type = OT_Pass; $$.value.nodePtr = $1; }
- | pass_option
- | code { $$.type = OT_Code; $$.value.nodePtr = $1; }
- ;
- technique_option
- : TOKEN_RENDERER '=' TOKEN_STRING ';' { $$.type = OT_Renderer; $$.value.strValue = $3; }
- | tags { $$.type = OT_Tags; $$.value.nodePtr = $1; }
- ;
-
- /* Technique tags */
- tags
- : tags_header '{' tags_body '}' ';' { nodePop(parse_state); $$ = $1; }
- ;
-
- tags_header
- : TOKEN_TAGS '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_Tags);
- nodePush(parse_state, $$);
- }
- ;
-
- tags_body
- : /* empty */
- | TOKEN_STRING
- {
- NodeOption entry; entry.type = OT_TagValue; entry.value.strValue = $1;
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &entry);
- }
- | TOKEN_STRING ',' tags_body
- {
- NodeOption entry; entry.type = OT_TagValue; entry.value.strValue = $1;
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &entry);
- }
- ;
- /* Technique qualifiers */
- technique_qualifier_list
- : /* empty */
- | technique_qualifier technique_qualifier_list { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- technique_qualifier
- : ':' TOKEN_BASE '(' TOKEN_STRING ')' { $$.type = OT_Base; $$.value.strValue = $4; }
- | ':' TOKEN_INHERITS '(' TOKEN_STRING ')' { $$.type = OT_Inherits; $$.value.strValue = $4; }
- ;
-
- /* Pass */
- pass
- : pass_header '{' pass_body '}' ';' { nodePop(parse_state); $$ = $1; }
- ;
- pass_header
- : TOKEN_PASS '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_Pass);
- nodePush(parse_state, $$);
- }
- ;
- pass_body
- : /* empty */
- | pass_statement pass_body { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- pass_statement
- : pass_option
- | code { $$.type = OT_Code; $$.value.nodePtr = $1; }
- ;
- pass_option
- : TOKEN_INDEX '=' TOKEN_INTEGER ';' { $$.type = OT_Index; $$.value.intValue = $3; }
- | TOKEN_FILLMODE '=' TOKEN_FILLMODEVALUE ';' { $$.type = OT_FillMode; $$.value.intValue = $3; }
- | TOKEN_CULLMODE '=' TOKEN_CULLMODEVALUE ';' { $$.type = OT_CullMode; $$.value.intValue = $3; }
- | TOKEN_DEPTHBIAS '=' TOKEN_FLOAT ';' { $$.type = OT_DepthBias; $$.value.floatValue = $3; }
- | TOKEN_SDEPTHBIAS '=' TOKEN_FLOAT ';' { $$.type = OT_SDepthBias; $$.value.floatValue = $3; }
- | TOKEN_DEPTHCLIP '=' TOKEN_BOOLEAN ';' { $$.type = OT_DepthClip; $$.value.intValue = $3; }
- | TOKEN_SCISSOR '=' TOKEN_BOOLEAN ';' { $$.type = OT_Scissor; $$.value.intValue = $3; }
- | TOKEN_MULTISAMPLE '=' TOKEN_BOOLEAN ';' { $$.type = OT_Multisample; $$.value.intValue = $3; }
- | TOKEN_AALINE '=' TOKEN_BOOLEAN ';' { $$.type = OT_AALine; $$.value.intValue = $3; }
- | TOKEN_DEPTHREAD '=' TOKEN_BOOLEAN ';' { $$.type = OT_DepthRead; $$.value.intValue = $3; }
- | TOKEN_DEPTHWRITE '=' TOKEN_BOOLEAN ';' { $$.type = OT_DepthWrite; $$.value.intValue = $3; }
- | TOKEN_COMPAREFUNC '=' TOKEN_COMPFUNCVALUE ';' { $$.type = OT_CompareFunc; $$.value.intValue = $3; }
- | TOKEN_STENCIL '=' TOKEN_BOOLEAN ';' { $$.type = OT_Stencil; $$.value.intValue = $3; }
- | TOKEN_STENCILREADMASK '=' TOKEN_INTEGER ';' { $$.type = OT_StencilReadMask; $$.value.intValue = $3; }
- | TOKEN_STENCILWRITEMASK '=' TOKEN_INTEGER ';' { $$.type = OT_StencilWriteMask; $$.value.intValue = $3; }
- | stencil_op_front_header '{' stencil_op_body '}' ';' { nodePop(parse_state); $$.type = OT_StencilOpFront; $$.value.nodePtr = $1; }
- | stencil_op_back_header '{' stencil_op_body '}' ';' { nodePop(parse_state); $$.type = OT_StencilOpBack; $$.value.nodePtr = $1; }
- | stencil_op_front_header '{' stencil_op_body_init '}' ';' { nodePop(parse_state); $$.type = OT_StencilOpFront; $$.value.nodePtr = $1; }
- | stencil_op_back_header '{' stencil_op_body_init '}' ';' { nodePop(parse_state); $$.type = OT_StencilOpBack; $$.value.nodePtr = $1; }
- | TOKEN_ALPHATOCOVERAGE '=' TOKEN_BOOLEAN ';' { $$.type = OT_AlphaToCoverage; $$.value.intValue = $3; }
- | TOKEN_INDEPENDANTBLEND '=' TOKEN_BOOLEAN ';' { $$.type = OT_IndependantBlend; $$.value.intValue = $3; }
- | target { $$.type = OT_Target; $$.value.nodePtr = $1; }
- | TOKEN_STENCILREF '=' TOKEN_INTEGER ';' { $$.type = OT_StencilRef; $$.value.intValue = $3; }
- ;
- /* Code blocks */
- code
- : code_header '{' TOKEN_INDEX '=' TOKEN_INTEGER ';' '}' ';'
- {
- NodeOption index;
- index.type = OT_Index;
- index.value.intValue = $5;
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &index);
- nodePop(parse_state);
- $$ = $1;
- }
- ;
- code_header
- : TOKEN_VERTEX '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeVertex);
- nodePush(parse_state, $$);
- }
- | TOKEN_FRAGMENT '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeFragment);
- nodePush(parse_state, $$);
- }
- | TOKEN_GEOMETRY '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeGeometry);
- nodePush(parse_state, $$);
- }
- | TOKEN_HULL '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeHull);
- nodePush(parse_state, $$);
- }
- | TOKEN_DOMAIN '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeDomain);
- nodePush(parse_state, $$);
- }
- | TOKEN_COMPUTE '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeCompute);
- nodePush(parse_state, $$);
- }
- | TOKEN_COMMON '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_CodeCommon);
- nodePush(parse_state, $$);
- }
- ;
- /* Stencil op */
- stencil_op_front_header
- : TOKEN_STENCILOPFRONT '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_StencilOp);
- nodePush(parse_state, $$);
- }
- ;
- stencil_op_back_header
- : TOKEN_STENCILOPBACK '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_StencilOp);
- nodePush(parse_state, $$);
- }
- ;
- stencil_op_body_init
- : TOKEN_OPVALUE ',' TOKEN_OPVALUE ',' TOKEN_OPVALUE ',' TOKEN_COMPFUNCVALUE
- {
- NodeOption fail; fail.type = OT_Fail; fail.value.intValue = $1;
- NodeOption zfail; zfail.type = OT_ZFail; zfail.value.intValue = $3;
- NodeOption pass; pass.type = OT_PassOp; pass.value.intValue = $5;
- NodeOption cmp; cmp.type = OT_CompareFunc; cmp.value.intValue = $7;
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &fail);
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &zfail);
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &pass);
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &cmp);
- }
- ;
- stencil_op_body
- : /* empty */
- | stencil_op_option stencil_op_body { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- stencil_op_option
- : TOKEN_FAIL '=' TOKEN_OPVALUE ';' { $$.type = OT_Fail; $$.value.intValue = $3; }
- | TOKEN_ZFAIL '=' TOKEN_OPVALUE ';' { $$.type = OT_ZFail; $$.value.intValue = $3; }
- | TOKEN_PASS '=' TOKEN_OPVALUE ';' { $$.type = OT_PassOp; $$.value.intValue = $3; }
- | TOKEN_COMPAREFUNC '=' TOKEN_COMPFUNCVALUE ';' { $$.type = OT_CompareFunc; $$.value.intValue = $3; }
- ;
- /* Target */
- target
- : target_header '{' target_body '}' ';' { nodePop(parse_state); $$ = $1; }
- ;
- target_header
- : TOKEN_TARGET '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_Target);
- nodePush(parse_state, $$);
- }
- ;
- target_body
- : /* empty */
- | target_statement target_body { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- target_statement
- : target_option
- ;
- target_option
- : TOKEN_INDEX '=' TOKEN_INTEGER ';' { $$.type = OT_Index; $$.value.intValue = $3; }
- | TOKEN_BLEND '=' TOKEN_BOOLEAN ';' { $$.type = OT_Blend; $$.value.intValue = $3; }
- | blend_color_header '{' blenddef_body '}' ';' { nodePop(parse_state); $$.type = OT_Color; $$.value.nodePtr = $1; }
- | blend_alpha_header '{' blenddef_body '}' ';' { nodePop(parse_state); $$.type = OT_Alpha; $$.value.nodePtr = $1; }
- | blend_color_header '{' blenddef_body_init '}' ';' { nodePop(parse_state); $$.type = OT_Color; $$.value.nodePtr = $1; }
- | blend_alpha_header '{' blenddef_body_init '}' ';' { nodePop(parse_state); $$.type = OT_Alpha; $$.value.nodePtr = $1; }
- | TOKEN_WRITEMASK '=' TOKEN_COLORMASK ';' { $$.type = OT_WriteMask; $$.value.intValue = $3; }
- ;
- /* Blend definition */
- blend_color_header
- : TOKEN_COLOR '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_BlendDef);
- nodePush(parse_state, $$);
- }
- ;
- blend_alpha_header
- : TOKEN_ALPHA '='
- {
- $$ = nodeCreate(parse_state->memContext, NT_BlendDef);
- nodePush(parse_state, $$);
- }
- ;
- blenddef_body
- : /* empty */
- | blenddef_option blenddef_body { nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &$1); }
- ;
- blenddef_body_init
- : TOKEN_OPVALUE ',' TOKEN_OPVALUE ',' TOKEN_BLENDOPVALUE
- {
- NodeOption src; src.type = OT_Source; src.value.intValue = $1;
- NodeOption dst; dst.type = OT_Dest; dst.value.intValue = $3;
- NodeOption op; op.type = OT_Op; op.value.intValue = $5;
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &src);
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &dst);
- nodeOptionsAdd(parse_state->memContext, parse_state->topNode->options, &op);
- }
- ;
- blenddef_option
- : TOKEN_SOURCE '=' TOKEN_OPVALUE ';' { $$.type = OT_Source; $$.value.intValue = $3; }
- | TOKEN_DEST '=' TOKEN_OPVALUE ';' { $$.type = OT_Dest; $$.value.intValue = $3; }
- | TOKEN_OP '=' TOKEN_BLENDOPVALUE ';' { $$.type = OT_Op; $$.value.intValue = $3; }
- ;
- %%
- void yyerror(YYLTYPE *locp, ParseState* parse_state, yyscan_t scanner, const char *msg)
- {
- parse_state->hasError = 1;
- parse_state->errorLine = locp->first_line;
- parse_state->errorColumn = locp->first_column;
- parse_state->errorMessage = mmalloc_strdup(parse_state->memContext, msg);
- parse_state->errorFile = locp->filename;
- }
|