1999-01-16 00:49:17 +08:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
|
1999-01-16 02:04:28 +08:00
|
|
|
%type <x> term
|
1999-03-03 03:49:28 +08:00
|
|
|
%type <x> cmds
|
1999-01-16 00:49:17 +08:00
|
|
|
|
|
|
|
CF_GRAMMAR
|
|
|
|
|
|
|
|
CF_ADDTO(conf, function)
|
|
|
|
function:
|
1999-03-03 03:49:28 +08:00
|
|
|
FUNCTION SYM '(' ')' '{' cmds '}' {
|
1999-01-16 00:49:17 +08:00
|
|
|
extern struct f_instruction *last_func;
|
|
|
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
|
|
|
$2->class = SYM_FUNCTION;
|
1999-03-03 03:49:28 +08:00
|
|
|
$2->def = $6;
|
1999-01-16 00:49:17 +08:00
|
|
|
last_func = $6;
|
|
|
|
printf("Hmm, we've got one function here\n");
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
CF_ADDTO(conf, filter)
|
|
|
|
filter:
|
1999-03-03 03:49:28 +08:00
|
|
|
FILTER SYM '{' cmds '}' {
|
1999-01-16 00:49:17 +08:00
|
|
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
|
|
|
$2->class = SYM_FILTER;
|
1999-03-03 03:49:28 +08:00
|
|
|
$2->def = $4;
|
1999-01-16 00:49:17 +08:00
|
|
|
printf( "We have new filter defined (%s)\n", $2->name )
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Programs */
|
|
|
|
|
1999-03-03 03:49:28 +08:00
|
|
|
cmds:
|
|
|
|
term {
|
|
|
|
if ($1) {
|
|
|
|
$1->next = NULL;
|
|
|
|
$$ = $1;
|
|
|
|
} else $$ = NULL;
|
|
|
|
}
|
|
|
|
| term ';' cmds {
|
|
|
|
if ($1) {
|
|
|
|
$1->next = $3;
|
|
|
|
$$ = $1;
|
|
|
|
} else $$ = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
term:
|
|
|
|
/* EMPTY */ {
|
|
|
|
$$ = NULL;
|
1999-01-16 00:49:17 +08:00
|
|
|
}
|
1999-02-03 20:28:16 +08:00
|
|
|
| INT SYM {
|
1999-01-16 00:49:17 +08:00
|
|
|
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;
|
|
|
|
}
|
1999-01-16 02:04:28 +08:00
|
|
|
| SYM '=' expr {
|
1999-03-03 03:49:28 +08:00
|
|
|
$$ = f_new_inst();
|
1999-01-16 00:49:17 +08:00
|
|
|
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 ')' {
|
1999-03-03 03:49:28 +08:00
|
|
|
$$ = f_new_inst();
|
1999-01-16 00:49:17 +08:00
|
|
|
printf( "Ook, we'll print something\n" );
|
|
|
|
$$->code = 'p';
|
|
|
|
$$->arg1 = $3;
|
|
|
|
$$->arg2 = NULL;
|
|
|
|
}
|
|
|
|
| PRINTDEBUG {
|
1999-03-03 03:49:28 +08:00
|
|
|
$$ = f_new_inst();
|
1999-01-16 00:49:17 +08:00
|
|
|
$$->code = 'D';
|
|
|
|
$$->arg1 = $$->arg2 = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
CF_END
|