home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / o / orbits / !orbits / y / orbpar
Text File  |  1991-11-16  |  2KB  |  91 lines

  1. /*
  2.  * Module:        orbits.y
  3.  * Creation:      28th July, 1991.
  4.  * Last modified: 16th November, 1991.
  5.  *
  6.  *     This file contains instructions to the "Yacc" parser
  7.  * generator, or some compatible genarator. The file produced by the 
  8.  * generator contains C source code for the parser for the "orbits"
  9.  * program.
  10.  *
  11.  *   This program is free software; you can redistribute it and/or modify
  12.  *   it under the terms of the GNU General Public License as published by
  13.  *   the Free Software Foundation; either version 1, or (at your option)
  14.  *   any later version.
  15.  *
  16.  *   This program is distributed in the hope that it will be useful,
  17.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *   GNU General Public License for more details.
  20.  *
  21.  *   You should have received a copy of the GNU General Public License
  22.  *   along with this program; if not, write to the Free Software
  23.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  *
  25.  */
  26.  
  27. %{
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <stddef.h>
  31. extern int    yyline;
  32. extern int    number;
  33. extern char   *yytext;
  34. extern int    yylex(void);
  35. extern double *x,*y,*dx,*dy,*mass;
  36. static void   yyerror(char *);
  37. static void   add_body(double,double,double,double,double);
  38. %}
  39.  
  40. %union
  41. {
  42.   int    ival;
  43.   double dval;
  44. }
  45. %token NUM RETURN
  46. %type <dval> number
  47. %start list
  48.  
  49. %%
  50.  
  51. list : body
  52.      | list RETURN body
  53.      ;
  54.  
  55. body : number '/' number ',' number '/' number ',' number
  56.        {
  57.          add_body($1,$3,$5,$7,$9);
  58.        }
  59.      | /* Blank lines are allowed. */
  60.      ;
  61.  
  62. number : NUM
  63.          {
  64.            $$=atof(yytext);
  65.          }
  66.        ;
  67.  
  68. %%
  69.  
  70. static void yyerror(char *s)
  71. {
  72.   (void)fprintf(stderr,"Orbits: %s at line %d\n",s,yyline);
  73.   exit(3);
  74. }
  75.  
  76. static void add_body(double im,double ix,double iy,double idx,double idy)
  77. {
  78.   number++;
  79.   x=   (double *)realloc(x,   sizeof(double)*number);
  80.   y=   (double *)realloc(y,   sizeof(double)*number);
  81.   dx=  (double *)realloc(dx,  sizeof(double)*number);
  82.   dy=  (double *)realloc(dy,  sizeof(double)*number);
  83.   mass=(double *)realloc(mass,sizeof(double)*number);
  84.   x[number-1]=ix;
  85.   y[number-1]=iy;
  86.   dx[number-1]=idx;
  87.   dy[number-1]=idy;
  88.   mass[number-1]=im;
  89.   return;
  90. }
  91.