[antlr-interest] Parsing problem in C++
Arnulf Heller
aheller at gmx.at
Tue Nov 9 05:38:35 PST 2010
hello david,
I think this is the "null value" of class E.
I recently read about that in the template book of Josuttis/Vandervorde.
Don't have a stroustrup book here but look for "Zero Initialization".
In the former book they say:
template <typename T>
void foo()
{
T x = T(); // cannot use T x = 0; for classes!
}
in the std code they probably want to compare _U != 0
-->
_U != E(0)
modern compilers translate T() to 0 if T is int, e.g.
hope that helps,
arnulf
looking forward to ANTLR3 in C++ :)
Am 09.11.2010 14:26, schrieb David Wigg:
> I updated the CPP_parser from Antlr1 to Antlr2. Ramin Zaghi has done a
> great job to convert that to run under Antlr3. However, we do still
> have a problem with understanding one particular piece of code.
>
> This is in an include file, iosfwd (1998). shown below. The line in question is
> for (_N = 0; !eq(*_U, _E(0)); ++_U)
> and I would like to know what _E(0) is in order to able to parse it
> properly. It must be something that returns a value (like a pointer?).
> It looks to me like very early C code for a typecast but a later
> version (2007) of iosfwd has something similar, "_Elem()", in that
> position so I suppose it can't be a typecast.
> Is it a function? It can't be a class because a class doesn't return a value.
>
> I hope some C++ expert can help. If so, it would be a great help if
> he/she could quote chapter and verse from Stroustrup's book (Third
> Edition, or indeed any other) as well since that would help to get our
> C++ grammar file correct..
>
> Thanks.
>
> David Wigg
>
> template<class _E>
> struct char_traits {
> typedef _E char_type;
> typedef _E int_type;
> typedef streampos pos_type;
> typedef streamoff off_type;
> typedef mbstate_t state_type;
> static void __cdecl assign(_E& _X, const _E& _Y)
> {_X = _Y; }
> static bool __cdecl eq(const _E& _X, const _E& _Y)
> {return (_X == _Y); }
> static bool __cdecl lt(const _E& _X, const _E& _Y)
> {return (_X< _Y); }
> static int __cdecl compare(const _E *_U, const _E *_V, size_t _N)
> {for (size_t _I = 0; _I< _N; ++_I, ++_U, ++_V)
> if (!eq(*_U, *_V))
> return (lt(*_U, *_V) ? -1 : +1);
> return (0); }
> static size_t __cdecl length(const _E *_U)
> {size_t _N;
> for (_N = 0; !eq(*_U, _E(0)); ++_U) // I would like
> to know what _E(0) is to parse it
> ++_N;
> return (_N); }
> static _E * __cdecl copy(_E *_U, const _E *_V, size_t _N)
> {_E *_S = _U;
> for (; 0< _N; --_N, ++_U, ++_V)
> assign(*_U, *_V);
> return (_S); }
> static const _E * __cdecl find(const _E *_U, size_t _N,
> const _E& _C)
> {for (; 0< _N; --_N, ++_U)
> if (eq(*_U, _C))
> return (_U);
> return (0); }
> static _E * __cdecl move(_E *_U, const _E *_V, size_t _N)
> {_E *_Ans = _U;
> if (_V< _U&& _U< _V + _N)
> for (_U += _N, _V += _N; 0< _N; --_N)
> assign(*--_U, *--_V);
> else
> for (; 0< _N; --_N, ++_U, ++_V)
> assign(*_U, *_V);
> return (_Ans); }
> static _E * __cdecl assign(_E *_U, size_t _N, const _E& _C)
> {_E *_Ans = _U;
> for (; 0< _N; --_N, ++_U)
> assign(*_U, _C);
> return (_Ans); }
> static _E __cdecl to_char_type(const int_type& _C)
> {return ((_E)_C); }
> static int_type __cdecl to_int_type(const _E& _C)
> {return ((int_type)_C); }
> static bool __cdecl eq_int_type(const int_type& _X,
> const int_type& _Y)
> {return (_X == _Y); }
> static int_type __cdecl eof()
> {return ((-1)); }
> static int_type __cdecl not_eof(const int_type& _C)
> {return (_C != eof() ? _C : !eof()); }
> };
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
> -----
> eMail ist virenfrei.
> Von AVG uberpruft - www.avg.de
> Version: 10.0.1153 / Virendatenbank: 424/3245 - Ausgabedatum: 08.11.2010
>
>
More information about the antlr-interest
mailing list