Hello everyone. I am sorry to post which is probably a lame question, but have 
been pulling my hair over this one and still can't figure it out.

I wrote a grammar to parse a simple string that begins with a fixed preamble 
and contains hex characters, such as this one:


0009FFF6415049A0022B28CC901F414444D001000300060A900F6D00012232037B3808035906A49A10F981F5381B803B5A27D50CDE7F73AFBD

However, after pasting the string to use it as inputthis is what appears in the 
"Input" debug window:

0009FFF6415049A022B28CC901F414444D0103060A90F6D012232037B3808035906A49A10F981F5381B803B5A27D50CDE7F73AFBD

As you can see, sequences of zeroes have been "compressed" into one zero only. 
The leading ones are not, but that may be because of the definition of the 
grammar.

If I escape the zeroes preceding them with a "\" like so
0009FFF6415049A0\022B28CC901F414444D0\010\0\030\0\060A90\0F6D0\0\012232037B3808035906A49A10F981F5381B803B5A27D50CDE7F73AFBD
the string is shown correctly in the input window and the grammar works as (I) 
expect.

Please note that the zero-stripping appears in the input window, I don't see 
how this can be affected by the grammar.

Just in case I'll post it - sorry if it's messy, it's my first one.

Thanks very much in advance,
Álvaro

---------------------------------------------------------------------------
grammar GrammarLog;

tokens {
        REG7_TIPO='0007FFF8';
        REG9_TIPO='0009FFF6';   
}


log     :       (reg7|reg9)* EOF;

reg7: REG7_TIPO regbody7 crc16 {System.out.println("found register 7 "); };

regbody7: secuencial_registro numero_sam latitud longitud fecha_hora 
tipo_pto_not tipo_det_pto_not codigo_pto_not seq_sam sello_sam  
{System.out.println("body: "); };                          
reg9    :        REG9_TIPO regbody9 crc16;

regbody9:       secuencial_registro numero_sam fecha_hora nro_boleto tipo_viaje 
tipo_dto tipo_tarifa parada_o parada_d ordinal_tramo cant_pasajeros latitud 
longitud importe seq_sam sello_sam ;

nro_boleto
        :        bytes04;
tipo_viaje
        :       bytes04;
tipo_dto:       bytes02;        
tipo_tarifa
        :       bytes02;
parada_o:       bytes02;
parada_d:       bytes02;
ordinal_tramo
        :       byte01;
cant_pasajeros
        :       byte01;
importe :       bytes02;                        
crc16   : bytes02 {System.out.println("CRC16 ->" + $bytes02.text); };

secuencial_registro     : bytes04 {System.out.println("secuencial_registro ->" 
+ $bytes04.text + " = " + Integer.decode("0x" + $bytes04.text)); };

numero_sam      :       bytes02 {System.out.println("numero_sam ->" + 
$bytes02.text + " = " + Integer.decode("0x" + $bytes02.text)); }; 
latitud :       bytes04 {System.out.println("latitud ->" + $bytes04.text ); };

longitud:       bytes04 {System.out.println("longitud ->" + $bytes04.text ); };

fecha_hora      :       bytes04 {System.out.println("fecha_hora ->" + 
$bytes04.text ); };

velocidad       :       byte01 {System.out.println("velocidad ->" + 
$byte01.text ); };  
seq_sam :       bytes08 {System.out.println("seq_sam ->" + $bytes08.text ); };  
        
sello_sam       :       bytes08 {System.out.println("sello_sam ->" + 
$bytes08.text ); };                        
tipo_pto_not    :        byte01 {System.out.println("tipo_pto_not ->" + 
$byte01.text + " = " + Integer.decode("0x" + $byte01.text)); }; 
tipo_det_pto_not        :       byte01 {System.out.println("tipo_det_pto_not 
->" + $byte01.text  + " = " + Integer.decode("0x" + $byte01.text)); };     
codigo_pto_not  :       bytes02 {System.out.println("codigo_pto_not ->" + 
$bytes02.text ); };                                                           

byte01  :(HEX_DIGIT HEX_DIGIT);

bytes02 :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT);

h4hex :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT);

bytes04 :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 
HEX_DIGIT);

bytes08 :(HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 
HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 
HEX_DIGIT);     
HEX_DIGIT : ('a'..'f'|'A'..'F'|'0'..'9');


      

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to