]> www.ginac.de Git - ginac.git/commitdiff
- changed comment starter from # to //
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 5 Apr 2000 19:30:47 +0000 (19:30 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 5 Apr 2000 19:30:47 +0000 (19:30 +0000)
- implemented #b, #o, #x and #nR prefixes for binary, octal, hexadecimal, and
  base-n integers
- added iprint() command for decimal, octal, and hexadecimal output of integers
- updated man page

ginsh/ginsh.1
ginsh/ginsh_lexer.ll
ginsh/ginsh_parser.yy

index 53e5bcdb467e7bf1d4e06d2bf1530f186d691c2a..b84aca96700fe43c909330dc19a83aad187193ce 100644 (file)
@@ -36,9 +36,12 @@ expressions on one line. Whitespace (spaces, tabs, newlines) can be applied
 freely between tokens. To quit ginsh, enter
 .BR quit " or " exit ,
 or type an EOF (Ctrl-D) at the prompt.
 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
 .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 ).
 precision integers and rationals as well as floating point numbers in standard
 or scientific notation (e.g.
 .BR 1.2E6 ).
@@ -46,6 +49,11 @@ The general rule is that if a number contains a decimal point
 .RB ( . ),
 it is an (inexact) floating point number; otherwise it is an (exact) integer or
 rational.
 .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 ( _ ),
 .SS SYMBOLS
 Symbols are made up of a string of alphanumeric characters and the underscore
 .RB ( _ ),
@@ -82,7 +90,7 @@ Archimedes' Constant
 .B Catalan
 Catalan's Constant
 .TP
 .B Catalan
 Catalan's Constant
 .TP
-.B gamma
+.B Euler
 Euler-Mascheroni Constant
 .TP
 .B I
 Euler-Mascheroni Constant
 .TP
 .B I
@@ -369,6 +377,14 @@ will print a dump of GiNaC's internal representation for the given
 .IR expression .
 This is useful for debugging and for learning about GiNaC internals.
 .PP
 .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 !
 Finally, the shell escape
 .RS
 .B !
index 250403536b19094cfea4ca69ade10bb6913341fa..d27d0fe275b8917ca06b32153e9e901716e6dd0b 100644 (file)
@@ -55,7 +55,7 @@ AN    [0-9a-zA-Z_]
 %%
 [ \t\n]+               /* skip whitespace */
 \\$                    /* skip line continuations */
 %%
 [ \t\n]+               /* skip whitespace */
 \\$                    /* skip line continuations */
-"#".*                  /* skip comments starting with "#" */
+"//".*                 /* skip comments starting with "//" */
 ^"!".*                 system(yytext + 1);     /* execute shell command */
 
                        /* special values */
 ^"!".*                 system(yytext + 1);     /* execute shell command */
 
                        /* special values */
@@ -70,8 +70,7 @@ Digits                        yylval = (long)Digits; return T_DIGITS;
 quit|exit              return T_QUIT;
 warranty               return T_WARRANTY;
 print                  return T_PRINT;
 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;
 time                   return T_TIME;
 xyzzy                  return T_XYZZY;
 inventory              return T_INVENTORY;
@@ -95,6 +94,10 @@ score                        return T_SCORE;
 
                        /* numbers */
 {D}+                   |
 
                        /* 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;
 {D}+"."{D}*({E})?      |
 {D}*"."{D}+({E})?      |
 {D}+{E}                        yylval = numeric(yytext); return T_NUMBER;
index 8538ad0bcf192b2d511be73f485188e703900d81..52a134f599fb0a9e8fee39ab8bc482f3bfba505d 100644 (file)
@@ -87,7 +87,7 @@ 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 T_MATRIX_BEGIN T_MATRIX_END
 
 %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 '='
 
 /* Operator precedence and associativity */
 %right '='
@@ -137,6 +137,20 @@ line       : ';'
                        YYERROR;
                }
        }
                        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;}
        | '?' T_SYMBOL          {print_help(ex_to_symbol($2).getname());}
        | '?' '?'               {print_help_topics();}
        | T_QUIT                {YYACCEPT;}
@@ -270,7 +284,7 @@ static ex f_pow(const exprseq &e) {return pow(e[0], e[1]);}
 static ex f_sqrt(const exprseq &e) {return sqrt(e[0]);}
 static ex f_subs2(const exprseq &e) {return e[0].subs(e[1]);}
 
 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)
 {
 
 static ex f_charpoly(const exprseq &e)
 {