| LLOOP Index | GSP Language | GSP Library | Framework Classes | Component Classes |
This is the verbatim text of the file "uint.gsp" part of the LLOOP package. The copyright remains with Michel MEHL. All rights reserved.
/**
* Reads a "unsigned long" C type (including overflow check).
*/
token UnsignedIntegerToken extends class universal::UnsignedInteger()
include <stdio.h>, <ctype.h>, <limits.h>, "universal__Numeric.h"
alias "uint"
parse
{{
/* Seems to be less efficient than the code below
unsigned long uVal = 0;
if (is.scan("%lu", &uVal).fail())
abort("");
*/
register unsigned long uVal = 0;
register unsigned long uCount = 0;
char c = 0;
register const unsigned long CHECK_MAX = ULONG_MAX/10;
is.get(c);
while ( isdigit(c) )
{
/* Overflow check */
if (uVal > CHECK_MAX)
{
uCount = 0;
break;
}
uVal = uVal*10;
if ( (uVal + (c - '0')) < uVal)
{
uCount = 0;
break;
}
uVal += (c - '0');
uCount++;
c = 0;
is.get(c);
}
if (uCount == 0)
abort("");
else
{
if (is.fail())
is.clear(); // In case of EOF
else
is.seekg(-1, ios::cur); // Set position to the immediate following char
UnsignedInteger::operator=(uVal);
}
}}
expand
{{
os << toString();
}}
This file is part of the LLOOP Reversible Object-Oriented Parser Generator. Copyright (c) 2005-2006 Michel MEHL, France. All rights reserved. LLOOP is distributed by the company ERSA SaRL.
| Copyright (c) 2005-2006 Michel MEHL, Haguenau, France |
| LLOOP version 1.1 |