parser.y 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * parser.y
  3. *
  4. * Copyright (C) 2015 Alexander Andrejevic <theflash AT sdf DOT lonestar DOT org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>
  18. *
  19. * SPDX-License-Identifier: AGPL-3.0-or-later
  20. */
  21. %{
  22. #include "element.h"
  23. %}
  24. %union
  25. {
  26. char *string;
  27. double number;
  28. element_t *element;
  29. list_t list;
  30. }
  31. %token SEMICOLON
  32. %token LEFT_CHEVRON
  33. %token RIGHT_CHEVRON
  34. %token LEFT_PARENTHESIS
  35. %token RIGHT_PARENTHESIS
  36. %token COMMA
  37. %token <string> ATOM
  38. %token <number> NUMBER
  39. %token <string> STRING
  40. %type <list> element_list statement_list
  41. %type <element> element tuple statement
  42. %start toplevel
  43. %%
  44. toplevel : statement_list
  45. {
  46. // TODO
  47. }
  48. statement_list : /* empty */
  49. {
  50. init_list(&$$);
  51. }
  52. | statement_list comment
  53. {
  54. /* Skip the comment */
  55. $$ = $1;
  56. }
  57. | statement_list statement
  58. {
  59. list_append(&$1, &$2->link);
  60. $$ = $1;
  61. }
  62. statement : LEFT_CHEVRON ATOM element_list RIGHT_CHEVRON
  63. {
  64. $$ = create_statement($2, &$3);
  65. }
  66. tuple : LEFT_PARENTHESIS element_list RIGHT_PARENTHESIS
  67. {
  68. $$ = create_tuple(&$2);
  69. }
  70. element_list : /* empty */
  71. {
  72. init_list(&$$);
  73. }
  74. | element_list comment
  75. {
  76. /* Skip the comment */
  77. $$ = $1;
  78. }
  79. | element_list element
  80. {
  81. list_append(&$1, &$2->link);
  82. $$ = $1;
  83. }
  84. element : ATOM
  85. {
  86. $$ = create_atom($1, 0);
  87. }
  88. | COMMA ATOM
  89. {
  90. $$ = create_atom($2, 1);
  91. }
  92. | STRING
  93. {
  94. $$ = create_string($1);
  95. }
  96. | NUMBER
  97. {
  98. $$ = create_number($1);
  99. }
  100. | statement
  101. {
  102. $$ = $1;
  103. }
  104. | tuple
  105. {
  106. $$ = $1;
  107. }
  108. comment : SEMICOLON element { /* Ignored */ }
  109. %%
  110. int yyerror(const char *str)
  111. {
  112. }