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

Marc Speyer m.y.speyer at inter.nl.net
Mon Jan 18 08:39:00 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. 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;
@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

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

    :   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?


>-----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.
>> 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
>> >> 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

More information about the antlr-interest mailing list