You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parser-wavefront-obj.y 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. %{
  2. /*#include <QtGui>*/
  3. #include <QVariant>
  4. #include <QDebug>
  5. #include "utils/wavefrontobj.h"
  6. #include "lexer-wavefront-obj.h"
  7. // yylex is a function generated by Flex and we must tell to Bison that it is
  8. // defined in other place.
  9. extern int wavefront_objlex(void);
  10. // Bison uses the yyerror function for informing us when a parsing error has
  11. // occurred.
  12. void wavefront_objerror(const char *s);
  13. %}
  14. %define api.prefix {wavefront_obj}
  15. %define api.token.prefix {TOK_}
  16. // Here we define our custom variable types.
  17. // Custom types must be of fixed size.
  18. %union {
  19. float number;
  20. char* string;
  21. void* wavefront;
  22. }
  23. // Define the terminal expression types.
  24. %token <float_number> NUMBER
  25. %token <string> STRING
  26. %token SLASH
  27. %token MTLLIB
  28. %token USEMTL
  29. %token O
  30. %token V
  31. %token VT
  32. %token VN
  33. %token VP
  34. %token F
  35. %token S
  36. // Define the non-terminal expression types.
  37. %type <wavefront> wavefront_obj
  38. %%
  39. start: wavefront_obj {
  40. /* qDebug() << $1;*/
  41. };
  42. wavefront_obj: stmt_list {
  43. }
  44. ;
  45. stmt_list: {}
  46. | stmt_list stmt {};
  47. stmt: mtllib {}
  48. | usemtl {}
  49. | named_object {}
  50. | vertex {}
  51. | texture_coordinate {}
  52. | vertex_normal {}
  53. | vertex_space {}
  54. | face {}
  55. | smooth {};
  56. mtllib: MTLLIB STRING {};
  57. usemtl: USEMTL STRING {};
  58. named_object: O STRING {};
  59. vertex: V NUMBER NUMBER NUMBER {}
  60. | V NUMBER NUMBER NUMBER NUMBER {};
  61. texture_coordinate: VT NUMBER NUMBER {}
  62. | VT NUMBER NUMBER NUMBER {};
  63. vertex_normal: VN NUMBER NUMBER NUMBER {};
  64. vertex_space: VP NUMBER NUMBER NUMBER {};
  65. face: F face_vertex_list {};
  66. face_vertex_list: {}
  67. | face_vertex_list face_vertex {};
  68. face_vertex: NUMBER {}
  69. | NUMBER SLASH NUMBER {}
  70. | NUMBER SLASH NUMBER SLASH NUMBER {}
  71. | NUMBER SLASH SLASH NUMBER {};
  72. smooth: S NUMBER {}
  73. | S STRING {};
  74. %%
  75. void wavefront_objerror(const char *s)
  76. {
  77. qDebug() << "parse error:" << s << "at line" << wavefront_objlineno << "at" << wavefront_objtext;
  78. }