]> www.ginac.de Git - ginac.git/blobdiff - ginac/input_parser.yy
- Remved obsolete remainders of preprocessor symbol NO_NAMESPACE_GINAC.
[ginac.git] / ginac / input_parser.yy
index 5a80c95cadf3f39c40ce3a47f4bda6dfb0e7b668..9eab1a594cb85a0e28eebece3c7cab9339eebfe5 100644 (file)
@@ -4,7 +4,7 @@
  *  This file must be processed with yacc/bison. */
 
 /*
  *  This file must be processed with yacc/bison. */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 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
  *
  *  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
 #include "matrix.h"
 #include "inifcns.h"
 
 #include "matrix.h"
 #include "inifcns.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 #define YYERROR_VERBOSE 1
 
 
 #define YYERROR_VERBOSE 1
 
-#define yylex ginac_yylex
-#define yyerror ginac_yyerror
-
 // Parsed output expression
 ex parsed_ex;
 
 // Last error message returned by parser
 // Parsed output expression
 ex parsed_ex;
 
 // Last error message returned by parser
-static string parser_error;
+static std::string parser_error;
 %}
 
 /* Tokens (T_LITERAL means a literal value returned by the parser, but not
 %}
 
 /* Tokens (T_LITERAL means a literal value returned by the parser, but not
@@ -81,8 +76,8 @@ input : exp {
                try {
                        parsed_ex = $1;
                        YYACCEPT;
                try {
                        parsed_ex = $1;
                        YYACCEPT;
-               } catch (exception &e) {
-                       parser_error = e.what();
+               } catch (std::exception &err) {
+                       parser_error = err.what();
                        YYERROR;
                }
        }
                        YYERROR;
                }
        }
@@ -90,12 +85,17 @@ input       : exp {
        ;
 
 exp    : T_NUMBER              {$$ = $1;}
        ;
 
 exp    : T_NUMBER              {$$ = $1;}
-       | T_SYMBOL              {$$ = $1.eval();}
+       | T_SYMBOL {
+               if (is_lexer_symbol_predefined($1))
+                       $$ = $1.eval();
+               else
+                       throw (std::runtime_error("unknown symbol '" + ex_to_symbol($1).get_name() + "'"));
+       }
        | T_LITERAL             {$$ = $1;}
        | T_DIGITS              {$$ = $1;}
        | T_SYMBOL '(' exprseq ')' {
        | T_LITERAL             {$$ = $1;}
        | T_DIGITS              {$$ = $1;}
        | T_SYMBOL '(' exprseq ')' {
-               unsigned i = function::find_function(ex_to_symbol($1).getname(), $3.nops());
-               $$ = function(i, static_cast<const exprseq &>(*($3.bp)));
+               unsigned i = function::find_function(ex_to_symbol($1).get_name(), $3.nops());
+               $$ = function(i, static_cast<const exprseq &>(*($3.bp))).eval(1);
        }
        | exp T_EQUAL exp       {$$ = $1 == $3;}
        | exp T_NOTEQ exp       {$$ = $1 != $3;}
        }
        | exp T_EQUAL exp       {$$ = $1 == $3;}
        | exp T_NOTEQ exp       {$$ = $1 != $3;}
@@ -107,14 +107,13 @@ exp       : T_NUMBER              {$$ = $1;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
-       | exp '%' exp           {$$ = $1 % $3;}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = pow($1, $3);}
        | exp '!'               {$$ = factorial($1);}
        | '(' exp ')'           {$$ = $2;}
        | '[' list_or_empty ']' {$$ = $2;}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = pow($1, $3);}
        | exp '!'               {$$ = factorial($1);}
        | '(' exp ')'           {$$ = $2;}
        | '[' list_or_empty ']' {$$ = $2;}
-       | T_MATRIX_BEGIN matrix T_MATRIX_END    {$$ = lst_to_matrix($2);}
+       | T_MATRIX_BEGIN matrix T_MATRIX_END    {$$ = lst_to_matrix(ex_to_lst($2));}
        ;
 
 exprseq        : exp                   {$$ = exprseq($1);}
        ;
 
 exprseq        : exp                   {$$ = exprseq($1);}
@@ -144,19 +143,16 @@ row       : exp                   {$$ = lst($1);}
 
 %%
 // Get last error encountered by parser
 
 %%
 // Get last error encountered by parser
-string get_parser_error(void)
+std::string get_parser_error(void)
 {
        return parser_error;
 }
 
 {
        return parser_error;
 }
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
 
 } // namespace GiNaC
 
-using GiNaC::parser_error;
-#endif // ndef NO_NAMESPACE_GINAC
-
 // Error print routine (store error string in parser_error)
 int ginac_yyerror(char *s)
 {
 // Error print routine (store error string in parser_error)
 int ginac_yyerror(char *s)
 {
-       parser_error = string(s) + " at " + string(ginac_yytext);
+       GiNaC::parser_error = std::string(s) + " at " + std::string(ginac_yytext);
+       return 0;
 }
 }