home *** CD-ROM | disk | FTP | other *** search
/ ftp.sunet.sepub/pictures / 2014.11.ftp.sunet.se-pictures.tar / ftp.sunet.se / pub / pictures / ACiD-artpacks / programs / unix / editors / gimp-plugins-unstable-0_99_23_tar.gz / gimp-plugins-unstable-0_99_23_tar / gimp-plugins-unstable-0.99.23 / user_filter / afsparse.y < prev    next >
Text File  |  1998-02-20  |  14KB  |  637 lines

  1. %{
  2. /*
  3.  * Written 1997 Jens Ch. Restemeier <jchrr@hrz.uni-bielefeld.de>
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20. #include <math.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <ctype.h>
  24.  
  25. #include "afstree.h"
  26. #include "afsparse.h"
  27.  
  28. #define YYSTYPE s_afstree *
  29.  
  30. s_afstree *afs_root;
  31.  
  32. int yyerror(char *s)
  33. {
  34.     return 0;
  35. }
  36.  
  37. s_afstree *get_afstree(char *s)
  38. {
  39.     do_parse(s);
  40.     return afs_root;
  41. }
  42. %}
  43.  
  44. %left t_comma
  45.  
  46. %right '?' ':'
  47.  
  48. %right t_abs
  49. %right t_add
  50. %right t_cnv
  51. %right t_ctl
  52. %right t_dif
  53. %right t_get
  54. %right t_put
  55. %right t_max
  56. %right t_min
  57. %right t_mix
  58. %right t_rnd
  59. %right t_scl
  60. %right t_sqr
  61. %right t_src
  62. %right t_sub
  63. %right t_val
  64. %right t_c2d
  65. %right t_c2m
  66. %right t_cos
  67. %right t_r2x
  68. %right t_r2y
  69. %right t_rad
  70. %right t_sin
  71. %right t_tan
  72.  
  73. %left '&' '|' '^'
  74. %right t_and
  75. %right t_or
  76. %right t_eq
  77. %right t_neq
  78. %right t_le
  79. %right t_be
  80. %right t_shl
  81. %right t_shr
  82.  
  83. %left LE BE NE '<' '>'
  84. %left '+' '-'
  85. %left '*' '/' '%'
  86. %left ','
  87. %token '(' ')'
  88.  
  89. %left t_sign '!' '~'
  90.  
  91. %token 'r' 'g' 'b' 'a' 'c' 'x' 'y' 'X' 'Y' 'i' 'u' 'v' 'z' 'Z' 'd' 'D' 'm' 'M' t_mmin t_dmin
  92.  
  93. %token v_int
  94.  
  95. %%
  96.  
  97. /****************************************************************************/
  98.  
  99. input:  { 
  100.         afs_root=NULL; 
  101.         YYABORT; 
  102.     }
  103.     | exp {
  104.         afs_root=$1;
  105.         YYACCEPT;
  106.     }
  107.     ;
  108.  
  109.  
  110. exp:    v_int            { $$ = $1; }
  111.     | 'r' { 
  112.         $$ = malloc(sizeof(s_afstree));
  113.         $$->op_type=OP_VAR_r;
  114.         $$->value=0;
  115.         $$->nodes=NULL;
  116.     }
  117.     | 'g' { 
  118.         $$ = malloc(sizeof(s_afstree));
  119.         $$->op_type=OP_VAR_g;
  120.         $$->value=0;
  121.         $$->nodes=NULL;
  122.     }
  123.     | 'b' { 
  124.         $$ = malloc(sizeof(s_afstree));
  125.         $$->op_type=OP_VAR_b;
  126.         $$->value=0;
  127.         $$->nodes=NULL;
  128.     }
  129.     | 'a' { 
  130.         $$ = malloc(sizeof(s_afstree));
  131.         $$->op_type=OP_VAR_a;
  132.         $$->value=0;
  133.         $$->nodes=NULL;
  134.     }
  135.     | 'c' { 
  136.         $$ = malloc(sizeof(s_afstree));
  137.         $$->op_type=OP_VAR_c;
  138.         $$->value=0;
  139.         $$->nodes=NULL;
  140.     }
  141.     | 'x' { 
  142.         $$ = malloc(sizeof(s_afstree));
  143.         $$->op_type=OP_VAR_x;
  144.         $$->value=0;
  145.         $$->nodes=NULL;
  146.     }
  147.     | 'y' { 
  148.         $$ = malloc(sizeof(s_afstree));
  149.         $$->op_type=OP_VAR_y;
  150.         $$->value=0;
  151.         $$->nodes=NULL;
  152.     }
  153.     | 'z' { 
  154.         $$ = malloc(sizeof(s_afstree));
  155.         $$->op_type=OP_VAR_z;
  156.         $$->value=0;
  157.         $$->nodes=NULL;
  158.     }
  159.     | 'X' { 
  160.         $$ = malloc(sizeof(s_afstree));
  161.         $$->op_type=OP_VAR_X;
  162.         $$->value=0;
  163.         $$->nodes=NULL;
  164.     }
  165.     | 'Y' { 
  166.         $$ = malloc(sizeof(s_afstree));
  167.         $$->op_type=OP_VAR_Y;
  168.         $$->value=0;
  169.         $$->nodes=NULL;
  170.     }
  171.     | 'Z' { 
  172.         $$ = malloc(sizeof(s_afstree));
  173.         $$->op_type=OP_VAR_Z;
  174.         $$->value=0;
  175.         $$->nodes=NULL;
  176.     }
  177.     | 'i' { 
  178.         $$ = malloc(sizeof(s_afstree));
  179.         $$->op_type=OP_VAR_i;
  180.         $$->value=0;
  181.         $$->nodes=NULL;
  182.     }
  183.     | 'u' { 
  184.         $$ = malloc(sizeof(s_afstree));
  185.         $$->op_type=OP_VAR_u;
  186.         $$->value=0;
  187.         $$->nodes=NULL;
  188.     }
  189.     | 'v' { 
  190.         $$ = malloc(sizeof(s_afstree));
  191.         $$->op_type=OP_VAR_v;
  192.         $$->value=0;
  193.         $$->nodes=NULL;
  194.     }
  195.     | 'd' { 
  196.         $$ = malloc(sizeof(s_afstree));
  197.         $$->op_type=OP_VAR_d;
  198.         $$->value=0;
  199.         $$->nodes=NULL;
  200.     }
  201.     | 'D' { 
  202.         $$ = malloc(sizeof(s_afstree));
  203.         $$->op_type=OP_VAR_D;
  204.         $$->value=0;
  205.         $$->nodes=NULL;
  206.     }
  207.     | 'm' { 
  208.         $$ = malloc(sizeof(s_afstree));
  209.         $$->op_type=OP_VAR_m;
  210.         $$->value=0;
  211.         $$->nodes=NULL;
  212.     }
  213.     | 'M' { 
  214.         $$ = malloc(sizeof(s_afstree));
  215.         $$->op_type=OP_VAR_M;
  216.         $$->value=0;
  217.         $$->nodes=NULL;
  218.     }
  219.     | t_dmin { 
  220.         $$ = malloc(sizeof(s_afstree));
  221.         $$->op_type=OP_VAR_dmin;
  222.         $$->value=0;
  223.         $$->nodes=NULL;
  224.     }
  225.     | t_mmin { 
  226.         $$ = malloc(sizeof(s_afstree));
  227.         $$->op_type=OP_VAR_mmin;
  228.         $$->value=0;
  229.         $$->nodes=NULL;
  230.     }
  231.         | exp '+' exp        { 
  232.         $$ = malloc(sizeof(s_afstree));
  233.         $$->op_type=OP_ADD;
  234.         $$->value=2;
  235.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  236.         $$->nodes[0]=$1;
  237.         $$->nodes[1]=$3;
  238.     }
  239.         | exp '-' exp        { 
  240.         $$ = malloc(sizeof(s_afstree));
  241.         $$->op_type=OP_SUB;
  242.         $$->value=2;
  243.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  244.         $$->nodes[0]=$1;
  245.         $$->nodes[1]=$3;
  246.     }
  247.         | exp '*' exp        { 
  248.         $$ = malloc(sizeof(s_afstree));
  249.         $$->op_type=OP_MUL;
  250.         $$->value=2;
  251.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  252.         $$->nodes[0]=$1;
  253.         $$->nodes[1]=$3;
  254.     }
  255.         | exp '/' exp { 
  256.         $$ = malloc(sizeof(s_afstree));
  257.         $$->op_type=OP_DIV;
  258.         $$->value=2;
  259.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  260.         $$->nodes[0]=$1;
  261.         $$->nodes[1]=$3;
  262.     } 
  263.         | exp '%' exp { 
  264.         $$ = malloc(sizeof(s_afstree));
  265.         $$->op_type=OP_MOD;
  266.         $$->value=2;
  267.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  268.         $$->nodes[0]=$1;
  269.         $$->nodes[1]=$3;
  270.     } 
  271.         | exp '^' exp { 
  272.         $$ = malloc(sizeof(s_afstree));
  273.         $$->op_type=OP_B_XOR;
  274.         $$->value=2;
  275.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  276.         $$->nodes[0]=$1;
  277.         $$->nodes[1]=$3;
  278.     } 
  279.         | exp '&' exp { 
  280.         $$ = malloc(sizeof(s_afstree));
  281.         $$->op_type=OP_B_AND;
  282.         $$->value=2;
  283.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  284.         $$->nodes[0]=$1;
  285.         $$->nodes[1]=$3;
  286.     } 
  287.         | exp '|' exp { 
  288.         $$ = malloc(sizeof(s_afstree));
  289.         $$->op_type=OP_B_OR;
  290.         $$->value=2;
  291.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  292.         $$->nodes[0]=$1;
  293.         $$->nodes[1]=$3;
  294.     } 
  295.         | '~' exp { 
  296.         $$ = malloc(sizeof(s_afstree));
  297.         $$->op_type=OP_B_NOT;
  298.         $$->value=1;
  299.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  300.         $$->nodes[0]=$2;
  301.     } 
  302.         | '-' exp %prec t_sign    { 
  303.         $$ = malloc(sizeof(s_afstree));
  304.         $$->op_type=OP_SUB;
  305.         $$->value=2;
  306.         $$->nodes=malloc(2*sizeof(s_afstree *));
  307.         $$->nodes[0]=malloc(sizeof(s_afstree));
  308.         $$->nodes[0]->op_type=OP_CONST;
  309.         $$->nodes[0]->value=0;
  310.         $$->nodes[0]->nodes=NULL;
  311.         $$->nodes[1]=$2;
  312.     }         
  313.         | exp '?' exp ':' exp   { 
  314.         $$ = malloc(sizeof(s_afstree));
  315.         $$->op_type=OP_COND;
  316.         $$->value=3;
  317.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  318.         $$->nodes[0]=$1;
  319.         $$->nodes[1]=$3;
  320.         $$->nodes[2]=$5;
  321.     }
  322.     | exp t_and exp { 
  323.         $$ = malloc(sizeof(s_afstree));
  324.         $$->op_type=OP_AND;
  325.         $$->value=2;
  326.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  327.         $$->nodes[0]=$1;
  328.         $$->nodes[1]=$3;
  329.     }
  330.     | exp t_or exp { 
  331.         $$ = malloc(sizeof(s_afstree));
  332.         $$->op_type=OP_OR;
  333.         $$->value=2;
  334.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  335.         $$->nodes[0]=$1;
  336.         $$->nodes[1]=$3;
  337.     }
  338.     | exp t_eq exp { 
  339.         $$ = malloc(sizeof(s_afstree));
  340.         $$->op_type=OP_EQ;
  341.         $$->value=2;
  342.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  343.         $$->nodes[0]=$1;
  344.         $$->nodes[1]=$3;
  345.     }
  346.     | exp t_neq exp { 
  347.         $$ = malloc(sizeof(s_afstree));
  348.         $$->op_type=OP_NEQ;
  349.         $$->value=2;
  350.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  351.         $$->nodes[0]=$1;
  352.         $$->nodes[1]=$3;
  353.     }
  354.     | exp t_le exp { 
  355.         $$ = malloc(sizeof(s_afstree));
  356.         $$->op_type=OP_LE;
  357.         $$->value=2;
  358.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  359.         $$->nodes[0]=$1;
  360.         $$->nodes[1]=$3;
  361.     }
  362.     | exp t_be exp { 
  363.         $$ = malloc(sizeof(s_afstree));
  364.         $$->op_type=OP_BE;
  365.         $$->value=2;
  366.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  367.         $$->nodes[0]=$1;
  368.         $$->nodes[1]=$3;
  369.     }
  370.     | exp '<' exp { 
  371.         $$ = malloc(sizeof(s_afstree));
  372.         $$->op_type=OP_LT;
  373.         $$->value=2;
  374.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  375.         $$->nodes[0]=$1;
  376.         $$->nodes[1]=$3;
  377.     }
  378.     | exp '>' exp { 
  379.         $$ = malloc(sizeof(s_afstree));
  380.         $$->op_type=OP_BT;
  381.         $$->value=2;
  382.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  383.         $$->nodes[0]=$1;
  384.         $$->nodes[1]=$3;
  385.     }
  386.     | '!' exp { 
  387.         $$ = malloc(sizeof(s_afstree));
  388.         $$->op_type=OP_NOT;
  389.         $$->value=1;
  390.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  391.         $$->nodes[0]=$2;
  392.     }
  393.     | exp t_shl exp { 
  394.         $$ = malloc(sizeof(s_afstree));
  395.         $$->op_type=OP_SHL;
  396.         $$->value=1;
  397.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  398.         $$->nodes[0]=$1;
  399.         $$->nodes[1]=$3;
  400.     }
  401.     | exp t_shr exp { 
  402.         $$ = malloc(sizeof(s_afstree));
  403.         $$->op_type=OP_SHR;
  404.         $$->value=2;
  405.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  406.         $$->nodes[0]=$1;
  407.         $$->nodes[1]=$3;
  408.     }
  409.     | exp t_comma exp { 
  410.         $$ = malloc(sizeof(s_afstree));
  411.         $$->op_type=OP_COMMA ;
  412.         $$->value=2;
  413.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  414.         $$->nodes[0]=$1;
  415.         $$->nodes[1]=$3;
  416.     }
  417.     | t_src '(' exp ',' exp ',' exp ')' { 
  418.         $$ = malloc(sizeof(s_afstree));
  419.         $$->op_type=F_SRC;
  420.         $$->value=3;
  421.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  422.         $$->nodes[0]=$3;
  423.         $$->nodes[1]=$5;
  424.         $$->nodes[2]=$7;
  425.     }
  426.     | t_rad '(' exp ',' exp ',' exp ')' { 
  427.         $$ = malloc(sizeof(s_afstree));
  428.         $$->op_type=F_RAD;
  429.         $$->value=3;
  430.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  431.         $$->nodes[0]=$3;
  432.         $$->nodes[1]=$5;
  433.         $$->nodes[2]=$7;
  434.     }
  435.     | t_cnv '(' exp ',' exp ',' exp ',' exp ',' exp ',' exp ',' exp ',' exp ',' exp ',' exp  ')' { 
  436.         $$ = malloc(sizeof(s_afstree));
  437.         $$->op_type=F_CNV;
  438.         $$->value=10;
  439.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  440.         $$->nodes[0]=$3;
  441.         $$->nodes[1]=$5;
  442.         $$->nodes[2]=$7;
  443.         $$->nodes[3]=$9;
  444.         $$->nodes[4]=$11;
  445.         $$->nodes[5]=$13;
  446.         $$->nodes[6]=$15;
  447.         $$->nodes[7]=$17;
  448.         $$->nodes[8]=$19;
  449.         $$->nodes[9]=$21;
  450.     }
  451.     | t_ctl '(' exp ')' { 
  452.         $$ = malloc(sizeof(s_afstree));
  453.         $$->op_type=F_CTL;
  454.         $$->value=1;
  455.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  456.         $$->nodes[0]=$3;
  457.     }
  458.     | t_abs '(' exp ')' { 
  459.         $$ = malloc(sizeof(s_afstree));
  460.         $$->op_type=F_ABS;
  461.         $$->value=1;
  462.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  463.         $$->nodes[0]=$3;
  464.     }
  465.     | t_dif '(' exp ',' exp  ')' { 
  466.         $$ = malloc(sizeof(s_afstree));
  467.         $$->op_type=F_DIF;
  468.         $$->value=2;
  469.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  470.         $$->nodes[0]=$3;
  471.         $$->nodes[1]=$5;
  472.     }
  473.     | t_scl '(' exp ',' exp ','exp ',' exp ',' exp ')' { 
  474.         $$ = malloc(sizeof(s_afstree));
  475.         $$->op_type=F_SCL;
  476.         $$->value=5;
  477.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  478.         $$->nodes[0]=$3;
  479.         $$->nodes[1]=$5;
  480.         $$->nodes[2]=$7;
  481.         $$->nodes[3]=$9;
  482.         $$->nodes[4]=$11;
  483.     }
  484.     | t_val '(' exp ',' exp ',' exp ')' { 
  485.         $$ = malloc(sizeof(s_afstree));
  486.         $$->op_type=F_VAL;
  487.         $$->value=3;
  488.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  489.         $$->nodes[0]=$3;
  490.         $$->nodes[1]=$5;
  491.         $$->nodes[2]=$7;
  492.     }
  493.     | t_add '(' exp ',' exp ',' exp ')' { 
  494.         $$ = malloc(sizeof(s_afstree));
  495.         $$->op_type=F_ADD;
  496.         $$->value=3;
  497.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  498.         $$->nodes[0]=$3;
  499.         $$->nodes[1]=$5;
  500.         $$->nodes[2]=$7;
  501.     }
  502.     | t_sub '(' exp ',' exp ',' exp ')' { 
  503.         $$ = malloc(sizeof(s_afstree));
  504.         $$->op_type=F_SUB;
  505.         $$->value=3;
  506.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  507.         $$->nodes[0]=$3;
  508.         $$->nodes[1]=$5;
  509.         $$->nodes[2]=$7;
  510.     }
  511.      | t_mix '(' exp ',' exp ',' exp ',' exp ')' { 
  512.         $$ = malloc(sizeof(s_afstree));
  513.         $$->op_type=F_MIX;
  514.         $$->value=4;
  515.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  516.         $$->nodes[0]=$3;
  517.         $$->nodes[1]=$5;
  518.         $$->nodes[2]=$7;
  519.         $$->nodes[3]=$9;
  520.     }
  521.     | t_rnd '(' exp ',' exp ')' { 
  522.         $$ = malloc(sizeof(s_afstree));
  523.         $$->op_type=F_RND;
  524.         $$->value=2;
  525.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  526.         $$->nodes[0]=$3;
  527.         $$->nodes[1]=$5;
  528.     }
  529.     | t_c2d '(' exp ',' exp ')' { 
  530.         $$ = malloc(sizeof(s_afstree));
  531.         $$->op_type=F_C2D;
  532.         $$->value=2;
  533.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  534.         $$->nodes[0]=$3;
  535.         $$->nodes[1]=$5;
  536.     }
  537.     | t_c2m '(' exp ',' exp ')' { 
  538.         $$ = malloc(sizeof(s_afstree));
  539.         $$->op_type=F_C2M;
  540.         $$->value=2;
  541.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  542.         $$->nodes[0]=$3;
  543.         $$->nodes[1]=$5;
  544.     }
  545.     | t_r2x '(' exp ',' exp ')' { 
  546.         $$ = malloc(sizeof(s_afstree));
  547.         $$->op_type=F_R2X;
  548.         $$->value=2;
  549.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  550.         $$->nodes[0]=$3;
  551.         $$->nodes[1]=$5;
  552.     }
  553.     | t_r2y '(' exp ',' exp ')' { 
  554.         $$ = malloc(sizeof(s_afstree));
  555.         $$->op_type=F_R2Y;
  556.         $$->value=2;
  557.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  558.         $$->nodes[0]=$3;
  559.         $$->nodes[1]=$5;
  560.     }
  561.     | t_min '(' exp ',' exp ')' { 
  562.         $$ = malloc(sizeof(s_afstree));
  563.         $$->op_type=F_MIN;
  564.         $$->value=2;
  565.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  566.         $$->nodes[0]=$3;
  567.         $$->nodes[1]=$5;
  568.     }
  569.     | t_max '(' exp ',' exp ')' { 
  570.         $$ = malloc(sizeof(s_afstree));
  571.         $$->op_type=F_MAX;
  572.         $$->value=2;
  573.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  574.         $$->nodes[0]=$3;
  575.         $$->nodes[1]=$5;
  576.     }
  577.     | t_put '(' exp ',' exp ')' { 
  578.         $$ = malloc(sizeof(s_afstree));
  579.         $$->op_type=F_PUT;
  580.         $$->value=2;
  581.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  582.         $$->nodes[0]=$3;
  583.         $$->nodes[1]=$5;
  584.     }
  585.     | t_get '(' exp ')' { 
  586.         $$ = malloc(sizeof(s_afstree));
  587.         $$->op_type=F_GET;
  588.         $$->value=1;
  589.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  590.         $$->nodes[0]=$3;
  591.     }
  592.         | t_sin '(' exp ')' { 
  593.         $$ = malloc(sizeof(s_afstree));
  594.         $$->op_type=F_SIN;
  595.         $$->value=1;
  596.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  597.         $$->nodes[0]=$3;
  598.     }            
  599.         | t_cos '(' exp ')' { 
  600.         $$ = malloc(sizeof(s_afstree));
  601.         $$->op_type=F_COS;
  602.         $$->value=1;
  603.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  604.         $$->nodes[0]=$3;
  605.     }            
  606.         | t_tan '(' exp ')'    { 
  607.         $$ = malloc(sizeof(s_afstree));
  608.         $$->op_type=F_TAN;
  609.         $$->value=1;
  610.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  611.         $$->nodes[0]=$3;
  612.     }            
  613.         | t_sqr '(' exp ')'    { 
  614.         $$ = malloc(sizeof(s_afstree));
  615.         $$->op_type=F_SQR;
  616.         $$->value=1;
  617.         $$->nodes=malloc(($$->value)*sizeof(s_afstree *));
  618.         $$->nodes[0]=$3;
  619.     }
  620.         | '(' exp ')'         { $$=$2; }
  621.     ;
  622.  
  623. %%
  624.  
  625. void free_tree(s_afstree *a)
  626. {
  627.     int i;
  628.     if (a==NULL) return;
  629.     if (a->op_type==OP_CONST) return;
  630.     for (i=0; i<a->value; i++) {
  631.         free_tree(a->nodes[i]);
  632.     }
  633.     free(a->nodes);
  634.     free(a);
  635.     return;
  636. }
  637.