| LLOOP Index | GSP Language | GSP Library | Framework Classes | Component Classes |
This is the verbatim text of the file "double.gsp" part of the LLOOP package. The copyright remains with Michel MEHL. All rights reserved.
/**
* Reads a "double" C type (including overflow check).
*/
symbol FloatToken extends class universal::Float()
include "universal__Numeric.h";
token DoubleToken extends class universal::Double()
include <stdio.h>, <ctype.h>, "universal__Numeric.h"
alias "double"
parse
{{
char c = 0;
short iSign = 1;
short iSignExp = 1;
universal::String s;
double dVal = 0.0;
double dExp = 0.0;
is.get(c);
if (c == '-')
{
iSign = -1;
is.get(c);
}
else if (c == '+')
{
iSign = 1;
is.get(c);
}
if (is.fail() || (!isdigit(c) && c != '.' && tolower(c) != 'e' ) )
{
abort("");
}
// Get integer part
for (dVal = 0.0; isdigit(c) && !is.fail(); is.get(c))
dVal = 10.0 * dVal + (c - '0');
if (c == '.')
is.get(c);
// Get decimal part
for (dExp = 10.0; isdigit(c) && !is.fail(); is.get(c)) {
dVal = dVal + (c - '0') / dExp;
dExp *= 10.0;
}
// Get exponent
dExp = 1.0;
if ( (tolower(c) == 'e') && !is.fail())
{
is.get(c);
if (c == '-')
{
iSignExp = -1;
is.get(c);
}
else if (c == '+')
{
iSignExp = 1;
is.get(c);
}
if (is.fail() || !isdigit(c))
{
abort("");
}
for (dExp = 0.0; isdigit(c) && !is.fail(); is.get(c))
dExp = 10.0 * dExp + (c - '0');
}
if (!is.fail())
{
is.seekg(-1, ios::cur); // Set pos. to the immediate following char
double dRes = iSign * dVal / dExp;
Double::operator=(dRes);
}
}}
expand
{{
os << toString();
}}
FloatToken ::= DoubleToken
{{
Float::operator=((float)$1);
}}
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 |