[antlr-interest] Help Needed on throwing exceptions

Srikantham, Anil Anil.Srikantham at ips.invensys.com
Tue Feb 7 20:06:33 PST 2006


Hi,

I'm currently working on a compiler for IEC 61131 languages.
I'm using ANTLR 2.7.2 and things look fine till now.
But I see a problem when I throw explicitly an exception based on a
condition in the parser. 

I use a default try-catch block and the catch block has a function
consumeUntil which consumes some tokens when this exception is raised.

To negate this I used mark and rewind.

Can there be a better solution??? Or is it a problem with this version of
ANTLR.

function_call! {int funcNameMark = 0; } :

r2:function_name  LEFT_PAREN! p2:param_value_list { funcNameMark = mark(); }
RIGHT_PAREN!
		{ 

//-----this is the exception that I throw -----
			if(gPositionalParamsCnt != 0 &&  gNamedParamsCnt !=
0)
			{
				gPositionalParamsCnt = 0;
				gNamedParamsCnt = 0;
				rewind(funcNameMark);
				throw new RecognitionException( "Function
call to " + r2_AST.ToString() + " has both positional and named arguments");

			}

			#function_call = #(#[FUNCTION_CALL,"FUNCTION_CALL"],
r2, p2 ); 
			
		}


Thanks --- Anil




Confidentiality Notice: The information contained in this electronic message
and any attachment(s) to this message are intended for the exclusive use of
the recipient(s) and may contain confidential, privileged or proprietary
information. If you are not the intended recipient, please notify the sender
immediately, delete all copies of this message and any attachment(s). Any
other use of the E-Mail by you is prohibited.





More information about the antlr-interest mailing list