[antlr-interest] MSVC 6.0 Compiler accuracy?

Wigg, J D wiggjd at lsbu.ac.uk
Mon May 22 06:29:50 PDT 2006


I am the latest author of the C++ parser available from the Antlr
website.
 
It has been brought to my attention that it does not parse the
following properly because of declarations in conditions,
 
bool fun()
 {
 int i, j, k, l = 0;
 
 if(int i = 1)   // MSVC++ 6.0 accepts declaration and redefinition of
i.
  {
  printf("%d ",i);
  }
 
 switch(int j = 1)   // MSVC++ 6.0 accepts declaration and
redefinition of j.    
  {
 case 1:
  return true;
 default:
  return false;
  }
 
 while(int k = 2)   // MSVC++ 6.0 accepts declaration and redefinition
of k.
  {
  k--;
  printf("%d ",k);
  }
 
 for(int i = 5; int l = i; i--) // MSVC++ 6.0 rejects redefinition of
i and
  {                                // declaration in condition   
  printf("%d ",l);
  } 
 
I have not made allowance for the apparently legal possibility
according to reliable grammar definitions of declaring a variable in
the condition statement of these four statements.
 
I am told that gcc 3.3.3 accepts the declaration in the above "for"
statement.
 
It therefore looks as though MSVC++ 6.0 is incorrect in this instance.
I would be grateful if someone would confirm this. Perhaps there is a
later version of MSVC which parses this "for" statement correctly?
 
I presume that each of these four statements opens a new scope.
 
I have been parsing various C++ programs for some years now and never
come across the declaration of variables in conditions. I suppose this
is not surprising. I can't think why one would want to do it. It seems
illogical to allow this in iteration statements since the condition
would appear to redeclare the variable on each iteration!
 
It would be interesting to hear of any use for this feature.
 
David
Centre for Systems and Software Engineering
London South Bank University
UK.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060522/4ccf35d3/attachment.html


More information about the antlr-interest mailing list