[antlr-interest] parametrized c# parser class

Costa Basil costa_basil at yahoo.ca
Mon Apr 30 00:31:19 PDT 2012

I take it there is no way to do what I want, and actually, this would be a Visitor pattern. I ended up skinning the cat differently by using the visitor pattern on the structures produced by the formulas compiler.


 From: Costa Basil <costa_basil at yahoo.ca>
To: 'antlr' <antlr-interest at antlr.org> 
Sent: Monday, April 23, 2012 9:43:20 AM
Subject: Re: [antlr-interest] parametrized c# parser class
I have a tree grammar which I use to compile formulas (additions, subtractions, relational expressions etc). I want to use the same grammar to translate the formulas in another language. I don't want to maintain two grammars, so I thought I will create an interface that would handle my grammar actions (i.e. the interface would have methods for each action - one for binary operations, one for handling strings etc). If I want to compile formulas I hand the parser one implementation of the interface, if I want to translate formulas I hand the parser another implementation. 

The problem is that when I compile formulas, the non-terminal attribute type that I am using for expressions is a custom type T1, while for the other case is T2. So, I was thinking of parameterizing the parser with a parameter type T. When I want to compile formulas I instantiate the parser with T1, when I want to translate the formulas I instantiate the parser with type T2.

Hence my question, whether I can customize the generation of the parser to specify my own parameter type T, so I can declare attributes of type T.


From: Sam Harwell <sam at tunnelvisionlabs.com>
To: 'Costa Basil' <costa_basil at yahoo.ca>; 'antlr' <antlr-interest at antlr.org> 
Sent: Monday, April 23, 2012 4:11:02 AM
Subject: RE: [antlr-interest] parametrized c# parser class

The CSharp2 and CSharp3 targets always generate generic classes. I've even
managed to get the CSharp3 target to generate a parser that used a value
type (struct in C#) for the token type without any boxing/unboxing involved.

I'll need more details about what you're trying to do to be more specific.

Sam Harwell
Owner, Lead Developer

-----Original Message-----
From: Costa Basil [mailto:costa_basil at yahoo.ca] 
Sent: Monday, April 23, 2012 2:06 AM
To: antlr
Subject: [antlr-interest] parametrized c# parser class

Using the cshap3 target, is it possible to generate a parametrized c# parser
class? Something like:

public class MyParser<T> and so on.

I also want to have some non-terminal attributes of type T.


List: http://www.antlr.org/mailman/listinfo/antlr-interest

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address

More information about the antlr-interest mailing list