[antlr-interest] Need help getting char * string from an ID
Jeffrey Newman
jeffn at photorepo.com
Thu Dec 16 17:00:53 PST 2010
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
More information about the antlr-interest
mailing list