dcsimg
ANTLR Exception Handling
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Muneer_Shareiff
Posted On:   Friday, April 26, 2002 08:47 AM

Hi... I am having trouble trying to set up exception handling for my parser. the following is my simplified grammar file :- header { #include ""DATANode.hh"" #include ""DELETENode.hh"" } options { language = ""Cpp""; } class ASLParser extends Parser; options { exportVocab = ASL; buildAST=true; defaultErrorHandler = true; k = 1; } break_stmt : BREAK^ ; delete_stmt : DEL   More>>

Hi...


I am having trouble trying to set up exception handling for my parser.


the following is my simplified grammar file :-


header


{


#include ""DATANode.hh""


#include ""DELETENode.hh""


}


options { language = ""Cpp""; }


class ASLParser extends Parser;


options { exportVocab = ASL;


buildAST=true;


defaultErrorHandler = true;


k = 1; }


break_stmt
: BREAK^ ;

delete_stmt
: DELETE^ OBJECT! INSTANCE!
local_variable ;
local_variable
: ID ;

stmt
: ( break_stmt | delete_stmt ) SEMI! ;

stmt_list
: ( stmt )* ;

class ASLLexer extends Lexer;
options { charVocabulary = '3'..'377';
exportVocab = ASL;
k = 10;
testLiterals = false;
caseSensitiveLiterals = false; }

tokens { BREAK = ""break"";
DELETE = ""delete"";
INSTANCE = ""instance"";
OBJECT = ""object""; }

SEMI options { paraphrase = ""Semi Colon""; } : ';' ;

ID options { testLiterals = true; }
: ('a'..'z'|'A'..'Z'|'_')
('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ;

WS options { paraphrase = ""White Space""; }
: (' '|' '|'
'{ newline(); }|'
')
{$setType(ANTLR_USE_NAMESPACE(antlr)Token::SKIP);};

I would appreciate it if u could help me with a simple example of exception handling on my grammar file.
Desired error messages will be :-
1. ""invalid start of a statement"" when the start of a statement is other than BREAK or DELETE.
2. ""missing semicolon at end of statement""
3. ""in DELETE statement : expecting OBJECT token"" when something else is there instead.

I do not need any fanciful stuff... just that the input must strictly correspond to the grammar or it will just exit from the program with the desired error messages.

Thanx for your help... regards...

   <<Less
About | Sitemap | Contact