mojoshader_parser_hlsl.lemon
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Thu, 27 Aug 2020 17:18:38 -0400
changeset 1302 974d2cc3558e
parent 984 b75637d50945
permissions -rw-r--r--
vulkan: Fix overlapping pixel/vertex shaders where one shader is NULL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     1
/**
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     3
 *  Direct3D shaders.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     4
 *
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     6
 *
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     7
 *  This file written by Ryan C. Gordon.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
     8
 */
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    10
// This is a Lemon Parser grammar for HLSL. It is based on an ANSI C YACC
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    11
//  grammar by Jeff Lee: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    13
// Lemon is here: http://www.hwaci.com/sw/lemon/  ...  the source is included
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    14
//  with MojoShader, and built with the library, so you don't have to track
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    15
//  down the dependency.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    16
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    17
// HLSL syntax is described, informally, here:
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    18
//  http://msdn.microsoft.com/en-us/library/bb509615(VS.85).aspx
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    20
%name ParseHLSL
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    21
787
04d5c34d8b40 Added statement block attributes to the HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 785
diff changeset
    22
// Some shift-reduce conflicts are basically unavoidable, but if the final
04d5c34d8b40 Added statement block attributes to the HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 785
diff changeset
    23
//  conflict count matches this value, we consider it known and acceptable.
788
9f4d32456f78 Allow vector initializers, like "float4 x = {a,b,c,d};"
Ryan C. Gordon <icculus@icculus.org>
parents: 787
diff changeset
    24
%expect 2
787
04d5c34d8b40 Added statement block attributes to the HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 785
diff changeset
    25
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    26
%start_symbol shader
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    27
%token_prefix TOKEN_HLSL_
778
a43d07e5da68 Added some structure for user types (struct at the moment).
Ryan C. Gordon <icculus@icculus.org>
parents: 777
diff changeset
    28
%token_type { TokenData }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    29
%extra_argument { Context *ctx }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    31
%include {
709
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 707
diff changeset
    32
#ifndef __MOJOSHADER_HLSL_COMPILER__
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 707
diff changeset
    33
#error Do not compile this file directly.
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 707
diff changeset
    34
#endif
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    35
}
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
785
5a0a763d74e1 Added totally unhelpful syntax error output.
Ryan C. Gordon <icculus@icculus.org>
parents: 783
diff changeset
    37
%syntax_error {
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    38
    // !!! FIXME: make this a proper fail() function.
848
8ff6c5d37d33 Make the error code blocks into fail() calls.
Ryan C. Gordon <icculus@icculus.org>
parents: 846
diff changeset
    39
    fail(ctx, "Syntax error");
785
5a0a763d74e1 Added totally unhelpful syntax error output.
Ryan C. Gordon <icculus@icculus.org>
parents: 783
diff changeset
    40
}
5a0a763d74e1 Added totally unhelpful syntax error output.
Ryan C. Gordon <icculus@icculus.org>
parents: 783
diff changeset
    41
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    42
%parse_failure {
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
    43
    // !!! FIXME: make this a proper fail() function.
848
8ff6c5d37d33 Make the error code blocks into fail() calls.
Ryan C. Gordon <icculus@icculus.org>
parents: 846
diff changeset
    44
    fail(ctx, "Giving up. Parser is hopelessly lost...");
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    45
}
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    46
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    47
%stack_overflow {
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
    48
    // !!! FIXME: make this a proper fail() function.
848
8ff6c5d37d33 Make the error code blocks into fail() calls.
Ryan C. Gordon <icculus@icculus.org>
parents: 846
diff changeset
    49
    fail(ctx, "Giving up. Parser stack overflow");
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    50
}
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    52
// operator precedence (matches C spec)...
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    54
%left COMMA.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    55
%right ASSIGN ADDASSIGN SUBASSIGN MULASSIGN DIVASSIGN MODASSIGN LSHIFTASSIGN
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    56
       RSHIFTASSIGN ANDASSIGN ORASSIGN XORASSIGN.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    57
%right QUESTION.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    58
%left OROR.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    59
%left ANDAND.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    60
%left OR.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    61
%left XOR.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    62
%left AND.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    63
%left EQL NEQ.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    64
%left LT LEQ GT GEQ.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    65
%left LSHIFT RSHIFT.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    66
%left PLUS MINUS.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    67
%left STAR SLASH PERCENT.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    68
%right TYPECAST EXCLAMATION COMPLEMENT MINUSMINUS PLUSPLUS.
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    69
%left DOT LBRACKET RBRACKET LPAREN RPAREN.
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
704
292ea2611014 Resolved "dangling else" problem in HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
    71
// bump up the precedence of ELSE, to avoid shift/reduce conflict on the
292ea2611014 Resolved "dangling else" problem in HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
    72
//  usual "dangling else ambiguity" ...
292ea2611014 Resolved "dangling else" problem in HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
    73
%right ELSE.
292ea2611014 Resolved "dangling else" problem in HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
    74
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    76
// The rules...
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
    77
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
    78
shader ::= compilation_units(B). { assert(ctx->ast == NULL); REVERSE_LINKED_LIST(MOJOSHADER_astCompilationUnit, B); ctx->ast = (MOJOSHADER_astNode *) B; }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    79
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
    80
%type compilation_units { MOJOSHADER_astCompilationUnit * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    81
%destructor compilation_units { delete_compilation_unit(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    82
compilation_units(A) ::= compilation_unit(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    83
compilation_units(A) ::= compilation_units(B) compilation_unit(C). { if (C) { C->next = B; A = C; } }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
    84
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
    85
%type compilation_unit { MOJOSHADER_astCompilationUnit * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    86
%destructor compilation_unit { delete_compilation_unit(ctx, $$); }
910
3ee487d85ecb Handle #pragma (or at least, don't fail on them).
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
    87
//compilation_unit(A) ::= PRAGMA . { A = NULL; }   // !!! FIXME: deal with pragmas.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    88
compilation_unit(A) ::= variable_declaration(B). { A = new_global_variable(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    89
compilation_unit(A) ::= function_signature(B) SEMICOLON. { A = new_function(ctx, B, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    90
compilation_unit(A) ::= function_signature(B) statement_block(C). { A = new_function(ctx, B, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    91
compilation_unit(A) ::= typedef(B). { A = new_global_typedef(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    92
compilation_unit(A) ::= struct_declaration(B) SEMICOLON. { A = new_global_struct(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    93
//compilation_unit(A) ::= error SEMICOLON. { A = NULL; }  // !!! FIXME: research using the error nonterminal
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
    94
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
    95
%type typedef { MOJOSHADER_astTypedef * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    96
%destructor typedef { delete_typedef(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    97
// !!! FIXME: should CONST be here, or in datatype?
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
    98
typedef(A) ::= TYPEDEF CONST datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 1, B, C); push_usertype(ctx, C->identifier, A->datatype); }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
    99
typedef(A) ::= TYPEDEF datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 0, B, C); push_usertype(ctx, C->identifier, A->datatype); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   100
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   101
%type function_signature { MOJOSHADER_astFunctionSignature * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   102
%destructor function_signature { delete_function_signature(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   103
function_signature(A) ::= function_storageclass(B) function_details(C) semantic(D). { A = C; A->storage_class = B; A->semantic = D; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   104
function_signature(A) ::= function_storageclass(B) function_details(C). { A = C; A->storage_class = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   105
function_signature(A) ::= function_details(B) semantic(C). { A = B; A->semantic = C; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   106
function_signature(A) ::= function_details(B). { A = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   107
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   108
%type function_details { MOJOSHADER_astFunctionSignature * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   109
%destructor function_details { delete_function_signature(ctx, $$); }
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   110
function_details(A) ::= datatype(B) IDENTIFIER(C) LPAREN function_parameters(D) RPAREN. { A = new_function_signature(ctx, B, C.string, D); }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   111
function_details(A) ::= VOID IDENTIFIER(B) LPAREN function_parameters(C) RPAREN. { A = new_function_signature(ctx, NULL, B.string, C); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   112
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   113
// !!! FIXME: there is a "target" storage class that is the name of the
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   114
// !!! FIXME:  platform that this function is meant for...but I don't know
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   115
// !!! FIXME:  what tokens are valid here.
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   116
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   117
// !!! FIXME: Also, the docs say "one of" inline or target, but I bet you can
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   118
// !!! FIXME:  specify both.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   119
%type function_storageclass { MOJOSHADER_astFunctionStorageClass }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   120
//function_storageclass(A) ::= target(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   121
function_storageclass(A) ::= INLINE. { A = MOJOSHADER_AST_FNSTORECLS_INLINE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   122
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   123
%type function_parameters { MOJOSHADER_astFunctionParameters * }
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   124
%destructor function_parameters { delete_function_params(ctx, $$); }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   125
function_parameters(A) ::= VOID. { A = NULL; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   126
function_parameters(A) ::= function_parameter_list(B). { REVERSE_LINKED_LIST(MOJOSHADER_astFunctionParameters, B); A = B; }
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   127
function_parameters(A) ::= . { A = NULL; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   128
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   129
%type function_parameter_list { MOJOSHADER_astFunctionParameters * }
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   130
%destructor function_parameter_list { delete_function_params(ctx, $$); }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   131
function_parameter_list(A) ::= function_parameter(B). { A = B; }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   132
function_parameter_list(A) ::= function_parameter_list(B) COMMA function_parameter(C). { C->next = B; A = C; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   133
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   134
// !!! FIXME: this is pretty unreadable.
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   135
// !!! FIXME: CONST?
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   136
%type function_parameter { MOJOSHADER_astFunctionParameters * }
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   137
%destructor function_parameter { delete_function_params(ctx, $$); }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   138
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) interpolation_mod(F) initializer(G). { A = new_function_param(ctx, B, C, D.string, E, F, G); }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   139
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) interpolation_mod(F). { A = new_function_param(ctx, B, C, D.string, E, F, NULL); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   140
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) initializer(F). { A = new_function_param(ctx, B, C, D.string, E, MOJOSHADER_AST_INTERPMOD_NONE, F); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   141
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E). { A = new_function_param(ctx, B, C, D.string, E, MOJOSHADER_AST_INTERPMOD_NONE, NULL); }
926
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   142
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) interpolation_mod(E) initializer(F). { A = new_function_param(ctx, B, C, D.string, NULL, E, F); }
8ac335735b37 Renamed function "arguments" to function "parameters" in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 924
diff changeset
   143
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) interpolation_mod(E). { A = new_function_param(ctx, B, C, D.string, NULL, E, NULL); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   144
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) initializer(E). { A = new_function_param(ctx, B, C, D.string, NULL, MOJOSHADER_AST_INTERPMOD_NONE, E); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   145
function_parameter(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D). { A = new_function_param(ctx, B, C, D.string, NULL, MOJOSHADER_AST_INTERPMOD_NONE, NULL); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   146
function_parameter(A) ::= datatype(B) IDENTIFIER(C) semantic(D) interpolation_mod(E) initializer(F). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, D, E, F); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   147
function_parameter(A) ::= datatype(B) IDENTIFIER(C) semantic(D) interpolation_mod(E). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, D, E, NULL); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   148
function_parameter(A) ::= datatype(B) IDENTIFIER(C) semantic(D) initializer(E). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, D, MOJOSHADER_AST_INTERPMOD_NONE, E); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   149
function_parameter(A) ::= datatype(B) IDENTIFIER(C) semantic(D). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, D, MOJOSHADER_AST_INTERPMOD_NONE, NULL); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   150
function_parameter(A) ::= datatype(B) IDENTIFIER(C) interpolation_mod(D) initializer(E). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, NULL, D, E); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   151
function_parameter(A) ::= datatype(B) IDENTIFIER(C) interpolation_mod(D). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, NULL, D, NULL); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   152
function_parameter(A) ::= datatype(B) IDENTIFIER(C) initializer(D). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, NULL, MOJOSHADER_AST_INTERPMOD_NONE, D); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   153
function_parameter(A) ::= datatype(B) IDENTIFIER(C). { A = new_function_param(ctx, MOJOSHADER_AST_INPUTMOD_NONE, B, C.string, NULL, MOJOSHADER_AST_INTERPMOD_NONE, NULL); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   154
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   155
%type input_modifier { MOJOSHADER_astInputModifier }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   156
input_modifier(A) ::= IN. { A = MOJOSHADER_AST_INPUTMOD_IN; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   157
input_modifier(A) ::= INOUT. { A = MOJOSHADER_AST_INPUTMOD_INOUT; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   158
input_modifier(A) ::= OUT. { A = MOJOSHADER_AST_INPUTMOD_OUT; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   159
input_modifier(A) ::= IN OUT. { A = MOJOSHADER_AST_INPUTMOD_INOUT; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   160
input_modifier(A) ::= OUT IN. { A = MOJOSHADER_AST_INPUTMOD_INOUT; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   161
input_modifier(A) ::= UNIFORM. { A = MOJOSHADER_AST_INPUTMOD_UNIFORM; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   162
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   163
%type semantic { const char * }
838
37e901d1b7bf Removed SEMANTIC token...we can do this with IDENTIFIER.
Ryan C. Gordon <icculus@icculus.org>
parents: 837
diff changeset
   164
semantic(A) ::= COLON IDENTIFIER(B). { A = B.string; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   165
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   166
// DX10 only?
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   167
%type interpolation_mod { MOJOSHADER_astInterpolationModifier }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   168
interpolation_mod(A) ::= LINEAR. { A = MOJOSHADER_AST_INTERPMOD_LINEAR; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   169
interpolation_mod(A) ::= CENTROID. { A = MOJOSHADER_AST_INTERPMOD_CENTROID; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   170
interpolation_mod(A) ::= NOINTERPOLATION. { A = MOJOSHADER_AST_INTERPMOD_NOINTERPOLATION; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   171
interpolation_mod(A) ::= NOPERSPECTIVE. { A = MOJOSHADER_AST_INTERPMOD_NOPERSPECTIVE; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   172
interpolation_mod(A) ::= SAMPLE. { A = MOJOSHADER_AST_INTERPMOD_SAMPLE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   173
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   174
%type variable_declaration { MOJOSHADER_astVariableDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   175
%destructor variable_declaration { delete_variable_declaration(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   176
variable_declaration(A) ::= variable_attribute_list(B) datatype(C) variable_declaration_details_list(D) SEMICOLON. { REVERSE_LINKED_LIST(MOJOSHADER_astVariableDeclaration, D); A = D; A->attributes = B; A->datatype = C; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   177
variable_declaration(A) ::= datatype(B) variable_declaration_details_list(C) SEMICOLON. { REVERSE_LINKED_LIST(MOJOSHADER_astVariableDeclaration, C); A = C; A->datatype = B; }
975
95b03c82cf51 Added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 973
diff changeset
   178
// !!! FIXME: this expects "struct Identifier {} varname" ... that "Identifier" is wrong.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   179
variable_declaration(A) ::= struct_declaration(B) variable_declaration_details_list(C) SEMICOLON. { REVERSE_LINKED_LIST(MOJOSHADER_astVariableDeclaration, C); A = C; A->anonymous_datatype = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   180
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   181
%type variable_attribute_list { int }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   182
variable_attribute_list(A) ::= variable_attribute(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   183
variable_attribute_list(A) ::= variable_attribute_list(B) variable_attribute(C). { A = B | C; }
725
5e3c35b63abd Reworked variable declaration syntax in the HLSL parser grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 724
diff changeset
   184
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   185
%type variable_attribute { int }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   186
variable_attribute(A) ::= EXTERN. { A = MOJOSHADER_AST_VARATTR_EXTERN; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   187
variable_attribute(A) ::= NOINTERPOLATION. { A = MOJOSHADER_AST_VARATTR_NOINTERPOLATION; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   188
variable_attribute(A) ::= SHARED. { A = MOJOSHADER_AST_VARATTR_SHARED; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   189
variable_attribute(A) ::= STATIC. { A = MOJOSHADER_AST_VARATTR_STATIC; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   190
variable_attribute(A) ::= UNIFORM. { A = MOJOSHADER_AST_VARATTR_UNIFORM; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   191
variable_attribute(A) ::= VOLATILE. { A = MOJOSHADER_AST_VARATTR_VOLATILE; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   192
variable_attribute(A) ::= CONST. { A = MOJOSHADER_AST_VARATTR_CONST; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   193
variable_attribute(A) ::= ROWMAJOR. { A = MOJOSHADER_AST_VARATTR_ROWMAJOR; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   194
variable_attribute(A) ::= COLUMNMAJOR. { A = MOJOSHADER_AST_VARATTR_COLUMNMAJOR; }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   195
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   196
%type variable_declaration_details_list { MOJOSHADER_astVariableDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   197
%destructor variable_declaration_details_list { delete_variable_declaration(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   198
variable_declaration_details_list(A) ::= variable_declaration_details(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   199
variable_declaration_details_list(A) ::= variable_declaration_details_list(B) COMMA variable_declaration_details(C). { A = C; A->next = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   200
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   201
%type variable_declaration_details { MOJOSHADER_astVariableDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   202
%destructor variable_declaration_details { delete_variable_declaration(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   203
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D) initializer(E) variable_lowlevel(F). { A = new_variable_declaration(ctx, B, C, D, E, F); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   204
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D) initializer(E). { A = new_variable_declaration(ctx, B, C, D, E, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   205
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D) variable_lowlevel(E). { A = new_variable_declaration(ctx, B, C, D, NULL, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   206
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) annotations(D). { A = new_variable_declaration(ctx, B, C, D, NULL, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   207
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) initializer(D) variable_lowlevel(E). { A = new_variable_declaration(ctx, B, C, NULL, D, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   208
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) initializer(D). { A = new_variable_declaration(ctx, B, C, NULL, D, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   209
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C) variable_lowlevel(D). { A = new_variable_declaration(ctx, B, C, NULL, NULL, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   210
variable_declaration_details(A) ::= scalar_or_array(B) semantic(C). { A = new_variable_declaration(ctx, B, C, NULL, NULL, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   211
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C) initializer(D) variable_lowlevel(E). { A = new_variable_declaration(ctx, B, NULL, C, D, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   212
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C) initializer(D). { A = new_variable_declaration(ctx, B, NULL, C, D, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   213
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C) variable_lowlevel(D). { A = new_variable_declaration(ctx, B, NULL, C, NULL, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   214
variable_declaration_details(A) ::= scalar_or_array(B) annotations(C). { A = new_variable_declaration(ctx, B, NULL, C, NULL, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   215
variable_declaration_details(A) ::= scalar_or_array(B) initializer(C) variable_lowlevel(D). { A = new_variable_declaration(ctx, B, NULL, NULL, C, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   216
variable_declaration_details(A) ::= scalar_or_array(B) initializer(C). { A = new_variable_declaration(ctx, B, NULL, NULL, C, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   217
variable_declaration_details(A) ::= scalar_or_array(B) variable_lowlevel(C). { A = new_variable_declaration(ctx, B, NULL, NULL, NULL, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   218
variable_declaration_details(A) ::= scalar_or_array(B). { A = new_variable_declaration(ctx, B, NULL, NULL, NULL, NULL); }
725
5e3c35b63abd Reworked variable declaration syntax in the HLSL parser grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 724
diff changeset
   219
724
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 722
diff changeset
   220
// !!! FIXME: we don't handle full sampler declarations at the moment.
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 722
diff changeset
   221
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   222
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   223
%type struct_declaration { MOJOSHADER_astStructDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   224
%destructor struct_declaration { delete_struct_declaration(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   225
struct_declaration(A) ::= struct_intro(B) LBRACE struct_member_list(C) RBRACE. { REVERSE_LINKED_LIST(MOJOSHADER_astStructMembers, C); A = new_struct_declaration(ctx, B, C); }
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   226
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   227
// This has to be separate from struct_declaration so that the struct is in the usertypemap when parsing its members.
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   228
%type struct_intro { const char * }
976
72f121a58548 Clean up bogus usertypes leftover from parse phase, during semantic analysis.
Ryan C. Gordon <icculus@icculus.org>
parents: 975
diff changeset
   229
struct_intro(A) ::= STRUCT IDENTIFIER(B). { A = B.string; push_usertype(ctx, A, &ctx->dt_none); }  // datatype is bogus until semantic analysis.
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   230
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   231
%type struct_member_list { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   232
%destructor struct_member_list { delete_struct_member(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   233
struct_member_list(A) ::= struct_member(B). { A = B; }
984
b75637d50945 Fixed dropping pieces of structs with comma-separated members.
Ryan C. Gordon <icculus@icculus.org>
parents: 976
diff changeset
   234
struct_member_list(A) ::= struct_member_list(B) struct_member(C). { A = C; MOJOSHADER_astStructMembers *i = A; while (i->next) { i = i->next; } i->next = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   235
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   236
%type struct_member { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   237
%destructor struct_member { delete_struct_member(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   238
struct_member(A) ::= interpolation_mod(B) struct_member_details(C). { MOJOSHADER_astStructMembers *i = C; A = C; while (i) { i->interpolation_mod = B; i = i->next; } }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   239
struct_member(A) ::= struct_member_details(B). { A = B; }
726
9f58e2b0ed8a Fixed struct declaration in the HLSL parser grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 725
diff changeset
   240
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   241
%type struct_member_details { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   242
%destructor struct_member_details { delete_struct_member(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   243
struct_member_details(A) ::= datatype(B) struct_member_item_list(C) SEMICOLON. { MOJOSHADER_astStructMembers *i = C; A = C; while (i) { i->datatype = B; i = i->next; } }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   244
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   245
%type struct_member_item_list { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   246
%destructor struct_member_item_list { delete_struct_member(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   247
struct_member_item_list(A) ::= scalar_or_array(B). { A = new_struct_member(ctx, B, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   248
struct_member_item_list(A) ::= scalar_or_array(B) semantic(C). { A = new_struct_member(ctx, B, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   249
struct_member_item_list(A) ::= struct_member_item_list(B) COMMA IDENTIFIER(C). { A = new_struct_member(ctx, new_scalar_or_array(ctx, C.string, 0, NULL), NULL); A->next = B; A->semantic = B->semantic; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   250
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   251
%type variable_lowlevel { MOJOSHADER_astVariableLowLevel * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   252
%destructor variable_lowlevel { delete_variable_lowlevel(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   253
variable_lowlevel(A) ::= packoffset(B) register(C). { A = new_variable_lowlevel(ctx, B, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   254
variable_lowlevel(A) ::= register(B) packoffset(C). { A = new_variable_lowlevel(ctx, C, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   255
variable_lowlevel(A) ::= packoffset(B). { A = new_variable_lowlevel(ctx, B, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   256
variable_lowlevel(A) ::= register(B). { A = new_variable_lowlevel(ctx, NULL, B); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   257
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   258
// !!! FIXME: I sort of hate this type name.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   259
%type scalar_or_array { MOJOSHADER_astScalarOrArray * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   260
%destructor scalar_or_array { delete_scalar_or_array(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   261
scalar_or_array(A) ::= IDENTIFIER(B) LBRACKET RBRACKET. { A = new_scalar_or_array(ctx, B.string, 1, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   262
scalar_or_array(A) ::= IDENTIFIER(B) LBRACKET expression(C) RBRACKET. { A = new_scalar_or_array(ctx, B.string, 1, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   263
scalar_or_array(A) ::= IDENTIFIER(B). { A = new_scalar_or_array(ctx, B.string, 0, NULL); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   264
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   265
%type packoffset { MOJOSHADER_astPackOffset * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   266
%destructor packoffset { delete_pack_offset(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   267
packoffset(A) ::= COLON PACKOFFSET LPAREN IDENTIFIER(B) DOT IDENTIFIER(C) RPAREN. { A = new_pack_offset(ctx, B.string, C.string); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   268
packoffset(A) ::= COLON PACKOFFSET LPAREN IDENTIFIER(B) RPAREN. { A = new_pack_offset(ctx, B.string, NULL); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   269
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   270
// !!! FIXME: can take a profile, like ": register(ps_5_0, s)"
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   271
// !!! FIXME: IDENTIFIER is wrong: "s[2]" works, apparently. Use scalar_or_array instead?
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   272
// !!! FIXME: (these might be SM4 features)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   273
%type register { const char * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   274
register(A) ::= COLON REGISTER LPAREN IDENTIFIER(B) RPAREN. { A = B.string; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   275
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   276
%type annotations { MOJOSHADER_astAnnotations * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   277
%destructor annotations { delete_annotation(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   278
annotations(A) ::= LT annotation_list(B) GT. { REVERSE_LINKED_LIST(MOJOSHADER_astAnnotations, B); A = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   279
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   280
%type annotation_list { MOJOSHADER_astAnnotations * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   281
%destructor annotation_list { delete_annotation(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   282
annotation_list(A) ::= annotation(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   283
annotation_list(A) ::= annotation_list(B) annotation(C). { A = C; A->next = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   284
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   285
// !!! FIXME: can this take a USERTYPE if we typedef'd a scalar type?
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   286
%type annotation { MOJOSHADER_astAnnotations * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   287
%destructor annotation { delete_annotation(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   288
annotation(A) ::= datatype_scalar(B) initializer(C) SEMICOLON. { A = new_annotation(ctx, B, C); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   289
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   290
%type initializer_block_list { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   291
%destructor initializer_block_list { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   292
initializer_block_list(A) ::= expression(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   293
initializer_block_list(A) ::= LBRACE initializer_block_list(B) RBRACE. { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   294
initializer_block_list(A) ::= initializer_block_list(B) COMMA initializer_block_list(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_COMMA, B, C); }
788
9f4d32456f78 Allow vector initializers, like "float4 x = {a,b,c,d};"
Ryan C. Gordon <icculus@icculus.org>
parents: 787
diff changeset
   295
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   296
%type initializer_block { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   297
%destructor initializer_block { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   298
initializer_block(A) ::= LBRACE initializer_block_list(B) RBRACE. { A = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   299
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   300
%type initializer { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   301
%destructor initializer { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   302
initializer(A) ::= ASSIGN initializer_block(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   303
initializer(A) ::= ASSIGN expression(B). { A = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   304
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   305
%type intrinsic_datatype { const MOJOSHADER_astDataType * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   306
intrinsic_datatype(A) ::= datatype_vector(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   307
intrinsic_datatype(A) ::= datatype_matrix(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   308
intrinsic_datatype(A) ::= datatype_scalar(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   309
intrinsic_datatype(A) ::= datatype_sampler(B). { A = B; }
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   310
intrinsic_datatype(A) ::= datatype_buffer(B). { A = B; }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   311
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   312
%type datatype { const MOJOSHADER_astDataType * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   313
datatype(A) ::= intrinsic_datatype(B). { A = B; }
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   314
datatype(A) ::= USERTYPE(B). { A = B.datatype; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   315
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   316
%type datatype_sampler { const MOJOSHADER_astDataType * }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   317
datatype_sampler(A) ::= SAMPLER. { A = &ctx->dt_sampler2d; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   318
datatype_sampler(A) ::= SAMPLER1D. { A = &ctx->dt_sampler1d; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   319
datatype_sampler(A) ::= SAMPLER2D. { A = &ctx->dt_sampler2d; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   320
datatype_sampler(A) ::= SAMPLER3D. { A = &ctx->dt_sampler3d; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   321
datatype_sampler(A) ::= SAMPLERCUBE. { A = &ctx->dt_samplercube; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   322
datatype_sampler(A) ::= SAMPLER_STATE. { A = &ctx->dt_samplerstate; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   323
datatype_sampler(A) ::= SAMPLERSTATE. { A = &ctx->dt_samplerstate; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   324
datatype_sampler(A) ::= SAMPLERCOMPARISONSTATE. { A = &ctx->dt_samplercompstate; }
724
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 722
diff changeset
   325
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   326
%type datatype_scalar { const MOJOSHADER_astDataType * }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   327
datatype_scalar(A) ::= BOOL. { A = &ctx->dt_bool; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   328
datatype_scalar(A) ::= INT. { A = &ctx->dt_int; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   329
datatype_scalar(A) ::= UINT. { A = &ctx->dt_uint; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   330
datatype_scalar(A) ::= HALF. { A = &ctx->dt_half; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   331
datatype_scalar(A) ::= FLOAT. { A = &ctx->dt_float; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   332
datatype_scalar(A) ::= DOUBLE. { A = &ctx->dt_double; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   333
datatype_scalar(A) ::= STRING. { A = &ctx->dt_string; } // this is for the effects framework, not HLSL.
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   334
datatype_scalar(A) ::= SNORM FLOAT. { A = &ctx->dt_float_snorm; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   335
datatype_scalar(A) ::= UNORM FLOAT. { A = &ctx->dt_float_unorm; }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   337
%type datatype_buffer { const MOJOSHADER_astDataType * }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   338
datatype_buffer(A) ::= BUFFER LT BOOL GT. { A = &ctx->dt_buf_bool; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   339
datatype_buffer(A) ::= BUFFER LT INT GT. { A = &ctx->dt_buf_int; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   340
datatype_buffer(A) ::= BUFFER LT UINT GT. { A = &ctx->dt_buf_uint; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   341
datatype_buffer(A) ::= BUFFER LT HALF GT. { A = &ctx->dt_buf_half; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   342
datatype_buffer(A) ::= BUFFER LT FLOAT GT. { A = &ctx->dt_buf_float; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   343
datatype_buffer(A) ::= BUFFER LT DOUBLE GT. { A = &ctx->dt_buf_double; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   344
datatype_buffer(A) ::= BUFFER LT SNORM FLOAT GT. { A = &ctx->dt_buf_float_snorm; }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   345
datatype_buffer(A) ::= BUFFER LT UNORM FLOAT GT. { A = &ctx->dt_buf_float_unorm; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   346
964
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   347
%type datatype_vector { const MOJOSHADER_astDataType * }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   348
datatype_vector(A) ::= VECTOR LT datatype_scalar(B) COMMA INT_CONSTANT(C) GT. { A = new_datatype_vector(ctx, B, (int) C.i64); }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   349
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   350
%type datatype_matrix { const MOJOSHADER_astDataType * }
e8c09c28162e Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 937
diff changeset
   351
datatype_matrix(A) ::= MATRIX LT datatype_scalar(B) COMMA INT_CONSTANT(C) COMMA INT_CONSTANT(D) GT. { A = new_datatype_matrix(ctx, B, (int) C.i64, (int) D.i64); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   352
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   353
%type statement_block { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   354
%destructor statement_block { delete_statement(ctx, $$); }
917
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   355
statement_block(A) ::= LBRACE RBRACE. { A = new_block_statement(ctx, NULL); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   356
statement_block(A) ::= LBRACE statement_list(B) RBRACE. { REVERSE_LINKED_LIST(MOJOSHADER_astStatement, B); A = new_block_statement(ctx, B); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   357
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   358
%type statement_list { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   359
%destructor statement_list { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   360
statement_list(A) ::= statement(B). { A = B; }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   361
statement_list(A) ::= statement_list(B) statement(C). { A = C; A->next = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   362
787
04d5c34d8b40 Added statement block attributes to the HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 785
diff changeset
   363
// These are for Shader Model 4 and Xbox 360 only, apparently.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   364
// !!! FIXME: ...so we ignore them for now.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   365
// !!! FIXME: can these stack?  "[isolate][unused]{}" or something?
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   366
%type statement_attribute { int }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   367
statement_attribute(A) ::= ISOLATE. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   368
statement_attribute(A) ::= MAXINSTRUCTIONCOUNT LPAREN INT_CONSTANT RPAREN. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   369
statement_attribute(A) ::= NOEXPRESSIONOPTIMIZATIONS. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   370
statement_attribute(A) ::= REMOVEUNUSEDINPUTS. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   371
statement_attribute(A) ::= UNUSED. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   372
statement_attribute(A) ::= XPS. { A = 0; }  // !!! FIXME
787
04d5c34d8b40 Added statement block attributes to the HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 785
diff changeset
   373
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   374
%type statement { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   375
%destructor statement { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   376
statement(A) ::= BREAK SEMICOLON. { A = new_break_statement(ctx); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   377
statement(A) ::= CONTINUE SEMICOLON. { A = new_continue_statement(ctx); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   378
statement(A) ::= DISCARD SEMICOLON. { A = new_discard_statement(ctx); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   379
statement(A) ::= LBRACKET statement_attribute(B) RBRACKET statement_block(C). { A = C; /* !!! FIXME: A->attributes = B;*/ B = 0; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   380
statement(A) ::= variable_declaration(B). { A = new_vardecl_statement(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   381
statement(A) ::= struct_declaration(B) SEMICOLON. { A = new_struct_statement(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   382
statement(A) ::= do_intro(B) DO statement(C) WHILE LPAREN expression(D) RPAREN SEMICOLON. { A = new_do_statement(ctx, B, C, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   383
statement(A) ::= while_intro(B) LPAREN expression(C) RPAREN statement(D). { A = new_while_statement(ctx, B, C, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   384
statement(A) ::= if_intro(B) LPAREN expression(C) RPAREN statement(D). { A = new_if_statement(ctx, B, C, D, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   385
statement(A) ::= if_intro(B) LPAREN expression(C) RPAREN statement(D) ELSE statement(E). { A = new_if_statement(ctx, B, C, D, E); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   386
statement(A) ::= switch_intro(B) LPAREN expression(C) RPAREN LBRACE switch_case_list(D) RBRACE. { REVERSE_LINKED_LIST(MOJOSHADER_astSwitchCases, D); A = new_switch_statement(ctx, B, C, D); }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   387
statement(A) ::= typedef(B). { A = new_typedef_statement(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   388
statement(A) ::= SEMICOLON. { A = new_empty_statement(ctx); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   389
statement(A) ::= expression(B) SEMICOLON. { A = new_expr_statement(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   390
statement(A) ::= RETURN SEMICOLON. { A = new_return_statement(ctx, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   391
statement(A) ::= RETURN expression(B) SEMICOLON. { A = new_return_statement(ctx, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   392
statement(A) ::= statement_block(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   393
statement(A) ::= for_statement(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   394
//statement(A) ::= error SEMICOLON. { A = NULL; }  // !!! FIXME: research using the error nonterminal
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   395
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   396
%type while_intro { int }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   397
while_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET WHILE. { A = (B.i64 < 0) ? 0 : B.i64; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   398
while_intro(A) ::= LBRACKET UNROLL RBRACKET WHILE. { A = -1; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   399
while_intro(A) ::= LBRACKET LOOP RBRACKET WHILE. { A = 0; }
854
65e06097e450 Filled in the rest of the missing print_ast() cases.
Ryan C. Gordon <icculus@icculus.org>
parents: 848
diff changeset
   400
while_intro(A) ::= WHILE. { A = -2; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   401
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   402
%type for_statement { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   403
%destructor for_statement { delete_statement(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   404
for_statement(A) ::= for_intro(B) for_details(C). { A = C; ((MOJOSHADER_astForStatement *) A)->unroll = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   405
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   406
%type for_intro { int }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   407
for_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET FOR. { A = (B.i64 < 0) ? 0 : B.i64; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   408
for_intro(A) ::= LBRACKET UNROLL RBRACKET FOR. { A = -1; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   409
for_intro(A) ::= LBRACKET LOOP RBRACKET FOR. { A = 0; }
854
65e06097e450 Filled in the rest of the missing print_ast() cases.
Ryan C. Gordon <icculus@icculus.org>
parents: 848
diff changeset
   410
for_intro(A) ::= FOR. { A = -2; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   411
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   412
%type for_details { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   413
%destructor for_details { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   414
for_details(A) ::= LPAREN expression(B) SEMICOLON expression(C) SEMICOLON expression(D) RPAREN statement(E). { A = new_for_statement(ctx, NULL, B, C, D, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   415
for_details(A) ::= LPAREN SEMICOLON SEMICOLON RPAREN statement(B). { A = new_for_statement(ctx, NULL, NULL, NULL, NULL, B); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   416
for_details(A) ::= LPAREN SEMICOLON SEMICOLON expression(B) RPAREN statement(C). { A = new_for_statement(ctx, NULL, NULL, NULL, B, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   417
for_details(A) ::= LPAREN SEMICOLON expression(B) SEMICOLON RPAREN statement(C). { A = new_for_statement(ctx, NULL, NULL, B, NULL, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   418
for_details(A) ::= LPAREN SEMICOLON expression(B) SEMICOLON expression(C) RPAREN statement(D). { A = new_for_statement(ctx, NULL, NULL, B, C, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   419
for_details(A) ::= LPAREN expression(B) SEMICOLON SEMICOLON RPAREN statement(C). { A = new_for_statement(ctx, NULL, B, NULL, NULL, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   420
for_details(A) ::= LPAREN expression(B) SEMICOLON SEMICOLON expression(C) RPAREN statement(D). { A = new_for_statement(ctx, NULL, B, NULL, C, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   421
for_details(A) ::= LPAREN expression(B) SEMICOLON expression(C) SEMICOLON RPAREN statement(D). { A = new_for_statement(ctx, NULL, B, C, NULL, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   422
for_details(A) ::= LPAREN variable_declaration(B) expression(C) SEMICOLON expression(D) RPAREN statement(E). { A = new_for_statement(ctx, B, NULL, C, D, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   423
for_details(A) ::= LPAREN variable_declaration(B) SEMICOLON RPAREN statement(C).  { A = new_for_statement(ctx, B, NULL, NULL, NULL, C); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   424
for_details(A) ::= LPAREN variable_declaration(B) SEMICOLON expression(C) RPAREN statement(D). { A = new_for_statement(ctx, B, NULL, C, NULL, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   425
for_details(A) ::= LPAREN variable_declaration(B) expression(C) SEMICOLON RPAREN statement(D). { A = new_for_statement(ctx, B, NULL, C, NULL, D); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   426
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   427
%type do_intro { int }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   428
do_intro(A) ::= LBRACKET UNROLL LPAREN INT_CONSTANT(B) RPAREN RBRACKET DO. { A = (B.i64 < 0) ? 0 : (int) B.i64; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   429
do_intro(A) ::= LBRACKET UNROLL RBRACKET DO. { A = -1; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   430
do_intro(A) ::= LBRACKET LOOP RBRACKET DO. { A = 0; }
854
65e06097e450 Filled in the rest of the missing print_ast() cases.
Ryan C. Gordon <icculus@icculus.org>
parents: 848
diff changeset
   431
do_intro(A) ::= DO. { A = -2; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   432
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   433
%type if_intro { int }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   434
if_intro(A) ::= LBRACKET BRANCH RBRACKET IF. { A = MOJOSHADER_AST_IFATTR_BRANCH; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   435
if_intro(A) ::= LBRACKET FLATTEN RBRACKET IF. { A = MOJOSHADER_AST_IFATTR_FLATTEN; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   436
if_intro(A) ::= LBRACKET IFALL RBRACKET IF. { A = MOJOSHADER_AST_IFATTR_IFALL; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   437
if_intro(A) ::= LBRACKET IFANY RBRACKET IF. { A = MOJOSHADER_AST_IFATTR_IFANY; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   438
if_intro(A) ::= LBRACKET PREDICATE RBRACKET IF. { A = MOJOSHADER_AST_IFATTR_PREDICATE; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   439
if_intro(A) ::= LBRACKET PREDICATEBLOCK RBRACKET IF. { A = MOJOSHADER_AST_IFATTR_PREDICATEBLOCK; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   440
if_intro(A) ::= IF. { A = MOJOSHADER_AST_IFATTR_NONE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   441
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   442
%type switch_intro { int }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   443
switch_intro(A) ::= LBRACKET FLATTEN RBRACKET SWITCH. { A = MOJOSHADER_AST_SWITCHATTR_FLATTEN; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   444
switch_intro(A) ::= LBRACKET BRANCH RBRACKET SWITCH. { A = MOJOSHADER_AST_SWITCHATTR_BRANCH; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   445
switch_intro(A) ::= LBRACKET FORCECASE RBRACKET SWITCH. { A = MOJOSHADER_AST_SWITCHATTR_FORCECASE; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   446
switch_intro(A) ::= LBRACKET CALL RBRACKET SWITCH. { A = MOJOSHADER_AST_SWITCHATTR_CALL; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   447
switch_intro(A) ::= SWITCH. { A = MOJOSHADER_AST_SWITCHATTR_NONE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   448
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   449
%type switch_case_list { MOJOSHADER_astSwitchCases * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   450
%destructor switch_case_list { delete_switch_case(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   451
switch_case_list(A) ::= switch_case(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   452
switch_case_list(A) ::= switch_case_list(B) switch_case(C). { A = C; A->next = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   453
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   454
// You can do math here, apparently, as long as it produces an int constant.
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   455
//  ...so "case 3+2:" works.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   456
%type switch_case { MOJOSHADER_astSwitchCases * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   457
%destructor switch_case { delete_switch_case(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   458
switch_case(A) ::= CASE expression(B) COLON statement_list(C). { REVERSE_LINKED_LIST(MOJOSHADER_astStatement, C); A = new_switch_case(ctx, B, C); }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   459
switch_case(A) ::= CASE expression(B) COLON. { A = new_switch_case(ctx, B, NULL); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   460
switch_case(A) ::= DEFAULT COLON statement_list(B). { REVERSE_LINKED_LIST(MOJOSHADER_astStatement, B); A = new_switch_case(ctx, NULL, B); }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   461
switch_case(A) ::= DEFAULT COLON. { A = new_switch_case(ctx, NULL, NULL); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   462
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   463
// the expression stuff is based on Jeff Lee's ANSI C grammar.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   464
%type primary_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   465
%destructor primary_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   466
primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, B.string); }
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   467
primary_expr(A) ::= INT_CONSTANT(B). { A = new_literal_int_expr(ctx, B.i64); }
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   468
primary_expr(A) ::= FLOAT_CONSTANT(B). { A = new_literal_float_expr(ctx, B.dbl); }
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   469
primary_expr(A) ::= STRING_LITERAL(B). { A = new_literal_string_expr(ctx, B.string); }
924
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   470
primary_expr(A) ::= TRUE. { A = new_literal_boolean_expr(ctx, 1); }
c99418745e1b Added boolean literals to parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 922
diff changeset
   471
primary_expr(A) ::= FALSE. { A = new_literal_boolean_expr(ctx, 0); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   472
primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   473
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   474
%type postfix_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   475
%destructor postfix_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   476
postfix_expr(A) ::= primary_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   477
postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_DEREF_ARRAY, B, C); }
973
6d4cdbc21301 Cleaned up the mess of function call processing.
Ryan C. Gordon <icculus@icculus.org>
parents: 964
diff changeset
   478
postfix_expr(A) ::= IDENTIFIER(B) arguments(C). { A = new_callfunc_expr(ctx, B.string, C); }
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   479
postfix_expr(A) ::= datatype(B) arguments(C). { A = new_constructor_expr(ctx, B, C); } // HLSL constructor
928
c9b0235e9d23 Made struct dereference a separate expression type, not a binary expression.
Ryan C. Gordon <icculus@icculus.org>
parents: 927
diff changeset
   480
postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_deref_struct_expr(ctx, B, C.string); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   481
postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_POSTINCREMENT, B); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   482
postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_POSTDECREMENT, B); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   484
%type arguments { MOJOSHADER_astArguments * }
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   485
%destructor arguments { delete_arguments(ctx, $$); }
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   486
arguments(A) ::= LPAREN RPAREN. { A = NULL; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   487
arguments(A) ::= LPAREN argument_list(B) RPAREN. { REVERSE_LINKED_LIST(MOJOSHADER_astArguments, B); A = B; }
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   488
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   489
%type argument_list { MOJOSHADER_astArguments * }
927
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   490
%destructor argument_list { delete_arguments(ctx, $$); }
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   491
argument_list(A) ::= assignment_expr(B). { A = new_argument(ctx, B); }
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   492
argument_list(A) ::= argument_list(B) COMMA assignment_expr(C). { A = new_argument(ctx, C); A->next = B; }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   494
%type unary_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   495
%destructor unary_expr { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   496
unary_expr(A) ::= postfix_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   497
unary_expr(A) ::= PLUSPLUS unary_expr(B). { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_PREINCREMENT, B); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   498
unary_expr(A) ::= MINUSMINUS unary_expr(B). { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_PREDECREMENT, B); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   499
unary_expr(A) ::= PLUS cast_expr(B). { A = B; }  // unary "+x" is always a no-op, so throw it away here.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   500
unary_expr(A) ::= MINUS cast_expr(B). { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_NEGATE, B); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   501
unary_expr(A) ::= COMPLEMENT cast_expr(B). { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_COMPLEMENT, B); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   502
unary_expr(A) ::= EXCLAMATION cast_expr(B). { A = new_unary_expr(ctx, MOJOSHADER_AST_OP_NOT, B); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   504
%type cast_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   505
%destructor cast_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   506
cast_expr(A) ::= unary_expr(B). { A = B; }
837
5f6528602658 Uncommented some grammar bits that got masked out in the calculator experiment.
Ryan C. Gordon <icculus@icculus.org>
parents: 836
diff changeset
   507
cast_expr(A) ::= LPAREN datatype(B) RPAREN cast_expr(C). { A = new_cast_expr(ctx, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   509
%type multiplicative_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   510
%destructor multiplicative_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   511
multiplicative_expr(A) ::= cast_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   512
multiplicative_expr(A) ::= multiplicative_expr(B) STAR cast_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_MULTIPLY, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   513
multiplicative_expr(A) ::= multiplicative_expr(B) SLASH cast_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_DIVIDE, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   514
multiplicative_expr(A) ::= multiplicative_expr(B) PERCENT cast_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_MODULO, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   516
%type additive_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   517
%destructor additive_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   518
additive_expr(A) ::= multiplicative_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   519
additive_expr(A) ::= additive_expr(B) PLUS multiplicative_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_ADD, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   520
additive_expr(A) ::= additive_expr(B) MINUS multiplicative_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_SUBTRACT, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   522
%type shift_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   523
%destructor shift_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   524
shift_expr(A) ::= additive_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   525
shift_expr(A) ::= shift_expr(B) LSHIFT additive_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_LSHIFT, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   526
shift_expr(A) ::= shift_expr(B) RSHIFT additive_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_RSHIFT, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   527
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   528
%type relational_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   529
%destructor relational_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   530
relational_expr(A) ::= shift_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   531
relational_expr(A) ::= relational_expr(B) LT shift_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_LESSTHAN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   532
relational_expr(A) ::= relational_expr(B) GT shift_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_GREATERTHAN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   533
relational_expr(A) ::= relational_expr(B) LEQ shift_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_LESSTHANOREQUAL, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   534
relational_expr(A) ::= relational_expr(B) GEQ shift_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_GREATERTHANOREQUAL, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   536
%type equality_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   537
%destructor equality_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   538
equality_expr(A) ::= relational_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   539
equality_expr(A) ::= equality_expr(B) EQL relational_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_EQUAL, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   540
equality_expr(A) ::= equality_expr(B) NEQ relational_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_NOTEQUAL, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   542
%type and_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   543
%destructor and_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   544
and_expr(A) ::= equality_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   545
and_expr(A) ::= and_expr(B) AND equality_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_BINARYAND, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   547
%type exclusive_or_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   548
%destructor exclusive_or_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   549
exclusive_or_expr(A) ::= and_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   550
exclusive_or_expr(A) ::= exclusive_or_expr(B) XOR and_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_BINARYXOR, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   551
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   552
%type inclusive_or_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   553
%destructor inclusive_or_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   554
inclusive_or_expr(A) ::= exclusive_or_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   555
inclusive_or_expr(A) ::= inclusive_or_expr(B) OR exclusive_or_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_BINARYOR, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   557
%type logical_and_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   558
%destructor logical_and_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   559
logical_and_expr(A) ::= inclusive_or_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   560
logical_and_expr(A) ::= logical_and_expr(B) ANDAND inclusive_or_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_LOGICALAND, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   562
%type logical_or_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   563
%destructor logical_or_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   564
logical_or_expr(A) ::= logical_and_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   565
logical_or_expr(A) ::= logical_or_expr(B) OROR logical_and_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_LOGICALOR, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   566
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   567
%type conditional_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   568
%destructor conditional_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   569
conditional_expr(A) ::= logical_or_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   570
conditional_expr(A) ::= logical_or_expr(B) QUESTION logical_or_expr(C) COLON conditional_expr(D). { A = new_ternary_expr(ctx, MOJOSHADER_AST_OP_CONDITIONAL, B, C, D); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   572
%type assignment_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   573
%destructor assignment_expr { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   574
assignment_expr(A) ::= conditional_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   575
assignment_expr(A) ::= unary_expr(B) ASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_ASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   576
assignment_expr(A) ::= unary_expr(B) MULASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_MULASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   577
assignment_expr(A) ::= unary_expr(B) DIVASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_DIVASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   578
assignment_expr(A) ::= unary_expr(B) MODASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_MODASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   579
assignment_expr(A) ::= unary_expr(B) ADDASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_ADDASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   580
assignment_expr(A) ::= unary_expr(B) SUBASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_SUBASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   581
assignment_expr(A) ::= unary_expr(B) LSHIFTASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_LSHIFTASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   582
assignment_expr(A) ::= unary_expr(B) RSHIFTASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_RSHIFTASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   583
assignment_expr(A) ::= unary_expr(B) ANDASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_ANDASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   584
assignment_expr(A) ::= unary_expr(B) XORASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_XORASSIGN, B, C); }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   585
assignment_expr(A) ::= unary_expr(B) ORASSIGN assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_ORASSIGN, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   586
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   587
%type expression { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   588
%destructor expression { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   589
expression(A) ::= assignment_expr(B). { A = B; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   590
expression(A) ::= expression(B) COMMA assignment_expr(C). { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_COMMA, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   591
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   592
// end of mojoshader_parser_hlsl.lemon ...
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   593