Add SPDX-License-Identifier to all files
[zilutils.git] / zilc / parser.y
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 %{
23
24 #include "element.h"
25
26 %}
27
28 %union
29 {
30     char *string;
31     double number;
32     element_t *element;
33     list_t list;
34 }
35
36 %token SEMICOLON
37 %token LEFT_CHEVRON
38 %token RIGHT_CHEVRON
39 %token LEFT_PARENTHESIS
40 %token RIGHT_PARENTHESIS
41 %token COMMA
42
43 %token <string> ATOM
44 %token <number> NUMBER
45 %token <string> STRING
46
47 %type <list> element_list statement_list
48 %type <element> element tuple statement
49
50 %start toplevel
51
52 %%
53
54 toplevel        : statement_list
55                 {
56                     // TODO
57                 }
58
59 statement_list  : /* empty */
60                 {
61                     init_list(&$$);
62                 }
63                 | statement_list comment
64                 {
65                     /* Skip the comment */
66                     $$ = $1;
67                 }
68                 | statement_list statement
69                 {
70                     list_append(&$1, &$2->link);
71                     $$ = $1;
72                 }
73
74 statement       : LEFT_CHEVRON ATOM element_list RIGHT_CHEVRON
75                 {
76                     $$ = create_statement($2, &$3);
77                 }
78
79 tuple           : LEFT_PARENTHESIS element_list RIGHT_PARENTHESIS
80                 {
81                     $$ = create_tuple(&$2);
82                 }
83
84 element_list    : /* empty */
85                 {
86                     init_list(&$$);
87                 }
88                 | element_list comment
89                 {
90                     /* Skip the comment */
91                     $$ = $1;
92                 }
93                 | element_list element
94                 {
95                     list_append(&$1, &$2->link);
96                     $$ = $1;
97                 }
98
99 element         : ATOM
100                 {
101                     $$ = create_atom($1, 0);
102                 }
103                 | COMMA ATOM
104                 {
105                     $$ = create_atom($2, 1);
106                 }
107                 | STRING
108                 {
109                     $$ = create_string($1);
110                 }
111                 | NUMBER
112                 {
113                     $$ = create_number($1);
114                 }
115                 | statement
116                 {
117                     $$ = $1;
118                 }
119                 | tuple
120                 {
121                     $$ = $1;
122                 }
123
124 comment         : SEMICOLON element { /* Ignored */ }
125
126 %%
127
128 int yyerror(const char *str)
129 {
130 }