>From an earlier email on the list...here's what was involved in getting this to work for me. (There's a working example in http://antlrcsharp.codeplex.com It's the browse project. It isn't included in any of the "releases" so you'll need to download the latest source.)
Here's how to get this working with a slightly modified antlr-3.2.jar and the latest CSharp2 runtime. Specifically I got the sample for pattern 19 (symtab/class) from Language Implementation Patterns working. That should cover all the filter=true; Downup() goodness. 1.) Download the latest CSharp2 runtime code and build it (I got a zip from http://fisheye2.atlassian.com/browse/antlr/runtime/CSharp2). There's a Visual Studio 2008 project file that builds it without modification. 2.) You'll need to make a few modifications to the string templates. The file to modify in the jar (antlr3-3.2.jar) is org\antlr\codegen\templates\CSharp2\CSharp2.stg. (To update...Unzip the jar, modify CSharp2.stg, and rezip sans any compression). Here are the updates to make. a.) Change Index() to just Index (there are 3 occurances) b.) Update the treeParser rule to use the TreeRewriter base class as shown below. Replace the old version (line 312) with this. /** How to generate a tree parser; same as parser except the input * stream is a different type. */ treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, labelType={<ASTLabelType>}, ASTLabelType="object", superClass={<if(filterMode)><if(buildAST)>TreeRewriter<else>TreeFilter<endif><else>TreeParser<endif>}, members={<actions.treeparser.members>}, filterMode) ::= << 3.) Add the override methods for Topdown / Bottomup to YourGrammar.g. [[To have this behave like the java runtime, the string template for rule would have to be modified to override the two methods topdown/bottomup. You have to explicitly "override" in C#. topdown/bottomup also need to be all lower case in CSharpN runtimes since they are not Lexer rules.]] @members { ... protected override void Topdown() { topdown(); } protected override void Bottomup() { bottomup(); } } 4.) Make sure you translate the java version of TreeAdapter class to explicitly override Create/DupNode/ErrorNode (or you'll get mysterious casting exceptions if left as create/dupNode/errorNode). Mine looks like this // test.cs public static Test.TreeAdaptor cymbalAdaptor = new Test.TreeAdaptor(); public class TreeAdaptor : CommonTreeAdaptor { public override object Create(IToken token) { return new CymbolAST(token); } public override object DupNode(object t) { if (t == null) return null; return Create(((CymbolAST)t).Token); } public override object ErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException e) { CymbolErrorNode t = new CymbolErrorNode(input, start, stop, e); Console.WriteLine("returning error node '"+t+"' @index="+input.Index); return t; } } Hopefully that helps. Andrew 2010/6/23 Sam Harwell <[email protected]> > The CSharp3 target should support the ANTLR 3.2 features. There are a few > known issues, such as the fact that the method generated for the bottomUp > and topDown rules doesn't match the name expected by the current CSharp3 > runtime (BottomUp and TopDown), so you have to manually override the > BottomUp and TopDown methods to call bottomUp and topDown instead. > > To use the CSharp3 target, you'll need to generate your grammar using the > C# > port of the ANTLR tool (Antlr3.exe). The binaries for the tool and the > CSharp3 runtime can be found here: > http://www.280z28.org/downloads/antlr/antlr-dotnet-binaries-3.2.0.6805.7z > > Thanks, > Sam > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Ranco Marcus > Sent: Wednesday, April 21, 2010 1:40 AM > To: Nazim Oztahtaci; [email protected] > Subject: Re: [antlr-interest] Runtime Library of v 3.2 for C# > > Johannes Luber, maintainer of the CSharp2 target, wrote in December 2009: > > <quote> > I'm working on the 3.2 release. The major issue I'm tackling is to make the > APIs of CSharp2 and CSharp3 source compatible and I have to coordinate this > with the other maintainer. I'll release a beta once I've finished this. > </quote> > > I don't know if it is viable to just pull the sources and compile it > yourself. I have not yet tried that. If the changes were trivial, I expect > it would have been in beta stage already. Until that time, I will try and > keep my patience... > > Best regards, > > Ranco Marcus > > > -----Original Message----- > > From: [email protected] [mailto:antlr-interest- > > [email protected]] On Behalf Of Nazim Oztahtaci > > Sent: dinsdag 20 april 2010 13:42 > > To: [email protected] > > Subject: [antlr-interest] Runtime Library of v 3.2 for C# > > > > > > Hello, > > > > I am sorry if I repeat this question. I have checked the history of > > mail list to find out current situation of C# library for v 3.2 > > Currently I use Java for the implementation of my grammar because when > > I apply theorems(DeMorgan, Distribution etc) on the tree, BottomUp > function is called to apply them. > > However in C# v.3.1.3 there is no support and I guess I need version > > 3.2 library. > > > > I read that version 3.2 for C# can be found in repository. Is that > > true? I just wanted to confirm that. I assume that to use BottomUp > > function, it is necessary to have TreeFilter class. If I cant use C# v > > 3.2 library yet and I have to implement my own TreeFilter class which > > has BottomUp function, which files in C# version 3.1.3 source code I > > should make changes?Is it too complex to implement just bottomup > > function manually? If it is, is there any implementation of C# v 3.2 > runtime dlls on the Net for Antlr? > > > > BEst regards > > > > > > __________________________________________________________ > > _______ > > Yeni Windows 7: Gündelik işlerinizi basitleştirin. Size en uygun > > bilgisayarı bulun. > > http://windows.microsoft.com/shop > > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > > email-address > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: > http://www.antlr.org/mailman/options/antlr-interest/your-email-address > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: > http://www.antlr.org/mailman/options/antlr-interest/your-email-address > -- /Andrew List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
