A downloadable tool for Windows

Buy Now5.00€ EUR or more

THE NEW C MACRO LANGUAGE (NCM)

NOTE: the free demo includes only a windows executable, but the full version includes Unix compatible C99 source code.

NCM is a replacement for the C/C++ macroprocessor, fixing its issues and extending the features. NCM was born out of my own work on the New C language, which is designed to provide an alternative to C++, without the quirks of C++, while sticking with the original C design philosophy. The New C compiler will be available for sale soon.

NCM can be used as a standalone program, or embedded into your application to preprocess arbitrary text data, including GLSL, XML, HTML and scripting languages. For example, NCM can be used for generating HTML page from database query.

NCM can also run on top of ordinary C/C++ preprocessor, since its passes escaped #\ directives to it unchanged.

src/main.c provides an example of a standalone use.

NCM improvements over the original C preprocessor:

- Succinct declarations: instead of `#define PI 3.14`, we now have `#PI 3.14`

  `#if #SYMBOL` instead of `#if defined SYMBOL`.

- `#pragma once` is made default for .h files, but user can at any

  time use the #multi directive to specify that the lines below

  can be included multiple times.

  The #once directive will move back into the single-include mode.

  Obviously there is no need for #ifndef/#define/#endif boilerplate.

- Optional arguments and keyword.

  Even if C99 doesn't support default values, NCM adds support for them:

    void foo(int x, int y, int z) {...}
    #foo(x,y=123,z=abc) foo(x,y,z)

  now that foo macro will supply the default values for y and z,

  and user can also call foo(456,z=789) to supply argument only for z

- Calculate arbitrary functions:

    #fac(n,x) #if n>0 fac(#[n-1],#[x*n]) #else x #endif
    fac(10,1) //expands into factorial of 10
    #count 0
    #next() {#<count> #<count=#[count+1]>}
    next() //expands into 0
    next() //expands into 1

- Redefine punctuation, like `+` and `-`:

    #+ -
    x+y    //expands into x-y

- Nest macros with different scopes, just like normal C variables.

    #x 123
    x //expands into 123
    #{
      #x 456 //shadow the x defined above
      #<x=#[x+1]> //increment x by 1
      x //expands into 457
    } //interior x gets out of scope
    x //expands int 123

- No need to escape newlines with `\`:

    #foo {
      printf("hello");
      printf("world");
    }

  The body will also produce proper #line numbers.

- Much easier to use variadic argument number macros. For example:

    #last([xs],x) x

  picks the last element of the arglist. While:

    #pp_map(f,x,[xs]) {f(x)#if xs_n != 0 , pp_map(f,xs) #endif}
    pp_map(f,a,b,c,d,e)

  expands into `f(a), f(b), f(c), f(d), f(e)`

  not how the auto argument xs_n got created to hold the length f xs

- printf style formatting:

    #("%-6s=%05d" "var1" 123)

  expands into `var1  =00123`

- Macros can be defined anywhere, not just at the start of the line.

  For example:

    #x 123
    #y #z{456} x z
    y

  will expand into `123 456`

- Insert macro arguments into strings:

   #foo(x, y) "#x+123+#y"

- Allows calling an external program or a user function with arguments.

  For example:

    #+ -
    #(echo "a+b")

  will expand into `a-b`: first external `echo` command is called with "a+b"

  Then then its stdout is being macroexpanded.

- Available as a single header library and can be used to preprocess

  other languages, like GLSL.

- Special builtin command #(say ...) printing to stdout. Useful for debugging.

- Nested /* */ comments.

- When a function-like macro invokation has no () arglist,

  NCM takes as the arguments everything up to the newline or the //-comment

  That would allow user the create elegant looking DSLs.

  Or use NCM to preprocess assembly files:

    #myopcode(a,b) {...}
    xor ax, ax
    myopcode bx, ax

- Escapable comas in arg list.

- A way to change `#` to another character, if you use the macroprocessor to

  preprocess a language where `#` is used for, say, comments.

- Auto adds extension ".h" to the files without one.

- And much more!


Usual github license rules apply:

You can use this source code in any project you want, commercial or not, modified or unmodified, but you can't resell or freely share this code as is, in the source code form.

I.e. you can't contribute it to GCC or make part of the Linux kernel, but can use it in your proprietary OS or a compiler.

Purchase

Buy Now5.00€ EUR or more

In order to download this tool you must purchase it at or above the minimum price of 5.00€ EUR. You will get access to the following files:

ncm-v1.1.zip 104 kB

Download demo

Download
ncm-v1.1-demo.zip 71 kB

Development log

Leave a comment

Log in with itch.io to leave a comment.