[antlr-interest] Parser stopping before matching the whole input

Jim Idle jimi at temporal-wave.com
Mon Jul 2 08:15:41 PDT 2007


You should probably add EOF to your compilation_unit rule, ANTLR knows
what this means. Hard to analyze without the rest of your grammar beyond
that guess though.

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Edson Tirelli
Sent: Monday, July 02, 2007 7:36 AM
To: antlr-interest at antlr.org
Cc: Mark Proctor; Michael Neale
Subject: [antlr-interest] Parser stopping before matching the whole
input

 


   All,

   I'm facing a problem I didn't found info on the archives. Being
short, the parser is stopping to parse before the end of the input
stream when it founds an unexpected token. For instance, my top level
rule is: 

compilation_unit
    :    prolog 
        statement+
    ;

   So, if the parser finds a valid prolog, and at least one valid
statement, and after that finds a token it does not recognize, it simply
stops parsing without any error message. Example: 

==========
package a.b.c;

import x.y.z;
xxxxxx
import r.s.t;
===========

   In the example above, the "package" is a valid prolog, the "import"
is a valid statement and both are parsed correctly. But when the parser
finds "xxxxxx" it does not recognize it and simply stops parsing without
any error. I understand the behavior from a parsing rule perspective,
but I want to force the parser to parse the whole input, reporting
errors for unrecognized tokens and recovering whenever possible.   
   How can I do that?

   I imagine that if I had a mandatory "end of stream" token, I could
simply do:

compilation_unit
    :    prolog 
        statement+
        MY_END_OF_STREAM_TOKEN
    ;

   But I don't have such token and can't add it to the language.

   Any ideas?

   Thank you in advance,
       Edson

-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer 
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070702/10564d4b/attachment.html 


More information about the antlr-interest mailing list