[antlr-interest] Need help getting char * string from an ID
Jeffrey Newman
jeffn at photorepo.com
Thu Dec 16 17:32:05 PST 2010
Perseverance paid off.
I got it.
First get the antlr string.
Then use chars to 8 but (ascii) string out of the string structure.
On Thu, 2010-12-16 at 17:00 -0800, Jeffrey Newman wrote:
> 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
More information about the antlr-interest
mailing list