[antlr-interest] Reporting a bug in C Target

Gokulakannan Somasundaram gokul007 at gmail.com
Tue Dec 8 17:07:26 PST 2009


Actually, i want to suggest the memset option only for making it work with
enums and not with C++ objects as i mentioned before. Since people expect C
target to work with enums, i made that suggestion.

Gokul.

On Mon, Dec 7, 2009 at 11:01 AM, Gokulakannan Somasundaram <
gokul007 at gmail.com> wrote:

> Jim,
>   I could make that from the C.stg file. I have decided to use char for
> enums.
>   But may i know, why you want to have the initialization stuff in there.
> Because, by leaving it to the user, this can provide more flexibility. If
> you feel that the memory locations have to get cleared, you can do a memset
> of 0 for the allocated memory.
>   Kindly let me know the reasoning behind the decision..
>
> Gokul.
>
>
> On Mon, Dec 7, 2009 at 12:03 AM, Jim Idle <jimi at temporal-wave.com> wrote:
>
>> Please search past posts for info on why this is and what to do. You must
>> use pointers basically.
>>
>> Jim
>>
>>
>> On Dec 5, 2009, at 13:42, Gokulakannan Somasundaram <gokul007 at gmail.com>
>> wrote:
>>
>> Just found out from C.stg, the types that are dealt by antlr and it sets
>> NULL to the rest. i feel that the initialization should  not be done like
>> this and left to the user to make his own initializations, if he needs it.
>> Or he should be provided with a way to customize the initialization that's
>> happening.
>>
>> Gokul.
>>
>> On Sun, Dec 6, 2009 at 2:50 AM, Gokulakannan Somasundaram <<gokul007 at gmail.com>
>> gokul007 at gmail.com> wrote:
>>
>>> 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.
>>>
>>
>>
>> List: <http://www.antlr.org/mailman/listinfo/antlr-interest>
>> http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> <http://www.antlr.org/mailman/options/antlr-interest/your-email-address>
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091209/aab54962/attachment.html 


More information about the antlr-interest mailing list