4th Aug 2025 This is a work-in-progress version of a utility I'm writing that will remove most of the redundant code that is output to a .csg file from OpenSCAD. It's really just a demonstration of how it might be done, as it would make more sense to perform this simplification in OpenSCAD itself rather than externally. The significant file is flatten.g which is the combined grammar for CSG files and code to perform the simplification. Everything else in this directory is a copy of my parser generator. If the code were added to OpenSCAD it would use the internal AST of OpenSCAD rather than parsing the output to recreate an AST. (And if anyone wanted an actual utility like this, I'ld recommend converting flatten.g into the format of whatever more well-known parser generator you prefer to use, for better portability. The main logic of the optimisation is all contained in the single function 'optimised_csg') This current version now also merges cascaded multmatrix() calls together. This final optimisation has reduced the original 5752 lines of test.csg to a mere 499 lines in test-out.csg! It is my hope is that a simplified csg file might form a basis for restructuring a model should you want to do that. And it's easier to read. (btw I generally replace tabs in csg files with a single space per tab, just to reduce the indentation and make files easier to read on-screen, and this code outputs the modified csg file in that fashion. But that is not a necessary part of the program and could be removed.). There is a statically-linked intel (x86-64) binary of flatten in this directory if compiling from source is too daunting (though it shouldn't be - just copy the files and type 'make'. The zip file here contains all the other files.) flatten-arm is the same binary, also compiled statically, for arm aarch64 (specifically raspberry pi). Graham