[Python-checkins] CVS: python/dist/src/Parser tokenizer.c,2.50,2.51

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 07 Aug 2001 22:00:20 -0700


Update of /cvsroot/python/python/dist/src/Parser
In directory usw-pr-cvs1:/tmp/cvs-serv23513/Parser

Modified Files:
	tokenizer.c 
Log Message:
Implement PEP 238 in its (almost) full glory.

This introduces:

- A new operator // that means floor division (the kind of division
  where 1/2 is 0).

- The "future division" statement ("from __future__ import division)
  which changes the meaning of the / operator to implement "true
  division" (where 1/2 is 0.5).

- New overloadable operators __truediv__ and __floordiv__.

- New slots in the PyNumberMethods struct for true and floor division,
  new abstract APIs for them, new opcodes, and so on.

I emphasize that without the future division statement, the semantics
of / will remain unchanged until Python 3.0.

Not yet implemented are warnings (default off) when / is used with int
or long arguments.

This has been on display since 7/31 as SF patch #443474.

Flames to /dev/null.



Index: tokenizer.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/tokenizer.c,v
retrieving revision 2.50
retrieving revision 2.51
diff -C2 -d -r2.50 -r2.51
*** tokenizer.c	2001/04/21 02:46:11	2.50
--- tokenizer.c	2001/08/08 05:00:18	2.51
***************
*** 81,84 ****
--- 81,86 ----
  	"RIGHTSHIFTEQUAL",
  	"DOUBLESTAREQUAL",
+ 	"DOUBLESLASH",
+ 	"DOUBLESLASHEQUAL",
  	/* This table must match the #defines in token.h! */
  	"OP",
***************
*** 409,412 ****
--- 411,415 ----
  	case '/':
  		switch (c2) {
+ 		case '/':	return DOUBLESLASH;
  		case '=':	return SLASHEQUAL;
  		}
***************
*** 466,469 ****
--- 469,482 ----
  			case '=':
  				return DOUBLESTAREQUAL;
+ 			}
+ 			break;
+ 		}
+ 		break;
+ 	case '/':
+ 		switch (c2) {
+ 		case '/':
+ 			switch (c3) {
+ 			case '=':
+ 				return DOUBLESLASHEQUAL;
  			}
  			break;