[antlr-interest] returning antlr w/c

Jim Idle jimi at temporal-wave.com
Wed Nov 26 13:05:09 PST 2008


On Wed, 2008-11-26 at 14:46 -0600, ian eyberg wrote:

> Hi, I'm using antlr 3.1.1 and evaluating
> it against boost::spirit and I'm having
> a pretty hard time coming up with even
> simple examples that work.


Please read through the C examples (see downloads for the examples tgz
download) and the examples in general, before trying to construct your
own examples. You should also consult the C API docs. You can also
search the past messages from the support page. All these links are
available from the antlr.org home page.

You might wish to start with the 5 minute intro and similar articles on
the wiki though as your questions are fundamental to ANTLR grammars of
all targets. 

$xxx.text
$xxx.text->chars

Return values of rules are usually contained in structures (returned,
not returned as pointers). Look at the generated source code and use an
IDE (Visual Studio is great but Netbeans 6.5 is not bad for *NIX), which
will help you with the structures.

Jim



> I have a grammar like so:
> --------------------
> grammar Blah
> options{ language = C; }
> r
> returns [char *s]
> :w1=ID ' ' w2=ID{ $s = "blah"; };
> ID: 'a'..'z'+;
> ------------------------
> 
> this will return me a "blah" but I'm having
> trouble figuring out howto return the value of
> w1 or w2;
> 
> I thought it was w1->getText() but that doesn't
> seem to work.
> 
> preferably I'd just like to pass in a struct
> and tack on w1 and w2 to it
> 
> I'm using the lexer/parser that this grammar
> generates in a c++ program.
> 
> can anyone point me to some resources on this?
> I've already looked through the examples tarball
> from the site and didn't find anything that related
> to these specific questions


Look for the C examples.

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081126/96c713ba/attachment.html 


More information about the antlr-interest mailing list