Hi Bart,

Could I abuse a bit more of your time ?

My initial ordering problem came back because of the order of my rules.

I have this input : STRUCT myvar1, myvar2 ( INTEGER i1; INTEGER j1; )

The tree I'd like to have is :
 #(DECL_VARIABLE 'myVar1' 
   #(STRUCT
     #(DECL_VARIABLE 'i1' INTEGER)
     #(DECL_VARIABLE 'j1' INTEGER)
    )
   )
 #(DECL_VARIABLE 'myVar2' 
   #(STRUCT
     #(DECL_VARIABLE 'i1' INTEGER)
     #(DECL_VARIABLE 'j1' INTEGER)
    )
   )

I have a rule 'structure_members which rewrites '( INTEGER i1; INTEGER j1;
)' into #(STRUCT #(DECL_VARIABLE 'i1' INTEGER) #(DECL_VARIABLE 'j1' INTEGER)).

My problem is the main declaration rule :
declaration
    : STRUCT identifiers[$structure_members.tree] structure_members
      -> ^(DECL_VARIABLE identifiers+ structure_members)

The 'structure_members' are only available after identifiers are parsed, and I
cannot give identifiers the parameter $structure_members.tree as I wished (I get
a forward reference error).

Is there a way to pass the structure_members tree to identifiers rule ?

Cheers.

--

Robert

PS: All the input data I'm using:
  => INPUT = "INTEGER good; STRUCT myvar1, myvar2 ( INTEGER i1; INTEGER j1; )"
  => The example grammar to demonstrate the issue
/******************************************************************************
 * LTR_ex4.g
 ******************************************************************************/
grammar LTR_ex4;

options {
  k=1;
  output=AST;
  ASTLabelType=CommonTree;
}

tokens {
  DIMS; DECL_VARIABLE;
}

translation_unit
        : declaration (';'! declaration)*
        ;
    
declaration
        : type_identifier identifiers[$type_identifier.tree]
        -> ^(DECL_VARIABLE identifiers)+
        | STRUCT identifiers[$structure_members.tree] '(' structure_members ')'
        -> ^(DECL_VARIABLE identifiers)
        ;

structure_members
        : (declaration ';')+
        -> ^(STRUCT declaration+)
        ;
    
identifiers[CommonTree type]
        : IDENTIFIER (',' IDENTIFIER)*
        -> ({type} IDENTIFIER)+
        ;

type_identifier
        :        'INTEGER'
        ;

STRUCT  :       'STRUCT' ;
IDENTIFIER  :('a'..'z' | '0'..'9')+ ;
WS  :   ( ' ' | '\t'| '\r'| '\n') {$channel=HIDDEN;};

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