Loading ...
Sorry, an error occurred while loading the content.

VC++ bug with antlr

Expand Messages
  • Ernest Pasour
    I don t know if this has been reported before, but it doesn t seem to be fixed in the official 2.7.1.
    Message 1 of 2 , Oct 2, 2000
    • 0 Attachment
      I don't know if this has been reported before, but it doesn't seem to be fixed in the official 2.7.1.

      =======================================================================================

      We recently ran into a bug with the implementation of the LA function using the 2.7.1a2 version (C++ variety) of antlr. The problem is that when the CharScanner::LA function calls toLower with a value of EOF_CHAR (-1), my antlr parser would get hung in an infinite loop. This is because the tolower library function in VC++ 6.0 checks to see if a locale is set and executes different code if it is.

      It turns out that if you have an up to date MSVCRT.dll (maybe from an IE installation--I couldn't reproduce the problem, but some of my coworkers could), and you have issued a SetLocale() call (which happens when you invoke an open dialog), then the tolower function has a different implementation that takes an input of -1 and returns a munged value instead of -1. If SetLocale() has not been called, then -1 gets returned. If passing in an input of -1 does not return -1, then some of the lexer loops can get hung.

      So, I propose changing the implementation of LA from:

      inline int CharScanner::LA(int i)
      {
      if ( caseSensitive ) {
      return inputState->getInput().LA(i);
      } else {
      return toLower(inputState->getInput().LA(i));
      }
      }

      to:

      inline int CharScanner::LA(int i)
      {
      int c = inputState->getInput().LA(i);
      if ( caseSensitive || c == EOF_CHAR) {
      return c;
      } else {
      return toLower(c);
      }
      }

      This seems to work fine for us.
    • Ric Klaren
      Hoi, ... Hadn t seen it. But it s in the devel branch now. ... Uch! This is really *broken* behaviour yuch! Or maybe it s related to locale handling and should
      Message 2 of 2 , Oct 3, 2000
      • 0 Attachment
        Hoi,

        On Mon, Oct 02, 2000 at 10:49:13AM -0400, Ernest Pasour wrote:
        > I don't know if this has been reported before, but it doesn't seem to be
        > fixed in the official 2.7.1.

        Hadn't seen it. But it's in the devel branch now.

        > invoke an open dialog), then the tolower function has a different
        > implementation that takes an input of -1 and returns a munged value
        > instead of -1. If SetLocale() has not been called, then -1 gets returned.
        > If passing in an input of -1 does not return -1, then some of the lexer
        > loops can get hung.

        Uch! This is really *broken* behaviour yuch! Or maybe it's related to
        locale handling and should EOF_CHAR be replaced by char_traits<char>::eof()
        somewhere (related to a bugreport with STLPort).

        Ric
        --
        -----+++++*****************************************************+++++++++-------
        -- Ric Klaren - klaren@... ------------------------------------------
        -----+++++*****************************************************+++++++++-------
        'And this 'rebooting' business? Give it a good kicking, do you?' 'Oh, no,
        of course, we ... that is ... well, yes, in fact,' said Ponder. 'Adrian
        goes round the back and ... er ... prods it with his foot. But in a
        technical way,' he added. --- From: Hogfather by Terry Pratchett.
        -------------------------------------------------------------------------------
      Your message has been successfully submitted and would be delivered to recipients shortly.