How does transpiling differ from compiling when it comes to Flex?

I’ve heard the term “transpiler” or “transpiled” used quite a bit when referring to Flex. What is is the distinction between transpiling vs. compiling in this context? Why is transpiling the preferred option with Flex?

That’s a great question Fred! Luckily the answer is not too complicated. When we say that a piece of flex code successfully transpiles, what we are saying is that it has produced some code in another language Java or C++ for example. When we then take that code and compile it, it results in machine code that can be executed either on specific hardware of a virtual environment (Java Virtual Machine). The goal of flex is to generate code in a variety of target languages and that is why we use transpiling with Flex code. Let me know if this helps shed some light on this process.


To provide a little more background about the terms “transpile” and “compile”, “transpiling” refers to converting code in one language to code in another language - in this case, Flex to C++ or Java, as Andrew said. “Compiling” usually refers to converting human-readable code in C++, Go, etc. to an executable file. The resulting executable contains low-level CPU instructions. Some programming languages such as Java and Python are not compiled directly to machine code, but instead are compiled to “byte code” which is then interpreted and executed by a different program (for Java, that is the Java Virtual Machine, or JVM).

1 Like

Thanks to you both for the clarification. I’ve come to learn that Flex is a specification language, but was wondering if it is strongly typed? It seems implied, but I don’t want to assume. If it is strongly typed, how are those types preserved Flex gets transpiled to from say Java to C++ or maybe even Rust or python?