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