Use antlr.markmail.org and search for how to do this, ot used the example gramamrs as guides. Using $ID.text->chars is easy with the C target but it will acculate all the memory you yse for the strings until you free the parser object (and it also isn't that fast to do that), whereas you can uuse the commontoken fields to gind the start and end of the text that represents the token and copy/print/etc directly from the input text.
Again, download the examples and look at the C parser in there. jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Jeffrey Newman > Sent: Thursday, December 16, 2010 5:01 PM > To: [email protected] > Subject: [antlr-interest] Need help getting char * string from an ID > > Hi, > I'm still trying to bring up my first test parser with the C runtime. > I'm using Qt, so I have translate from C to C++ and Qt's runtime. > > I have most of working, except I have not been able to get the ID > string. > > Here is the grammar: > > grammar T; > > options { > language = C; > } > > @header { > #include "../parserBindings.h" > } > > @members { > char buffer[256]; > } > > r : 'call' ID ';' { > sprintf(buffer, "Invoked with: \%s", $ID.text); > debug(buffer); > } ; > > ID: 'a'..'z'+ ; > WS: (' ' | '\n' | '\r')+ {$channel=HIDDEN;}; > > The generated code in TParser looks like. > > sprintf(buffer, "Invoked with: %s", (ID1->getText(ID1))); > debug(buffer); > > where debug is a simple function in my C to C++ bindings. > > So, how do I get a string from the grammar? > Please direct me to an example in C. > > > thanks > > Jeffrey > > > 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 -- 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.
