[antlr-interest] (no subject)

Daniel Powell divot_powell at hotmail.com
Wed Feb 20 11:07:52 PST 2008


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


More information about the antlr-interest mailing list