[antlr-interest] 8 bit ASCII and cpp source code

Hill, Robert rhill03 at eds.com
Mon Jan 29 06:07:22 PST 2007


Maybe im misunderstanding this but how about a simple

return (int) c & 0x000000ff;

You could also (just) switch on that too.

switch (c & 0xff) { ..blah.. }

Regards, 

Rob

Robert Hill
Information Engineer
Agile Alliance Member
UKIMEA DWP ACU, Hallamshire Business Park, 100 Napier St, Sheffield. S11
8HD
email:	rhill03 at eds.com
Office:	+44 114 291 1928
Mobile:	+44 7903 185 516

 

>-----Original Message-----
>From: antlr-interest-bounces at antlr.org 
>[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim O'Connor
>Sent: 29 January 2007 13:55
>To: antlr-interest at antlr.org
>Subject: Re: [antlr-interest] 8 bit ASCII and cpp source code
>
>Great minds think alike?? :0)
>
>I tried that. The 8 bit character "turns into" 0xffd8 before 
>getting to the critical point
>
>Switch(0xffd8) doesn't match case(0xd8).
>
>> -----Original Message-----
>> From: Gavin Lambert [mailto:antlr at mirality.co.nz]
>> Sent: Saturday, January 27, 2007 3:14 PM
>> To: Jim O'Connor
>> Cc: antlr-interest at antlr.org
>> Subject: Re: [antlr-interest] 8 bit ASCII and cpp source code
>> 
>> At 10:25 27/01/2007, Jim O'Connor wrote:
>> >  The charscanner and inputbuffer classes have a return type of int 
>> > for LA().  LA(1) returns 0Xffd8 for my "problem" character.
>> >
>> >Solution: change the LA() to return unsigned?  Ric hinted 
>at such in 
>> >a 2004 archive note.
>> 
>> I haven't actually looked at the code for LA, but probably a simpler 
>> solution is to cast through unsigned char along the way.
>> 
>> ie. somewhere it'll have a bit that says "return c;" where c 
>is a char 
>> (or maybe "return (int)c;" -- change that to "return (int)(unsigned 
>> char)c;" (or the equivalent static_casts, if you're that way 
>inclined) 
>> and it should fix up your problem character without changing the 
>> function signature, which might be important if something is 
>depending 
>> on it to return negative answers sometimes.
>> 
>> 
>> 
>> This message has been scanned for viruses by MailController - 
>> www.MailController.altohiway.com
>


More information about the antlr-interest mailing list