| LLOOP Index | GSP Language | GSP Library | Framework Classes | Component Classes |
This is the verbatim text of the file "int.gsp" part of the LLOOP package. The copyright remains with Michel MEHL. All rights reserved.
/**
* Reads a "long" C type (including overflow check).
*/
token SignedIntegerToken extends class universal::SignedInteger()
include <stdio.h>, <ctype.h>, <limits.h>, "universal__Numeric.h"
alias "int"
parse
{{
/* Seems to be less efficient than the code below
unsigned long uVal = 0;
if (is.scan("%ld", &iVal).fail())
abort("");
*/
register unsigned long uVal = 0;
register unsigned long uCount = 0;
char c = 0;
register char minus = 1;
register unsigned long MINUS_EXTRA = 0;
register const unsigned long CHECK_MAX = (unsigned long) (LONG_MAX/10);
is.get(c);
if (c == '-')
{
minus = -1;
MINUS_EXTRA = 1;
c = 0;
is.get(c);
}
while ( isdigit(c) )
{
/* Overflow check */
if (uVal > CHECK_MAX)
{
uCount = 0;
break;
}
uVal = uVal*10;
if ( (uVal + (c - '0')) > ((unsigned long)LONG_MAX + MINUS_EXTRA) )
{
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
SignedInteger::operator=(uVal*minus);
}
}}
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 |