From: Christian Bauer Date: Thu, 17 Oct 2002 18:34:38 +0000 (+0000) Subject: - added print_latex() and print_csrc() X-Git-Tag: release_1-0-12~13 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=dff5209ee7cc816583f6abe27a4e784e34f0a664;ds=sidebyside - added print_latex() and print_csrc() - updated the man page --- diff --git a/ginsh/ginsh.1.in b/ginsh/ginsh.1.in index 46b6ac0b..9f797f57 100644 --- a/ginsh/ginsh.1.in +++ b/ginsh/ginsh.1.in @@ -144,9 +144,6 @@ unary minus .B * multiplication .TP -.B % -non-commutative multiplication -.TP .B / division .TP @@ -407,6 +404,22 @@ This is useful for debugging and for learning about GiNaC internals. .PP The command .RS +.BI print_latex( expression ); +.RE +prints a LaTeX representation of the given +.IR expression . +.PP +The command +.RS +.BI print_csrc( expression ); +.RE +prints the given +.I expression +in a way that can be used in a C or C++ program (complex numbers are not +supported, though). +.PP +The command +.RS .BI iprint( expression ); .RE prints the given diff --git a/ginsh/ginsh_lexer.ll b/ginsh/ginsh_lexer.ll index c4beae09..0a0a7f48 100644 --- a/ginsh/ginsh_lexer.ll +++ b/ginsh/ginsh_lexer.ll @@ -72,6 +72,8 @@ quit|exit return T_QUIT; warranty return T_WARRANTY; print return T_PRINT; iprint return T_IPRINT; +print_latex return T_PRINTLATEX; +print_csrc return T_PRINTCSRC; time return T_TIME; xyzzy return T_XYZZY; inventory return T_INVENTORY; diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index 12aa103a..7c7e548c 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -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($2).get_name());} | '?' T_TIME {print_help("time");} | '?' '?' {print_help_topics();}