Look a the documentation for @sections - there are different ones so you can include before, after the .h or before or after antlr.h and so on. Also look at how I put together the header files in my examples. Basicalyl I have one .h file that everything includes.
Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Bob > Sent: Sunday, May 30, 2010 10:00 AM > To: [email protected] > Subject: Re: [antlr-interest] Can "returns" return an aggregate? > > My target is "C" (wish it was "C++") and because I'm accustomed to > byson's > stack items being a user-definable union, e.g.: > > > > %union { <------- > declares a union of all rule return types > void* node; > struct ModuleHeader moduleHeader; > } > > %type <moduleHeader> module_ansi_header <----- > - declares > return type of the specific rule > > module_ansi_header > : TokModule { struct ModuleHeader _mh; $$ = _mh; } <------ rule > returns a ModuleHeader struct on stack > > > > it was natural for me to think I could do something similar in Antlar, > like > this: > > @members > { > struct ModuleHeader { void* a; void* b }; > } > > > module_ansi_header returns [struct ModuleHeader rslt] > scope { > struct ModuleHeader mh; > } > : TokModule { $rslt = mh; } > > > > Which does not work. So I altered the rule: > > > module_ansi_header returns [void* a,void* b] > scope { > struct ModuleHeader mh; > } > : TokModule { $a = mh.a; $b = mh.b; } > > > > My problem is `ModuleHeader` is undefined in "xxParser.h" because the > inclusion order is incorrect: > > xxParser.c: > > #include "xxParser.h" <-------- typedef for rule > return > type refers to not-yet-defined `ModuleHeader` > ..... > struct ModuleHeader { void* a; void* b }; <--- placement of > @members > block > > > Being inexperienced with Antlr, I'm thinking I've just missed something > simple. > > Is there a way to get the "@members" block emitted prior to the > inclusion of > the "xxParser.h" file? > > Thanks, > Bob > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Jim Idle > Sent: Saturday, May 29, 2010 3:19 PM > To: [email protected] > Subject: Re: [antlr-interest] Can "returns" return an aggregate? > > You might have more success if you said what target you were using :-) > Also > remember antlr.markmail.com. > > The generated routines already return a struct, so you cannot put a > struct > in that struct. You need to return a pointer to a struct. > > Jim > > > -----Original Message----- > > From: [email protected] [mailto:antlr-interest- > > [email protected]] On Behalf Of Bob > > Sent: Friday, May 28, 2010 5:06 PM > > To: [email protected] > > Subject: [antlr-interest] Can "returns" return an aggregate? > > > > Is there a way to return an aggregate ? > > > > > > > > struct A { int m; double n; }; > > > > extern struct A foo(void); > > > > > > > > myrule returns [struct A a] > > > > : X > > > > { $a = foo(); } > > > > ; > > > > > > 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 > > > 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 -- 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.
