]> www.ginac.de Git - ginac.git/blobdiff - ginsh/ginsh_parser.yy
- added print_latex() and print_csrc()
[ginac.git] / ginsh / ginsh_parser.yy
index f2cfc769103a4a47f5e818a523d0e758d4ee2d99..7c7e548cc41d8a01a036a7c38616cec456c644c7 100644 (file)
@@ -4,7 +4,7 @@
  *  This file must be processed with yacc/bison. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2002 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
@@ -92,14 +92,15 @@ static void print_help_topics(void);
 %token T_NUMBER T_SYMBOL T_LITERAL T_DIGITS T_QUOTE T_QUOTE2 T_QUOTE3
 %token T_EQUAL T_NOTEQ T_LESSEQ T_GREATEREQ
 
-%token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
+%token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_PRINTLATEX T_PRINTCSRC T_TIME
+%token T_XYZZY T_INVENTORY T_LOOK T_SCORE
 
 /* Operator precedence and associativity */
 %right '='
 %left T_EQUAL T_NOTEQ
 %left '<' '>' T_LESSEQ T_GREATEREQ
 %left '+' '-'
-%left '*' '/' '%'
+%left '*' '/'
 %nonassoc NEG
 %right '^'
 %nonassoc '!'
@@ -156,6 +157,22 @@ line       : ';'
                        YYERROR;
                }
        }
+       | T_PRINTLATEX '(' exp ')' ';' {
+               try {
+                       $3.print(print_latex(std::cout)); cout << endl;
+               } catch (exception &e) {
+                       std::cerr << e.what() << endl;
+                       YYERROR;
+               }
+       }
+       | T_PRINTCSRC '(' exp ')' ';' {
+               try {
+                       $3.print(print_csrc_double(std::cout)); cout << endl;
+               } catch (exception &e) {
+                       std::cerr << e.what() << endl;
+                       YYERROR;
+               }
+       }
        | '?' T_SYMBOL          {print_help(ex_to<symbol>($2).get_name());}
        | '?' T_TIME            {print_help("time");}
        | '?' '?'               {print_help_topics();}
@@ -203,13 +220,13 @@ exp       : T_NUMBER              {$$ = $1;}
        | T_SYMBOL '(' exprseq ')' {
                fcn_tab::const_iterator i = find_function($1, $3.nops());
                if (i->second.is_ginac) {
-                       $$ = ((fcnp2)(i->second.p))(static_cast<const exprseq &>(*($3.bp)), i->second.serial);
+                       $$ = ((fcnp2)(i->second.p))(ex_to<exprseq>($3), i->second.serial);
                } else {
-                       $$ = (i->second.p)(static_cast<const exprseq &>(*($3.bp)));
+                       $$ = (i->second.p)(ex_to<exprseq>($3));
                }
        }
        | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to<numeric>($3).to_int();}
-       | T_SYMBOL '=' exp      {$$ = $3; ex_to_nonconst_symbol($1).assign($3);}
+       | T_SYMBOL '=' exp      {$$ = $3; const_cast<symbol&>(ex_to<symbol>($1)).assign($3);}
        | exp T_EQUAL exp       {$$ = $1 == $3;}
        | exp T_NOTEQ exp       {$$ = $1 != $3;}
        | exp '<' exp           {$$ = $1 < $3;}
@@ -230,7 +247,7 @@ exp : T_NUMBER              {$$ = $1;}
        ;
 
 exprseq        : exp                   {$$ = exprseq($1);}
-       | exprseq ',' exp       {exprseq es(static_cast<exprseq &>(*($1.bp))); $$ = es.append($3);}
+       | exprseq ',' exp       {exprseq es(ex_to<exprseq>($1)); $$ = es.append($3);}
        ;
 
 list_or_empty: /* empty */     {$$ = *new lst;}
@@ -238,15 +255,15 @@ list_or_empty: /* empty */        {$$ = *new lst;}
        ;
 
 list   : exp                   {$$ = lst($1);}
-       | list ',' exp          {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($3);}
+       | list ',' exp          {lst l(ex_to<lst>($1)); $$ = l.append($3);}
        ;
 
 matrix : '[' row ']'           {$$ = lst($2);}
-       | matrix ',' '[' row ']' {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($4);}
+       | matrix ',' '[' row ']' {lst l(ex_to<lst>($1)); $$ = l.append($4);}
        ;
 
 row    : exp                   {$$ = lst($1);}
-       | row ',' exp           {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($3);}
+       | row ',' exp           {lst l(ex_to<lst>($1)); $$ = l.append($3);}
        ;
 
 
@@ -490,7 +507,7 @@ static ex f_transpose(const exprseq &e)
 static ex f_unassign(const exprseq &e)
 {
        CHECK_ARG(0, symbol, unassign);
-       ex_to_nonconst_symbol(e[0]).unassign();
+       const_cast<symbol&>(ex_to<symbol>(e[0])).unassign();
        return e[0];
 }
 
@@ -766,7 +783,7 @@ static char **fcn_completion(const char *text, int start, int end)
                rl_basic_word_break_characters = orig_basic_word_break_characters;
                rl_completer_word_break_characters = rl_basic_word_break_characters;
 #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2)
-               return completion_matches(text, (CPFunction *)filename_completion_function);
+               return completion_matches(const_cast<char *>(text), (CPFunction *)filename_completion_function);
 #else
                return rl_completion_matches(text, rl_filename_completion_function);
 #endif
@@ -776,7 +793,7 @@ static char **fcn_completion(const char *text, int start, int end)
                rl_basic_word_break_characters = " \t\n\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~";
                rl_completer_word_break_characters = rl_basic_word_break_characters;
 #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2)
-               return completion_matches(text, (CPFunction *)fcn_generator);
+               return completion_matches(const_cast<char *>(text), (CPFunction *)fcn_generator);
 #else
                return rl_completion_matches(text, fcn_generator);
 #endif
@@ -786,7 +803,7 @@ static char **fcn_completion(const char *text, int start, int end)
 void greeting(void)
 {
     cout << "ginsh - GiNaC Interactive Shell (" << PACKAGE << " V" << VERSION << ")" << endl;
-    cout << "  __,  _______  Copyright (C) 1999-2001 Johannes Gutenberg University Mainz,\n"
+    cout << "  __,  _______  Copyright (C) 1999-2002 Johannes Gutenberg University Mainz,\n"
          << " (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.\n"
          << "  ._) i N a C | You are welcome to redistribute it under certain conditions.\n"
          << "<-------------' For details type `warranty;'.\n" << endl;
@@ -810,10 +827,10 @@ int main(int argc, char **argv)
 
        // Init help for operators (automatically generated from man page)
        insert_help("operators", "Operators in falling order of precedence:");
-#include "ginsh_op_help.c"
+#include "ginsh_op_help.h"
 
        // Init help for built-in functions (automatically generated from man page)
-#include "ginsh_fcn_help.c"
+#include "ginsh_fcn_help.h"
 
        // Help for GiNaC functions is added manually
        insert_help(builtin_help);