| 1 | %start WholeEnchilada |
|---|
| 2 | %name-prefix="ps10_" |
|---|
| 3 | %{ |
|---|
| 4 | |
|---|
| 5 | /* |
|---|
| 6 | |
|---|
| 7 | This is a parser for the DX8 PS1.0 pixel shaders. I intend |
|---|
| 8 | to use it to set NV_texture_shader* and NV_register_combiners* |
|---|
| 9 | state in OpenGL, but the parse tree could be used for any |
|---|
| 10 | other purpose. |
|---|
| 11 | |
|---|
| 12 | Cass Everitt |
|---|
| 13 | 7-19-01 |
|---|
| 14 | |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | void yyerror(char* s); |
|---|
| 18 | int yylex ( void ); |
|---|
| 19 | |
|---|
| 20 | #ifdef _WIN32 |
|---|
| 21 | # include <windows.h> |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | #include <stdlib.h> |
|---|
| 26 | |
|---|
| 27 | #include "ps1.0_program.h" |
|---|
| 28 | #include "nvparse_errors.h" |
|---|
| 29 | #include "nvparse_externs.h" |
|---|
| 30 | |
|---|
| 31 | #include <list> |
|---|
| 32 | #include <vector> |
|---|
| 33 | |
|---|
| 34 | using namespace std; |
|---|
| 35 | using namespace ps10; |
|---|
| 36 | |
|---|
| 37 | //#define DBG_MESG(msg, line) errors.set(msg, line) |
|---|
| 38 | #define DBG_MESG(msg, line) |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | %} |
|---|
| 42 | %union |
|---|
| 43 | { |
|---|
| 44 | int ival; |
|---|
| 45 | float fval; |
|---|
| 46 | |
|---|
| 47 | string * sval; |
|---|
| 48 | constdef * cdef; |
|---|
| 49 | vector<constdef> * consts; |
|---|
| 50 | vector<string> * line; |
|---|
| 51 | list<vector<string> > * lines; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | %token <ival> HEADER NEWLINE |
|---|
| 55 | %token <fval> NUMBER |
|---|
| 56 | %token <sval> REG |
|---|
| 57 | %token <sval> DEF |
|---|
| 58 | %token <sval> ADDROP |
|---|
| 59 | %token <sval> BLENDOP |
|---|
| 60 | |
|---|
| 61 | %type <cdef> Def |
|---|
| 62 | %type <consts> Defs |
|---|
| 63 | %type <line> AddrOp BlendOp |
|---|
| 64 | %type <lines> AddrOps BlendOps |
|---|
| 65 | %type <ival> MaybePlus |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | %% |
|---|
| 69 | |
|---|
| 70 | WholeEnchilada : |
|---|
| 71 | |
|---|
| 72 | HEADER Newlines Defs AddrOps BlendOps |
|---|
| 73 | { |
|---|
| 74 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 75 | ps10::invoke($3, $4, $5); |
|---|
| 76 | } |
|---|
| 77 | | |
|---|
| 78 | |
|---|
| 79 | Newlines HEADER Newlines Defs AddrOps BlendOps |
|---|
| 80 | { |
|---|
| 81 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 82 | ps10::invoke($4, $5, $6); |
|---|
| 83 | } |
|---|
| 84 | | |
|---|
| 85 | |
|---|
| 86 | HEADER Newlines AddrOps BlendOps |
|---|
| 87 | { |
|---|
| 88 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 89 | ps10::invoke( 0, $3, $4); |
|---|
| 90 | } |
|---|
| 91 | | |
|---|
| 92 | |
|---|
| 93 | Newlines HEADER Newlines AddrOps BlendOps |
|---|
| 94 | { |
|---|
| 95 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 96 | ps10::invoke( 0, $4, $5); |
|---|
| 97 | } |
|---|
| 98 | | |
|---|
| 99 | |
|---|
| 100 | HEADER Newlines Defs BlendOps |
|---|
| 101 | { |
|---|
| 102 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 103 | ps10::invoke($3, 0, $4); |
|---|
| 104 | } |
|---|
| 105 | | |
|---|
| 106 | |
|---|
| 107 | Newlines HEADER Newlines Defs BlendOps |
|---|
| 108 | { |
|---|
| 109 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 110 | ps10::invoke($4, 0, $5); |
|---|
| 111 | } |
|---|
| 112 | | |
|---|
| 113 | |
|---|
| 114 | HEADER Newlines BlendOps |
|---|
| 115 | { |
|---|
| 116 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 117 | ps10::invoke( 0, 0, $3); |
|---|
| 118 | } |
|---|
| 119 | | |
|---|
| 120 | |
|---|
| 121 | Newlines HEADER Newlines BlendOps |
|---|
| 122 | { |
|---|
| 123 | DBG_MESG("dbg: WholeEnchilada", line_number); |
|---|
| 124 | ps10::invoke( 0, 0, $4); |
|---|
| 125 | } |
|---|
| 126 | ; |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | Defs : |
|---|
| 130 | |
|---|
| 131 | Def |
|---|
| 132 | { |
|---|
| 133 | $$ = new vector<constdef>; |
|---|
| 134 | $$->push_back(* $1); |
|---|
| 135 | delete $1; |
|---|
| 136 | } |
|---|
| 137 | | |
|---|
| 138 | |
|---|
| 139 | Defs Def |
|---|
| 140 | { |
|---|
| 141 | $$ = $1; |
|---|
| 142 | $$->push_back(* $2); |
|---|
| 143 | delete $2; |
|---|
| 144 | } |
|---|
| 145 | ; |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | Def : |
|---|
| 150 | |
|---|
| 151 | DEF REG ',' NUMBER ',' NUMBER ',' NUMBER ',' NUMBER Newlines |
|---|
| 152 | { |
|---|
| 153 | $$ = new constdef; |
|---|
| 154 | $$->reg = * $2; |
|---|
| 155 | $$->r = $4; |
|---|
| 156 | $$->g = $6; |
|---|
| 157 | $$->b = $8; |
|---|
| 158 | $$->a = $10; |
|---|
| 159 | delete $2; |
|---|
| 160 | } |
|---|
| 161 | ; |
|---|
| 162 | |
|---|
| 163 | AddrOps: |
|---|
| 164 | |
|---|
| 165 | AddrOp |
|---|
| 166 | { |
|---|
| 167 | $$ = new list<vector<string> >; |
|---|
| 168 | $$->push_back(* $1); |
|---|
| 169 | delete $1; |
|---|
| 170 | } |
|---|
| 171 | | |
|---|
| 172 | |
|---|
| 173 | AddrOps AddrOp |
|---|
| 174 | { |
|---|
| 175 | $$ = $1; |
|---|
| 176 | $$->push_back(* $2); |
|---|
| 177 | delete $2; |
|---|
| 178 | } |
|---|
| 179 | ; |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | AddrOp : |
|---|
| 183 | |
|---|
| 184 | ADDROP REG Newlines |
|---|
| 185 | { |
|---|
| 186 | $$ = new vector<string>; |
|---|
| 187 | $$->push_back(* $1); |
|---|
| 188 | $$->push_back(* $2); |
|---|
| 189 | delete $1; |
|---|
| 190 | delete $2; |
|---|
| 191 | } |
|---|
| 192 | | |
|---|
| 193 | |
|---|
| 194 | ADDROP REG ',' REG Newlines |
|---|
| 195 | { |
|---|
| 196 | $$ = new vector<string>; |
|---|
| 197 | $$->push_back(* $1); |
|---|
| 198 | $$->push_back(* $2); |
|---|
| 199 | $$->push_back(* $4); |
|---|
| 200 | delete $1; |
|---|
| 201 | delete $2; |
|---|
| 202 | delete $4; |
|---|
| 203 | } |
|---|
| 204 | | |
|---|
| 205 | |
|---|
| 206 | ADDROP REG ',' REG ',' REG Newlines |
|---|
| 207 | { |
|---|
| 208 | $$ = new vector<string>; |
|---|
| 209 | $$->push_back(* $1); |
|---|
| 210 | $$->push_back(* $2); |
|---|
| 211 | $$->push_back(* $4); |
|---|
| 212 | $$->push_back(* $6); |
|---|
| 213 | delete $1; |
|---|
| 214 | delete $2; |
|---|
| 215 | delete $4; |
|---|
| 216 | delete $6; |
|---|
| 217 | } |
|---|
| 218 | ; |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | BlendOps: |
|---|
| 222 | |
|---|
| 223 | BlendOp |
|---|
| 224 | { |
|---|
| 225 | $$ = new list<vector<string> >; |
|---|
| 226 | $$->push_back(* $1); |
|---|
| 227 | delete $1; |
|---|
| 228 | } |
|---|
| 229 | | |
|---|
| 230 | |
|---|
| 231 | BlendOps BlendOp |
|---|
| 232 | { |
|---|
| 233 | $$ = $1; |
|---|
| 234 | $$->push_back(* $2); |
|---|
| 235 | delete $2; |
|---|
| 236 | } |
|---|
| 237 | ; |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | BlendOp : |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | MaybePlus BLENDOP REG ',' REG Newlines |
|---|
| 244 | { |
|---|
| 245 | $$ = new vector<string>; |
|---|
| 246 | if ( $1 ) |
|---|
| 247 | $$->push_back("+"); |
|---|
| 248 | $$->push_back(* $2); |
|---|
| 249 | $$->push_back(* $3); |
|---|
| 250 | $$->push_back(* $5); |
|---|
| 251 | delete $2; |
|---|
| 252 | delete $3; |
|---|
| 253 | delete $5; |
|---|
| 254 | } |
|---|
| 255 | | |
|---|
| 256 | |
|---|
| 257 | MaybePlus BLENDOP REG ',' REG ',' REG Newlines |
|---|
| 258 | { |
|---|
| 259 | $$ = new vector<string>; |
|---|
| 260 | if ( $1 ) |
|---|
| 261 | $$->push_back("+"); |
|---|
| 262 | $$->push_back(* $2); |
|---|
| 263 | $$->push_back(* $3); |
|---|
| 264 | $$->push_back(* $5); |
|---|
| 265 | $$->push_back(* $7); |
|---|
| 266 | delete $2; |
|---|
| 267 | delete $3; |
|---|
| 268 | delete $5; |
|---|
| 269 | delete $7; |
|---|
| 270 | } |
|---|
| 271 | | |
|---|
| 272 | |
|---|
| 273 | MaybePlus BLENDOP REG ',' REG ',' REG ',' REG Newlines |
|---|
| 274 | { |
|---|
| 275 | $$ = new vector<string>; |
|---|
| 276 | if ( $1 ) |
|---|
| 277 | $$->push_back("+"); |
|---|
| 278 | $$->push_back(* $2); |
|---|
| 279 | $$->push_back(* $3); |
|---|
| 280 | $$->push_back(* $5); |
|---|
| 281 | $$->push_back(* $7); |
|---|
| 282 | $$->push_back(* $9); |
|---|
| 283 | delete $2; |
|---|
| 284 | delete $3; |
|---|
| 285 | delete $5; |
|---|
| 286 | delete $7; |
|---|
| 287 | delete $9; |
|---|
| 288 | } |
|---|
| 289 | ; |
|---|
| 290 | |
|---|
| 291 | MaybePlus : |
|---|
| 292 | /* empty */ |
|---|
| 293 | { $$=0; } |
|---|
| 294 | | |
|---|
| 295 | '+' |
|---|
| 296 | { $$=1; } |
|---|
| 297 | ; |
|---|
| 298 | |
|---|
| 299 | Newlines : |
|---|
| 300 | |
|---|
| 301 | NEWLINE |
|---|
| 302 | {} |
|---|
| 303 | | |
|---|
| 304 | |
|---|
| 305 | Newlines NEWLINE |
|---|
| 306 | {} |
|---|
| 307 | ; |
|---|
| 308 | |
|---|
| 309 | %% |
|---|
| 310 | |
|---|
| 311 | void yyerror(char* s) |
|---|
| 312 | { |
|---|
| 313 | errors.set("parser: syntax error", line_number); |
|---|
| 314 | } |
|---|