[antlr-interest] How do I throw exception on ERROR "no viable alternative at character "

Bharath R r.bharath at huawei.com
Fri May 15 07:07:55 PDT 2009


Thanx a lot.  Its working fine ! 
 
I have overridden the below method in the parser and lexer code generated. 
 
public void displayRecognitionError
<http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_base_recogni
zer.html#85afd3931a36f93c5e1fee84349b5673> (String[]
tokenNames,RecognitionException
<http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_recognition_
exception.html>  e)

The exception can be handled , but i am facing 2 below issues 
 
1. getting the passed input from the Lexer code. 
    Let say I have passed the string input , but from the lexer code I cant
able to get the "input" string passed. 
    I am expecting the same behaviour as the paser . ( where the input
variable is accessible ). 
 
2. Embedding the code to lexer , when i override the method in the grammar
file. Its inserted only in the parser code not 
    in the lexer code. 
 
HUAWEI TECHNOLOGIES CO.,LTD. huawei_logo 


Address: Huawei Industrial Base
Bantian Longgang
Shenzhen 518129, P.R.China
www.huawei.com
----------------------------------------------------------------------------
---------------------------------------------------------
This e-mail and its attachments contain confidential information from
HUAWEI, which 
is intended only for the person or entity whose address is listed above. Any
use of the 
information contained herein in any way (including, but not limited to,
total or partial 
disclosure, reproduction, or dissemination) by persons other than the
intended 
recipient(s) is prohibited. If you receive this e-mail in error, please
notify the sender by 
phone or email immediately and delete it!

 

  _____  

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Tilman Bender
Sent: Friday, May 15, 2009 2:21 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] How do I throw exception on ERROR "no viable
alternative at character "


Hi, 

Please have a look at the error reporting and recovery page on the wiki:

http://www.antlr.org/wiki/display/ANTLR3/Error+reporting+and+recovery

Maybe you could also override this:
http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_base_recogniz
er.html#6c32f5b03a9049357f3ddfbccee9a5e0

Allthough I am not sure this is a good idea.

HTH

Tilman Bender
Student des Software Engineering
Hochschule Heilbronn
tbender at stud.hs-heilbronn.de



Am 15.05.2009 um 06:51 schrieb Bharath R:


Hi All ,
 
Currentl when I parse my String , I am getting some errors printed in the
console. 
 
Like below : - 
 
line 1:6 no viable alternative at character '?'

line 1:6 no viable alternative at character ' '
 
and for the other characters also ( '@' ,',' ) 
 
Instead of having the System.err , I need the parser to through the
exception. 
 
How Should I achieve this ?? 
 


HUAWEI TECHNOLOGIES CO.,LTD. <att157f6.jpg> 


Address: Huawei Industrial Base
Bantian Longgang
Shenzhen 518129, P.R.China
www.huawei.com
----------------------------------------------------------------------------
---------------------------------------------------------
This e-mail and its attachments contain confidential information from
HUAWEI, which 
is intended only for the person or entity whose address is listed above. Any
use of the 
information contained herein in any way (including, but not limited to,
total or partial 
disclosure, reproduction, or dissemination) by persons other than the
intended 
recipient(s) is prohibited. If you receive this e-mail in error, please
notify the sender by 
phone or email immediately and delete it!

 

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090515/4df87964/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: attbb472.jpg
Type: image/jpeg
Size: 6737 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090515/4df87964/attachment.jpg 


More information about the antlr-interest mailing list