[antlr-interest] C Runtime and Strings

Jim Idle jimi at temporal-wave.com
Sat Aug 25 10:35:21 PDT 2007


>From a rule, you can return the pANTLR3_STRING (which is generated by a
reference to a .text in an attribute) or the char pointer that it
references.

There is no requirement to use the pANTLR3_STRING stuff, it just makes
things easier and the runtime uses it for rule text etc.

The offsets in the tokens will tell you the absolute addresses when
combined with the start of your input text and you are better using
those as a STRING may not always be pointing into the input, though it
usually is.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Stefan Klinger
> Sent: Saturday, August 25, 2007 10:01 AM
> To: Gavin Lambert
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] C Runtime and Strings
> 
> Gavin Lambert wrote:
> > >And if there is a way, is the input buffer read into one big buffer
> > >so that it is valid for the whole parser?
> >
> > Yep.
> So it should be valid to return something like this from such a rule
> (with the advantace that nothing needs to be allocated):
> 
> scoped_identifier : NAMESPACE_COLON? (IDENTIFIER NAMESPACE_COLON)*
> IDENTIFIER;
> 
> struct MyReturn {
>     pANTLR3_UINT8 *begin_of_rule;
>     pANTLR3_UINT8 *end_of_rule;
> };
> 
> for e.g. the input "12 + my::identifier::name + 34"
> 
> begin_of_rule should be pointing to 'm' and end_of_rule to 'e'.
> 
> 
> If someone could give me a hint how i can accomplish that it would be
> great.
> 
> Thanks,
> 
> Stefan



More information about the antlr-interest mailing list