Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

127 righe
1.9 KiB

  1. %{
  2. #include <cstdio>
  3. #include <iostream>
  4. extern "C" int yylex();
  5. extern "C" int yyparse();
  6. extern "C" FILE *yyin;
  7. extern "C" int yylineno;
  8. void yyerror(const char *s);
  9. %}
  10. /* The classic Bison union trick */
  11. %union
  12. {
  13. int ival;
  14. float fval;
  15. char *sval;
  16. }
  17. /*
  18. * All the LolFx tokens
  19. */
  20. %token TECHNIQUE PASS
  21. %token <ival> INT
  22. %token <fval> FLOAT
  23. %token <sval> STRING NAME
  24. %%
  25. fx:
  26. section_list
  27. ;
  28. section_list:
  29. section
  30. | section_list section
  31. ;
  32. section:
  33. technique
  34. | shader
  35. ;
  36. /*
  37. * Grammar for techniques
  38. */
  39. technique:
  40. TECHNIQUE NAME '{' pass_list '}' { std::cout << "TECHNIQUE" << std::endl; }
  41. ;
  42. /*
  43. * Grammar for passes
  44. */
  45. pass_list:
  46. pass
  47. | pass_list pass
  48. ;
  49. pass:
  50. PASS NAME '{' pass_stmt_list '}' { std::cout << "PASS" << std::endl; }
  51. ;
  52. pass_stmt_list:
  53. pass_stmt
  54. | pass_stmt_list pass_stmt
  55. ;
  56. pass_stmt:
  57. ';'
  58. | NAME '=' NAME ';'
  59. | NAME '=' INT ';'
  60. | NAME '[' INT ']' '=' NAME ';'
  61. | NAME '[' INT ']' '=' INT ';'
  62. ;
  63. /*
  64. * Grammar for shaders
  65. */
  66. shader:
  67. shader_region shader_code
  68. | shader_region
  69. ;
  70. shader_region:
  71. '#' NAME shader_name { std::cout << "new shader " << $2 << std::endl; }
  72. ;
  73. shader_name:
  74. NAME
  75. | shader_name '.' NAME
  76. ;
  77. shader_code:
  78. INT shader_code { std::cout << "int: " << $1 << std::endl; }
  79. | FLOAT shader_code { std::cout << "float: " << $1 << std::endl; }
  80. | STRING shader_code { std::cout << "string: " << $1 << std::endl; }
  81. | INT { std::cout << "int: " << $1 << std::endl; }
  82. | FLOAT { std::cout << "float: " << $1 << std::endl; }
  83. | STRING { std::cout << "string: " << $1 << std::endl; }
  84. ;
  85. %%
  86. main()
  87. {
  88. yyin = fopen("test.lolfx", "r");
  89. do
  90. {
  91. yyparse();
  92. }
  93. while (!feof(yyin));
  94. fclose(yyin);
  95. }
  96. void yyerror(const char *s)
  97. {
  98. std::cout << "Parse error line " << yylineno << ": " << s << std::endl;
  99. exit(-1);
  100. }