[antlr-interest] Bug in generated C for AST rewrite rule with repetition of a production element
David Benn
david.benn at astc-design.com
Thu May 29 01:17:47 PDT 2008
Hi Jim, all
I appear to have found a bug in the generation of C code for AST rewrite
rules where an element is repeated. I am using ANTLR3.1b1.
The Wiki (http://www.antlr.org/wiki/display/ANTLR3/Tree+construction)
gives an example of this:
<quote>
ANTLR tracks all elements with the same name into a single implicit list:
formalArgs
: formalArg (',' formalArg)* -> formalArg+
|
;
</quote>
I have the following production which has essentially the same form:
enumerated_type_def
: ENUMERATED IDENT
LBRACE
enumerated_type_element
(COMMA enumerated_type_element)* RBRACE
SEMI?
-> ^(TYPE ENUMERATED IDENT enumerated_type_element+)
;
Code is generated just fine but compiling the parser results in this
error (source file name changed to protect the innocent):
XParser.c: In function `XParser_enumerated_type_def_return
enumerated_type_def(XParser_Ctx_struct*)':
XParser.c:2191: error: invalid conversion from `const void*' to `void*'
However, changing the + into a * does work okay, and yields the expected
AST, i.e.
-> ^(TYPE ENUMERATED IDENT enumerated_type_element*)
I am compiling the resulting parser and lexer source files with g++
3.4.6. I specifically want to use C++, and yes, I realise this is not
the most recent g++ version. :)
Using a const_cast in the generated code suppresses the error, but that
only fixes the symptom. I haven't looked further at the generated code
yet to suggest another solution.
Thanks.
Rgds,
DJB
--
David Benn
Australian Semiconductor Technology Company (ASTC) Pty Ltd
76 Waymouth Street
Adelaide 5000, South Australia
ABN: 18 117 392 784
Tel: +61 8 8231 2782
Mob: +61 407 261163
Email: david.benn at astc-design.com
Web: www.astc-design.com
More information about the antlr-interest
mailing list