home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
o
/
orbits
/
!orbits
/
y
/
orbpar
Wrap
Text File
|
1991-11-16
|
2KB
|
91 lines
/*
* Module: orbits.y
* Creation: 28th July, 1991.
* Last modified: 16th November, 1991.
*
* This file contains instructions to the "Yacc" parser
* generator, or some compatible genarator. The file produced by the
* generator contains C source code for the parser for the "orbits"
* program.
*
* 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
%{
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
extern int yyline;
extern int number;
extern char *yytext;
extern int yylex(void);
extern double *x,*y,*dx,*dy,*mass;
static void yyerror(char *);
static void add_body(double,double,double,double,double);
%}
%union
{
int ival;
double dval;
}
%token NUM RETURN
%type <dval> number
%start list
%%
list : body
| list RETURN body
;
body : number '/' number ',' number '/' number ',' number
{
add_body($1,$3,$5,$7,$9);
}
| /* Blank lines are allowed. */
;
number : NUM
{
$$=atof(yytext);
}
;
%%
static void yyerror(char *s)
{
(void)fprintf(stderr,"Orbits: %s at line %d\n",s,yyline);
exit(3);
}
static void add_body(double im,double ix,double iy,double idx,double idy)
{
number++;
x= (double *)realloc(x, sizeof(double)*number);
y= (double *)realloc(y, sizeof(double)*number);
dx= (double *)realloc(dx, sizeof(double)*number);
dy= (double *)realloc(dy, sizeof(double)*number);
mass=(double *)realloc(mass,sizeof(double)*number);
x[number-1]=ix;
y[number-1]=iy;
dx[number-1]=idx;
dy[number-1]=idy;
mass[number-1]=im;
return;
}