Vagrearg Logo  
gcmc - G-Code Meta Compiler


Gcmc is a front-end language for generating G-code, SVG and DXF for CNC mills, lathes, laser cutters and other numerical controlled machines employing G-code, SVG or DXF. The language is a context-free grammar created to overcome the archaic format of G-code programming and aims to be more readable and understandable. Gcmc makes extensive use of vector mathematics to support the 3D nature of CNC machining.

An introduction document is available. The introduction goes through basic syntax and program outline and describes an example to create involute gears in under 200 lines of code (under 100 lines when excluding source code comments).

Getting and building gcmc

You can get the source from the link below. The windows executable is a 32bit MinGW cross-compiled command-line version.
Source tarball: gcmc-1.5.1.tar.gz
Windows exe:
Git repo:

Older sources are available and a SHA1 sum and/or SHA256 sum may be used to verify the archives.

Building from source is straight forward and should function on Linux, *BSD, MinGW/MSYS and Cygwin:
$ tar xzf gcmc-1.5.1.tar.gz
$ cd gcmc-1.5.1
$ ./configure
$ make

After 'make' you should have an executable in the 'src' directory named 'gcmc'. For a MinGW cross-compile you should use 'configure --host i686-w64-mingw32' or whatever your cross-target-host specifier is and it should result in 'gcmc.exe'.

Running gcmc

Running gcmc, assuming you are in the src directory, is as simple as:
$ ./gcmc -o output.ngc input.gcmc

This will convert the input file "input.gcmc" into a G-code file "output.ngc". The output is written to stdout if no -o option is given. Stdin is used if no input file is given.

You may compile and inspect the examples by running (from the top or the example directory):
$ make examples

This will give you G-code, SVG and DXF versions of the examples, which can be inspected with the appropriate programs.

The gcmc man-page gives you a complete summary of all option.


gcmc-1.5.1 - 2014-03-14
  • Feature: Add trochoidal milling example
  • Feature: Add continuous curvature pocketing example
  • Feature: Add tool-compensated path library call and example
  • Feature: Add involute gears example
  • Feature: Add floret example (sunflower pattern) with sorting examples
  • Feature: Add an "introduction to gcmc" to the documentation
  • Feature: Add to_distance() function
  • Feature: Implement insert() and delete() functions to manipulate vectors and vectorlists
  • Feature: Implement sign() function
  • Feature: Accept string and vector comparison
  • Feature: Allow command-line offsets options to include units
  • Feature: Allow vector entry merge/replace with | and &
  • Feature: Add missing binary operators &, |, ^ and ~
  • Feature: All normal statements are now expressions to unify the syntactic form
  • Change: Empty strings are false in boolean eval and true when not empty
  • Change: Rename gcmc internal global tracking variables and warn on script-use
  • Change: Epsilon reduced to 1e-12 to catch rounding better
  • Fix: Expand and reorganize syntax documentation
  • Fix: Function to_native() missed copying the original units
  • Fix: Lexer must not ignore %= token
  • Fix: Dot product must allow unit-less result
  • Fix: Multiplication of scalar*vector and scalar*vectorlist take LHS units
  • Fix: Internal value dereferencing could result in wrong value
  • Fix: Resolve memory issues by using valgrind
  • Fix: Lexer string handling could be off-by-one
For older changes see Changes page for details.

Bugs reports and feature requests

Please report any bugs you may encounter to gcmc _at_ Please include an example that triggers the bug.

If you want more/extra/different features included, then write me an email with the request and a description what you want to add and want to achieve with the change or addition.

Gcmc documentation

gcmc man-page All command-line options and switches.
gcmc introduction page Starting with a simple step-by-step introduction to the basic concepts and ending with the creation of an example to create involute gears.
gcmc syntax page Detailed description of language syntax and its semantics.
gcmc function reference page All built-in functions described with all parameters, types and operational modes.
gcmc library page Library functions are more complex operations like tool compensation and canned drill sequences.

Gcmc examples and screenshots

(click on images to enlarge)

Involute gears (sources: involute-gear.gcmc and

Continuous curvature pocketing (sources: cc_hole.gcmc and

Sunflower floret arrangement of 500 holes (source: floret-vogel.gcmc)
Rapid path is about 55.5 meters without sorting the individual holes:

Sorting the holes with a simple nearest neighbor algorithm shortens the rapid path to about 4.1 meters:

Using a bin-sorting algorithm shortens the rapid path to about 3.7 meters using 20 bins:

Tool-size compensation of an open or closed path on either left or right side (source: tool-compensate.gcmc)

High-speed milling using trochoidal movement (source: trochoidal.gcmc)

Executive Decision Maker Pro box example (source)
edm-pro-ngc edm-pro-svg
Cutter example (source)
cutter-ngc cutter-svg
Wheels example (source)
wheels-ngc wheels-svg

Posted: 2013-11-04
Updated: 2013-12-11

Overengineering @ request