After generating tokens; checking the sequence of the tokens semantically including the syntax by using CFG and parse tree; generating the intermediate code we are on the last step of our compiler completion which is to generate code of the information used from by the previous phase. Moreover, Code generation in compiler simply means generating the code in the source language provided by the previous stage into some machine understandable language. Furthermore, The significance of code generators is as follows;
The Pros of Code Generation in Compiler:
- No hand or manual coding, which means less error.
- Massive time savings possible implementing larger and more complex schemas.
- Apps and PoCs can have a simple turnaround as it is faster to go to market
- Stable underlying architecture means less time wasted
- Eliminates errors when dealing with multiple source files and file types in end-to-end code generation
- Lastly, New functionality can be rolled into the underlying templates; to implement across large code bases in a single build.
The Cons of Code Generation:
- Not all applications will benefit from code generation.
- Code generation can be more inflexible than hand-selecting each code library, pattern, and coding style.
- The developer’s code must be careful; isolated in the codebase from generated code.
- Regeneration should be possible without impacting any existing code as the risk of overwriting developer code exists.
- Complexity is a real problem in code generation as it requires understanding and working with generators.
- Other code can get squirrelly especially when writing apps that generate other apps written by the mental paradigm of writing code.