blob: 73a75888a84b9282099a251887a8d798e127cab3 (
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
|
/*
* BIRD - filters
*
* Copyright 1998 Pavel Machek
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
CF_HDR
#include "nest/bird.h"
#include "filter/filter.h"
#include "lib/resource.h"
#include "lib/socket.h"
#include "lib/timer.h"
#include "nest/protocol.h"
#include "nest/iface.h"
#include "nest/route.h"
CF_DECLS
CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT)
%type <x> term
%type <x> cmds
CF_GRAMMAR
CF_ADDTO(conf, function)
function:
FUNCTION SYM '(' ')' '{' cmds '}' {
extern struct f_instruction *last_func;
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
$2->class = SYM_FUNCTION;
$2->def = $6;
last_func = $6;
printf("Hmm, we've got one function here\n");
}
;
CF_ADDTO(conf, filter)
filter:
FILTER SYM '{' cmds '}' {
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
$2->class = SYM_FILTER;
$2->def = $4;
printf( "We have new filter defined (%s)\n", $2->name )
}
;
/* Programs */
cmds:
term {
if ($1) {
$1->next = NULL;
$$ = $1;
} else $$ = NULL;
}
| term ';' cmds {
if ($1) {
$1->next = $3;
$$ = $1;
} else $$ = $3;
}
;
term:
/* EMPTY */ {
$$ = NULL;
}
| INT SYM {
if ($2->class != SYM_VOID) cf_error("Symbol already defined, can not use as variable\n" );
$2->class = SYM_VARIABLE_INT;
printf( "New variable\n" );
$$ = NULL;
}
| SYM '=' expr {
$$ = f_new_inst();
printf( "Ook, we'll set value\n" );
if ($1->class != SYM_VARIABLE_INT)
cf_error( "You may only set variables\n" );
$$->code = '=';
$$->arg1 = $1;
$$->arg2 = $3;
}
| PRINT '(' SYM ')' {
$$ = f_new_inst();
printf( "Ook, we'll print something\n" );
$$->code = 'p';
$$->arg1 = $3;
$$->arg2 = NULL;
}
| PRINTDEBUG {
$$ = f_new_inst();
$$->code = 'D';
$$->arg1 = $$->arg2 = NULL;
}
;
CF_END
|