/* -*-c++-*- */ /* * smeg - A satellite modelling and prediction tool * Copyright (C) 1999 Tom Rothamel * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ %{ #include "sts2.h" #include #include void yyerror(char *); void quit(); int yylex(); #define YYDEBUG 1 %} %union { char *str; STEP *step; int i; double dbl; } %token STR %token ECHO %token SET %token DEF %token CALL %token TLE %token FILTER %token UNFILTER %token NORADFILTER %token CURRENT %token POSITION %token SATX %token SHOW %token SATLIST %token LOCATION %token LOOK %token LIVE %token PREDICT %token PASSES %token _STEP %token PAGER %token PRINT %token QUIET %token VERBOSE %token DEBUG %token TEST %token QUIT %token TRUE %token FALSE %type expr %type expr1 %type expr2 %token STARTDATE %token ENDDATE %token DATENUMBER %token NOW %token YESTERDAY %token TODAY %token TOMORROW %token NOON %token MIDNIGHT %token SECONDS %token MINUTES %token HOURS %token DAYS %type timespec %type datespec %type fullspec %type evenmorefullspec %type sgptimespec %% program: | program statement | program error ; statement: PAGER { open_less(); } statement { close_less(); } | PRINT { open_print(); } statement { close_print(); } | ECHO STR { fprintf(out, "%s\n", $2); } | SET STR STR { Set($2, $3); } | DEF STR STR { DefProc($2, $3); } | CALL STR { CallProc($2); } | TLE STR { LoadSatsFromFile($2); } | FILTER SATLIST expr { SatlistFilter($3); } | FILTER PASSES expr { PasslistFilter($3); } | UNFILTER SATLIST { SatlistUnfilter(); } | UNFILTER PASSES { PasslistUnfilter(); } | NORADFILTER { NoradFilter(); } | SHOW SATLIST { ShowSatlist(); } | SHOW LOCATION { ShowLocation(); } | SHOW PASSES { ShowPasslist(); } | CURRENT POSITION { CurrentPosition(NULL); } | CURRENT POSITION expr { CurrentPosition($3); } | CURRENT SATX { CurrentSatX(); } | CURRENT LOOK { CurrentLook(NULL); } | PREDICT PASSES { Predict(sgp_now(), sgp_now()+1); } | PREDICT PASSES sgptimespec { Predict(sgp_now(), $3); } | PREDICT PASSES sgptimespec sgptimespec{ Predict($3, $4); } | LIVE SATLIST { LiveSatlist(); } | LIVE SATLIST expr { SatlistFilter($3); LiveSatlist(); SatlistUnfilter(); } | _STEP PASSES expr { StepPasses(30, $3); } | _STEP PASSES STR expr { StepPasses(atoi($3), $4); } | LIVE PASSES { LivePasslist(); } | QUIET { verbose = 0; } | VERBOSE { verbose = 1; } | DEBUG TEST expr { if (run(NULL, $3)) { printf("True.\n"); } else { printf("False.\n"); } } | DEBUG LOCATION { DebugLocation(); } | DEBUG sgptimespec { char buf[100]; strfsgptime(buf, 100, "%Y%m%d %H:%M:%S", $2); printf("Parsed date is: %s\n", buf); } | QUIT { quit(); } ; expr: { $$ = newSTEP(op_true, 0, "Empty_true"); } | expr1 {$$ = $1;} | expr '|' expr { $$ = newSTEP(op_or, 0, "Or"); $$->s1 = $1; $$->s2 = $3; } ; expr1: expr2 {$$ = $1;} | expr1 '&' expr1 { $$ = newSTEP(op_and, 0, "And"); $$->s1 = $1; $$->s2 = $3; } ; expr2: '(' expr ')' { $$ = $2; } | STR '<' STR { $$ = newSTEPident($1, '<'); if (!$$) { fprintf(stderr, "Error: Unknown expressor %s.\n", $1); YYERROR; } $$->str = $3; $$->d = atof($3); $$->i = atoi($3); } | STR '>' STR { $$ = newSTEPident($1, '>'); if (!$$) { fprintf(stderr, "Error: Unknown expressor %s.\n", $1); YYERROR; } $$->str = $3; $$->d = atof($3); $$->i = atoi($3); } | STR '=' STR { $$ = newSTEPident($1, '='); if (!$$) { fprintf(stderr, "Error: Unknown expressor %s.\n", $1); YYERROR; } $$->str = $3; $$->d = atof($3); $$->i = atoi($3); } | STR '~' STR { $$ = newSTEPident($1, '~'); if (!$$) { fprintf(stderr, "Error: Unknown expressor %s.\n", $1); YYERROR; } if (regcomp(&($$->reg), $3, REG_EXTENDED | REG_ICASE)) { fprintf(stderr, "Error: Error compiling regexp.\n"); YYERROR; } $$->str = $3; $$->d = atof($3); $$->i = atoi($3); } | STR { $$ = newSTEPident($1, ' '); if (!$$) { fprintf(stderr, "Error: Unknown expressor %s.\n", $1); YYERROR; } } | TRUE { $$ = newSTEP(op_true, 0, "True"); } | FALSE { $$ = newSTEP(op_false, 0, "False"); } ; evenmorefullspec: fullspec { $$ = $1} | evenmorefullspec '+' DATENUMBER SECONDS { $$ = $1 + $3; } | evenmorefullspec '+' DATENUMBER MINUTES { $$ = $1 + $3 * 60; } | evenmorefullspec '+' DATENUMBER HOURS { $$ = $1 + $3 * 3600; } | evenmorefullspec '+' DATENUMBER DAYS { $$ = $1 + $3 * 86400; } | evenmorefullspec '-' DATENUMBER SECONDS { $$ = $1 - $3; } | evenmorefullspec '-' DATENUMBER MINUTES { $$ = $1 - $3 * 60; } | evenmorefullspec '-' DATENUMBER HOURS { $$ = $1 - $3 * 3600; } | evenmorefullspec '-' DATENUMBER DAYS { $$ = $1 - $3 * 86400; } ; fullspec: timespec datespec { $$ = $1 + $2; } | datespec timespec { $$ = $1 + $2;} | timespec { $$ = today() + $1; if ($$ < time(NULL)) $$ += 86400; } | NOW { $$ = time(NULL); } ; sgptimespec: STARTDATE evenmorefullspec ENDDATE { $$ = -10957.5 + (1.0/86400.0 * (double) $2); } | STARTDATE ENDDATE { $$ = sgp_now(); } ; timespec: DATENUMBER ':' DATENUMBER ':' DATENUMBER { $$ = randomtime($1, $3, $5); } | DATENUMBER ':' DATENUMBER { $$ = randomtime($1, $3, 0); } | NOON { $$ = noon(); } | MIDNIGHT { $$ = midnight(); } ; datespec: DATENUMBER '-' DATENUMBER '-' DATENUMBER { $$ = randomdate($1, $3, $5); } | DATENUMBER '/' DATENUMBER '/' DATENUMBER { $$ = randomdate($5, $1, $3); } | YESTERDAY { $$ = yesterday(); } | TODAY { $$ = today(); } | TOMORROW { $$ = tomorrow(); } ; %% void yyerror(char *s) { printf("Error: %s\n", s); } void scan_string(char *); void ParseString(char *read) { scan_string(read); yyparse(); }