[antlr-interest] Newbie question

Ric Klaren klaren at cs.utwente.nl
Wed Apr 21 02:40:42 PDT 2004


On Fri, Apr 16, 2004 at 07:15:37PM -0000, Andres Chaves wrote:
> postfixExpr
{ int num_args = 0; }
> 	:	(id:ID LPAREN)=>
> 		id2:ID^
> 		(
>          parenArgs
       num_args=parenArgs
> 		)?
   {
     // pseudo code...	
      int expected_args = lookupsym(id2->getText())->numArgs();
      if( expected_args != num_args )
         throw SemanticException()		
   }	
> 	|	atom
> 	;

And change parenArgs to something like:

parenArgs [returns int num_args = 0] :
"(" ( arg { num_args++; } ) ")" ;

> I have to detect when the number of arguments is wrong (for example 
> sin() or sin(a,b)), and raise a parser exception, when i parse the 
> function (not when im calculating).
> 
> I wonder if someone could give some advice about how to do this.

Making it all java/or C++ is left to the reader ;) This is the gist of it
anyway.

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
     "Evil will always triumph, because Good is dumb." ---  Spaceballs



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list