]> www.ginac.de Git - ginac.git/blobdiff - ginsh/ginsh_parser.yy
- added using namespace GiNaC; after each #include<ginac/ginac.h>;
[ginac.git] / ginsh / ginsh_parser.yy
index 6601a2a04e2c950fdcea3c733ef6aed37f1feb74..99478df7ecbc44a67ee2095b03b3ee1066a5cf5a 100644 (file)
@@ -1,7 +1,23 @@
-/*
- *  ginsh.y - GiNaC Interactive Shell, input grammar definition
+/** @file ginsh_parser.yy
+ *
+ *  Input grammar definition for ginsh.
+ *  This file must be processed with yacc/bison.
+ *
+ *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *
+ *  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.
  *
- *  This file must be processed with yacc/bison
+ *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 
 #include <unistd.h>
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-extern "C" {
-#include <readline/readline.h>
-#include <readline/history.h>
-}
-
 #include <map>
 #include <string>
 #include <stdexcept>
 
-#include <ginac/ginac.h>
 #include "ginsh.h"
 
 // Original readline settings
@@ -110,6 +116,15 @@ line       : ';'
                                YYERROR;
                        }
                }
+       | exp ':'
+               {
+                       try {
+                               push($1);
+                       } catch (exception &e) {
+                               cerr << e.what() << endl;
+                               YYERROR;
+                       }
+               }
        | T_PRINT '(' exp ')' ';'
                {
                        try {
@@ -130,6 +145,7 @@ line        : ';'
                        cout << " out of a possible 350.\n";
                }
        | error ';'             {yyclearin; yyerrok;}
+       | error ':'             {yyclearin; yyerrok;}
        ;
 
 exp    : T_NUMBER              {$$ = $1;}
@@ -207,9 +223,6 @@ row : exp                   {$$ = lst($1);}
  */
 
 %%
-const int GINSH_VERSION = 0;
-const int GINSH_REVISION = 3;
-
 // Error print routine
 int yyerror(char *s)
 {
@@ -474,7 +487,7 @@ static ex f_ginac_function(const exprseq &es, int serial)
        return function(serial, es).eval(1);
 }
 
-void ginsh_get_ginac_functions(void)
+void GiNaC::ginsh_get_ginac_functions(void)
 {
        vector<registered_function_info>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
        unsigned serial = 0;
@@ -582,7 +595,7 @@ int main(int argc, char **argv)
 {
        // Print banner in interactive mode
        if (isatty(0)) {
-               cout << "ginsh - GiNaC Interactive Shell V" << GINSH_VERSION << "." << GINSH_REVISION << endl;
+               cout << "ginsh - GiNaC Interactive Shell (" << PACKAGE << " " << VERSION << ")\n";
                cout << "Copyright (C) 1999 Johannes Gutenberg Universitaet Mainz, Germany\n";
                cout << "This is free software, and you are welcome to redistribute it\n";
                cout << "under certain conditions; see the file COPYING for details.\n"; 
@@ -645,6 +658,19 @@ int main(int argc, char **argv)
        orig_completion_append_character = rl_completion_append_character;
        orig_basic_word_break_characters = rl_basic_word_break_characters;
 
+       // Init input file list, open first file
+       num_files = argc - 1;
+       file_list = argv + 1;
+       if (num_files) {
+               yyin = fopen(*file_list, "r");
+               if (yyin == NULL) {
+                       cerr << "Can't open " << *file_list << endl;
+                       exit(1);
+               }
+               num_files--;
+               file_list++;
+       }
+
        // Parse input, catch all remaining exceptions
        int result;
 again: try {