1 /*
2 * SysDB - src/frontend/grammar.y
3 * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
28 %{
30 #include "frontend/connection.h"
31 #include "frontend/parser.h"
32 #include "frontend/grammar.h"
34 #include "utils/error.h"
35 #include "utils/llist.h"
37 #include <stdio.h>
39 sdb_fe_yyextra_t *
40 sdb_fe_yyget_extra(sdb_fe_yyscan_t scanner);
42 void
43 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
45 /* quick access to the current parse tree */
46 #define pt sdb_fe_yyget_extra(scanner)->parsetree
48 %}
50 %pure-parser
51 %lex-param {sdb_fe_yyscan_t scanner}
52 %parse-param {sdb_fe_yyscan_t scanner}
53 %locations
54 %error-verbose
55 %expect 0
56 %name-prefix="sdb_fe_yy"
58 %union {
59 sdb_llist_t *list;
60 sdb_conn_node_t *node;
61 }
63 %start statements
65 %token SCANNER_ERROR
67 %token IDENTIFIER
68 %token <node> LIST
70 %type <list> statements
71 %type <node> statement
72 list_statement
74 %%
76 statements:
77 statements ';' statement
78 {
79 if ($3) {
80 sdb_llist_append(pt, SDB_OBJ($3));
81 sdb_object_deref(SDB_OBJ($3));
82 }
83 }
84 |
85 statement
86 {
87 if ($1) {
88 sdb_llist_append(pt, SDB_OBJ($1));
89 sdb_object_deref(SDB_OBJ($1));
90 }
91 }
92 ;
94 statement:
95 list_statement
96 |
97 /* empty */
98 {
99 $$ = NULL;
100 }
101 ;
103 list_statement:
104 LIST
105 {
106 $$ = sdb_object_create_T(/* name = */ NULL, sdb_conn_node_t);
107 ((sdb_conn_node_t *)$$)->cmd = CONNECTION_LIST;
108 }
109 ;
111 %%
113 void
114 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg)
115 {
116 sdb_log(SDB_LOG_ERR, "frontend: parse error: %s", msg);
117 } /* sdb_fe_yyerror */
119 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */