[antlr-interest] Reporting a bug in C Target
Gokulakannan Somasundaram
gokul007 at gmail.com
Sat Dec 5 13:20:42 PST 2009
Hi,
Seems like the C Target initializes unknown types to NULL. I made a rule
which returns enum value and the code generated by ANTLR C Target is nt
getting compiled in MSVC.
The code is as follows..
grammar Test1;
options
{
language = C;
}
@includes
{
enum ObjectType
{
OBJECT_A
, OBJECT_B
, OBJECT_C
, OBJECT_TOTAL
};
}
id_list returns [ObjectType result]:
a=id { $result = $a.result; }
(',' b=id { $result = OBJECT_C; } )*
;
id returns [ObjectType result]: ID+ '=' ID+ ';' NEWLINE { $result =
OBJECT_A; }
| NEWLINE { $result = OBJECT_B; }
;
NEWLINE: '\r'? '\n' ;
ID: ('a' .. 'z' | 'A' .. 'Z')+ ;
WS: (' '|'\t'|'\r'|'\n')+ {skip();} ;
I actually tried writing a code returning C++ objects (not pointers) and i
found that ANTLR initializes it to NULL. Later found that it is doing the
same for enum values also. Is it possible to fix this, so that it works for
C++ objects also. Like when i return a std::string, it assigns NULL and the
compiler reports an error.
Thanks,
Gokul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091206/b5dc8736/attachment.html
More information about the antlr-interest
mailing list