mojoshader_parser_hlsl.lemon
author Ryan C. Gordon <icculus@icculus.org>
Thu, 14 Oct 2010 01:48:27 -0400
changeset 919 eeb5decdf548
parent 917 85afb474f99d
child 922 9b5879d36f36
permissions -rw-r--r--
Fixed constructor syntax parsing.
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
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    78
shader ::= compilation_units(B). { assert(ctx->ast == NULL); REVERSE_LINKED_LIST(CompilationUnit, B); ctx->ast = B; }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    79
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    80
%type compilation_units { CompilationUnit * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    85
%type compilation_unit { CompilationUnit * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
    95
%type typedef { Typedef * }
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?
846
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
    98
typedef(A) ::= TYPEDEF CONST datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 1, B, C); add_usertype(ctx, C->identifier); }
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
    99
typedef(A) ::= TYPEDEF datatype(B) scalar_or_array(C). { A = new_typedef(ctx, 0, B, C); add_usertype(ctx, C->identifier); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   100
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   101
%type function_signature { FunctionSignature * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   108
%type function_details { FunctionSignature * }
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, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   110
function_details(A) ::= datatype(B) IDENTIFIER(C) LPAREN function_arguments(D) RPAREN. { A = new_function_signature(ctx, B, C.string, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   111
function_details(A) ::= VOID IDENTIFIER(B) LPAREN function_arguments(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.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   119
%type function_storageclass { FunctionStorageClass }
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; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   121
function_storageclass(A) ::= INLINE. { A = FNSTORECLS_INLINE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   122
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   123
%type function_arguments { FunctionArguments * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   124
%destructor function_arguments { delete_function_args(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   125
function_arguments(A) ::= VOID. { A = NULL; }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   126
function_arguments(A) ::= function_argument_list(B). { REVERSE_LINKED_LIST(FunctionArguments, B); A = B; }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   127
function_arguments(A) ::= . { A = NULL; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   128
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   129
%type function_argument_list { FunctionArguments * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   130
%destructor function_argument_list { delete_function_args(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   131
function_argument_list(A) ::= function_argument(B). { A = B; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   132
function_argument_list(A) ::= function_argument_list(B) COMMA function_argument(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.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   135
%type function_argument { FunctionArguments * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   136
%destructor function_argument { delete_function_args(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   137
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) interpolation_mod(F) initializer(G). { A = new_function_arg(ctx, B, C, D.string, E, F, G); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   138
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) interpolation_mod(F). { A = new_function_arg(ctx, B, C, D.string, E, F, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   139
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E) initializer(F). { A = new_function_arg(ctx, B, C, D.string, E, INTERPMOD_NONE, F); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   140
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) semantic(E). { A = new_function_arg(ctx, B, C, D.string, E, INTERPMOD_NONE, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   141
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) interpolation_mod(E) initializer(F). { A = new_function_arg(ctx, B, C, D.string, NULL, E, F); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   142
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) interpolation_mod(E). { A = new_function_arg(ctx, B, C, D.string, NULL, E, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   143
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D) initializer(E). { A = new_function_arg(ctx, B, C, D.string, NULL, INTERPMOD_NONE, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   144
function_argument(A) ::= input_modifier(B) datatype(C) IDENTIFIER(D). { A = new_function_arg(ctx, B, C, D.string, NULL, INTERPMOD_NONE, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   145
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D) interpolation_mod(E) initializer(F). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, E, F); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   146
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D) interpolation_mod(E). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, E, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   147
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D) initializer(E). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, INTERPMOD_NONE, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   148
function_argument(A) ::= datatype(B) IDENTIFIER(C) semantic(D). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, D, INTERPMOD_NONE, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   149
function_argument(A) ::= datatype(B) IDENTIFIER(C) interpolation_mod(D) initializer(E). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, D, E); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   150
function_argument(A) ::= datatype(B) IDENTIFIER(C) interpolation_mod(D). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, D, NULL); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   151
function_argument(A) ::= datatype(B) IDENTIFIER(C) initializer(D). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, INTERPMOD_NONE, D); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   152
function_argument(A) ::= datatype(B) IDENTIFIER(C). { A = new_function_arg(ctx, INPUTMOD_NONE, B, C.string, NULL, INTERPMOD_NONE, NULL); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   153
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   154
%type input_modifier { InputModifier }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   155
input_modifier(A) ::= IN. { A = INPUTMOD_IN; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   156
input_modifier(A) ::= INOUT. { A = INPUTMOD_INOUT; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   157
input_modifier(A) ::= OUT. { A = INPUTMOD_OUT; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   158
input_modifier(A) ::= IN OUT. { A = INPUTMOD_INOUT; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   159
input_modifier(A) ::= OUT IN. { A = INPUTMOD_INOUT; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   160
input_modifier(A) ::= UNIFORM. { A = 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?
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   166
%type interpolation_mod { InterpolationModifier }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   167
interpolation_mod(A) ::= LINEAR. { A = INTERPMOD_LINEAR; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   168
interpolation_mod(A) ::= CENTROID. { A = INTERPMOD_CENTROID; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   169
interpolation_mod(A) ::= NOINTERPOLATION. { A = INTERPMOD_NOINTERPOLATION; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   170
interpolation_mod(A) ::= NOPERSPECTIVE. { A = INTERPMOD_NOPERSPECTIVE; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   171
interpolation_mod(A) ::= SAMPLE. { A = INTERPMOD_SAMPLE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   172
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   173
%type variable_declaration { VariableDeclaration * }
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, $$); }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   175
variable_declaration(A) ::= variable_attribute_list(B) datatype(C) variable_declaration_details_list(D) SEMICOLON. { REVERSE_LINKED_LIST(VariableDeclaration, D); A = D; A->attributes = B; A->datatype = C; }
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   176
variable_declaration(A) ::= datatype(B) variable_declaration_details_list(C) SEMICOLON. { REVERSE_LINKED_LIST(VariableDeclaration, C); A = C; A->datatype = B; }
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   177
variable_declaration(A) ::= struct_declaration(B) variable_declaration_details_list(C) SEMICOLON. { REVERSE_LINKED_LIST(VariableDeclaration, 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 }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   184
variable_attribute(A) ::= EXTERN. { A = VARATTR_EXTERN; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   185
variable_attribute(A) ::= NOINTERPOLATION. { A = VARATTR_NOINTERPOLATION; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   186
variable_attribute(A) ::= SHARED. { A = VARATTR_SHARED; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   187
variable_attribute(A) ::= STATIC. { A = VARATTR_STATIC; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   188
variable_attribute(A) ::= UNIFORM. { A = VARATTR_UNIFORM; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   189
variable_attribute(A) ::= VOLATILE. { A = VARATTR_VOLATILE; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   190
variable_attribute(A) ::= CONST. { A = VARATTR_CONST; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   191
variable_attribute(A) ::= ROWMAJOR. { A = VARATTR_ROWMAJOR; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   192
variable_attribute(A) ::= COLUMNMAJOR. { A = VARATTR_COLUMNMAJOR; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   193
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   194
%type variable_declaration_details_list { VariableDeclaration * }
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
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   199
%type variable_declaration_details { VariableDeclaration * }
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
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   221
%type struct_declaration { StructDeclaration * }
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, $$); }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   223
struct_declaration(A) ::= struct_intro(B) LBRACE struct_member_list(C) RBRACE. { REVERSE_LINKED_LIST(StructMembers, 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 * }
10eb8be2c919 Added better (?) USERTYPE management.
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   227
struct_intro(A) ::= STRUCT IDENTIFIER(B). { A = B.string; add_usertype(ctx, A); }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   228
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   229
%type struct_member_list { StructMembers * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   234
%type struct_member { StructMembers * }
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, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   236
struct_member(A) ::= interpolation_mod(B) struct_member_details(C). { StructMembers *i = C; A = C; while (i) { i->interpolation_mod = B; i = i->next; } }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   239
%type struct_member_details { StructMembers * }
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, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   241
struct_member_details(A) ::= datatype(B) struct_member_item_list(C) SEMICOLON. { StructMembers *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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   243
%type struct_member_item_list { StructMembers * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   249
%type variable_lowlevel { VariableLowLevel * }
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.
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   257
%type scalar_or_array { ScalarOrArray * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   263
%type packoffset { PackOffset * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   274
%type annotations { Annotations * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   275
%destructor annotations { delete_annotation(ctx, $$); }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   276
annotations(A) ::= LT annotation_list(B) GT. { REVERSE_LINKED_LIST(Annotations, B); A = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   277
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   278
%type annotation_list { Annotations * }
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?
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   284
%type annotation { Annotations * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   288
%type initializer_block_list { Expression * }
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; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   292
initializer_block_list(A) ::= initializer_block_list(B) COMMA initializer_block_list(C). { A = new_binary_expr(ctx, 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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   294
%type initializer_block { Expression * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   298
%type initializer { Expression * }
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 * }
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   314
datatype_sampler(A) ::= SAMPLER. { A = stringcache_fmt(ctx->strcache, "s1"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   315
datatype_sampler(A) ::= SAMPLER1D. { A = stringcache_fmt(ctx->strcache, "s1"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   316
datatype_sampler(A) ::= SAMPLER2D. { A = stringcache_fmt(ctx->strcache, "s2"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   317
datatype_sampler(A) ::= SAMPLER3D. { A = stringcache_fmt(ctx->strcache, "s3"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   318
datatype_sampler(A) ::= SAMPLERCUBE. { A = stringcache_fmt(ctx->strcache, "sc"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   319
datatype_sampler(A) ::= SAMPLER_STATE. { A = stringcache_fmt(ctx->strcache, "ss"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   320
datatype_sampler(A) ::= SAMPLERSTATE. { A = stringcache_fmt(ctx->strcache, "ss"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   321
datatype_sampler(A) ::= SAMPLERCOMPARISONSTATE. { A = stringcache_fmt(ctx->strcache, "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 * }
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   324
datatype_scalar(A) ::= BOOL. { A = stringcache_fmt(ctx->strcache, "b"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   325
datatype_scalar(A) ::= INT. { A = stringcache_fmt(ctx->strcache, "i"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   326
datatype_scalar(A) ::= UINT. { A = stringcache_fmt(ctx->strcache, "u"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   327
datatype_scalar(A) ::= HALF. { A = stringcache_fmt(ctx->strcache, "h"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   328
datatype_scalar(A) ::= FLOAT. { A = stringcache_fmt(ctx->strcache, "f"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   329
datatype_scalar(A) ::= DOUBLE. { A = stringcache_fmt(ctx->strcache, "d"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   330
datatype_scalar(A) ::= STRING. { A = stringcache_fmt(ctx->strcache, "S"); } // this is for the effects framework, not HLSL.
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   331
datatype_scalar(A) ::= SNORM FLOAT. { A = stringcache_fmt(ctx->strcache, "Fs"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
diff changeset
   332
datatype_scalar(A) ::= UNORM FLOAT. { A = stringcache_fmt(ctx->strcache, "Fu"); }
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
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 * }
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
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 * }
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 857
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   346
%type statement_block { Statement * }
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); }
85afb474f99d Make statement blocks explicit in the AST.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   349
statement_block(A) ::= LBRACE statement_list(B) RBRACE. { REVERSE_LINKED_LIST(Statement, 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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   351
%type statement_list { Statement * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   367
%type statement { Statement * }
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); }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   379
statement(A) ::= switch_intro(B) LPAREN expression(C) RPAREN LBRACE switch_case_list(D) RBRACE. { REVERSE_LINKED_LIST(SwitchCases, 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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   389
%type while_intro { int64 }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   395
%type for_statement { Statement * }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   396
%destructor for_statement { delete_statement(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   397
for_statement(A) ::= for_intro(B) for_details(C). { A = C; ((ForStatement *) A)->unroll = B; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   398
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   399
%type for_intro { int64 }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   405
%type for_details { Statement * }
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
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   420
%type do_intro { int64 }
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 }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   427
if_intro(A) ::= LBRACKET BRANCH RBRACKET IF. { A = IFATTR_BRANCH; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   428
if_intro(A) ::= LBRACKET FLATTEN RBRACKET IF. { A = IFATTR_FLATTEN; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   429
if_intro(A) ::= LBRACKET IFALL RBRACKET IF. { A = IFATTR_IFALL; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   430
if_intro(A) ::= LBRACKET IFANY RBRACKET IF. { A = IFATTR_IFANY; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   431
if_intro(A) ::= LBRACKET PREDICATE RBRACKET IF. { A = IFATTR_PREDICATE; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   432
if_intro(A) ::= LBRACKET PREDICATEBLOCK RBRACKET IF. { A = IFATTR_PREDICATEBLOCK; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   433
if_intro(A) ::= IF. { A = 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 }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   436
switch_intro(A) ::= LBRACKET FLATTEN RBRACKET SWITCH. { A = SWITCHATTR_FLATTEN; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   437
switch_intro(A) ::= LBRACKET BRANCH RBRACKET SWITCH. { A = SWITCHATTR_BRANCH; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   438
switch_intro(A) ::= LBRACKET FORCECASE RBRACKET SWITCH. { A = SWITCHATTR_FORCECASE; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   439
switch_intro(A) ::= LBRACKET CALL RBRACKET SWITCH. { A = SWITCHATTR_CALL; }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   440
switch_intro(A) ::= SWITCH. { A = SWITCHATTR_NONE; }
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 709
diff changeset
   441
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   442
%type switch_case_list { SwitchCases * }
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.
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   449
%type switch_case { SwitchCases * }
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, $$); }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   451
switch_case(A) ::= CASE expression(B) COLON statement_list(C). { REVERSE_LINKED_LIST(Statement, 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); }
855
575a443074af Reverse all the linked lists that we generate backwards in the parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
   453
switch_case(A) ::= DEFAULT COLON statement_list(B). { REVERSE_LINKED_LIST(Statement, 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.
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   457
%type primary_expr { Expression * }
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); }
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   463
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
   464
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   465
%type postfix_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   466
%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
   467
postfix_expr(A) ::= primary_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   468
postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, AST_OP_DEREF_ARRAY, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   469
postfix_expr(A) ::= postfix_expr(B) LPAREN RPAREN. { A = new_binary_expr(ctx, AST_OP_CALLFUNC, B, NULL); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   470
postfix_expr(A) ::= postfix_expr(B) LPAREN argument_expr_list(C) RPAREN. { A = new_binary_expr(ctx, AST_OP_CALLFUNC, B, C); }
919
eeb5decdf548 Fixed constructor syntax parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 917
diff changeset
   471
postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = new_constructor_expr(ctx, B, C); } // HLSL constructor
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   472
postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, AST_OP_DEREF_STRUCT, B, new_identifier_expr(ctx, C.string)); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   473
postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, AST_OP_POSTINCREMENT, B); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   474
postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, AST_OP_POSTDECREMENT, B); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   476
%type argument_expr_list { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   477
%destructor argument_expr_list { delete_expr(ctx, $$); }
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   478
argument_expr_list(A) ::= assignment_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   479
argument_expr_list(A) ::= argument_expr_list(B) COMMA assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_COMMA, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   481
%type unary_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   482
%destructor unary_expr { delete_expr(ctx, $$); }
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   483
unary_expr(A) ::= postfix_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   484
unary_expr(A) ::= PLUSPLUS unary_expr(B). { A = new_unary_expr(ctx, AST_OP_PREINCREMENT, B); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   485
unary_expr(A) ::= MINUSMINUS unary_expr(B). { A = new_unary_expr(ctx, 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
   486
unary_expr(A) ::= PLUS cast_expr(B). { A = B; }  // unary "+x" is always a no-op, so throw it away here.
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   487
unary_expr(A) ::= MINUS cast_expr(B). { A = new_unary_expr(ctx, AST_OP_NEGATE, B); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   488
unary_expr(A) ::= COMPLEMENT cast_expr(B). { A = new_unary_expr(ctx, AST_OP_COMPLEMENT, B); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   489
unary_expr(A) ::= EXCLAMATION cast_expr(B). { A = new_unary_expr(ctx, AST_OP_NOT, B); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   491
%type cast_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   492
%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
   493
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
   494
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
   495
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   496
%type multiplicative_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   497
%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
   498
multiplicative_expr(A) ::= cast_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   499
multiplicative_expr(A) ::= multiplicative_expr(B) STAR cast_expr(C). { A = new_binary_expr(ctx, AST_OP_MULTIPLY, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   500
multiplicative_expr(A) ::= multiplicative_expr(B) SLASH cast_expr(C). { A = new_binary_expr(ctx, AST_OP_DIVIDE, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   501
multiplicative_expr(A) ::= multiplicative_expr(B) PERCENT cast_expr(C). { A = new_binary_expr(ctx, AST_OP_MODULO, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   503
%type additive_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   504
%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
   505
additive_expr(A) ::= multiplicative_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   506
additive_expr(A) ::= additive_expr(B) PLUS multiplicative_expr(C). { A = new_binary_expr(ctx, AST_OP_ADD, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   507
additive_expr(A) ::= additive_expr(B) MINUS multiplicative_expr(C). { A = new_binary_expr(ctx, AST_OP_SUBTRACT, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   509
%type shift_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   510
%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
   511
shift_expr(A) ::= additive_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   512
shift_expr(A) ::= shift_expr(B) LSHIFT additive_expr(C). { A = new_binary_expr(ctx, AST_OP_LSHIFT, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   513
shift_expr(A) ::= shift_expr(B) RSHIFT additive_expr(C). { A = new_binary_expr(ctx, AST_OP_RSHIFT, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   514
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   515
%type relational_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   516
%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
   517
relational_expr(A) ::= shift_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   518
relational_expr(A) ::= relational_expr(B) LT shift_expr(C). { A = new_binary_expr(ctx, AST_OP_LESSTHAN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   519
relational_expr(A) ::= relational_expr(B) GT shift_expr(C). { A = new_binary_expr(ctx, AST_OP_GREATERTHAN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   520
relational_expr(A) ::= relational_expr(B) LEQ shift_expr(C). { A = new_binary_expr(ctx, AST_OP_LESSTHANOREQUAL, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   521
relational_expr(A) ::= relational_expr(B) GEQ shift_expr(C). { A = new_binary_expr(ctx, AST_OP_GREATERTHANOREQUAL, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   523
%type equality_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   524
%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
   525
equality_expr(A) ::= relational_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   526
equality_expr(A) ::= equality_expr(B) EQL relational_expr(C). { A = new_binary_expr(ctx, AST_OP_EQUAL, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   527
equality_expr(A) ::= equality_expr(B) NEQ relational_expr(C). { A = new_binary_expr(ctx, AST_OP_NOTEQUAL, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   529
%type and_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   530
%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
   531
and_expr(A) ::= equality_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   532
and_expr(A) ::= and_expr(B) AND equality_expr(C). { A = new_binary_expr(ctx, AST_OP_BINARYAND, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   534
%type exclusive_or_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   535
%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
   536
exclusive_or_expr(A) ::= and_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   537
exclusive_or_expr(A) ::= exclusive_or_expr(B) XOR and_expr(C). { A = new_binary_expr(ctx, AST_OP_BINARYXOR, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   538
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   539
%type inclusive_or_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   540
%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
   541
inclusive_or_expr(A) ::= exclusive_or_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   542
inclusive_or_expr(A) ::= inclusive_or_expr(B) OR exclusive_or_expr(C). { A = new_binary_expr(ctx, AST_OP_BINARYOR, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   544
%type logical_and_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   545
%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
   546
logical_and_expr(A) ::= inclusive_or_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   547
logical_and_expr(A) ::= logical_and_expr(B) ANDAND inclusive_or_expr(C). { A = new_binary_expr(ctx, AST_OP_LOGICALAND, B, C); }
702
7bf680ef6fc3 Added Jeff Lee's ANSI C yacc grammar.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   549
%type logical_or_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   550
%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
   551
logical_or_expr(A) ::= logical_and_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   552
logical_or_expr(A) ::= logical_or_expr(B) OROR logical_and_expr(C). { A = new_binary_expr(ctx, AST_OP_LOGICALOR, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   553
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   554
%type conditional_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   555
%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
   556
conditional_expr(A) ::= logical_or_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   557
conditional_expr(A) ::= logical_or_expr(B) QUESTION logical_or_expr(C) COLON conditional_expr(D). { A = new_ternary_expr(ctx, 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
   558
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   559
%type assignment_expr { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   560
%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
   561
assignment_expr(A) ::= conditional_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   562
assignment_expr(A) ::= unary_expr(B) ASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   563
assignment_expr(A) ::= unary_expr(B) MULASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_MULASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   564
assignment_expr(A) ::= unary_expr(B) DIVASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_DIVASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   565
assignment_expr(A) ::= unary_expr(B) MODASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_MODASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   566
assignment_expr(A) ::= unary_expr(B) ADDASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ADDASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   567
assignment_expr(A) ::= unary_expr(B) SUBASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_SUBASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   568
assignment_expr(A) ::= unary_expr(B) LSHIFTASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_LSHIFTASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   569
assignment_expr(A) ::= unary_expr(B) RSHIFTASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_RSHIFTASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   570
assignment_expr(A) ::= unary_expr(B) ANDASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ANDASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   571
assignment_expr(A) ::= unary_expr(B) XORASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_XORASSIGN, B, C); }
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   572
assignment_expr(A) ::= unary_expr(B) ORASSIGN assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_ORASSIGN, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   573
827
2f955ce29b7b Moved the calculator experiment work back into the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents: 796
diff changeset
   574
%type expression { Expression * }
836
d975fa785f1e Bunch More Work on HLSL parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 827
diff changeset
   575
%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
   576
expression(A) ::= assignment_expr(B). { A = B; }
844
06494572317b Make AST nodes a little more generic, add source position info to them.
Ryan C. Gordon <icculus@icculus.org>
parents: 838
diff changeset
   577
expression(A) ::= expression(B) COMMA assignment_expr(C). { A = new_binary_expr(ctx, AST_OP_COMMA, B, C); }
703
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   578
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   579
// end of mojoshader_parser_hlsl.lemon ...
8bc7b33377e7 Converted original YACC grammar to Lemon grammar.
Ryan C. Gordon <icculus@icculus.org>
parents: 702
diff changeset
   580