freely between tokens. To quit ginsh, enter
.BR quit " or " exit ,
or type an EOF (Ctrl-D) at the prompt.
+.SS COMMENTS
+Anything following a double slash
+.RB ( // )
+up to the end of the line is treated as a comment and ignored.
.SS NUMBERS
-ginsh accepts numbers in all formats accepted by CLN (the Class Library for
-Numbers, that is the foundation of GiNaC's numerics). This includes arbitrary
+ginsh accepts numbers in the usual decimal notations. This includes arbitrary
precision integers and rationals as well as floating point numbers in standard
or scientific notation (e.g.
.BR 1.2E6 ).
.RB ( . ),
it is an (inexact) floating point number; otherwise it is an (exact) integer or
rational.
+Integers can be specified in binary, octal, hexadecimal or arbitrary (2-36) base
+by prefixing them with
+.BR #b ", " #o ", " #x ", or "
+.BI # n R
+, respectively.
.SS SYMBOLS
Symbols are made up of a string of alphanumeric characters and the underscore
.RB ( _ ),
.B Catalan
Catalan's Constant
.TP
-.B gamma
+.B Euler
Euler-Mascheroni Constant
.TP
.B I
.IR expression .
This is useful for debugging and for learning about GiNaC internals.
.PP
+The command
+.RS
+.BI iprint( expression );
+.RE
+prints the given
+.I expression
+(which must evaluate to an integer) in decimal, octal, and hexadecimal representations.
+.PP
Finally, the shell escape
.RS
.B !
%%
[ \t\n]+ /* skip whitespace */
\\$ /* skip line continuations */
-"#".* /* skip comments starting with "#" */
+"//".* /* skip comments starting with "//" */
^"!".* system(yytext + 1); /* execute shell command */
/* special values */
quit|exit return T_QUIT;
warranty return T_WARRANTY;
print return T_PRINT;
-read return T_READ;
-write return T_WRITE;
+iprint return T_IPRINT;
time return T_TIME;
xyzzy return T_XYZZY;
inventory return T_INVENTORY;
/* numbers */
{D}+ |
+"#"{D}+"R"{AN}+ |
+"#b"([01])+ |
+"#o"[0-7]+ |
+"#x"[0-9a-fA-F]+ |
{D}+"."{D}*({E})? |
{D}*"."{D}+({E})? |
{D}+{E} yylval = numeric(yytext); return T_NUMBER;
%token T_NUMBER T_SYMBOL T_LITERAL T_DIGITS T_QUOTE T_QUOTE2 T_QUOTE3
%token T_EQUAL T_NOTEQ T_LESSEQ T_GREATEREQ T_MATRIX_BEGIN T_MATRIX_END
-%token T_QUIT T_WARRANTY T_PRINT T_READ T_WRITE T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
+%token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
/* Operator precedence and associativity */
%right '='
YYERROR;
}
}
+ | T_IPRINT '(' exp ')' ';' {
+ try {
+ ex e = $3;
+ if (!e.info(info_flags::integer))
+ throw (std::invalid_argument("argument to iprint() must be an integer"));
+ long i = ex_to_numeric(e).to_long();
+ cout << i << endl;
+ cout << "#o" << oct << i << endl;
+ cout << "#x" << hex << i << endl;
+ } catch (exception &e) {
+ cerr << e.what() << endl;
+ YYERROR;
+ }
+ }
| '?' T_SYMBOL {print_help(ex_to_symbol($2).getname());}
| '?' '?' {print_help_topics();}
| T_QUIT {YYACCEPT;}
static ex f_sqrt(const exprseq &e) {return sqrt(e[0]);}
static ex f_subs2(const exprseq &e) {return e[0].subs(e[1]);}
-#define CHECK_ARG(num, type, fcn) if (!is_ex_of_type(e[num], type)) throw(std::invalid_argument("argument " #num " to " #fcn " must be a " #type))
+#define CHECK_ARG(num, type, fcn) if (!is_ex_of_type(e[num], type)) throw(std::invalid_argument("argument " #num " to " #fcn "() must be a " #type))
static ex f_charpoly(const exprseq &e)
{