[pure-lang-svn] SF.net SVN: pure-lang: [43] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-03 23:33:33
|
Revision: 43 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=43&view=rev Author: agraef Date: 2008-05-03 16:33:41 -0700 (Sat, 03 May 2008) Log Message: ----------- Add an explicit notation for big integers. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lexer.ll pure/trunk/printer.cc pure/trunk/test/test1.log Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-05-03 23:01:13 UTC (rev 42) +++ pure/trunk/ChangeLog 2008-05-03 23:33:41 UTC (rev 43) @@ -1,5 +1,13 @@ 2008-05-04 Albert Graef <Dr....@t-...> + * lexer.ll, printer.cc: Add an explicit notation for big + integers. Any integer immediately followed by the uppercase letter + "G" (as in "biG" or "GMP") will now always be interpreted as a + bigint constant, even if it fits into a machine integer. This + notation is also used when printing bigint constants. This change + was necessary to make it possible to write rules matching against + "small bigint" constants. + * lib/primitives.pure: Added operations to recognize function applications and extract the function and argument parts, implemented in runtime.cc. Note that these operations can't be Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-05-03 23:01:13 UTC (rev 42) +++ pure/trunk/lexer.ll 2008-05-03 23:33:41 UTC (rev 43) @@ -604,6 +604,13 @@ return token::BIGINT; } } +{int}G { + mpz_t *z = (mpz_t*)malloc(sizeof(mpz_t)); + mpz_init(*z); + mpz_set_str(*z, yytext, 0); + yylval->zval = z; + return token::BIGINT; +} {float} yylval->dval = my_strtod(yytext, NULL); return(token::DBL); \"{str}\" { char *msg; Modified: pure/trunk/printer.cc =================================================================== --- pure/trunk/printer.cc 2008-05-03 23:01:13 UTC (rev 42) +++ pure/trunk/printer.cc 2008-05-03 23:33:41 UTC (rev 43) @@ -202,7 +202,7 @@ return os << x.ival(); case EXPR::BIGINT: { char *s = mpz_get_str(NULL, 10, x.zval()); - os << s; free(s); + os << s << "G"; free(s); return os; } case EXPR::DBL: { @@ -439,7 +439,7 @@ return os << " state " << tr.st->s << endl; case EXPR::BIGINT: { char *s = mpz_get_str(NULL, 10, tr.z); - os << "\t" << s; + os << "\t" << s << "G"; print_ttag(os, tr.ttag); os << " state " << tr.st->s << endl; free(s); @@ -621,7 +621,7 @@ return os << x->data.i; case EXPR::BIGINT: { char *s = mpz_get_str(NULL, 10, x->data.z); - os << s; free(s); + os << s << "G"; free(s); return os; } case EXPR::DBL: { Modified: pure/trunk/test/test1.log =================================================================== --- pure/trunk/test/test1.log 2008-05-03 23:01:13 UTC (rev 42) +++ pure/trunk/test/test1.log 2008-05-03 23:33:41 UTC (rev 43) @@ -92,7 +92,7 @@ state 2: #1 #2 } fact 50; -30414093201713378043612608166064768844377641568960512000000000000 +30414093201713378043612608166064768844377641568960512000000000000G fib1 0 = 0; fib1 1 = 1; fib1 n/*0:1*/ = fib1 (n/*0:1*/-2)+fib1 (n/*0:1*/-1) if n/*0:1*/>1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |