Nanomechanical computers promise a greatly improved energetic efficiency compared to their electrical counterparts. However, progress towards this goal is hindered by a lack of modular components, such as logic gates or transistors, and systematic design strategies. This article describes a universal logic gate implemented as a nonlinear mass-spring-damper model, followed by an automated method to translate computations, expressed as source code of arbitrary complexity, into combinations of this basic building block. The proposed approach is validated numerically in two steps: First, a set of discrete models are generated from code. The models implement computations with increasing complexity, starting by a simple adder and ending in a 8-bit Turing complete mechanical processor. Then, the models are forward integrated to demonstrate their computing performance. The processor is validated by executing the Erathostenes' sieve algorithm to mechanically compute prime numbers.