Thread: commands suitable for a custom preprocessor to run before gcc etc

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    commands suitable for a custom preprocessor to run before gcc etc

    After I get the paw up and running I plan to deal with the next inconvenience of development, the inconsistent preprocessor command support (and the lack of #for etc). I'd like to start a debate here on what options would be desirable vs what is possible implementation wise, so far these are the notes for what I plan to implement (and how on some of them)

    Code:
    /* prepaw (paw preprocessor) planned features
     * >	Case sensitive for faster preprocessing
     * >	No escape characters for macros, just slows down preprocessing & makes
     * 	code unneccessarily confusing, commands are used for multi-line defines
     * 	instead
     * >	All commands search for macros with matching name in scope
     * >	#trigger prepaw looks for a new trigger before treating as a command,
     * 	for example to switch to @command then back you would use:
     *	#trigger @
     *	@trigger #
     * >	#undef Behaves as usual, triggers an error & aborts when attempting to
     * 	undefine anything defined with #predef
     * >	#global Behaves as #define would've but ends with #end,
     * 	escape characters are unneeded
     * >	#static Behaves as #global but it's define shows up only in the file
     *	scope
     * 	#line N ID, used for declaring what line and file id is relavent from
     * 	here on, for example if an include was on the first line of a file that
     * 	happened to have the id 3 (that's where paw's GC starts assigning new
     * 	IDs, 0, 1 & 2 are reserved for pawin, pawout, & pawerr) then prepaw
     *	will insert the contents of the file before the #include command then
     *	replace the #include with #line 1 3
     * >	#scoped Behaves as #static but in macro scope (if there is one)
     * >	#predef Behaves as #scoped, but cannot be undefined
     * >	#include Behaves as usual
     * >	#import Behaves as usual
     * >	#source No commands are processed between this, #end, #import & #include
     * >	#warnof Expects a string, emits it as a message, increases warning count
     * >	#fixerr Expects a string, emits it as a message, increases error count
     * >	#abort Behaves as #fixerr but aborts preprocessing
     * >	#pragma once behaves as usual
     * >	#if, #ifdef, #elif & #endif behave as usual
     * >	#for([i = macro/constant, ...]; exit_condition; [modify var,...])
     * 	where [...] is optional, scope ends with #end, variables behave as if
     *	declared with #predef
     * >	#while(exit_condition)
     * >	#do ends with #while, done at least once
     * >	#modify(name,operator) expression, needed for #for, #while & #do loops
     * 	to modify their scoped variables, names that are not flat literals like
     * 	0xC0FFEEUL, 0.01f, 'x', "string" or `multi-line string` get treated as
     * 	a `multi-line string`
     * >	#end Ends scope, triggers an error & aborts if in global scope
    */

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    * > #if, #ifdef, #elif & #endif behave as usual
    * > #for([i = macro/constant, ...]; exit_condition; [modify var,...])
    * where [...] is optional, scope ends with #end, variables behave as if
    * declared with #predef
    * > #while(exit_condition)
    Why implement one language, when you can double the fun and implement two.
    Turing completeness - Wikipedia

    Maybe you need a pawpaw post-processor to go along with it .

    I know it's a waste of time saying this, but something much more capable than your proposal already exists.
    m4 (computer language) - Wikipedia
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by Salem View Post
    * > #if, #ifdef, #elif & #endif behave as usual
    * > #for([i = macro/constant, ...]; exit_condition; [modify var,...])
    * where [...] is optional, scope ends with #end, variables behave as if
    * declared with #predef
    * > #while(exit_condition)
    Why implement one language, when you can double the fun and implement two.
    Turing completeness - Wikipedia

    Maybe you need a pawpaw post-processor to go along with it .

    I know it's a waste of time saying this, but something much more capable than your proposal already exists.
    m4 (computer language) - Wikipedia
    1st, I didn't even know that existed so drop the sarcastic attitude please, 2nd from what I saw via the link you provided, I cannot see how anyone would want to use that for programming, I can see newbs & experts alike getting confused when looking at normal source code that has that mess mixed in, the existing C/C++/C# preprocessors are extremely clear at what is an is not being treated as a command, I do not see a reason why anyone would pick the m4 style over the existing preprocessor style, that's why I was basing my plans on the existing preprocessor style, the only thing lacking about the existing preprocessor style was the lack of certain types of commands such as loop support or array support in the values or scopes & variables. The main reason I'm even making it is because I need a preprocessor I can plug into my app directly via a shared library for glsl & hlsl to co-exist in the same file and have proper header support, I just figured if I'm gonna do my own preprocessor I might as well do it properly and have a wrapper app that can be used prior to gcc etc, at the very least it serves as a good learning experience just to do the preprocessor at all

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    You are right @awsdert, as a former 'sendmail' admin I can confirm that m4 is an abomination, and best avoided as much as possible.

    It does show the ultimate end result of desiring a completely flexible text preprocessor to run on top of programs and config files. You summed it up perfectly:

    I cannot see how anyone would want to use that for programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No suitable constructor?!?!
    By adam.morin in forum C++ Programming
    Replies: 5
    Last Post: 02-18-2011, 06:42 AM
  2. Suitable Compiler?
    By Carola in forum Windows Programming
    Replies: 4
    Last Post: 08-25-2009, 02:01 AM
  3. Which OS is more suitable for programming?
    By Utopus in forum Tech Board
    Replies: 32
    Last Post: 06-27-2007, 05:39 PM
  4. #Preprocessor commands
    By nurulsiddik in forum C Programming
    Replies: 2
    Last Post: 05-15-2003, 04:02 AM

Tags for this Thread