Implementing a preprocessor for xBase language

I’m thinking about the implementation of the preprocessor of a compiler that I’m implementing, which is based on CA-Clipper … the preprocessor has several commands and tricks that I can’t imagine how it can be implemented … so, I’m coming to ask for ideas here in the group, how to do this implementation

Here is the description of the xBase ( CA-Clipper / (x)Harbour ) pre-processor: https://gist.github.com/bencz/1a61785958a948b8cf47a1f0fbe94644

Let’s take as an example, the following pre-processing command:

#command USE <(db)> [VIA ] [ALIAS ] [] ;
            [] [] [] ;
            [CODEPAGE ] [INDEX <(index1)> [, <(indexN)>]] ;
            [ TABLE  ] ;
            [  ];
            [ FROM  ] ;
            [ QUERY  ] ;
            [ USER  PASSWORD  ]=> ;
         [ HB_AdoSetTable(  ) ; ] ;
         [ HB_AdoSetEngine( <(dbEngine)> ) ; ] ;
         [ HB_AdoSetServer(  ) ; ] ;
         [ HB_AdoSetQuery(  ) ; ] ;
         [ HB_AdoSetUser(  ); HB_AdoSetPassword(  ) ; ] ;
         dbUseArea( <.nw.>, , <(db)>, <(a)>, ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.> [, ] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]

Parsing the code is not so complicated … the problem goes into the analysis of the ‘options’, which are the items that are between ‘[’ & ‘]’.
In the code, it is possible to have several “#command” that I started in USE <(db)>, but, when doing the pre-processing, it is necessary to identify which is the correct USE <(db)> …
There is also the USE <(db)> of the standard CA-Clipper / xHarbour, which is as follows:

#command USE <(db)> [VIA ] [ALIAS ] [] ;
            [] [] [] ;
            [CODEPAGE ] [CONNECTION ] [INDEX <(index1)> [, <(indexN)>]] => ;
         dbUseArea( <.nw.>, , <(db)>, <(a)>, ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>,  [], [] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]

Another point … the first word of #command, may already be a marker, for example:

#command <(db)> USE  [VIA ] [ALIAS ] [] ;
            [] [] [] ;
            [CODEPAGE ] [CONNECTION ] [INDEX <(index1)> [, <(indexN)>]] => ;
         dbUseArea( <.nw.>, , <(db)>, <(a)>, ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>,  [], [] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]

    *** So, to use this command, the following line of code would be used:
    CLIENTES USE NEW

I’m implementing my own parse system, so I’m not using a code generation and analysis system, like ANTLR or Bison …

Hi, Ale

i’ve a parsre for Visual FoxPro 9. The grammar was implemented in GPPG Yacc/Lex.

Do you any thing please contact me. Adrua@hotmail.com or mobile (57)316-259-1801-

Good Luck