[antlr-interest] Could anyone give an example definition of isType(IToken itk)

Kay Roepke kroepke at dolphin-services.de
Thu Feb 23 08:06:05 PST 2006


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


More information about the antlr-interest mailing list