summaryrefslogtreecommitdiffstats
path: root/agents/virt/config/config.y
blob: 2ae038072122cbf8aa0a22deafca4af667e0eefe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%{
#include "config.h"
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <assert.h>
#include "config-stack.h"

extern int yylex (void);
int yyerror(const char *foo);

int
_sc_value_add(char *id, char *val, struct value **list)
{
	struct value *v;

	v = malloc(sizeof(*v));
	assert(v);

	memset(v, 0, sizeof(*v));
	v->id = id;
	v->val = val;
	//snprintf(v->id, sizeof(v->id), "%s", id);
	//snprintf(v->val, sizeof(v->val), "%s", val);
	//printf("add %s %s on to %p\n", id, val, *list);

	v->next = *list;
	*list = v;

	//printf("new list %p\n", *list);
	return 0;
}


int
_sc_node_add(char *id, char *val, struct value *vallist,
	     struct node *nodelist, struct node **list)
{
	struct node *n;

	n = malloc(sizeof(*n));
	assert(n);

	//printf("nodes %p values %p\n", nodelist, vallist);

	memset(n, 0, sizeof(*n));
	//snprintf(n->id, sizeof(n->id), "%s", id);
	n->id = id; /* malloc'd during parsing */
	n->val = val; /* malloc'd during parsing */
	n->values = vallist;
	n->nodes = nodelist;
	n->next = *list;
	*list = n;

	return 0;
}

%}

%token <sval> T_ID
%token <sval> T_VAL
%token T_OBRACE T_CBRACE T_EQ T_SEMI

%start stuff

%union {
	char *sval;
	int ival;
}

%%
node:
	T_ID T_OBRACE stuff T_CBRACE {
		struct parser_context *c = NULL;

		c = context_stack;
		_sc_node_add($1, NULL, val_list, node_list, &c->node_list);
		val_list = c->val_list;
		node_list = c->node_list;
        	context_stack = c->next;

		free(c);
	}
	|
	T_ID T_EQ T_VAL T_OBRACE stuff T_CBRACE {
		struct parser_context *c = NULL;

		c = context_stack;
		_sc_node_add($1, $3, val_list, node_list, &c->node_list);
		val_list = c->val_list;
		node_list = c->node_list;
        	context_stack = c->next;

		free(c);
	}
	|
	T_ID T_OBRACE T_CBRACE {
		struct parser_context *c = NULL;

		c = context_stack;
		_sc_node_add($1, NULL, val_list, node_list, &c->node_list);
		val_list = c->val_list;
		node_list = c->node_list;
        	context_stack = c->next;

		free(c);
	}
	|
	T_ID T_EQ T_VAL T_OBRACE T_CBRACE {
		struct parser_context *c = NULL;

		c = context_stack;
		_sc_node_add($1, $3, val_list, node_list, &c->node_list);
		val_list = c->val_list;
		node_list = c->node_list;
        	context_stack = c->next;

		free(c);
	}
	;

stuff:
	node stuff | assign stuff | node | assign
	;

assign:
	T_ID T_EQ T_VAL T_SEMI {
		_sc_value_add($1, $3, &val_list);
	}
	;
%%

extern int _line_count;

int
yyerror(const char *foo)
{
	printf("%s on line %d\n", foo, _line_count);
	return 0;
}