[antlr-interest] (no subject)

Daniels, Troy (US SSA) troy.daniels at baesystems.com
Wed Feb 20 12:02:16 PST 2008


 

> -----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:34 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] (no subject)
> 
> 
> Thanks, unfortunately I've already tried that one. Whilst it 
> does catch the error of the jargon, it also creates the error 
> "exception: line 1:5: unexpected char: 0xA" with legitimate 
> code, i.e. 'a=5;'. Any thoughts?

Are you sure that you're input is 

'a=5;'

and not

'a=5;
'

with an extra blank line at the end?  0xA is either CR or LF, so I'm
guessing you're probably (possibly accidentally) including an newline at
the end of your input.

Most likely, you want to fix this by adding a rule to ignore whitespace.

Troy

> 
> Dan
> 
> ----------------------------------------
> > Date: Wed, 20 Feb 2008 14:18:47 -0500
> > From: Ari.Steinberg at EMBARCADERO.COM
> > To: antlr-interest at antlr.org
> > Subject: Re: [antlr-interest] (no subject)
> > 
> > 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.
> > 
> 
> _________________________________________________________________
> Free games, great prizes - get gaming at Gamesbox. 
> http://www.searchgamesbox.com
> 


More information about the antlr-interest mailing list