[antlr-interest] Re: While using preliminary C# code generator.

dinurp dinurp at yahoo.com
Mon Apr 29 21:00:02 PDT 2002


Hi Micheal
My question was more from the ANTLR grammer's point of view rather 
than C#'s. #[OR] is an ANTLR construct and not a Csharp construct. 
The parser generates code from using this. So my question is can't 
the parser generater generate the proper code so that grammer syntax 
is not different deppending on the target parser language?

Any way this is what I did:
options {
    language="CSharp";
    namespace="myNamespace";
}

{
using TT=MyWalkerTokenTypes;
}
<SNIP>
predicate :
      (simple_predicate)=> simple_predicate
    | (compound_predicate)=> compound_predicate
    | (controlled_predicate)=> controlled_predicate
    |! p:complex_predicate! { ## = #( #[TT.COMPLEX_FILTER], p); }
    ;
<SNIP>

PS:
I made changes for namespace too. But it is not to my liking. I can 
share it if you are interested.

Thanks,
Dinu



--- In antlr-interest at y..., "micheal_jor" <open.zone at v...> wrote:
> --- In antlr-interest at y..., "dinurp" <dinurp at y...> wrote:
> > Hi,
> > I am trying to use the new C# code generator. I faced a peculiar 
> > problem while using it for tree construction. 
> > 
> > condition :
> >     boolean_term ( OR! boolean_term )*
> >     {
> >         if ( null != ##.getNextSibling() )
> >             ## = #(#[OR],##);
> >     }
> >     ;
> > 
> > OR token is defined in another grammer and the grammer from which 
> the 
> > above piece is extracted imports that grammer.
> > 
> > The code generated by the CSharp generator doen't recognize OR in 
#
> > [OR]. This is because the symbol OR is not known to the Parser 
> class. 
> > It is defined in TokenTypes class. Now I can go ahead and re-
write 
> it 
> > as #[TokenTypes.OR]. But is that the correct way? All the samples 
I 
> > have seen, they are for Java or C++, use #[OR] construct.
> 
> For C#, you have to prefix the Tokens with the xxxTokenTypes class 
> name. C# interfaces cannot contain constants like in Java and there 
> is no support for global identifiers like in C++.
> 
> > For the time being I copied all definitions from TokenTypes to 
the 
> > Parser class.
> > 
> > What are your suggestions?
> > Thanks,
> 
> It's better to get used to using the "TokenTypes.OR" style. This is 
> how things will be done with C#. Study the CSharp examples for more 
> info....
> 
> Micheal


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list