mojoshader_parser_hlsl.lemon
author Ryan C. Gordon <icculus@icculus.org>
Thu, 28 Oct 2010 03:42:12 -0400
changeset 931 4aa1f68d8292
parent 929 5d2d66bd35e7
child 937 94e50ba3f956
permissions -rw-r--r--
Heavy rework of the AST code. Moved AST stuff to a public API and filled in AST and compile API stubs. print_ast() has been cleaned up, and moved from MojoShader to the compiler application. type_check_ast() is much cleaner, too. This has turned into a massive (and incomplete) undertaking. Next steps are filling in the formal API code, moving the AST stuff to a separate file, and wiring it up to the compiler application. (Not to mention polishing up semantic analysis, finishing up the IR, reworking the nasty datatype system, etc, etc, etc...)
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?
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 919
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, NULL); }
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 919
diff changeset
    99
typedef(A) ::= TYPEDEF datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 0, B, C); push_usertype(ctx, C->identifier, NULL); }
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.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   135
%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
   136
%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
   137
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
   138
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
   139
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
   140
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
   141
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
   142
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
   143
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
   144
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
   145
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
   146
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
   147
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
   148
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
   149
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
   150
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
   151
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
   152
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
   153
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   154
%type input_modifier { MOJOSHADER_astInputModifier }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   155
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
   156
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
   157
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
   158
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
   159
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
   160
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
   161
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   162
%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
   163
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
   164
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   165
// DX10 only?
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   166
%type interpolation_mod { MOJOSHADER_astInterpolationModifier }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   167
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
   168
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
   169
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
   170
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
   171
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
   172
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   173
%type variable_declaration { MOJOSHADER_astVariableDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   174
%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
   175
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
   176
variable_declaration(A) ::= datatype(B) variable_declaration_details_list(C) SEMICOLON. { REVERSE_LINKED_LIST(MOJOSHADER_astVariableDeclaration, C); A = C; A->datatype = B; }
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   177
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
   178
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   179
%type variable_attribute_list { int }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   180
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
   181
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
   182
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   183
%type variable_attribute { int }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   184
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
   185
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
   186
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
   187
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
   188
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
   189
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
   190
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
   191
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
   192
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
   193
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   194
%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
   195
%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
   196
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
   197
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
   198
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   199
%type variable_declaration_details { MOJOSHADER_astVariableDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   200
%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
   201
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
   202
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
   203
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
   204
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
   205
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
   206
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
   207
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
   208
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
   209
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
   210
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
   211
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
   212
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
   213
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
   214
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
   215
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
   216
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
   217
724
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 722
diff changeset
   218
// !!! 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
   219
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   220
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   221
%type struct_declaration { MOJOSHADER_astStructDeclaration * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   222
%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
   223
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
   224
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   225
// 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
   226
%type struct_intro { const char * }
922
9b5879d36f36 Cleaned up UserTypeMap into a generic symbol tracker.
Ryan C. Gordon <icculus@icculus.org>
parents: 919
diff changeset
   227
struct_intro(A) ::= STRUCT IDENTIFIER(B). { A = B.string; push_usertype(ctx, A, NULL); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   228
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   229
%type struct_member_list { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   230
%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
   231
struct_member_list(A) ::= struct_member(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   232
struct_member_list(A) ::= struct_member_list(B) struct_member(C). { A = C; A->next = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   233
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   234
%type struct_member { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   235
%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
   236
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
   237
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
   238
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   239
%type struct_member_details { MOJOSHADER_astStructMembers * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   240
%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
   241
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
   242
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   243
%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
   244
%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
   245
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
   246
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
   247
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
   248
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   249
%type variable_lowlevel { MOJOSHADER_astVariableLowLevel * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   250
%destructor variable_lowlevel { delete_variable_lowlevel(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   251
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
   252
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
   253
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
   254
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
   255
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   256
// !!! 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
   257
%type scalar_or_array { MOJOSHADER_astScalarOrArray * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   258
%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
   259
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
   260
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
   261
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
   262
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   263
%type packoffset { MOJOSHADER_astPackOffset * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   264
%destructor packoffset { delete_pack_offset(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   265
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
   266
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
   267
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   268
// !!! 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
   269
// !!! 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
   270
// !!! FIXME: (these might be SM4 features)
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   271
%type register { const char * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   272
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
   273
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   274
%type annotations { MOJOSHADER_astAnnotations * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   275
%destructor annotations { delete_annotation(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   276
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
   277
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   278
%type annotation_list { MOJOSHADER_astAnnotations * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   279
%destructor annotation_list { delete_annotation(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   280
annotation_list(A) ::= annotation(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   281
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
   282
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   283
// !!! 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
   284
%type annotation { MOJOSHADER_astAnnotations * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   285
%destructor annotation { delete_annotation(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   286
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
   287
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   288
%type initializer_block_list { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   289
%destructor initializer_block_list { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   290
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
   291
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
   292
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
   293
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   294
%type initializer_block { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   295
%destructor initializer_block { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   296
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
   297
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   298
%type initializer { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   299
%destructor initializer { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   300
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
   301
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
   302
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   303
%type intrinsic_datatype { const char * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   304
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
   305
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
   306
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
   307
intrinsic_datatype(A) ::= datatype_sampler(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   308
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   309
%type datatype { const char * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   310
datatype(A) ::= intrinsic_datatype(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   311
datatype(A) ::= USERTYPE(B). { A = B.string; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   312
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   313
%type datatype_sampler { const char * }
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   314
datatype_sampler(A) ::= SAMPLER. { A = ctx->str_s1; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   315
datatype_sampler(A) ::= SAMPLER1D. { A = ctx->str_s1; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   316
datatype_sampler(A) ::= SAMPLER2D. { A = ctx->str_s2; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   317
datatype_sampler(A) ::= SAMPLER3D. { A = ctx->str_s3; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   318
datatype_sampler(A) ::= SAMPLERCUBE. { A = ctx->str_sc; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   319
datatype_sampler(A) ::= SAMPLER_STATE. { A = ctx->str_ss; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   320
datatype_sampler(A) ::= SAMPLERSTATE. { A = ctx->str_ss; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   321
datatype_sampler(A) ::= SAMPLERCOMPARISONSTATE. { A = ctx->str_sS; }
724
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 722
diff changeset
   322
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   323
%type datatype_scalar { const char * }
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   324
datatype_scalar(A) ::= BOOL. { A = ctx->str_b; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   325
datatype_scalar(A) ::= INT. { A = ctx->str_i; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   326
datatype_scalar(A) ::= UINT. { A = ctx->str_u; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   327
datatype_scalar(A) ::= HALF. { A = ctx->str_h; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   328
datatype_scalar(A) ::= FLOAT. { A = ctx->str_f; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   329
datatype_scalar(A) ::= DOUBLE. { A = ctx->str_d; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   330
datatype_scalar(A) ::= STRING. { A = ctx->str_S; } // this is for the effects framework, not HLSL.
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   331
datatype_scalar(A) ::= SNORM FLOAT. { A = ctx->str_ns; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   332
datatype_scalar(A) ::= UNORM FLOAT. { A = ctx->str_nu; }
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   333
datatype_scalar(A) ::= BUFFER LT datatype_scalar(B) GT. { A = stringcache_fmt(ctx->strcache, "B{%s}", B); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   335
// !!! FIXME: MSDN suggests that the matrix ones are just typedefs inserted
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   336
// !!! FIXME:  before parsing begins, like:
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   337
// !!! FIXME: typedef matrix <bool,4,3> bool4x3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   338
// !!! FIXME:  ...maybe we can rip these out of the grammar and just create
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   339
// !!! FIXME:  them at startup?
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   340
%type datatype_vector { const char * }
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   341
datatype_vector(A) ::= VECTOR LT datatype_scalar(B) COMMA INT_CONSTANT(C) GT. { A = stringcache_fmt(ctx->strcache, "V{%d,%s}", (int) C.i64, B); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   342
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   343
%type datatype_matrix { const char * }
929
5d2d66bd35e7 First shot at semantic analysis (take the AST and type check, make sane, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 928
diff changeset
   344
datatype_matrix(A) ::= MATRIX LT datatype_scalar(B) COMMA INT_CONSTANT(C) COMMA INT_CONSTANT(D) GT. { A = stringcache_fmt(ctx->strcache, "M{%d,%d,%s}", (int) C.i64, (int) D.i64, B); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   345
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   346
%type statement_block { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   347
%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
   348
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
   349
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
   350
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   351
%type statement_list { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   352
%destructor statement_list { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   353
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
   354
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
   355
787
04d5c34d8b40 Added statement block attributes to the HLSL grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 785
diff changeset
   356
// 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
   357
// !!! FIXME: ...so we ignore them for now.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   358
// !!! 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
   359
%type statement_attribute { int }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   360
statement_attribute(A) ::= ISOLATE. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   361
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
   362
statement_attribute(A) ::= NOEXPRESSIONOPTIMIZATIONS. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   363
statement_attribute(A) ::= REMOVEUNUSEDINPUTS. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   364
statement_attribute(A) ::= UNUSED. { A = 0; }  // !!! FIXME
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   365
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
   366
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   367
%type statement { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   368
%destructor statement { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   369
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
   370
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
   371
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
   372
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
   373
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
   374
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
   375
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
   376
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
   377
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
   378
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
   379
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
   380
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
   381
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
   382
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
   383
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
   384
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
   385
statement(A) ::= statement_block(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   386
statement(A) ::= for_statement(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   387
//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
   388
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   389
%type while_intro { int }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   390
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
   391
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
   392
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
   393
while_intro(A) ::= WHILE. { A = -2; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   394
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   395
%type for_statement { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   396
%destructor for_statement { delete_statement(ctx, $$); }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   397
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
   398
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   399
%type for_intro { int }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   400
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
   401
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
   402
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
   403
for_intro(A) ::= FOR. { A = -2; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   404
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   405
%type for_details { MOJOSHADER_astStatement * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   406
%destructor for_details { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   407
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
   408
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
   409
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
   410
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
   411
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
   412
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
   413
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
   414
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
   415
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
   416
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
   417
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
   418
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
   419
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   420
%type do_intro { int }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   421
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
   422
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
   423
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
   424
do_intro(A) ::= DO. { A = -2; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   425
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   426
%type if_intro { int }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   427
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
   428
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
   429
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
   430
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
   431
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
   432
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
   433
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
   434
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   435
%type switch_intro { int }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   436
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
   437
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
   438
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
   439
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
   440
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
   441
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   442
%type switch_case_list { MOJOSHADER_astSwitchCases * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   443
%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
   444
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
   445
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
   446
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   447
// 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
   448
//  ...so "case 3+2:" works.
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   449
%type switch_case { MOJOSHADER_astSwitchCases * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   450
%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
   451
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
   452
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
   453
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
   454
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
   455
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   456
// 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
   457
%type primary_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   458
%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
   459
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
   460
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
   461
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
   462
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
   463
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
   464
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
   465
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
   466
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   467
%type postfix_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   468
%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
   469
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
   470
postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, MOJOSHADER_AST_OP_DEREF_ARRAY, B, 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
   471
postfix_expr(A) ::= postfix_expr(B) arguments(C). { A = new_callfunc_expr(ctx, B, C); }
0e8b7f053a45 Reworked AST to not use AST_OP_COMMA for function/constructor argument lists.
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   472
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
   473
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
   474
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
   475
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
   476
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   477
%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
   478
%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
   479
arguments(A) ::= LPAREN RPAREN. { A = NULL; }
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   480
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
   481
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   482
%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
   483
%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
   484
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
   485
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
   486
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   487
%type unary_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   488
%destructor unary_expr { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   489
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
   490
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
   491
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
   492
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
   493
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
   494
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
   495
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
   496
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   497
%type cast_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   498
%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
   499
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
   500
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
   501
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   502
%type multiplicative_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   503
%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
   504
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
   505
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
   506
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
   507
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
   508
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   509
%type additive_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   510
%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
   511
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
   512
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
   513
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
   514
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   515
%type shift_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   516
%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
   517
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
   518
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
   519
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
   520
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   521
%type relational_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   522
%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
   523
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
   524
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
   525
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
   526
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
   527
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
   528
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   529
%type equality_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   530
%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
   531
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
   532
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
   533
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
   534
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   535
%type and_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   536
%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
   537
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
   538
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
   539
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   540
%type exclusive_or_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   541
%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
   542
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
   543
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
   544
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   545
%type inclusive_or_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   546
%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
   547
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
   548
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
   549
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   550
%type logical_and_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   551
%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
   552
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
   553
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
   554
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   555
%type logical_or_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   556
%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
   557
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
   558
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
   559
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   560
%type conditional_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   561
%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
   562
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
   563
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
   564
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   565
%type assignment_expr { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   566
%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
   567
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
   568
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
   569
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
   570
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
   571
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
   572
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
   573
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
   574
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
   575
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
   576
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
   577
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
   578
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
   579
931
4aa1f68d8292 Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents: 929
diff changeset
   580
%type expression { MOJOSHADER_astExpression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   581
%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
   582
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
   583
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
   584
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   585
// end of mojoshader_parser_hlsl.lemon ...
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   586