[antlr-interest] (no subject)

Ari Steinberg Ari.Steinberg at EMBARCADERO.COM
Wed Feb 20 11:18:47 PST 2008


Add EOF to the end of your rule program (or start) rule.

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Daniel Powell
Sent: Wednesday, February 20, 2008 2:08 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] (no subject)


Hi,

I'm currently making a parser for a project and have encountered an
issue I can't find a solution to.

I have made my lexer and that works fine, but when I apply rules I've
found an odd situation. The rules are followed exactly up until it
reaches the end of all of the rules, and then it ignores all text after
that point. Instead I would like it to throw an error because there
should not be any text once the final rule has been completed.

A very basic example of my antlr code is below:

   class SmallCParser extends Parser;
   options {
     buildAST=true;
   }

   program
       : start
       ;

   start
       : IDENTIFIER EQUALS INT SEMICOLON
       ;
         class SmallCLexer extends Lexer;

   protected
   CHAR_LIT : ('a'..'z'|'A'..'Z');

   protected
   DIGIT : ('0'..'9');

   IDENTIFIER : CHAR_LIT (CHAR_LIT | DIGIT)*;
   INT   : (DIGIT)+;

   EQUALS : '=';
   SEMICOLON : ';';

This code works to the extent described above in that it will happily
accept the code 'a=5;' as it should do, but will also accept the code
'a=5;hfjdshfkjs'. Instead I would like it to throw an error when it
reaches the hfjdshfkjs. The hfjdshfkjs does not make it to the AST so
the final code would be correct in this circumstance but not in all and
I would like it to be able to point out an error to the programmer
because the extra code should not be there..

Any advice would be greatly appreciated..


Thanks

Dan
divot underscore powell at hotmail dot com


_________________________________________________________________
Get Hotmail on your mobile, text MSN to 63463!
http://mobile.uk.msn.com/pc/mail.aspx
CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) 
and may contain confidential and privileged information. Any unauthorized review, use, 
disclosure or distribution is prohibited. If you are not the intended recipient, please 
contact the sender by reply email and destroy all copies of the original message.



More information about the antlr-interest mailing list