[antlr-interest] [C Target] Example without treewalker

Jim Idle jimi at temporal-wave.com
Wed Oct 15 20:11:42 PDT 2008


On Wed, 2008-10-15 at 21:11 -0500, Shaun Bogan wrote:

> Is anyone aware of an example for the C target that doesn't use a tree
> parser.  I prefer to walk the AST myself for my application.  I've had
> considerable luck using the C# target, but the C target seems to elude
> me.  I can't even do simple things like print out the text of a node,
> etc.  If anyone has an example that would help me greatly.  Unless I
> missed one, none of the examples in the downloads section walk the
> tree manually.


Well, if you have worked out how to walk the tree manually in C# there
is really little difference in C. A good way to find out things is to
use VS 2008 and just type '->', which gives you all the 'methods' and
which you will find are pretty much exactly the same, other than being
nX faster. The C source code also shows you how to do so, but where are
you having problems getting started? It might be easier to help if I
know what you are trying to do as walking the tree manually is just a
few (i =0; ... and getChild() calls. For instance a good example in the
3.1.1 source is the methods that produce a .dot spec of any tree. The
codes is about 40 lines worth.

I may also be guilty of assuming that anyone using my C target is
willing to dive in to the sources and so on, but I have tried to
document the code :-)

Jim


> 
> Thanks,
> Shaun Bogan
> 
> On Wed, Oct 15, 2008 at 2:00 PM,  <antlr-interest-request at antlr.org> wrote:
> > Send antlr-interest mailing list submissions to
> >        antlr-interest at antlr.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >        http://www.antlr.org/mailman/listinfo/antlr-interest
> > or, via email, send a message with subject or body 'help' to
> >        antlr-interest-request at antlr.org
> >
> > You can reach the person managing the list at
> >        antlr-interest-owner at antlr.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of antlr-interest digest..."
> >
> >
> > Today's Topics:
> >
> >   1. Re: Understanding ANTLR's 'multiple alternatives' (Gavin Lambert)
> >   2. Re: VS2008 Integration Example (Gavin Lambert)
> >   3. Re: VS2008 Integration Example (Sam Harwell)
> >   4. is there any good example can change prolog to    .dot file by
> >      antlr? (Su Zhang)
> >   5. Problem with multiple treeparser ... (LdK ^^)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Wed, 15 Oct 2008 09:13:53 +1300
> > From: Gavin Lambert <antlr at mirality.co.nz>
> > Subject: Re: [antlr-interest] Understanding ANTLR's 'multiple
> >        alternatives'
> > To: `VL <vl.homutov at gmail.com>, "antlr-interest at antlr.org"
> >        <antlr-interest at antlr.org>
> > Message-ID: <20081014201402.3E52E3D16ED at www.antlr.org>
> > Content-Type: text/plain; charset="us-ascii"; format=flowed
> >
> > At 07:54 15/10/2008, `VL wrote:
> >  >Hmm. This looks better. But it doesn't match construction
> >  >like this: $(VAR)/some/path.
> >
> > That's a different form than what you were showing before :)
> >
> > To match that, you can treat them all as equals:
> >
> > PATH : ('/' | ENVAR | ID | INT)+;
> >
> > Of course, this no longer guarantees that there is a '/' present
> > at all.
> >
> > Another option specifically for the leading-ENVAR case (basically
> > assuming that all paths must be absolute, but the base path may be
> > contained in an ENVAR):
> >
> > PATH : ENVAR? ('/' (ID | INT)*)+;
> >
> >
> > You do need to be careful you're not doing too much work in the
> > lexer, though.  Remember that the lexer is context-free, and all
> > top-level rules are always candidates to match the input.  You may
> > therefore end up with a different token type than you're
> > expecting, if there is overlap between the token rules.
> >
> >
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Wed, 15 Oct 2008 09:22:53 +1300
> > From: Gavin Lambert <antlr at mirality.co.nz>
> > Subject: Re: [antlr-interest] VS2008 Integration Example
> > To: "Sam Harwell" <sharwell at pixelminegames.com>, Andr?  van der Merwe
> >        <AndrevdM at pyrogenesis.co.za>, <antlr-interest at antlr.org>
> > Message-ID: <20081014202312.DB8E03D16F5 at www.antlr.org>
> > Content-Type: text/plain; charset="us-ascii"; format=flowed
> >
> > At 05:28 15/10/2008, Sam Harwell wrote:
> >>Here's how you can get the Clean and Rebuild tasks working as
> >>well. If you delete the .tokens files associated with each
> >>grammar, then the grammar will get properly rebuilt:
> >>
> >><PropertyGroup>
> >>
> >><CoreCleanDependsOn>$(CoreCleanDependsOn);CleanAntlrCode</CoreCleanDependsOn>
> >></PropertyGroup>
> >><Target Name="CleanAntlrCode">
> >>         <ItemGroup>
> >>                 <_CleanAntlrFileWrites
> >> Include="@(Antlr3->'%(RelativeDir)%(Filename).tokens')" />
> >>         </ItemGroup>
> >>         <Message Importance="normal" Text="Antlr: Deleting
> >> output files '@(_CleanAntlrFileWrites)'" />
> >>         <Delete Files="@(_CleanAntlrFileWrites)" />
> >></Target>
> >
> > Wouldn't it be better to remove all the output files, not just the
> > .tokens file?  You should be able to do that by using this line
> > instead (though I haven't tested it):
> >
> > <Delete Files="%(Antlr3.OutputFiles)" />
> >
> >
> >
> > ------------------------------
> >
> > Message: 3
> > Date: Tue, 14 Oct 2008 15:25:01 -0500
> > From: "Sam Harwell" <sharwell at pixelminegames.com>
> > Subject: Re: [antlr-interest] VS2008 Integration Example
> > To: "Gavin Lambert" <antlr at mirality.co.nz>, Andr?  van der Merwe
> >        <AndrevdM at pyrogenesis.co.za>,   <antlr-interest at antlr.org>
> > Message-ID:
> >        <86403CA0939415448BCCB83855EFE09A64E5EE at Bloodymary.ironwillgames.com>
> > Content-Type: text/plain;       charset="iso-8859-1"
> >
> > Delete doesn't properly handle ; delimited lists of files. :( Plus we check the generated .cs files into Perforce so it's good to have them around (in our case).
> >
> > Sam
> >
> > -----Original Message-----
> > From: Gavin Lambert [mailto:antlr at mirality.co.nz]
> > Sent: Tuesday, October 14, 2008 3:23 PM
> > To: Sam Harwell; Andr? van der Merwe; antlr-interest at antlr.org
> > Subject: RE: [antlr-interest] VS2008 Integration Example
> >
> > At 05:28 15/10/2008, Sam Harwell wrote:
> >>Here's how you can get the Clean and Rebuild tasks working as
> >>well. If you delete the .tokens files associated with each
> >>grammar, then the grammar will get properly rebuilt:
> >>
> >><PropertyGroup>
> >>
> >><CoreCleanDependsOn>$(CoreCleanDependsOn);CleanAntlrCode</CoreCleanDependsOn>
> >></PropertyGroup>
> >><Target Name="CleanAntlrCode">
> >>         <ItemGroup>
> >>                 <_CleanAntlrFileWrites
> >> Include="@(Antlr3->'%(RelativeDir)%(Filename).tokens')" />
> >>         </ItemGroup>
> >>         <Message Importance="normal" Text="Antlr: Deleting
> >> output files '@(_CleanAntlrFileWrites)'" />
> >>         <Delete Files="@(_CleanAntlrFileWrites)" />
> >></Target>
> >
> > Wouldn't it be better to remove all the output files, not just the
> > .tokens file?  You should be able to do that by using this line
> > instead (though I haven't tested it):
> >
> > <Delete Files="%(Antlr3.OutputFiles)" />
> >
> >
> >
> > ------------------------------
> >
> > Message: 4
> > Date: Tue, 14 Oct 2008 18:18:01 -0700
> > From: "Su Zhang" <westlifezs at gmail.com>
> > Subject: [antlr-interest] is there any good example can change prolog
> >        to      .dot file by antlr?
> > To: antlr-interest at antlr.org
> > Message-ID:
> >        <e2842950810141818v4b1d124bia85bbd0ea9a2888d at mail.gmail.com>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > question is the same as subject
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081014/c522c87f/attachment-0001.html
> >
> > ------------------------------
> >
> > Message: 5
> > Date: Wed, 15 Oct 2008 20:56:16 +0200
> > From: "LdK ^^" <elldekaa at gmail.com>
> > Subject: [antlr-interest] Problem with multiple treeparser ...
> > To: antlr-interest at antlr.org
> > Message-ID:
> >        <b3e94fd60810151156qc50cb17mb7020fe788f94d29 at mail.gmail.com>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Hi,
> > I have a problem when i use multiple treeparser,
> > the first is in same file that the parser
> > but the second is in a other file and i always get an "" when i make a
> > get.text() in this tree parser
> > so i dont uderstand, are there any options to share informations ???
> > thx a lot,
> >
> > Herve
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081015/852c2d6f/attachment-0001.html
> >
> > ------------------------------
> >
> > _______________________________________________
> > antlr-interest mailing list
> > antlr-interest at antlr.org
> > http://www.antlr.org/mailman/listinfo/antlr-interest
> >
> >
> > End of antlr-interest Digest, Vol 47, Issue 15
> > **********************************************
> >
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081015/c1e94d73/attachment.html 


More information about the antlr-interest mailing list