Lex & Grammer for GPPG

May 4, 2012 at 6:21 PM

Hi,

I'm new to writing grammer. I have a need to develop a parser from a file, which has schema/data format desc & data. I just started reding about lex & yacc. I found GPPG does generate perser in c# for lex & Yacc style grammer.

I do not see many examples of using GPPG. Anybody help me post some basic example of using GPPG to write lex & grammer to generate parser in c#.

ex file, I need to parse.
data format structure:
"KP_BLOB" struct {
               uint;
                    
               ulong;
               ulong;
               taggedstruct {
                  ("RASTER" uchar )*;                    
               };
 
 
"KP_BLOB" struct {
            long; 
            enum {
              "BYTE" = 1,
              "WORD" = 2,
              "LONG" = 4
            };   
          };

Data:
 
/begin MEASUREMENT n5pidurDeg ""
        UWORD deg_formula_A_6_0_1234_0 1 0.5 0 11.989013
        BYTE_ORDER MSB_FIRST
        READ_WRITE
        ECU_ADDRESS 0xabc12
        FORMAT "%11.6"
        /begin IF_DATA ASAP1B_CCP
            KP_BLOB 0 0xcd321 0x2
        /end IF_DATA
        /begin IF_DATA CAN_EXT 011
            LINK_MAP "aaa.4.wc.data.dp.angle" 0x2ac21 0 0 0 0 0 0
        /end IF_DATA
        DISPLAY_IDENTIFIER pilot_duration_in_deg__5
    /end MEASUREMENT

 

Thanks in advance.

Thank you,
Ardi