StructParser.lime 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. %class StructParser
  2. %start file
  3. file =
  4. directives structures {
  5. $$ = array(
  6. "directives" => $1,
  7. "structures" => $2
  8. );
  9. }.
  10. directives =
  11. {
  12. $$ = array();
  13. } |
  14. directive semicolon directives {
  15. $$ = array_merge(array($1), $3);
  16. }.
  17. directive =
  18. include string {
  19. $$ = array(
  20. "type" => "include",
  21. "file" => $2
  22. );
  23. }.
  24. structures =
  25. structspec {
  26. $$ = array($1);
  27. } |
  28. structspec structures {
  29. $$ = array_merge(array($1), $2);
  30. }.
  31. structspec =
  32. structure name srpar string erpar spar entries epar semicolon {
  33. $$ = array(
  34. "name" => $2,
  35. "parameters" => $4,
  36. "entries" => $7
  37. );
  38. }.
  39. entries =
  40. entry {
  41. $$ = array($1);
  42. } |
  43. entry entries {
  44. $$ = array_merge(array($1), $2);
  45. }.
  46. entry =
  47. typespec name semicolon {
  48. $$ = array(
  49. "type" => $1,
  50. "name" => $2,
  51. "num" => "1"
  52. );
  53. } |
  54. typespec name sbracket string ebracket semicolon {
  55. $$ = array(
  56. "type" => $1,
  57. "name" => $2,
  58. "num" => $4
  59. );
  60. }.
  61. typespec =
  62. string {
  63. $$ = array(
  64. "type" => "sizealign",
  65. "ctype" => $1,
  66. "size" => "sizeof($1)",
  67. "align" => "__alignof__($1)"
  68. );
  69. } |
  70. size string align string {
  71. $$ = array(
  72. "type" => "sizealign",
  73. "ctype" => "void",
  74. "size" => $2,
  75. "align" => $4
  76. );
  77. } |
  78. structure name srpar string erpar {
  79. $$ = array(
  80. "type" => "structure",
  81. "ctype" => $2,
  82. "name" => $2,
  83. "parameters" => $4
  84. );
  85. }.