%{ /* * This is a plug-in for the GIMP. * * Split up images according to a given formula. * * Copyright (C) 1999 Maurits Rijk lpeek.mrijk@consunet.nl * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include "expression.h" extern int yylex(); extern void yy_scan_string(const char*); static void yyerror(char* s); static Expression_t* l_formula; static guint l_width; static guint l_height; %} %union { int ival; double dval; Expression_t *exp; } %token X Y WIDTH HEIGHT %token ACOS ASIN ATAN ATAN2 SIN COS TAN COSH SINH TANH %token ABS MOD E_TOKEN PI_TOKEN RAND %token POW SQRT EXP LOG LOG10 LDEXP %token FLOOR CEIL RINT MIN MAX %token INT %token DOUBLE %type exp %left '-' '+' %left '*' '/' '%' %left NEG /* Negation--unary minus */ %right '^' /* Exponentiation */ %% formula: exp {l_formula = $1;} exp: DOUBLE {$$ = expression_num_new($1);} | INT {$$ = expression_num_new((double) $1);} | WIDTH {$$ = expression_num_new((double) l_width);} | HEIGHT {$$ = expression_num_new((double) l_height);} | X {$$ = expression_x_new();} | Y {$$ = expression_y_new();} | E_TOKEN {$$ = expression_num_new(M_E);} | PI_TOKEN {$$ = expression_num_new(M_PI);} | exp '+' exp {$$ = expression_add_new($1, $3);} | exp '-' exp {$$ = expression_sub_new($1, $3);} | exp '*' exp {$$ = expression_mul_new($1, $3);} | exp '/' exp {$$ = expression_div_new($1, $3);} | exp '%' exp {$$ = expression_mod_new($1, $3);} | exp '^' exp {$$ = expression_pow_new($1, $3);} | exp '^' '2' {$$ = expression_mul_new($1, $1);} | '-' exp %prec NEG {$$ = expression_neg_new($2);} | '(' exp ')' {$$ = $2;} | ABS '(' exp ')' {$$ = expression_abs_new($3);} | ACOS '(' exp ')' {$$ = expression_acos_new($3);} | ASIN '(' exp ')' {$$ = expression_asin_new($3);} | ATAN '(' exp ')' {$$ = expression_atan_new($3);} | ATAN2 '(' exp ')' {$$ = expression_atan2_new($3);} | CEIL '(' exp ')' {$$ = expression_ceil_new($3);} | COS '(' exp ')' {$$ = expression_cos_new($3);} | COSH '(' exp ')' {$$ = expression_cosh_new($3);} | EXP '(' exp ')' {$$ = expression_exp_new($3);} | FLOOR '(' exp ')' {$$ = expression_floor_new($3);} | LDEXP '(' exp ',' exp ')' {$$ = expression_ldexp_new($3, $5);} | LOG '(' exp ')' {$$ = expression_log_new($3);} | LOG10 '(' exp ')' {$$ = expression_log10_new($3);} | MAX '(' exp ',' exp ')' {$$ = expression_max_new($3, $5);} | MIN '(' exp ',' exp ')' {$$ = expression_min_new($3, $5);} | MOD '(' exp ',' exp ')' {$$ = expression_mod_new($3, $5);} | POW '(' exp ',' exp ')' {$$ = expression_pow_new($3, $5);} | RAND '(' ')' {$$ = expression_rand_new();} | RINT '(' exp ')' {$$ = expression_rint_new($3);} | SIN '(' exp ')' {$$ = expression_sin_new($3);} | SINH '(' exp ')' {$$ = expression_sinh_new($3);} | SQRT '(' exp ')' {$$ = expression_sqrt_new($3);} | TAN '(' exp ')' {$$ = expression_tan_new($3);} | TANH '(' exp ')' {$$ = expression_tanh_new($3);} ; %% static void yyerror(char* s) { if (l_formula) expression_destruct(l_formula); l_formula = NULL; } Expression_t* parse_formula(const char *formula, guint width, guint height) { l_width = width; l_height = height; yy_scan_string(formula); yyparse(); return l_formula; }