[antlr-interest] anybody using dynamic scopes?

Terence Parr parrt at cs.usfca.edu
Wed Feb 10 09:55:54 PST 2010


Cool. i'll keep them.
T
On Feb 10, 2010, at 9:04 AM, Eslam A. AlMorshdy wrote:

> wanna/am  using it.(2 yrs user)
> 
> On Wed, Feb 10, 2010 at 4:31 AM, <kferrio at gmail.com> wrote:
> Don't do it on my account, but I think I would use it because it looks much more transparent and maintainable.  As a new and occasional user, my biggest challenge is getting my head back in the game after some time away from the code.  This would help.
> 
> Kyle
> 
> Sent from my Verizon Wireless BlackBerry
> 
> -----Original Message-----
> From: Terence Parr <parrt at cs.usfca.edu>
> Date: Tue, 9 Feb 2010 17:30:12
> To: antlr-interest interest<antlr-interest at antlr.org>
> Subject: [antlr-interest] anybody using dynamic scopes?
> 
> Hi,
> 
> Is anybody using scopes?  E.g., here is the use C grammar:
> 
> scope Symbols {
>        Set types; // only track types in order to get parser working
> }
> 
> Every rule that declares its usage of Symbols pushes a new copy on the stack effectively creating a new symbol scope.
> 
> translation_unit
> scope Symbols; // entire file is a scope
> @init {
>  $Symbols::types = new HashSet();
> }
>    : external_declaration+
>    ;
> 
> 
> Then rule declaration declares a rule scope that lets any invoked rule see isTypedef boolean.  It's much easier than passing that info down as parameters:
> 
> declaration
> scope {
>  boolean isTypedef;
> }
> @init {
>  $declaration::isTypedef = false;
> }
>    : 'typedef' declaration_specifiers? {$declaration::isTypedef=true;}
>      init_declarator_list ';' // special case, looking for typedef
>    | declaration_specifiers init_declarator_list? ';'
>    ;
> 
> 
> Rule direct_declarator can then easily determine whether the IDENTIFIER
> should be declared as a type name.
> 
> direct_declarator
>    :   (   IDENTIFIER
>            {
>            if ($declaration.size()>0&&$declaration::isTypedef) {
>                $Symbols::types.add($IDENTIFIER.text);
>                System.out.println("define type "+$IDENTIFIER.text);
>            }
>            }
>        |   '(' declarator ')'
>        )
>        declarator_suffix*
>    ;
> 
> Trying to decide if it's worth reimplementing for v4.
> 
> Ter
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
> 
> 
> -- 
> Best Regards,
> Eslam A. AlMorshdy



More information about the antlr-interest mailing list