Changeset 1590 for trunk/src/gpu/lolfx-parser.y
- Timestamp:
- Jul 8, 2012, 12:25:52 AM (9 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gpu/lolfx-parser.y
r1589 r1590 1 1 %{ 2 #include <cstdio> 3 #include <iostream> 4 5 extern "C" int yylex(); 6 extern "C" int yyparse(); 7 extern "C" FILE *yyin; 8 extern "C" int yylineno; 9 10 void yyerror(const char *s); 2 // 3 // Lol Engine 4 // 5 // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the Do What The Fuck You Want To 8 // Public License, Version 2, as published by Sam Hocevar. See 9 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 10 // 11 12 #if defined HAVE_CONFIG_H 13 # include "config.h" 14 #endif 15 16 #include "core.h" 17 18 #include <string> 19 11 20 %} 21 22 %require "2.3" 23 %debug 24 %defines 25 %skeleton "lalr1.cc" 26 %name-prefix="lol" 27 %define parser_class_name "LolFxParser" 28 %locations 29 %parse-param { class LolFxCompiler& mc } 30 %error-verbose 12 31 13 32 /* The classic Bison union trick */ … … 20 39 } 21 40 22 %type <sval> lolfx_shader_name 41 /* %type <sval> lolfx_shader_name */ 23 42 24 43 /* … … 181 200 %token PREPROCESSOR_REGION 182 201 202 %token PRAGMA_LOLFX 203 183 204 /* 184 205 * HLSL reserved keywords … … 208 229 209 230 /* 231 * Special tokens 232 */ 233 234 %token T_END 0 235 %token T_ERROR 236 237 /* 210 238 * Our entry point 211 239 */ 212 240 213 241 %start lolfx_file 242 243 %{ 244 #include "gpu/lolfx-compiler.h" 245 246 #undef yylex 247 #define yylex mc.m_lexer->lex 248 %} 214 249 215 250 %% … … 692 727 693 728 lolfx_technique: 694 HT_TECHNIQUE IDENTIFIER '{' pass_list '}' { std::cout << "New tech "<< std::endl; }729 HT_TECHNIQUE IDENTIFIER '{' pass_list '}' { std::cout << "New tech " << $2 << std::endl; } 695 730 ; 696 731 … … 705 740 706 741 pass: 707 HT_PASS IDENTIFIER '{' pass_stmt_list '}' { std::cout << "New pass "<< std::endl; }742 HT_PASS IDENTIFIER '{' pass_stmt_list '}' { std::cout << "New pass " << $2 << std::endl; } 708 743 ; 709 744 … … 737 772 738 773 lolfx_shader: 739 lolfx_shader_region glsl_translation_unit 740 | lolfx_shader_region 741 ; 742 743 lolfx_shader_region: 744 PREPROCESSOR_REGION lolfx_shader_name { std::cout << "new shader " << $2 << std::endl; } 745 ; 746 747 lolfx_shader_name: 748 IDENTIFIER { $$ = $1; } 749 | lolfx_shader_name '.' IDENTIFIER { $$ = $3; } /* FIXME: concatenate */ 774 lolfx_shader_declaration glsl_translation_unit 775 ; 776 777 lolfx_shader_declaration: 778 PRAGMA_LOLFX lolfx_shader_type '(' lolfx_shader_description_list ')' { std::cout << "new shader" << std::endl; } 779 ; 780 781 lolfx_shader_type: 782 HT_VERTEXSHADER 783 | HT_PIXELSHADER 784 ; 785 786 lolfx_shader_description_list: 787 lolfx_shader_description ',' lolfx_shader_description 788 | lolfx_shader_description 789 ; 790 791 lolfx_shader_description: 792 IDENTIFIER '=' IDENTIFIER FLOATCONSTANT 793 | IDENTIFIER '=' IDENTIFIER 750 794 ; 751 795 … … 1309 1353 %% 1310 1354 1311 main() 1355 void lol::LolFxParser::error(const LolFxParser::location_type& l, 1356 const std::string& m) 1312 1357 { 1313 yyin = stdin;//fopen("test.lolfx", "r"); 1314 do 1315 { 1316 yyparse(); 1317 } 1318 while (!feof(yyin)); 1319 1320 fclose(yyin); 1358 mc.Error(l, m); 1321 1359 } 1322 1360 1323 void yyerror(const char *s)1324 {1325 std::cout << "Parse error line " << yylineno << ": " << s << std::endl;1326 exit(-1);1327 }1328
Note: See TracChangeset
for help on using the changeset viewer.