[antlr-interest] Tree pattern maching using the C# (was C) target

Johannes Luber JALuber at gmx.de
Tue Jan 19 16:42:02 PST 2010


> Hi Johannes,
> 
> I tried the version that you mentioned by downloading it from
> antlr:/runtime/CSharp2 in the Fisheye code repository and then tried to
> compile it using VS2008. This didn't work because a file
> "TokenConstants.cs"
> was reported missing by VS2008 and gave me compilation errors. I managed
> to
> get a version from the CSharp3 repository and after making one change I
> could compile.

Oops - I thought that I had checked in that file already. Can you send both TokenConstants.cs (for comparing with my own version) and the modified grammar file to the list? I'm not sure where the error can be as I lifted more than a few file from the CSharp3 target.

Sam, can you check if the grammar works with CSharp3 target? It would be helpful to narrow down the cause.

Johannes

> I noticed that the Downup method is part of the Treefilter
> class which inherits from the TreeParser class. The grammar for the tree
> parser from the example has the following header:
> 
> // START: header
> tree grammar DefRef;
> options {
>   tokenVocab = Cymbol;
>   ASTLabelType = CommonTree;
>   filter = true;
>   language=CSharp2;
> }
> @members {
>     SymbolTable symtab;
>     Scope currentScope;
>     public DefRef(ITreeNodeStream input, SymbolTable symtab) 
>     	: this(input) 
>     {
>         this.symtab = symtab;
>         currentScope = symtab.globals;
>     }
> }
> // END: header
> 
> Generating the tree parser gives DefRef.cs with the DefRef class declared
> as:
> 
> public partial class DefRef : TreeParser
> 
> 
> Now I can cast this into the TreeFilter class but to test things quickly I
> changed the above line in the DefRef.cs into:
> 
> public partial class DefRef : TreeFilter
> 
> 
> In the calling program I use:
> 
> DefRef def = new DefRef(nodes, symtab); // use custom constructor
> def.Downup(t); // trigger symtab actions upon certain subtrees
> 
> When I run this nothings happens whereas I have grammar rules and actions
> like:
> 
> exitBlock
>     :   BLOCK
>         {
>         Console.WriteLine("locals: "+currentScope);
>         currentScope = currentScope.getEnclosingScope();    // pop scope
>         }
>     ;
> 
> I have not figured out yet why this doesn't work. The examples is a
> one-to-one port of the Java example of pattern 17 Symbol Table for Nested
> Scopes of the Language Implementation Patterns.
> 
> Any idea?
> 
> Thanks,
> 
> Marc
> >-----Original Message-----
> >From: Johannes Luber [mailto:JALuber at gmx.de]
> >Sent: Friday, January 15, 2010 1:59 PM
> >To: Marc Speyer; antlr-interest at antlr.org
> >Subject: Re: [antlr-interest] Tree pattern maching using the C target
> >
> >> Hi all,
> >>
> >> I have a similar issue using the C# target. Using the Cymbol.g example
> of
> >> pattern 17 Symbol Table for Nested Scopes of the Language
> Implementation
> >> Patterns book I could not get it to work because there is now downup
> >> method.
> >> According to the documentation this method walks the AST code using
> >> ANTLR's
> >> built-in downup( ) strategy.
> >>
> >> Am I correct assuming that this has not been implemented yet for the C#
> >> target (as Jim implies in his response). Is it difficult to implement
> it
> >> myself? I guess it would involve implementing the tree pattern matching
> >> stuff.
> >>
> >> Marc
> >
> >You are correct - there is no official version yet, which implements tree
> >pattern matching. I haven't gotten around to the API changes yet (will
> work
> >on that next week), though I have checked in some untested changes. It
> >would be the easieast if you'd base your own code on that for now.
> >
> >Johannes
> >
> >> P.S. Hope this email files under the proper subject thread, and
> apologies
> >> in
> >> advance if it isn't (Just subscribed to the mailing list but I could
> not
> >> find out how to get previous posts from it)
> >>
> >> > Pattern matcher or normal tree walker? The pattern stuff is not
> >> implemented in the C target yet.
> >> >
> >> > Jim
> >> >
> >> >> -----Original Message-----
> >> >> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >> >> bounces at antlr.org] On Behalf Of Heiko Folkerts
> >> >> Sent: Thursday, January 14, 2010 5:01 AM
> >> >> To: antlr-interest at antlr.org
> >> >> Subject: [antlr-interest] Tree pattern maching using the C target
> >> >>
> >> >> Hi all,
> >> >> I wrote al litle tree pattern matcher for a specific validation we
> >need
> >> >> in our grammar. ANTLR and the C compiler compile it all well but
> there
> >> >> is now "downup" mehtod for running the matcher. Instead I only see
> our
> >> >> own rules in the generated parser. So, is the method to run when
> using
> >> >> a tree pattern macher in the C target different than ^"downup"? How
> to
> >> >> run the matcher?
> >> >>
> >> >> I tried to find an answer in the C examples but there was only a
> >> >> treeparser and no tree pattern matcher.
> >> >>
> >> >> Thx+
> >> >> Heiko
> >> >>
> >> >>
> >> >> --
> >>
> >>
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
> >--
> >GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> >Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser


More information about the antlr-interest mailing list