Code

Include config.h in source files.
[sysdb.git] / src / frontend / grammar.y
index ef88272d6b237f9885ca30761891ca3e00ab9437..e6c627b3a4b966e288c9aadbbcf02ddfea5e0eb6 100644 (file)
 
 %{
 
+#include "frontend/connection.h"
 #include "frontend/parser.h"
 #include "frontend/grammar.h"
+
 #include "utils/error.h"
+#include "utils/llist.h"
 
 #include <stdio.h>
 
+int
+sdb_fe_yylex(YYSTYPE *yylval, YYLTYPE *yylloc, sdb_fe_yyscan_t yyscanner);
+
+sdb_fe_yyextra_t *
+sdb_fe_yyget_extra(sdb_fe_yyscan_t scanner);
+
 void
 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 
+/* quick access to the current parse tree */
+#define pt sdb_fe_yyget_extra(scanner)->parsetree
+
 %}
 
 %pure-parser
@@ -46,35 +58,58 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 %expect 0
 %name-prefix="sdb_fe_yy"
 
+%union {
+       sdb_llist_t     *list;
+       sdb_conn_node_t *node;
+}
+
 %start statements
 
 %token SCANNER_ERROR
 
 %token IDENTIFIER
-%token LIST
+%token <node> LIST
+
+%type <list> statements
+%type <node> statement
+       list_statement
 
 %%
 
 statements:
        statements ';' statement
                {
+                       if ($3) {
+                               sdb_llist_append(pt, SDB_OBJ($3));
+                               sdb_object_deref(SDB_OBJ($3));
+                       }
                }
        |
        statement
                {
+                       if ($1) {
+                               sdb_llist_append(pt, SDB_OBJ($1));
+                               sdb_object_deref(SDB_OBJ($1));
+                       }
                }
        ;
 
 statement:
        list_statement
-               {
-               }
        |
        /* empty */
+               {
+                       $$ = NULL;
+               }
        ;
 
 list_statement:
        LIST
+               {
+                       $$ = SDB_CONN_NODE(sdb_object_create_T(/* name = */ NULL,
+                                               sdb_conn_node_t));
+                       ((sdb_conn_node_t *)$$)->cmd = CONNECTION_LIST;
+               }
        ;
 
 %%