Hi !

I'm ANTLR newbie and need some suggestions about the way ANTLR works.
I have very simple language construct. For example

struct
{
   Integer i;
   String str1;
   Integer x;
   Integer y;
   String z;
}

I want to generate a couple of files from this structure. First of all
- appropriate POJO with getters and setters. At this moment I have
working grammar and generated lexer/parser using antlr3-maven-plugin.
It looks like this (the most interesting part):

/*
        entry point
*/
main :(WS* myStruct)*;
        

myStruct returns [String structName]
        :       'struct ' IDENT
                '{'
                        variable*
                '}'
                {$structName = $IDENT.text;}
        ;

type returns [String typeName]
        :
        'Integer' {$typeName = "Integer ";}
        |'String' {$typeName = "String ";}
            ;
variable returns [String variableName]
        :       type WS* IDENT WS*';' {$variableName = $IDENT.text;}
        ;

Using the following code I can access the name of the structure. But
how to get variables with their types ??

CommonTokenStream tokens = new CommonTokenStream(lexer);

SampleParser parser = new SampleParser(tokens);
SampleParser.myStruct_return msr = parser.myStruct();
System.out.println("struct name from code : "+msr.structName);

I see that StringTemplate is used as template engine. Could I use
Velocity together with ANTLR ? I have some ready-made templates in
Velocity, so it will be cool to just reuse them.

Since I need to use the same source for generation of different sorts
of output files I need some kind of reuse of AST or something else.
Any ideas how it's could be achieved ?
I'm lost a little, please help me to get out. Thanks !

Best regards, Stas.

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.

Reply via email to