diff options
author | Pavel Machek <pavel@ucw.cz> | 2000-05-15 12:27:45 +0000 |
---|---|---|
committer | Pavel Machek <pavel@ucw.cz> | 2000-05-15 12:27:45 +0000 |
commit | c5a06f65ee20328b8d0f2276287e223e4fd4a595 (patch) | |
tree | 2b6aa28cd22fe7e54481d1cd5727564bc34fd204 /filter | |
parent | f4ab23174688920e44bb4cae6e8b4f280a066e28 (diff) |
Allow other operations than +.
Diffstat (limited to 'filter')
-rw-r--r-- | filter/config.Y | 3 | ||||
-rw-r--r-- | filter/filter.c | 18 | ||||
-rw-r--r-- | filter/test.conf | 4 |
3 files changed, 23 insertions, 2 deletions
diff --git a/filter/config.Y b/filter/config.Y index 0d1d716f..a99e4a54 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -334,6 +334,9 @@ function_call: term: '(' term ')' { $$ = $2; } | term '+' term { $$ = f_new_inst(); $$->code = '+'; $$->a1.p = $1; $$->a2.p = $3; } + | term '-' term { $$ = f_new_inst(); $$->code = '-'; $$->a1.p = $1; $$->a2.p = $3; } + | term '*' term { $$ = f_new_inst(); $$->code = '*'; $$->a1.p = $1; $$->a2.p = $3; } + | term '/' term { $$ = f_new_inst(); $$->code = '/'; $$->a1.p = $1; $$->a2.p = $3; } | term '=' term { $$ = f_new_inst(); $$->code = P('=','='); $$->a1.p = $1; $$->a2.p = $3; } | term NEQ term { $$ = f_new_inst(); $$->code = P('!','='); $$->a1.p = $1; $$->a2.p = $3; } | term '<' term { $$ = f_new_inst(); $$->code = '<'; $$->a1.p = $1; $$->a2.p = $3; } diff --git a/filter/filter.c b/filter/filter.c index 84680c66..344368e6 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -230,6 +230,22 @@ interpret(struct f_inst *what) default: runtime( "Usage of unknown type" ); } break; + case '-': + TWOARGS_C; + switch (res.type = v1.type) { + case T_VOID: runtime( "Can not operate with values of type void" ); + case T_INT: res.val.i = v1.val.i - v2.val.i; break; + default: runtime( "Usage of unknown type" ); + } + break; + case '*': + TWOARGS_C; + switch (res.type = v1.type) { + case T_VOID: runtime( "Can not operate with values of type void" ); + case T_INT: res.val.i = v1.val.i * v2.val.i; break; + default: runtime( "Usage of unknown type" ); + } + break; case '/': TWOARGS_C; switch (res.type = v1.type) { @@ -582,6 +598,8 @@ i_same(struct f_inst *f1, struct f_inst *f2) switch(f1->code) { case ',': /* fall through */ case '+': + case '-': + case '*': case '/': case P('!','='): case P('=','='): diff --git a/filter/test.conf b/filter/test.conf index d734d57c..bce8cfec 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -6,7 +6,7 @@ router id 62.168.0.1; -define xyzzy = 120+10; +#define xyzzy = 120+10; function callme(int arg1; int arg2) int local1; @@ -75,7 +75,7 @@ ip p; { print "Testing filter language:"; i = four; - i = 1230 + i; + i = 12*100 + 60/2 + i; i = ( i + 0 ); print " arithmetics: 1234 = ", i; printn " if statements "; |