Compiler /PREPROCESS

Just starting out? Need help? Post your questions and find answers here.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Compiler /PREPROCESS

Post by Josh »

PureBasic Help wrote:/PREPROCESS "Filename": Preprocess the source code and write the output in the specified "Filename". The processed file is a single file with all macro expanded, compiler directive handled and multiline resolved. This allows an easier parsing of a PureBasic source file, as all is expanded and is available in a flat file format. No comments are included by default, but the flag /COMMENTED can be used to have all untouched original source as comments and allow comments processing. The preprocessed file can be recompiled as any other PureBasic source file to create the final executable.
  • Compiler shouldn't break
    Don't know if it is possible, but I think the PREPROCESS feature should do what is written in the Help and nothing more. In my eyes, it makes no sense if the compiler breaks in the same cases, like the compiler would build a final exe. For exempel:

    Code: Select all

    Test()
    
    Procedure Test()
      MessageRequester ("", "TEST")
    EndProcedure
    To solve this problem and write the Declare command would be a typical job for users preprocessor.
  • Crate a second File with source-file and source-line
    There should be a parallel file to the produced preprocessed file, where for each line in the preprocessed file is a line with information of source-file an source-line. So my preprocessor could give this informations back to the Ide.
thxs
sorry for my bad english
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Compiler /PREPROCESS

Post by blueznl »

I think you can already do this, though it's not triggered by a keyword. It's how I use CodeCaddy. CodeCaddy takes the unprocessed source, and processes it before passing it on to the compiler.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: Compiler /PREPROCESS

Post by Justin »

Totally agree with Josh, i have not tested this but if the compiler breaks with some syntax error it is totally useless.
The point of preprocessing is that you can put preprocessor directives or things like not declaring procedures etc.., handle them(preprocess) and then send the arranged file to the pb compiler, but if the compiler breaks when finding a prepocessor directive what is the point?
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Compiler /PREPROCESS

Post by kenmo »

The /PREPROCESS is working correctly and it not useless!

It runs the standard PB preprocessing (replace macros, process CompilerIfs, concatenate multi-lines, etc) but of course it still requires a PB valid-syntax file... how can it resolve input code which has syntax errors?

If you want to write a custom preprocessor which extends the PB syntax (which many users here have done), you just need to execute it first in your toolchain:

syntax preprocessor --> PB compile
or
syntax preprocessor --> /PREPROCESS --> more processing --> PB compile
or
/PREPROCESS --> more processing --> PB compile

These usage cases all work fine. Very handy to have. :)
Post Reply