[antlr-interest] End of file

jg z zjg1964 at yahoo.com
Mon Apr 22 09:00:22 PDT 2002


Hi, 
   We are converting a parser from PCCTS version to
ANTLR version to produce C++ code using ANTLR 2.7.1.

   Now we confront with a problem with detecting the
end of file.

   The related code in our .g file(ANTLR version) is
as following,

translation_unit
   :  {enterExternalScope();}
      (external_declaration)+  EOF
      {exitExternalScope();}
   ;

   The problem is, at the end of a testing file, the
parser goes into external_declaration again instead of
match the EOF. This is because the conditions
controlling the entry of external_declaration both
contain EOF.

   We don't understand why this is not the case in the
example of java.g which is provided in CPP directory
of examples of ANTLR-2.7.1. The corresponding code in
java.g file is,

compilationUnit:
(packageDefinition|/* nothing */)		
( importDefinition )*	
( typeDefinition )*
    EOF!  
;

This version detects end of file correctly. The
condition controlling the entry to typeDefinition does
not contain EOF.

Thanks.

Zuo.


__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list