home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / rayce27s / rayparse.y < prev    next >
Encoding:
Lex Description  |  1994-01-26  |  34.5 KB  |  1,272 lines

  1. %{
  2.   /* rayparse.y -- a Bison definition file for the Rayce language. 
  3.    *
  4.    * (c) 1993,94 by Han-Wen Nienhuys, <hanwen@stack.urc.tue.nl>
  5.    *
  6.    * This program is free software; you can redistribute it and/or modify it
  7.    * under the terms of the GNU General Public License as published by the
  8.    * Free Software Foundation;
  9.    *
  10.    * This program is distributed in the hope that it will be useful,
  11.    * but WITHOUT
  12.    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14.    * more details.
  15.    *
  16.    * You should have received a copy of the GNU General Public License along
  17.    * with this program; if not, write to the Free Software Foundation,
  18.    * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.    */
  20.  
  21.   /*
  22.    * August 1993
  23.    *
  24.    * How does it work??
  25.    *
  26.    * I dunno, Bison does the difficult stuff.
  27.    *
  28.    * most of the elements of a PoV/Rayce file consist of an keyword xxx and
  29.    * some info enclosed in {}.  In my grammar, this is called a xxx_block,
  30.    * which has the value of a pointer to an xxx.  The pointer has space
  31.    * alloced, so it suffices to copy the pointer, not it's contents.
  32.    *
  33.    * Stuff enclosed in the { } of a xxx_block is called the xxx_body.
  34.    */
  35.  
  36.   #include <stdio.h>
  37.   #include "ray.h"
  38.   #include "proto.h"
  39.   #include "parse.h"
  40.   #include "extern.h"
  41.  
  42.   #ifdef DEBUG
  43.   #define YYDEBUG 1
  44.   #endif
  45.  
  46.   PRIVATE void kill_alloca(void);
  47.  
  48. #ifdef __TURBOC__
  49. #define FIXALLOCA
  50. #endif
  51.  
  52. #ifdef FIXALLOCA
  53.  #define alloca allocaa        /* some compilers dosn't have alloca(), allocaa() is bugfix */
  54.  void *allocaa(size_t size); 
  55. #endif
  56.  
  57. #define YYINITDEPTH 50
  58.  
  59.   PRIVATE void polycodenext(void);
  60.   PRIVATE struct poly_instruction *poly_code;
  61.   PRIVATE int code_p, current_maxcode = 1;
  62.  
  63. %}
  64.  
  65. %union {
  66.   color     colorval;
  67.   double     doubleval;
  68.   vector     vectorval;
  69.   struct texture_data    *textureval;
  70.   char        stringval[200];
  71.   int intval;
  72.  
  73.   struct declare_tab     *dectabptr;
  74.   struct camera        *cameraval;
  75.   object        *objectval;
  76.   struct image_map    *imageval;
  77. }
  78.  
  79. /*tokens */
  80.  
  81. %token       INCLUDE
  82. %token      OPTIONS
  83. %token    DEFAULTTEXT
  84.  
  85. %token    BACKGROUND ANTIALIAS
  86. %token       TOLERANCE  DEPTH
  87. %token    TIME ITERATIONS CUTOFF
  88.  
  89. %token    OBJECT
  90. %token    COMPOSITE_T
  91.  
  92. %token       COLOR RGB
  93. %token      RED GREEN BLUE ALPHA
  94. %token        ATMOSPHERE FOG 
  95.  
  96. %token    TRANSLATE ROTATE SCALE
  97.  
  98. %token       TEXTURE
  99. %token    AMBIENT DIFFUSE BRILLIANCE
  100. %token    ROUGHNESS SPECULAR
  101. %token    IOR
  102. %token    REFRACTION REFLECTION
  103. %token    REFRACT_ANGLE REFLECT_ANGLE
  104. %token       TARGA GIF
  105. %token       IMAGE_MAP MAPTYPE ONCE INTERPOLATE USENORMAL
  106. %token    UVRANGE UVOFFSET UVSWAP
  107.  
  108. %token     SPHERE_T PLANE_T QUADRIC_T BOX_T LIGHT_SOURCE_T
  109. %token     TRIANGLE_T TORUS_T ALGEBRAIC_T POLYGON_T SMOOTH_TRIANGLE_T
  110. %token     SUPERQ_T EXTRUSION_T CYLINDER_T DISC_T
  111. %token     OPEN
  112.  
  113. %token  BOUNDED_BY CLIPPED_BY
  114. %token  SPEED
  115.  
  116. %token     CAMERA_T
  117. %token  DIRECTION LOCATION
  118. %token  SKY FOV
  119. %token    LOOK_AT ASPECT
  120.  
  121. %token    DECLARE
  122. %token    X_T
  123. %token    Y_T
  124. %token    Z_T
  125.  
  126. %token    RADIUS ATTENUATION
  127. %token      SPOTLIGHT TIGHTNESS POINT_AT 
  128. %token      INVERSE INTERSECTION UNION
  129. %token      STURM CLOSEDCURVE
  130.  
  131. %token <doubleval> FLOAT_CONST
  132.  
  133. %token <dectabptr> FLOAT_IDENTIFIER IDENTIFIER QUADRIC_IDENTIFIER
  134. %token <dectabptr> COLOR_IDENTIFIER TEXTURE_IDENTIFIER SPHERE_IDENTIFIER
  135. %token <dectabptr> PLANE_IDENTIFIER  LIGHT_IDENTIFIER SMOOTH_TRIANGLE_IDENTIFIER
  136. %token <dectabptr> BOX_IDENTIFIER VECTOR_IDENTIFIER COMPOSITE_IDENTIFIER
  137. %token <dectabptr> CAMERA_IDENTIFIER TRIANGLE_IDENTIFIER  UNION_IDENTIFIER 
  138. %token <dectabptr> INTERSECTION_IDENTIFIER  TORUS_IDENTIFIER DISK_IDENTIFIER
  139. %token <dectabptr> ALGEBRAIC_IDENTIFIER SUPERQ_IDENTIFIER EXTRUSION_IDENTIFIER
  140.  
  141. %token <dectabptr> POLYGON_IDENTIFIER DISC_IDENTIFIER
  142. %token <dectabptr> OBJECT_IDENTIFIER
  143. %token <dectabptr> IMAGEMAP_IDENTIFIER
  144.  
  145. %token <stringval> STRING
  146.  
  147.  
  148. /* grammar elements */
  149.  
  150. %type <dectabptr>     any_identifier old_identifier shape_identifier
  151.  
  152. %type <colorval> color_spec
  153. %type <doubleval> pfloat
  154. %type <vectorval> vexp
  155. %type <doubleval> fexp
  156. %type <vectorval> scale_stuff
  157.  
  158. %type <textureval> texture_block
  159. %type <textureval> texture_body
  160. %type <cameraval> camera_block
  161. %type <cameraval> camera_body
  162.  
  163. %type <objectval> bounded_by clipped_by bounded_body
  164.  
  165. %type <objectval> sphere_body        sphere_block
  166. %type <objectval> plane_body        plane_block
  167. %type <objectval> quadric_block     quadric_body
  168. %type <objectval> box_body        box_block 
  169. %type <objectval> light_block         light_body 
  170. %type <objectval> triangle_body        triangle_block
  171. %type <objectval> disc_body        disc_block
  172. %type <objectval> union_body        union_block
  173. %type <objectval> intersection_block    intersection_body
  174. %type <objectval> csg_shape_block
  175. %type <objectval> composite_body    composite_block
  176. %type <objectval> torus_body        torus_block 
  177. %type <objectval> algebraic_block    algebraic_body
  178. %type <objectval> superq_block        superq_body
  179. %type <objectval> polygon_block polygon_defn polygon_body
  180. %type <objectval> smooth_triangle_block        smooth_triangle_body
  181. %type <objectval> extrusion_block    extrusion_body
  182. %type <objectval> cylinder_block    cylinder_body
  183.  
  184. %type <objectval> object_block         object_body
  185.  
  186.  
  187. %type <objectval> shape_block
  188.  
  189. %type <imageval> image_map_body        image_map_block
  190.  
  191. /* precedences */
  192.  
  193. %nonassoc '='
  194. %left '-' '+'
  195. %left '*' '/'
  196. %right '^'    /* exponentiation        */
  197. %left NEG     /* negation--unary minus */
  198. %left VNEG    /* vector negation. needed for reduce/reduce conflicts */
  199.  
  200. %%         
  201.  
  202. /****************************************************************
  203.    GRAMMAR
  204.  ****************************************************************/
  205.  
  206. /* GLOBAL PARTS */
  207.  
  208. /* frame is the start token */
  209. frame:     /* empty */        {  }
  210.     | frame shape_block    {    /* read an object at top-level */
  211.         noo++;
  212.         add_to_composite (thescene, $2);
  213.     }
  214.     | frame composite_block    {    /* composite */
  215.         noo++;
  216.         add_to_composite(thescene, $2);
  217.     }
  218.     | frame object_block {
  219.         noo++;
  220.         add_to_composite(thescene, $2);
  221.     }
  222.     | frame camera_block         {    /* the scene camera */
  223.         free_camera(thecamera);
  224.         thecamera = $2;
  225.     }
  226.     | frame declare_block        { }    /* a declaration */
  227.     | frame options_block        { }    /* options {} */
  228.     | frame default_text_block    { }
  229.      | frame atmosphere_block     { }
  230.     ;
  231.  
  232. default_text_block: DEFAULTTEXT '{' texture_body '}'    { free_texture(thescene->text); thescene->text = $3; }
  233.     ;
  234.  
  235. options_body:    /* empty */    { }
  236.     | options_body TIME fexp ',' fexp             {
  237.         time1 = $3; time2 = $5;
  238.     }
  239.     | options_body BACKGROUND vexp color_spec     {
  240.         bggradient = $3;
  241.         background_color = $4;
  242.     }
  243.     | options_body BACKGROUND color_spec              {
  244.         setvector(bggradient,0,0,0);
  245.         background_color = $3;
  246.     }
  247.     | options_body TOLERANCE fexp {
  248.       tolerance = $3;
  249.     }
  250.     | options_body ITERATIONS fexp    {
  251.         if (!iter_override)    /* commandline override? */
  252.             tries = (int) $3;    /* No, use $3 */
  253.     }
  254.     | options_body DEPTH fexp        { max_trace_level = (int) $3; }
  255.     | options_body ANTIALIAS fexp        { Aalias_width = $3; }
  256.     | options_body CUTOFF fexp        { depth_cutoff = $3; }
  257.     ;
  258.  
  259. options_block:    OPTIONS '{' options_body '}'    { /*empty*/ }
  260.     ;
  261.  
  262. camera_body:/* empty */        {
  263.         $$ = get_new_camera();
  264.     }
  265.     | CAMERA_IDENTIFIER    {
  266.         $$ = get_new_camera();
  267.         copy_camera($$, (struct camera *) $1->data);
  268.     }
  269.     | camera_body ASPECT fexp        { $$->aspect = $3; }
  270.     | camera_body LOOK_AT vexp        { point_camera($$, $3); }
  271.     | camera_body LOCATION vexp        { $$->eye = $3;  }
  272.     | camera_body DIRECTION vexp        { $$->eye_dir = $3; }
  273.     | camera_body SKY  vexp            { $$->sky = $3; }
  274.     | camera_body FOV fexp            { $$->fov = to_fov_coeff($$, $3); }
  275.     | camera_body TRANSLATE vexp        { translate_camera($$, $3); }
  276.     | camera_body ROTATE vexp        { matrix rm; make_rotation_matrix(rm,$3);rotate_camera($$, rm); }
  277.     | camera_body scale_stuff        { scale_camera($$, $2); }
  278.     ;
  279.  
  280. camera_block: CAMERA_T '{' camera_body '}'    { $$ = $3; }
  281.     ;
  282.  
  283. atmosphere_block: ATMOSPHERE '{' atmosphere_body '}' { }
  284.     ;
  285.  
  286. atmosphere_body: AMBIENT color_spec         { ambient_light = $2; }
  287.     ;
  288.     
  289. /****************************************************************
  290.     BASICS
  291.  ****************************************************************/
  292.  
  293. pfloat: FLOAT_CONST        { $$ = $1; }
  294.     | FLOAT_IDENTIFIER    { $$ = * (double *) $1->data; }
  295.     ;
  296.  
  297. vexp:     '<' fexp ',' fexp ',' fexp '>'    { setvector($$, $2, $4, $6); }
  298.     | '<' fexp '>'            { setvector($$, $2, $2, $2); }
  299.     | VECTOR_IDENTIFIER        { $$ = *(vector *) $1->data; }
  300.     | X_T                { setvector($$,1,0,0); }
  301.     | Y_T                { setvector($$,0,1,0); }
  302.     | Z_T                { setvector($$,0,0,1); }
  303.     | '<' color_spec '>'        { setvector($$,$2.r, $2.g, $2.b); }
  304.     | vexp '+' vexp            { vadd($$, $1, $3); }
  305.     | '-' vexp %prec NEG        { vneg($$, $2); }
  306.     | vexp '-' vexp            { vsub($$, $1, $3); }
  307.     | fexp '*' vexp            { svproduct($$, $1, $3); }
  308.     | vexp '*' fexp            { svproduct($$, $3, $1); }
  309.     | vexp '^' vexp            { vcross ($$, $1, $3); }
  310.     | vexp '/' fexp            {
  311.       if ($3 == 0.0)
  312.         errormsg("division by zero");
  313.       svproduct($$, 1/$3, $1);
  314.     }
  315.     | '(' vexp ')'            { $$ = $2; }
  316.     ;
  317.  
  318.  
  319.  
  320. fexp:    '-' fexp %prec VNEG    { $$ = -$2; }
  321.     | pfloat        { $$ = $1; }
  322.     |  '(' vexp ',' vexp ')'    { $$ = vdot($2,$4); }
  323.     | fexp '+' fexp        { $$ = $1 + $3; }
  324.     | fexp '*'fexp        { $$ = $1 * $3; }
  325.     | fexp '-' fexp        { $$ = $1 - $3; }
  326.     | '(' fexp  ')'        { $$ = $2; }
  327.     | fexp '/' fexp        {
  328.       if ($3 == 0.0)
  329.         errormsg("division by zero");
  330.       $$ = $1 / $3;
  331.       }
  332.     | fexp '^' fexp        {
  333.        $$ = pow($1, $3);
  334.     }
  335.     ;
  336.  
  337. scale_stuff:
  338.     SCALE vexp        { $$ = $2; }
  339.     ;
  340.  
  341. /***************************************************************************
  342.  * TEXTURES                                   *
  343.  ***************************************************************************/
  344.  
  345. /* stricly speaking, "color" for specifying black is correct. ugh */
  346. color_spec: COLOR            { $$.r = $$.g = $$.b = 0.0; }
  347.     | color_spec RED fexp        { $$.r = $3 }
  348.     | color_spec GREEN fexp        { $$.g = $3 }
  349.     | color_spec BLUE fexp        { $$.b = $3 }
  350.         | color_spec COLOR_IDENTIFIER    { $$ = *(color *) $2->data }
  351.     | color_spec ALPHA fexp        {  }
  352.     | color_spec RGB vexp        { $$.r = $3.x; $$.g = $3.y; $$.b = $3.z; }
  353.     ;
  354.  
  355. image_map_body:
  356.     TARGA STRING    {
  357.       $$ = get_new_image_map();
  358.       $$->pic = get_TGA_pixels($2);
  359.     }
  360.     | GIF STRING    {
  361.       $$ = get_new_image_map();
  362.       $$->pic = get_GIF_pixels($2);
  363.     }
  364.      | IMAGEMAP_IDENTIFIER         {
  365.       $$ = get_new_image_map();
  366.       copy_image_map($$, $1->data);
  367.     }
  368.      | image_map_body MAPTYPE fexp    {
  369.       switch((int) $3) {
  370.       case 0: $$->inv_map = inverse_planemap; break;
  371.       case 1: $$->inv_map = inverse_spheremap; break;
  372.       case 2: $$->inv_map = inverse_cylindermap; break;
  373.       case 3: $$->inv_map = inverse_torusmap; break;
  374.       default: errormsg("unknown maptype");
  375.       }
  376.     }
  377.         | image_map_body INTERPOLATE fexp      {
  378.       $$->interpolated = (bool) $3;
  379.     }
  380.     | image_map_body USENORMAL        { $$->usenormal = TRUE; }
  381.     | image_map_body ONCE            { $$->once = TRUE; }
  382.     | image_map_body UVRANGE fexp ',' fexp    { $$->u_range = $3; $$->v_range = $5; }
  383.     | image_map_body UVOFFSET fexp ',' fexp    { $$->u_offs = $3; $$->v_offs = $5; }
  384.     | image_map_body UVSWAP         { $$->uvswap = TRUE; }
  385.     ;
  386.  
  387. image_map_block: IMAGE_MAP    '{' image_map_body '}'    { $$ = $3; }
  388.     ;
  389.  
  390.  
  391. texture_body: /* empty */
  392.     {
  393.       $$ = get_new_texture();     /* first, alloc ourself a texture */
  394.     }
  395.     | TEXTURE_IDENTIFIER    {
  396.       $$ = get_new_texture();
  397.       copy_texture($$, (struct texture_data*) $1->data);
  398.     }
  399.     | texture_body color_spec     {     /* PoV compatibility */
  400.       $$->PoVcolor = get_new_color(); copy_color($$->PoVcolor, &$2);
  401.       setcolor ($$->ambient, .2,.2,.2);
  402.       setcolor ($$->diffuse, .6,.6,.6);
  403.     }
  404.     | texture_body AMBIENT color_spec    { $$->ambient = $3 }
  405.     | texture_body AMBIENT fexp        {
  406.       if ($$->PoVcolor != NULL)
  407.         setcolor($$->ambient , $3, $3, $3);
  408.       else
  409.         scale_color(&$$->ambient,$3);    
  410.     }
  411.  
  412.     | texture_body DIFFUSE color_spec    { $$->diffuse = $3 }
  413.     | texture_body DIFFUSE fexp        {
  414.       if ($$->PoVcolor != NULL)
  415.         setcolor($$->diffuse , $3, $3, $3);
  416.       else
  417.         scale_color(&$$->diffuse,$3);
  418.     }
  419.  
  420.     | texture_body ROUGHNESS fexp        { $$->roughness = $3; }
  421.  
  422.     | texture_body SPECULAR color_spec    { $$->specular  = $3; }
  423.     | texture_body SPECULAR fexp        {
  424.       if ($$->PoVcolor != NULL)
  425.         setcolor($$->specular , $3, $3, $3);
  426.       else
  427.         scale_color(&$$->specular,$3);    
  428.     }
  429.  
  430.     | texture_body IOR fexp            { $$->index = $3; }
  431.     | texture_body BRILLIANCE fexp        { $$->brilliance = $3; }
  432.  
  433.     | texture_body REFLECTION color_spec    { $$->refl_color = $3; }
  434.     | texture_body REFLECTION fexp        {     
  435.       if ($$->PoVcolor != NULL)
  436.         setcolor($$->refl_color , $3, $3, $3);
  437.       else
  438.         scale_color(&$$->refl_color,$3);    
  439.     }
  440.  
  441.     | texture_body REFRACTION color_spec    { $$->refr_color = $3; }
  442.     | texture_body REFRACTION fexp        {
  443.       if ($$->PoVcolor != NULL)
  444.         setcolor($$->refr_color, $3, $3, $3);
  445.       else
  446.         scale_color(&$$->refr_color,$3);
  447.     }
  448.  
  449.     | texture_body REFRACT_ANGLE fexp    { $$->refr_diffuse = degtorad($3); }
  450.  
  451.     | texture_body REFLECT_ANGLE fexp    { $$->refl_diffuse = degtorad($3); }
  452.     | texture_body image_map_block        { $$->type = T_IMAGEMAP; $$->exttext.image = $2; }
  453.     | texture_body scale_stuff        { scale_texture($$, $2); }
  454.     | texture_body TRANSLATE vexp        { translate_texture($$, $3); }
  455.     | texture_body ROTATE vexp        { matrix rm; make_rotation_matrix(rm,$3);rotate_texture($$, rm); }
  456.     ;
  457.  
  458. texture_block:     TEXTURE '{' texture_body '}'    { $$  = $3; }
  459.     ;
  460.  
  461. /***************************************************************************
  462.  * SHAPES                                   *
  463.  ***************************************************************************/
  464.  
  465. sphere_body: vexp ',' fexp             {
  466.         $$ = get_new_sphere_object();
  467.         $$->data.sphere->center  = $1;
  468.         $$->data.sphere->radius = ABS($3);
  469.  
  470.           }
  471.               | SPHERE_IDENTIFIER        {
  472.             $$ = get_new_sphere_object();
  473.         copy_object($$, (object *) $1->data);
  474.           }
  475.           | sphere_body TRANSLATE vexp    { translate_object($$, $3); }
  476.           | sphere_body ROTATE vexp     { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  477.           | sphere_body scale_stuff        { scale_object($$, $2); }
  478.           | sphere_body INVERSE        { $$->inverted = !$$->inverted; }
  479.           | sphere_body texture_block    { $$->text = $2; }
  480.           ;
  481.  
  482.  
  483. sphere_block: SPHERE_T '{' sphere_body '}'    { $$ = $3; }
  484.         ;
  485.  
  486. /* flat and infinite plane : */
  487. plane_body:   vexp ',' fexp             {
  488.         $$ = get_new_plane_object();
  489.         $$->data.plane->n = $1; $$->data.plane->mov = $3;
  490.           }
  491.               | PLANE_IDENTIFIER        {
  492.             $$ = get_new_plane_object();
  493.         copy_object($$, (object *) $1->data);
  494.           }
  495.           | plane_body TRANSLATE vexp    { translate_object($$, $3); }
  496.           | plane_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  497.           | plane_body scale_stuff    { scale_object($$, $2); }
  498.           | plane_body INVERSE        { $$->inverted = !$$->inverted; }
  499.           | plane_body texture_block    { $$->text = $2; }
  500.           ;
  501.  
  502. plane_block: PLANE_T '{' plane_body '}'        { $$ = $3 }
  503.           ;
  504.  
  505. quadric_body:
  506.     vexp ',' vexp ',' vexp ',' fexp {
  507.       {
  508.         struct quadric_data *q;
  509.         $$ = get_new_quadric_object();
  510.         q = $$->data.quadric;
  511.         q->xx = $1.x;  q->yy = $1.y;  q->zz = $1.z;
  512.         q->xy = $3.x;  q->yz = $3.y;  q->xz = $3.z;
  513.         q->x0 = $5.x;  q->y0 = $5.y;  q->z0 = $5.z;
  514.         q->a = $7;
  515.       }
  516.     }
  517.     | QUADRIC_IDENTIFIER        {
  518.       $$ = get_new_quadric_object();
  519.       copy_object ($$, (object *) $1->data);
  520.     }
  521.     | quadric_body TRANSLATE vexp    { translate_object($$, $3); }
  522.     | quadric_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  523.     | quadric_body scale_stuff    { scale_object($$, $2); }
  524.     | quadric_body INVERSE        { $$->inverted = !$$->inverted; }
  525.     | quadric_body texture_block    { $$->text = $2; }
  526.     | quadric_body CLOSEDCURVE    { $$->data.quadric->isclosed = TRUE; }
  527.     ;
  528.  
  529. quadric_block: QUADRIC_T '{' quadric_body '}'    { $$ = $3; }
  530.     ;
  531.  
  532. box_body: vexp ',' vexp        {
  533.         $$ = get_new_box_object();
  534.         $$->data.box->p1 = $1; $$->data.box->p2 = $3;
  535.  
  536.     }
  537.     | BOX_IDENTIFIER        {
  538.         $$ = get_new_box_object();
  539.         copy_object($$, (object *) $1->data);
  540.     }
  541.     | box_body TRANSLATE vexp    { translate_object($$, $3); }
  542.     | box_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  543.     | box_body scale_stuff    { scale_object($$, $2); }
  544.         | box_body INVERSE        { $$->inverted = !$$->inverted; }
  545.     | box_body texture_block    { $$->text = $2; }
  546.     ;
  547.  
  548. box_block: BOX_T '{' box_body '}'        { $$ = $3; }
  549.     ;
  550.  
  551. light_body: vexp color_spec        {
  552.         $$ = get_new_light_object();
  553.         $$->data.light->org = $1;
  554.         $$->data.light->lcolor = $2;
  555.     }
  556.     | LIGHT_IDENTIFIER        {
  557.         $$ = get_new_light_object();
  558.         copy_object($$, (object *) $1->data);
  559.     }
  560.     | light_body RADIUS fexp    { $$->data.light->radius = $3; }
  561.     | light_body ATTENUATION fexp    {
  562.         $$->data.light->attenuation_exp = $3;
  563.     }
  564.     | light_body SPOTLIGHT POINT_AT vexp TIGHTNESS fexp    {
  565.         struct light_data *l;
  566.         l = $$->data.light;
  567.  
  568.         vsub(l->direction, $4,l->org);
  569.         norm(l->direction, l->direction);
  570.         l->tightness = $6;
  571.         l->spotlight = TRUE;
  572.     }           
  573.     | light_body TRANSLATE vexp    { translate_object($$, $3); }
  574.     | light_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  575.     | light_body scale_stuff    { scale_object($$, $2); }
  576.     ;
  577.  
  578.  
  579.  
  580.  
  581. light_block: LIGHT_SOURCE_T '{' light_body '}'    { $$ = $3; }
  582.     ;
  583.  
  584. triangle_body:
  585.     vexp ',' vexp ',' vexp {
  586.       struct triangle_data *s;  
  587.       $$ = get_new_triangle_object();
  588.       s = $$->data.triangle;
  589.  
  590.       s->vertices[0] = $1;
  591.       s->vertices[1] = $3;
  592.       s->vertices[2] = $5;
  593.     }
  594.      | TRIANGLE_IDENTIFIER        {
  595.       $$ = get_new_triangle_object();
  596.       copy_object($$, (object *) $1->data);
  597.     }
  598.     | triangle_body TRANSLATE vexp    { translate_object($$, $3);}
  599.     | triangle_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  600.     | triangle_body scale_stuff    { scale_object($$, $2); }
  601.     | triangle_body texture_block    { $$->text = $2; }
  602.     ;
  603.  
  604. triangle_block: TRIANGLE_T    '{' triangle_body '}'    { $$ =$3; }
  605.     ;
  606.  
  607. smooth_triangle_body:
  608.     vexp ',' vexp ',' vexp ',' vexp ',' vexp ',' vexp {
  609.       struct triangle_data *s;  
  610.       $$ = get_new_smooth_triangle_object();
  611.       s = $$->data.triangle;
  612.  
  613.       s->vertices[0] = $1;
  614.       s->normals[0] = $3;
  615.       s->vertices[1] = $5;
  616.       s->normals[1] = $7;
  617.       s->vertices[2] = $9;
  618.       s->normals[2] = $11;  
  619.     }
  620.      | SMOOTH_TRIANGLE_IDENTIFIER            {
  621.       $$ = get_new_smooth_triangle_object();
  622.       copy_object($$, (object *) $1->data);
  623.     }
  624.     | smooth_triangle_body TRANSLATE vexp    { translate_object($$, $3);}
  625.     | smooth_triangle_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  626.     | smooth_triangle_body scale_stuff    { scale_object($$, $2); }
  627.     | smooth_triangle_body texture_block    { $$->text = $2; }
  628.     ;
  629.  
  630. smooth_triangle_block: SMOOTH_TRIANGLE_T    '{' smooth_triangle_body '}'    { $$ =$3; }
  631.     ;
  632.  
  633.  
  634. torus_body:
  635.     fexp ',' fexp     {
  636.         $$ = get_new_torus_object();
  637.         $$->data.torus->Rad = $1; $$->data.torus->rad = $3;
  638.     }
  639.     | TORUS_IDENTIFIER    {
  640.       $$ = get_new_torus_object();
  641.       copy_object( $$, (object *) $1->data);
  642.     }
  643.     | torus_body TRANSLATE vexp    { translate_object($$, $3); }
  644.     | torus_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  645.     | torus_body scale_stuff    { scale_object($$, $2); }
  646.     | torus_body INVERSE        { $$->inverted = !$$->inverted; }
  647.     | torus_body STURM        { $$->data.torus->use_sturm = TRUE }
  648.     | torus_body texture_block    { $$->text = $2; }
  649.     ;
  650.  
  651. torus_block: TORUS_T    '{' torus_body '}'    { $$ =$3; }
  652.     ;
  653.  
  654. /* a nonempty sequence of vectors */
  655. polygon_defn:
  656.     vexp                {
  657.       $$ = get_new_polygon_object();
  658.       add_vertex_to_polygon($$, $1);
  659.     }
  660.     | polygon_defn ',' vexp        {
  661.       add_vertex_to_polygon($$, $3);
  662.     }
  663.     ;
  664.  
  665. polygon_body:
  666.     polygon_defn            {
  667.       $$ = $1;
  668.      }
  669.     | POLYGON_IDENTIFIER        {
  670.       $$ = get_new_polygon_object();
  671.       copy_object($$, $1->data);
  672.     }
  673.     | polygon_body TRANSLATE vexp    { translate_object($$, $3); }
  674.     | polygon_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  675.     | polygon_body scale_stuff    { scale_object($$, $2); }
  676.     | polygon_body texture_block    { $$->text = $2; }
  677.     ;
  678.  
  679. polygon_block:    POLYGON_T '{' polygon_body '}'    { $$=  $3; }
  680.     ;
  681.  
  682. disc_body:
  683.     vexp ',' vexp ',' fexp         {
  684.         struct disc_data *d;
  685.         $$ = get_new_disc_object();
  686.         d = $$->data.disc;
  687.         d->center = $1; d->n = $3; d->R = $5;        
  688.     }
  689.     | vexp ',' vexp ',' fexp ',' fexp         {
  690.         struct disc_data *d;
  691.         $$ = get_new_disc_object();
  692.         d = $$->data.disc;
  693.         d->center = $1; d->n = $3; d->R = $5; d->r = $7;
  694.     }
  695.     | DISC_IDENTIFIER        { $$ = get_new_disc_object(); copy_object($$, $1->data); }
  696.     | disc_body TRANSLATE vexp    { translate_object($$, $3); }
  697.     | disc_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  698.     | disc_body scale_stuff    { scale_object($$, $2); }
  699.     | disc_body texture_block    { $$->text = $2; }
  700.     ;
  701.  
  702. disc_block:    DISC_T    '{' disc_body '}'    { $$ = $3;}
  703.         
  704.  
  705. superq_block:    SUPERQ_T '{' superq_body '}'        { $$ = $3; }
  706.     ;
  707.     
  708.  
  709. superq_body:    vexp            { $$ = get_new_superq_object(); $$->data.superq->powvect = $1; }
  710.     | SUPERQ_IDENTIFIER        { $$ = get_new_superq_object(); copy_object($$, $1->data); }
  711.     | superq_body TRANSLATE vexp    { translate_object($$, $3); }
  712.     | superq_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  713.     | superq_body scale_stuff    { scale_object($$, $2); }
  714.     | superq_body texture_block    { $$->text = $2; }
  715.     ;
  716.     
  717. extrusion_block: EXTRUSION_T '{' extrusion_body '}'    { $$ = $3; }
  718.            ;
  719.     
  720. extrusion_body:    fexp shape_block    {
  721.       $$ = get_new_extrusion_object();
  722.       ($$->data.extrusion->shape = $2)->daddy = $$;
  723.       $$->data.extrusion->height = $1;
  724.     }
  725.     | extrusion_body OPEN fexp    {
  726.       int i = (int) $3;
  727.       $$->data.extrusion->locap = (i & 0x01);
  728.       $$->data.extrusion->hicap = (i & 0x02);
  729.     }
  730.     | EXTRUSION_IDENTIFIER             {
  731.       $$ = get_new_extrusion_object();
  732.       copy_object($$, $1->data);
  733.     }
  734.     | extrusion_body TRANSLATE vexp    { translate_object($$, $3); }
  735.     | extrusion_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  736.     | extrusion_body scale_stuff    { scale_object($$, $2); }
  737.     | extrusion_body texture_block    { $$->text = $2; }
  738.     ;
  739.  
  740. cylinder_block:    CYLINDER_T '{' cylinder_body '}'    { $$ = $3; }
  741.     ;
  742.  
  743. cylinder_body:    vexp ',' vexp ',' fexp        { 
  744.       $$ = make_cylinder_object($1, $3, $5);
  745.     }
  746.     | EXTRUSION_IDENTIFIER {
  747.       $$ = get_new_extrusion_object();
  748.       copy_object($$, $1->data);
  749.     }
  750.     | cylinder_body TRANSLATE vexp    { translate_object($$, $3); }
  751.     | cylinder_body ROTATE    vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  752.     | cylinder_body scale_stuff    { scale_object($$, $2); }
  753.     | cylinder_body texture_block    { $$->text = $2; }
  754.     ;
  755.  
  756. /*****************************************************************
  757.  * algebraic surfaces.
  758.  *****************************************************************/
  759.  
  760. algebraic_block: ALGEBRAIC_T    '{' algebraic_body '}'    { $$ = $3; }
  761.     ;
  762.  
  763. algebraic_body:
  764.     poly_decl          {
  765.       int i;
  766.       struct algebraic_data *a;
  767.  
  768.       $$ = get_new_algebraic_object();
  769.       a = $$->data.algebraic;
  770.  
  771.       i = code_p * sizeof(struct poly_instruction);
  772.       a->code = (struct poly_instruction *) malloc(i);
  773.       CHECK_MEM(a->code, "poly instructions");
  774.       a->codesize = code_p;
  775.  
  776.       for (i = 0; i < code_p; i++)
  777.             *(a->code + i) = poly_code[i];
  778.     }
  779.     | ALGEBRAIC_IDENTIFIER        {
  780.       $$ = get_new_algebraic_object();
  781.       copy_object( $$, (object *) $1->data);
  782.     }
  783.     | algebraic_body ROTATE vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  784.         | algebraic_body scale_stuff    { scale_object($$,$2); }
  785.     | algebraic_body TRANSLATE vexp { translate_object ($$, $3); }
  786.     | algebraic_body INVERSE    { $$->inverted = !$$->inverted; }                
  787.     | algebraic_body STURM        { $$->data.algebraic->usesturm = TRUE; }
  788.     | algebraic_body CLOSEDCURVE    { $$->data.algebraic->isclosed = TRUE; }
  789.     | algebraic_body texture_block    { $$->text = $2; }
  790.     ;
  791.  
  792. poly_decl: poly_start poly3 poly_end    { }
  793.     ;
  794.  
  795. /* start of poly. Needed to clean old code */
  796. poly_start:    '$'     { code_p = 0; }
  797.     ;
  798.  
  799. poly_end:    '$'    { }
  800.     ;
  801.  
  802. /*
  803.   parse a polynomial, translate it into code for a stack oriented
  804.   machine. See Kernighan and Pike, the Unix Programming Environment.
  805. */
  806.  
  807. poly3:
  808.   pfloat        {
  809.     poly_code[code_p].type = POLY_CONS;
  810.     poly_code[code_p].data.factor = $1;
  811.     polycodenext();
  812.   }
  813.   | '(' poly3 ')'    {
  814.     /* nothing. */
  815.   }
  816.   | X_T            {
  817.     poly_code[code_p].type = POLY_X;
  818.     polycodenext();
  819.   }
  820.   | Y_T            {
  821.     poly_code[code_p].type = POLY_Y;
  822.     polycodenext();
  823.   }
  824.   | Z_T            {
  825.     poly_code[code_p].type = POLY_Z;
  826.     polycodenext();
  827.   }
  828.   | poly3 '+' poly3    {
  829.     poly_code[code_p].type = POLY_OP;
  830.     poly_code[code_p].data.op = '+';
  831.     polycodenext();
  832.   }
  833.   | poly3 '-' poly3    {
  834.     poly_code[code_p].type = POLY_OP;
  835.     poly_code[code_p].data.op = '-';
  836.     polycodenext();
  837.   }
  838.   | '-' poly3 %prec NEG {
  839.     poly_code[code_p].type = POLY_OP;
  840.     poly_code[code_p].data.op = 'n';
  841.     polycodenext();
  842.   }
  843.   | poly3 '*' poly3    {
  844.     poly_code[code_p].type = POLY_OP;
  845.     poly_code[code_p].data.op = '*';
  846.     polycodenext();
  847.   }
  848.   | poly3 '^' poly3    {
  849.     if (poly_code[code_p-1].type != POLY_CONS)
  850.       errormsg("^ must have integer");
  851.     poly_code[code_p].type = POLY_OP;
  852.     poly_code[code_p].data.op = '^';
  853.     polycodenext();
  854.   }
  855.   | poly3 '=' poly3    {
  856.     poly_code[code_p].type = POLY_OP;
  857.     poly_code[code_p].data.op = '-';
  858.     polycodenext();
  859.   }
  860.   ;
  861.  
  862.  
  863. /***************************************************************************
  864.  * CSG                                       *
  865.  ***************************************************************************/
  866.  
  867.  
  868. intersection_body:
  869.     csg_shape_block                {
  870.       $$ = get_new_CSGinter_object();
  871.       add_to_CSG($$, $1);
  872.     }
  873.     | INTERSECTION_IDENTIFIER            {
  874.       $$ = get_new_CSGinter_object();
  875.       copy_object($$, (object *) $1->data);
  876.     }
  877.     | intersection_body csg_shape_block    { add_to_CSG($$, $2); }
  878.     | intersection_body INVERSE        { $$->inverted = !$$->inverted }
  879.     | intersection_body scale_stuff        { scale_object($$, $2); }
  880.     | intersection_body ROTATE vexp        { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  881.     | intersection_body TRANSLATE vexp    { translate_object($$, $3); }
  882.     | intersection_body texture_block    { $$->text = $2; }
  883.     ;
  884.  
  885. union_body:
  886.     csg_shape_block                {
  887.       $$ = get_new_CSGunion_object();
  888.       add_to_CSG($$, $1);
  889.     }
  890.     | UNION_IDENTIFIER            {
  891.       $$ = get_new_CSGunion_object();
  892.       copy_object($$, (object *) $1->data);
  893.     }
  894.     | union_body csg_shape_block    { add_to_CSG($$, $2); }
  895.     | union_body TRANSLATE vexp    { translate_object($$, $3); }
  896.     | union_body ROTATE vexp    { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  897.     | union_body scale_stuff        { scale_object($$, $2); }
  898.     | union_body INVERSE        { $$->inverted = !$$->inverted; }
  899.     | union_body texture_block    { $$->text = $2; }
  900.     ;
  901.  
  902. intersection_block: INTERSECTION '{' intersection_body '}'    { $$ = $3; }
  903.     ;
  904.  
  905. union_block: UNION '{' union_body '}'        { $$ = $3; }
  906.     ;
  907.  
  908.  
  909. /*
  910.  * GENERIC OBJECTS
  911.  */
  912.  
  913. csg_shape_block:
  914.     sphere_block         { $$ = $1; }
  915.     | plane_block        { $$ = $1; }
  916.     | quadric_block     { $$ = $1; }
  917.     | torus_block        { $$ = $1; }
  918.     | box_block        { $$ = $1; }
  919.     | intersection_block    { $$ = $1; }
  920.     | union_block        { $$ = $1; }
  921.     | algebraic_block    { $$ = $1; }    
  922.     | superq_block        { $$ = $1; }
  923.     | extrusion_block        { $$ = $1; }
  924.     | cylinder_block        { $$ = $1; }
  925.     ;
  926.  
  927.  
  928. shape_block:
  929.     csg_shape_block    {
  930.       $$ = $1;
  931.     }
  932.     | polygon_block     { $$ = $1; }
  933.     | light_block        { $$ = $1; }
  934.     | triangle_block     { $$ = $1; }
  935.     | smooth_triangle_block    { $$ = $1; }
  936.     | disc_block        { $$ = $1; }
  937.     ;
  938.  
  939. bounded_body:
  940.     csg_shape_block            { $$ = $1; }
  941.     | bounded_body csg_shape_block    { 
  942.       append_to_object_list($$, $2);
  943.     }
  944.     ;
  945.  
  946. clipped_by:  CLIPPED_BY    '{' bounded_body '}'    { $$ = $3; }
  947.     ;
  948.  
  949. bounded_by:  BOUNDED_BY    '{' bounded_body '}'    { $$ = $3; }
  950.     ;
  951.  
  952. composite_block: COMPOSITE_T '{' composite_body '}'    { $$ = $3; }
  953.     ;
  954.  
  955. composite_body: /* empty */     {
  956.         $$ = get_new_composite_object();
  957.     }
  958.     | COMPOSITE_IDENTIFIER    {
  959.         $$ = get_new_composite_object();
  960.         copy_object($$, (object *) $1->data);
  961.     }
  962.     | composite_body composite_block {
  963.         add_to_composite($$, $2);
  964.     }
  965.     | composite_body shape_block    {
  966.         add_to_composite($$, $2); 
  967.     }
  968.     | composite_body object_block    {
  969.         add_to_composite($$, $2);
  970.     }
  971.     | composite_body bounded_by    {
  972.       $$->bound = $2;
  973.      }
  974.     | composite_body clipped_by    {
  975.       $$->clip = $2;      
  976.     }
  977.     | composite_body clipped_by_bound    {
  978.       add_bounds_to_clip($$);      
  979.     }
  980.     | composite_body TRANSLATE vexp     { translate_object($$, $3); }
  981.     | composite_body ROTATE vexp        { matrix rm; make_rotation_matrix(rm,$3);rotate_object($$, rm); }
  982.     | composite_body scale_stuff        { scale_object($$, $2); }
  983.     | composite_body texture_block        { $$->text = $2; }
  984.     | composite_body SPEED vexp        { speed_composite($$, $3); }
  985.     ;
  986.  
  987. clipped_by_bound: CLIPPED_BY '{' BOUNDED_BY '}'     { }
  988.     ;
  989.  
  990. object_block: OBJECT '{' object_body '}'     { $$ = $3; }
  991.     ;
  992.  
  993. object_body: shape_identifier             {
  994.       $$ = get_new_object();
  995.       copy_object($$, (object *) $1->data);
  996.     }
  997.     | shape_block                { $$ = $1; }
  998.     | object_body TRANSLATE vexp        { translate_object($$, $3); }
  999.     | object_body scale_stuff        { scale_object($$,$2); }
  1000.     | object_body ROTATE vexp        { matrix rm; make_rotation_matrix(rm,$3); rotate_object($$, rm); }
  1001.     | object_body bounded_by        {
  1002.       $$->bound = $2;
  1003.  
  1004.     }
  1005.     | object_body clipped_by        {
  1006.       $$->clip = $2;
  1007.     }
  1008.     | object_body clipped_by_bound    {
  1009.       add_bounds_to_clip($$);        
  1010.     }
  1011.     | object_body SPEED vexp        { vadd($$->speed, $$->speed, $3); }
  1012.     | object_body texture_block        { $$->text = $2; }
  1013.     ;
  1014.  
  1015.  
  1016. /***************************************************************************
  1017.  * DECLARATIONS                                   *
  1018.  ***************************************************************************/
  1019.  
  1020. /* an assignment will be done to this thing. */
  1021. any_identifier:
  1022.     IDENTIFIER        { $$ = $1; }
  1023.     | old_identifier    { warning("redeclaration of %s", $1->name);  $$ = $1; }
  1024.         ;
  1025.  
  1026.  
  1027. shape_identifier:
  1028.     QUADRIC_IDENTIFIER    { $$ = $1; }
  1029.     | SPHERE_IDENTIFIER    { $$ = $1; }
  1030.     | PLANE_IDENTIFIER    { $$ = $1; }
  1031.     | LIGHT_IDENTIFIER    { $$ = $1; }
  1032.     | BOX_IDENTIFIER    { $$ = $1; }
  1033.     | TRIANGLE_IDENTIFIER    { $$ = $1; }
  1034.     | SMOOTH_TRIANGLE_IDENTIFIER    { $$ = $1; }
  1035.     | INTERSECTION_IDENTIFIER    { $$ = $1;  }
  1036.     | UNION_IDENTIFIER    { $$ = $1; }
  1037.     | TORUS_IDENTIFIER    { $$ = $1; }
  1038.     | ALGEBRAIC_IDENTIFIER    { $$ = $1; }
  1039.     | SUPERQ_IDENTIFIER    { $$ = $1; }
  1040.     | OBJECT_IDENTIFIER    { $$ = $1; }
  1041.     | COMPOSITE_IDENTIFIER  { $$ = $1; }
  1042.     ;
  1043.  
  1044. /* an old identifier is reused. free up the space it used. */
  1045. old_identifier:
  1046.     FLOAT_IDENTIFIER    { free_float((double *) $1->data); $$ = $1; }
  1047.     | shape_identifier    { free_object($1->data); $$ = $1; }
  1048.     | VECTOR_IDENTIFIER    { free_vector((vector *) $1->data); $$ = $1; }
  1049.     | CAMERA_IDENTIFIER    { free_camera ((struct camera *) $1->data); $$ = $1; }
  1050.     | TEXTURE_IDENTIFIER    { free_texture ((struct texture_data *) $1->data); $$ = $1; }
  1051.     | COLOR_IDENTIFIER    { free_color($1->data); $$ = $1; }
  1052.     | IMAGEMAP_IDENTIFIER    { free_image_map($1->data); $$ = $1; }
  1053.     ;
  1054.  
  1055. declare_block:
  1056.     DECLARE any_identifier '=' object_block {
  1057.         $2->data = (void *) $4;
  1058.         $2->type = OBJECT_IDENTIFIER;
  1059.       }
  1060.     | DECLARE any_identifier '=' composite_block    {
  1061.         $2->data= (void *) $4;
  1062.         $2->type = COMPOSITE_IDENTIFIER;
  1063.  
  1064.     }
  1065.  
  1066.     | DECLARE any_identifier '=' sphere_block {
  1067.         $2->data= (void *) $4;
  1068.         $2->type = SPHERE_IDENTIFIER;
  1069.     }
  1070.     | DECLARE any_identifier '=' light_block {
  1071.         $2->data= (void *) $4;
  1072.         $2->type = LIGHT_IDENTIFIER;
  1073.     }
  1074.     | DECLARE any_identifier '=' plane_block    {
  1075.         $2->data= (void *) $4;
  1076.         $2->type = PLANE_IDENTIFIER;
  1077.     }
  1078.     | DECLARE any_identifier '=' quadric_block    {
  1079.         $2->data= (void *) $4;
  1080.         $2->type = QUADRIC_IDENTIFIER;
  1081.     }
  1082.      | DECLARE any_identifier '=' box_block        {
  1083.         $2->data= (void *) $4;
  1084.         $2->type = BOX_IDENTIFIER;
  1085.     }
  1086.     | DECLARE any_identifier '=' torus_block    {
  1087.         $2->data = (void *) $4;
  1088.         $2->type = TORUS_IDENTIFIER;
  1089.     }
  1090.     | DECLARE any_identifier '=' algebraic_block    {
  1091.         $2->data = (void*) $4;
  1092.         $2->type = ALGEBRAIC_IDENTIFIER;
  1093.     }
  1094.     | DECLARE any_identifier '=' superq_block    {
  1095.         $2->data = (void*) $4;
  1096.         $2->type = SUPERQ_IDENTIFIER;
  1097.     }
  1098.     | DECLARE any_identifier '=' polygon_block    {
  1099.         $2->data = (void*) $4;
  1100.         $2->type = POLYGON_IDENTIFIER;
  1101.     }
  1102.     | DECLARE any_identifier '=' triangle_block    {
  1103.         $2->data = (void*) $4;
  1104.         $2->type = TRIANGLE_IDENTIFIER;
  1105.     }
  1106.     | DECLARE any_identifier '=' disc_block    {
  1107.         $2->data = (void*) $4;
  1108.         $2->type = DISC_IDENTIFIER;
  1109.     }
  1110.     | DECLARE any_identifier '=' smooth_triangle_block    {
  1111.         $2->data = (void*) $4;
  1112.         $2->type = SMOOTH_TRIANGLE_IDENTIFIER;
  1113.     }
  1114.     | DECLARE any_identifier '=' extrusion_block    {
  1115.         $2->data = (void*) $4;
  1116.         $2->type = EXTRUSION_IDENTIFIER;
  1117.     }
  1118.     | DECLARE any_identifier '=' cylinder_block    {
  1119.         $2->data = (void*) $4;
  1120.         $2->type = EXTRUSION_IDENTIFIER;
  1121.     }
  1122.  
  1123.  
  1124.  
  1125.     | DECLARE any_identifier '=' union_block {
  1126.       $2->data = (void *) $4;
  1127.       $2->type = UNION_IDENTIFIER;
  1128.     }
  1129.     | DECLARE any_identifier '=' intersection_block {
  1130.       $2->data = (void *) $4;
  1131.       $2->type = INTERSECTION_IDENTIFIER;
  1132.     }
  1133.  
  1134.     | DECLARE any_identifier '=' texture_block    {
  1135.         $2->data= (void *) $4;
  1136.         $2->type = TEXTURE_IDENTIFIER;
  1137.     }
  1138.     | DECLARE any_identifier '=' image_map_block    {
  1139.         $2->data = (void*) $4;
  1140.         $2->type = IMAGEMAP_IDENTIFIER;
  1141.     }
  1142.     | DECLARE any_identifier '=' color_spec    {
  1143.         color  *p;
  1144.         p = get_new_color();
  1145.         $2->data = (void *) p;
  1146.         $2->type = COLOR_IDENTIFIER;
  1147.         *p = $4;
  1148.     }
  1149.  
  1150.     | DECLARE any_identifier '=' camera_block    {
  1151.         $2->data= (void *) $4;
  1152.         $2->type = CAMERA_IDENTIFIER;
  1153.     }
  1154.     | DECLARE any_identifier '=' vexp    {
  1155.         vector *p;
  1156.         $2->data  = p = get_new_vector();
  1157.         copy_vector(p, &$4);
  1158.         $2->type = VECTOR_IDENTIFIER;
  1159.     }
  1160.         | DECLARE any_identifier '=' fexp    {
  1161.         double *p;
  1162.         p = get_new_float();
  1163.         $2->data= (void *) p;
  1164.         $2->type = FLOAT_IDENTIFIER;
  1165.         *p = $4;
  1166.     }
  1167.     ;
  1168.  
  1169. /****************************************************************
  1170.   END OF GRAMMAR
  1171.  ****************************************************************/
  1172.  
  1173. %%
  1174.  
  1175. PUBLIC void
  1176. print_interior(void)
  1177. {
  1178.     printf("-------------------INTERIOR------------------------\n");
  1179.     print_camera(thecamera);
  1180.     printf("t1 %lf, t2 %lf, tolerance %lf\n", time1, time2, tolerance);
  1181.     printf("frames %d\n", tries);
  1182.     print_v("background gradient", bggradient);
  1183.     printf("cutoff %lf\nantialias %lf\n", depth_cutoff, Aalias_width);
  1184.     printf("\n=================SCENE ELEMENTS==================\n");
  1185.     print_object(thescene);
  1186.     printf("\n==================LIGHT LIST=====================\n");
  1187.     print_light_list();
  1188.     printf("\n=================DECLARATIONS====================\n");
  1189.     print_dectab();
  1190. }
  1191.  
  1192. PUBLIC void
  1193. yyerror(char *s)
  1194. {
  1195.   errormsg("%s", s);
  1196. }
  1197.  
  1198.  
  1199. #ifdef FIXALLOCA
  1200.  
  1201. PRIVATE void *alloca_ptr[300];
  1202. PRIVATE int alloca_idx =  0;
  1203.  
  1204. void *allocaa(size_t size)
  1205. {
  1206.   void *p;
  1207.  
  1208.   if (alloca_idx++  >= 300)
  1209.     errormsg("Get a life!");
  1210.  
  1211.   p = malloc(size);
  1212.   CHECK_MEM(p, "allocaa");
  1213.   return alloca_ptr[alloca_idx] = p;
  1214. }
  1215. #endif
  1216.  
  1217. PRIVATE void kill_alloca(void)
  1218. {
  1219. #ifdef FIXALLOCA
  1220.   while (alloca_idx --)
  1221.     free(alloca_ptr[alloca_idx]);
  1222. #endif
  1223. }
  1224.  
  1225. /* increment code pointer, and do a realloc if necessary */
  1226. PRIVATE  void
  1227. polycodenext(void)
  1228. {
  1229.   if (++code_p  >= current_maxcode) {
  1230.     current_maxcode *= 2;
  1231.     poly_code = realloc(poly_code, current_maxcode*sizeof(struct poly_instruction));
  1232.     if (poly_code == NULL)
  1233.       alloc_err("input polycode instructions.");
  1234.     poly_code[code_p].data.factor = 1.0;
  1235.   }
  1236. }
  1237.  
  1238.  
  1239. PUBLIC void
  1240. readfile(char *fn)
  1241. {
  1242.     set_input(fn);        /* set the input */
  1243.     poly_code = malloc(current_maxcode * sizeof(struct poly_instruction));
  1244.     CHECK_MEM(poly_code, "poly code");
  1245.  
  1246. #ifdef DEBUG
  1247.     if (debug_options & DEBUGPARS)
  1248.       yydebug = TRUE;
  1249.     else
  1250.       yydebug = FALSE;
  1251. #endif
  1252.  
  1253.    yyparse();
  1254.    make_light_list(thescene);    /* set up the light_source list */
  1255.  
  1256.    if (Aalias_width < 0)
  1257.     Aalias_width = 1.0 - 1/(double) tries;
  1258.  
  1259.    precompute_object(thescene);
  1260.  
  1261. #ifdef DEBUG
  1262.    if (debug_options & DEBUGDECL)
  1263.     print_interior();
  1264. #endif
  1265.  
  1266.     close_input();
  1267.     kill_alloca();
  1268.     free(poly_code);
  1269.  
  1270. }
  1271.  
  1272.