summaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-03-19 14:53:07 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-03-19 14:53:07 +0000
commitd55f73ddbb0dc099b1471f3493e505142ce94a97 (patch)
tree7d4bcc778ed6f35fe043962b29873cff9ef9e24c /parse.y
downloadlibcg-d55f73ddbb0dc099b1471f3493e505142ce94a97.tar.gz
libcg-d55f73ddbb0dc099b1471f3493e505142ce94a97.tar.xz
libcg-d55f73ddbb0dc099b1471f3493e505142ce94a97.zip
First initial revision. Look for TODOs and BUGs
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/src@1 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y257
1 files changed, 257 insertions, 0 deletions
diff --git a/parse.y b/parse.y
new file mode 100644
index 0000000..fe7d5fe
--- /dev/null
+++ b/parse.y
@@ -0,0 +1,257 @@
+/*
+ * Copyright IBM Corporation. 2007
+ *
+ * Authors: Balbir Singh <balbir@linux.vnet.ibm.com>
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * NOTE: The grammar has been modified, not to be the most efficient, but
+ * to allow easy updation of internal data structures.
+ */
+%{
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <libcg.h>
+
+int yylex(void);
+extern int line_no;
+extern char *yytext;
+
+void yyerror(char *s)
+{
+ fprintf(stderr, "error at line number %d at %c:%s", line_no, *yytext,
+ s);
+}
+
+int yywrap(void)
+{
+ return 1;
+}
+
+%}
+
+%token ID MOUNT GROUP PERM TASK ADMIN
+
+%union {
+ char *name;
+ char chr;
+ int val;
+}
+%type <name> ID namevalue_conf
+%type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
+%type <val> admin_conf task_conf task_or_admin group_conf group start
+%start start
+%%
+
+start : start group
+ {
+ $$ = $1;
+ }
+ | start mount
+ {
+ $$ = $1;
+ }
+ |
+ {
+ $$ = 1;
+ }
+ ;
+
+group : GROUP ID '{' group_conf '}'
+ {
+ $$ = $4;
+ if ($$)
+ cg_insert_group($2);
+ else {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+group_conf
+ : ID '{' namevalue_conf '}'
+ {
+ $$ = cg_parse_controller_options($1, $3);
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ | group_conf ID '{' namevalue_conf '}'
+ {
+ $$ = cg_parse_controller_options($2, $4);
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ | PERM '{' task_or_admin '}'
+ {
+ $$ = $3;
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+namevalue_conf
+ : ID '=' ID ';'
+ {
+ $1 = realloc($1, strlen($1) + strlen($3) + 2);
+ $1 = strncat($1, " ", strlen(" "));
+ $$ = strncat($1, $3, strlen($3));
+ free($3);
+ }
+ | namevalue_conf ID '=' ID ';'
+ {
+ $2 = realloc($2, strlen($2) + strlen($4) + 2);
+ $2 = strncat($2, " ", strlen(" "));
+ $$ = strncat($2, $4, strlen($4));
+ free($4);
+ }
+ ;
+
+task_namevalue_conf
+ : ID '=' ID ';'
+ {
+ $$ = cg_group_task_perm($1, $3);
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ | task_namevalue_conf ID '=' ID ';'
+ {
+ $$ = $1 && cg_group_task_perm($2, $4);
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+admin_namevalue_conf
+ : ID '=' ID ';'
+ {
+ $$ = cg_group_admin_perm($1, $3);
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ | admin_namevalue_conf ID '=' ID ';'
+ {
+ $$ = $1 && cg_group_admin_perm($2, $4);
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+task_or_admin
+ : TASK '{' task_namevalue_conf '}' admin_conf
+ {
+ $$ = $3 && $5;
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ | ADMIN '{' admin_namevalue_conf '}' task_conf
+ {
+ $$ = $3 && $5;
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+admin_conf: ADMIN '{' admin_namevalue_conf '}'
+ {
+ $$ = $3;
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+task_conf: TASK '{' task_namevalue_conf '}'
+ {
+ $$ = $3;
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+mountvalue_conf
+ : ID '=' ID ';'
+ {
+ if (!cg_insert_into_mount_table($1, $3)) {
+ cg_cleanup_mount_table();
+ $$ = 0;
+ return $$;
+ }
+ $$ = 1;
+ }
+ | mountvalue_conf ID '=' ID ';'
+ {
+ if (!cg_insert_into_mount_table($2, $4)) {
+ cg_cleanup_mount_table();
+ $$ = 0;
+ return $$;
+ }
+ $$ = 1;
+ }
+ ;
+
+mount : MOUNT '{' mountvalue_conf '}'
+ {
+ $$ = $3;
+ if (!$$) {
+ fprintf(stderr, "parsing failed at line number %d\n",
+ line_no);
+ $$ = 0;
+ return $$;
+ }
+ }
+ ;
+
+
+%%