Add interface for running filters (please comment!), avoid bison warnings
This commit is contained in:
parent
05a845ed8e
commit
84c7e1943f
3 changed files with 59 additions and 20 deletions
|
@ -22,20 +22,17 @@ CF_DECLS
|
||||||
CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT)
|
CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT)
|
||||||
|
|
||||||
%type <x> term
|
%type <x> term
|
||||||
|
%type <x> cmds
|
||||||
|
|
||||||
CF_GRAMMAR
|
CF_GRAMMAR
|
||||||
|
|
||||||
program: /* EMPTY */
|
|
||||||
| program function
|
|
||||||
;
|
|
||||||
|
|
||||||
CF_ADDTO(conf, function)
|
CF_ADDTO(conf, function)
|
||||||
function:
|
function:
|
||||||
FUNCTION SYM '(' ')' '{' term '}' {
|
FUNCTION SYM '(' ')' '{' cmds '}' {
|
||||||
extern struct f_instruction *last_func;
|
extern struct f_instruction *last_func;
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
||||||
$2->class = SYM_FUNCTION;
|
$2->class = SYM_FUNCTION;
|
||||||
$2->aux = $6;
|
$2->def = $6;
|
||||||
last_func = $6;
|
last_func = $6;
|
||||||
printf("Hmm, we've got one function here\n");
|
printf("Hmm, we've got one function here\n");
|
||||||
}
|
}
|
||||||
|
@ -43,23 +40,34 @@ function:
|
||||||
|
|
||||||
CF_ADDTO(conf, filter)
|
CF_ADDTO(conf, filter)
|
||||||
filter:
|
filter:
|
||||||
FILTER SYM '{' term '}' {
|
FILTER SYM '{' cmds '}' {
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
||||||
$2->class = SYM_FILTER;
|
$2->class = SYM_FILTER;
|
||||||
$2->aux = $4;
|
$2->def = $4;
|
||||||
printf( "We have new filter defined (%s)\n", $2->name )
|
printf( "We have new filter defined (%s)\n", $2->name )
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Programs */
|
/* Programs */
|
||||||
|
|
||||||
term: /* EMPTY */ { $$ = NULL; }
|
cmds:
|
||||||
| term ';' term {
|
term {
|
||||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
if ($1) {
|
||||||
printf( "We've got statement here\n" );
|
$1->next = NULL;
|
||||||
$$->code = ',';
|
$$ = $1;
|
||||||
$$->arg1 = $1;
|
} else $$ = NULL;
|
||||||
$$->arg2 = $3;
|
}
|
||||||
|
| term ';' cmds {
|
||||||
|
if ($1) {
|
||||||
|
$1->next = $3;
|
||||||
|
$$ = $1;
|
||||||
|
} else $$ = $3;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
term:
|
||||||
|
/* EMPTY */ {
|
||||||
|
$$ = NULL;
|
||||||
}
|
}
|
||||||
| INT SYM {
|
| INT SYM {
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined, can not use as variable\n" );
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined, can not use as variable\n" );
|
||||||
|
@ -68,7 +76,7 @@ term: /* EMPTY */ { $$ = NULL; }
|
||||||
$$ = NULL;
|
$$ = NULL;
|
||||||
}
|
}
|
||||||
| SYM '=' expr {
|
| SYM '=' expr {
|
||||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
$$ = f_new_inst();
|
||||||
printf( "Ook, we'll set value\n" );
|
printf( "Ook, we'll set value\n" );
|
||||||
if ($1->class != SYM_VARIABLE_INT)
|
if ($1->class != SYM_VARIABLE_INT)
|
||||||
cf_error( "You may only set variables\n" );
|
cf_error( "You may only set variables\n" );
|
||||||
|
@ -77,14 +85,14 @@ term: /* EMPTY */ { $$ = NULL; }
|
||||||
$$->arg2 = $3;
|
$$->arg2 = $3;
|
||||||
}
|
}
|
||||||
| PRINT '(' SYM ')' {
|
| PRINT '(' SYM ')' {
|
||||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
$$ = f_new_inst();
|
||||||
printf( "Ook, we'll print something\n" );
|
printf( "Ook, we'll print something\n" );
|
||||||
$$->code = 'p';
|
$$->code = 'p';
|
||||||
$$->arg1 = $3;
|
$$->arg1 = $3;
|
||||||
$$->arg2 = NULL;
|
$$->arg2 = NULL;
|
||||||
}
|
}
|
||||||
| PRINTDEBUG {
|
| PRINTDEBUG {
|
||||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
$$ = f_new_inst();
|
||||||
$$->code = 'D';
|
$$->code = 'D';
|
||||||
$$->arg1 = $$->arg2 = NULL;
|
$$->arg1 = $$->arg2 = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ interpret(struct f_instruction *what)
|
||||||
{
|
{
|
||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
if (!what)
|
if (!what)
|
||||||
return 0;
|
return;
|
||||||
switch(what->code) {
|
switch(what->code) {
|
||||||
case ',':
|
case ',':
|
||||||
interpret(what->arg1);
|
interpret(what->arg1);
|
||||||
|
@ -36,7 +36,7 @@ interpret(struct f_instruction *what)
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
sym = what->arg1;
|
sym = what->arg1;
|
||||||
sym->aux = what->arg2;
|
sym->aux = (int) what->arg2;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
sym = what->arg1;
|
sym = what->arg1;
|
||||||
|
@ -52,7 +52,11 @@ interpret(struct f_instruction *what)
|
||||||
case 'D':
|
case 'D':
|
||||||
printf( "DEBUGGING PRINT\n" );
|
printf( "DEBUGGING PRINT\n" );
|
||||||
break;
|
break;
|
||||||
|
case '0':
|
||||||
|
printf( "No operation\n" );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
interpret(what->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -65,3 +69,24 @@ filters_postconfig(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct f_instruction *
|
||||||
|
f_new_inst(void)
|
||||||
|
{
|
||||||
|
struct f_instruction * ret;
|
||||||
|
ret = cfg_alloc(sizeof(struct f_instruction));
|
||||||
|
ret->code = 0;
|
||||||
|
ret->arg1 = ret->arg2 = ret->next = NULL;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
f_run(struct symbol *filter, struct rte *rtein, struct rte **rteout)
|
||||||
|
{
|
||||||
|
struct f_instruction *inst;
|
||||||
|
debug( "Running filter `%s'...", filter->name );
|
||||||
|
|
||||||
|
inst = filter->def;
|
||||||
|
interpret(inst);
|
||||||
|
debug( "done\n" );
|
||||||
|
return F_ACCEPT;
|
||||||
|
}
|
||||||
|
|
|
@ -14,10 +14,16 @@
|
||||||
/* Lexer */
|
/* Lexer */
|
||||||
|
|
||||||
struct f_instruction {
|
struct f_instruction {
|
||||||
|
struct f_instruction *next; /* Structure is 16 bytes, anyway */
|
||||||
int code;
|
int code;
|
||||||
void *arg1, *arg2;
|
void *arg1, *arg2;
|
||||||
};
|
};
|
||||||
|
|
||||||
void filters_postconfig(void);
|
void filters_postconfig(void);
|
||||||
|
struct f_instruction *f_new_inst(void);
|
||||||
|
|
||||||
|
#define F_ACCEPT 1
|
||||||
|
#define F_REJECT 2
|
||||||
|
#define F_MODIFY 3
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue