[prev in list] [next in list] [prev in thread] [next in thread] 

List:       antlr-interest
Subject:    [antlr-interest] Could anyone give an example definition of
From:       kroepke () dolphin-services ! de (Kay Roepke)
Date:       2006-02-23 8:06:10
Message-ID: 74FE73BB-30FC-4171-B896-C8D3681B3672 () dolphin-services ! de
[Download RAW message or body]


On 23. Feb 2006, at 16:44 Uhr, ??? Jigang (Robert) Sun wrote:

> Could anyone give an example definition of
> isType(IToken itk) in
>
> http://www.antlr.org/doc/glossary.html
>
> decl     : typename ID SEMICOLON
>          | ID ID SEMICOLON
>          ;
> typename : {isType(LT(1))}? ID
>          ;
>
> I think typename() is used to declare user defined
> variable type, can be any identifier names, not
> predifined types.

The paragraph you refer to is this one, is it not?

http://www.antlr.org/doc/glossary.html:
-------------------------------------
The predicate is not needed in typename as there is no decision,  
however, rule decl needs it to distinguish between its two  
alternatives. The first alternative would look like:
if ( LA(1)==ID && isType(LT(1)) ) {
   typename();
   match(ID);
   match(SEMICOLON);
}
-------------------------------------

Here 'typename();' is simply the method call for the invokation of  
the typename parser rule. It doesn't do anything related to types at  
all. If you would rename the rule 'typename'
to 'foobar' the code would have 'foobar();' in it.

isType() is user defined, there is no default implementation. You  
need to do that yourself (maintain a symbol table and whatnot). It is  
merely shown here for illustration purposes, to
demonstrate the effect predicate hoisting has.

HTH,

Kay

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic