[antlr-interest] End of file

Ric Klaren klaren at cs.utwente.nl
Tue Apr 23 05:12:32 PDT 2002


On Mon, Apr 22, 2002 at 09:00:22AM -0700, jg z wrote:
>    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,

I had a short look at the files David sent me earlier the problem is most
probable in the external_declaration rule where there's an alternative:

	  {K_and_R = TRUE;}
	   {printf("CPP_parser.g Ln490\n");}
	  function_definition
	 |
      // templated forward class decl, init/decl of static member in template
      {beginTemplateDefinition();}
      (template_head declaration_specifiers
		 ( init_declarator_list ) ? SEMICOLON { end_of_stmt();}
		 ) =>      {endTemplateDefinition();}

 /*** what is missing here???? ***/

   |
      // Templated FUNCTIONS and CONSTRUCTORS matched here.
      {beginTemplateDefinition();}
      template_head
      (

Note the predicate pointing to nothing. Removing that eliminates the EOF
from the lookahead set of external_declaration.

Advice: antlr -diagnostic <yourinputfile> is your friend. (The textfile it
generates lists all lookahead sets in readable format, that way you can
track down which alternative is the culprit if something gets a wrong piece
of lookahead)

Advice2: I'm getting the impression that you are trying to convert the old
PCCTS grammar as a whole? If so then it's probably not the most practical
approach. Try to convert it piece by piece (or better said alternative by
alternative). That way it's easier to pinpoint rules that give trouble.

Good luck,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
     Human beings, who are almost unique in having the ability to learn
   from the experience of others, are also remarkable for their apparent
         disinclination to do so. --- Douglas Adams, Last Chance to See


 

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



More information about the antlr-interest mailing list