[antlr-interest] Newbie question (not seeing expected error)

derek_kusiak derek_kusiak at yahoo.com
Thu Dec 2 09:37:41 PST 2004




Pardon the rather verbose post, but I'm sure the problem I'm having is
very basic as I'm new to both parsers and Antlr.  Anyway, to learn
Antlr I'm writing a simple parser to read a graphics text-based file
format containing simple shape descriptions.  The most simple file
might look like this:

  sphere 10
  sphere 20
  sphere 30

where 10, 20, and 30 are the radii of each sphere to be drawn.  My C++
parser, which I have simplified here, looks like this:

  class P extends Parser;
  start  : (shape)+ ;
  shape  : sphere ;
  sphere : SPHERE NUMBER { cout << ... } ;

and my lexer looks like this:

  class L extends Lexer;
  NUMBER : ('0'..'9')+ ;
  SPHERE : "sphere" ;

This all works as expected and generates understandable error message
when there is an error in the input, but not in all cases.  Let me
illustrate with a few examples.  If my input is this:

  sphere 10

I get the following (correct) output from my output statement in the
parser:

  Sphere(radius=10)

If I swap the parameters and make my input

  10 sphere

I get a sensible error (via caught exception):

  line 1:1: unexpected token: 10

Now if I add a second sphere (or any number of valid spheres for that
matter):

  sphere 10
  sphere 20

I again get the output I expect:

  Sphere(radius=10)
  Sphere(radius=20) 

So far so good.  However, I don't get the expected error if my mistake
is in the SECOND sphere:

  sphere 10
  20 sphere

Now the first statement is parsed correctly, but there is no error on
the second one.  It's just silently ignored and my ouput is this:

  Sphere(radius=10)

Why is there no error about the second sphere?  Clearly the "20
sphere" line is wrong, so why does my parser bail silently after the
error?

Thanks for any help.

Derek 








 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list