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 int
40 sdb_fe_yylex(YYSTYPE *yylval, YYLTYPE *yylloc, sdb_fe_yyscan_t yyscanner);
42 sdb_fe_yyextra_t *
43 sdb_fe_yyget_extra(sdb_fe_yyscan_t scanner);
45 void
46 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
48 /* quick access to the current parse tree */
49 #define pt sdb_fe_yyget_extra(scanner)->parsetree
51 %}
53 %pure-parser
54 %lex-param {sdb_fe_yyscan_t scanner}
55 %parse-param {sdb_fe_yyscan_t scanner}
56 %locations
57 %error-verbose
58 %expect 0
59 %name-prefix="sdb_fe_yy"
61 %union {
62 sdb_llist_t *list;
63 sdb_conn_node_t *node;
64 }
66 %start statements
68 %token SCANNER_ERROR
70 %token IDENTIFIER
71 %token <node> LIST
73 %type <list> statements
74 %type <node> statement
75 list_statement
77 %%
79 statements:
80 statements ';' statement
81 {
82 if ($3) {
83 sdb_llist_append(pt, SDB_OBJ($3));
84 sdb_object_deref(SDB_OBJ($3));
85 }
86 }
87 |
88 statement
89 {
90 if ($1) {
91 sdb_llist_append(pt, SDB_OBJ($1));
92 sdb_object_deref(SDB_OBJ($1));
93 }
94 }
95 ;
97 statement:
98 list_statement
99 |
100 /* empty */
101 {
102 $$ = NULL;
103 }
104 ;
106 list_statement:
107 LIST
108 {
109 $$ = SDB_CONN_NODE(sdb_object_create_T(/* name = */ NULL,
110 sdb_conn_node_t));
111 ((sdb_conn_node_t *)$$)->cmd = CONNECTION_LIST;
112 }
113 ;
115 %%
117 void
118 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg)
119 {
120 sdb_log(SDB_LOG_ERR, "frontend: parse error: %s", msg);
121 } /* sdb_fe_yyerror */
123 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */