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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to