[antlr-interest] Lexer/Parser Design Issues

Kaleb Pederson kibab at icehouse.net
Mon Jul 26 21:46:28 PDT 2004


On Sunday 25 July 2004 7:31 pm, Jason wrote:
> 1) There are three or four rules which have several
> indirect recursions between them.

That's fine as long as none of them are direct or indirect left recursive 
cycles.  If they are then it will loop forever.

> 2) The language contains several (~40) predefined
> functions which occur on the right hand side of the
> recursive rules.  I'm treating each separate function
> name as it's own token.

I'm not familiar with the language, but I would hope that you can recognize 
the syntax for a function, whether builtin or not.  If so, then just refer to 
the function non-terminal in place of all the individual built in ones.  
Then, you can just insert the predefined builtins into the symbol table when 
you are actually processing it.  It should be cleaner than trying to create a 
rule for each possible builtin.

[snip]
> A couple of questions:
>
> 1) Given these two alternatives for example:
>
> set: Children '(' item ')'
>
>      Descendents '(' item ')'
>
> would most ANTLR users define 'children' and
> 'descendents' as separate tokens and recognize them in
> the lexer or just write a rule something like:
>
> set: Identifier '(' item ')' ?

I would use the latter, and then, based on the context, you can do a 
#id.setType(CHILD) or #id.setType(DESCENDANT).

Or, if the first sets don't overlap, then you can have identifier be something 
like:

identifier: child | descendant ;
child: ... ;
descendant: ... ;

I hope that helps a bit.

--Kaleb


 
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