[antlr-interest] Objective-C Codegen?

Hiroyuki Sato hiro at kanagawa-u.ac.jp
Wed May 15 23:02:34 PDT 2002


Hi Chris.

How about following arrow point?
In fact, when I use filter=RULE feature in lexer,
ANTLR for Java generate following code in nextToken().

try {
   ...
   ...
   try {   // try in catch
   } catch( FooException e ){
   } catch( Exception ex ){
   }
} catch ( BarExceptionException e ){
   try { // try in catch               <--
      ...                              <-- How to translate into ObjC?
      ...                              <--
   } catch (Exception ex ){            <--
      throw ex;                        <--
   }                                   <--
} catch ( Exception e ){
  throw e;
}

- (void) blah
{
     NS_DURING
     {
         NS_DURING
         {
             NSException*    ex = [ NSException 
exceptionWithName:@"BlahException"
                                                  reason: @"just because"
                                                      userInfo: nil ];
             [ ex raise ];
         }
         NS_HANDLER    // exception is local variable localException
         {
             if( [ [ localException name ] isEqualToString: 
@"BlahException"] )
             {
                 // ...
             }

             [ localException raise ];
         }
         NS_ENDHANDLER
     }
     NS_HANDLER    // exception is local variable localException
     {
         if( [ [ localException name ] isEqualToString: 
@"BlahException" ] )
         {
             // ....
             NS_DURING               <----
             {                       <---- Is this correct ?
             }                       <----
             NS_HANDLER              <----
             {                       <----
             }                       <----
             NS_ENDHANDLER           <----
         }
     }
     NS_ENDHANDLER
}

On 2002.05.16, at 14:36, Chris Rudolph wrote:

>> For example, how to translate following code into Objective-C?
>>
>> try {
>>  ...
>>  ...
>>  try {   // try in catch
>>  } catch( FooException e ){
>>  } catch( Exception ex ){
>>  }
>> } catch ( BarExceptionException e ){
>>  try { // try in catch
>>     ...
>>     ...
>>  } catch (Exception ex ){
>>     throw ex;
>>  }
>> } catch ( Exception e ){
>> throw e;
>> }
>>
>> On 2002.05.16, at 02:08, mzukowski at yci.com wrote:
>>
>
> Hi Hiroyuki,
>
> How about:
>
> - (void) blah
> {
>     NS_DURING
>     {
>         NS_DURING
>         {
>             NSException*    ex = [ NSException exceptionWithName:
> @"BlahException"
>                                                        reason: @"just
> because"
>                                                      userInfo: nil ];
>             [ ex raise ];
>
>         }
>         NS_HANDLER    // exception is local variable localException
>         {
>             if( [ [ localException name ] isEqualToString: 
> @"BlahException"
> ] )
>             {
>                 // ...
>             }
>
>             [ localException raise ];
>         }
>         NS_ENDHANDLER
>     }
>     NS_HANDLER    // exception is local variable localException
>     {
>         if( [ [ localException name ] isEqualToString: 
> @"BlahException" ] )
>         {
>             // ...
>         }
>     }
>     NS_ENDHANDLER
> }
>
> Cheers,
> Chris
>
>
--
Hiroyuki Sato
CCSO, Kanagawa University.
Voice: +81-45-491-2572
FAX: +81-45-491-2575


 

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



More information about the antlr-interest mailing list