Articles
| Open Access |
https://doi.org/10.37547/ajast/Volume05Issue10-20
Arithmetic Expression Compiler Using Python And LLVM
Abstract
This paper presents the implementation of a compiler that translates arithmetic expressions into native machine code using the LLVM compiler infrastructure's Python API. This work demonstrates a complete compilation pipeline. It converts high-level arithmetic expressions into native assembly code using llvmlite, which is the Python binding for LLVM. The compiler performs several tasks. It handles lexical analysis, parsing with operator precedence, constructing the abstract syntax tree, and generating LLVM IR. By connecting native execution and interpreted Python code, the system allows for compilation without the delays of interpretation. This work sets the stage for future experiments in Python-to-native compilation. It also helps us understand how to access modern compiler infrastructures programmatically.
Keywords
Compiler, LLVM, Python
References
B. Hoyt, "Writing a simple x86-64 JIT compiler from scratch in stock Python," 2021. [Online]. Available: https://benhoyt.com/writings/pyast64/
A. Author, "Gustav: A Tree-Walk Interpreter Implementation in Python," Web of Journals, vol. 1, no. 12, pp. 1-10, 2024. [Online]. Available: https://webofjournals.com/index.php/12/article/view/5047/5084
C. Lattner and V. Adve, "LLVM: A compilation framework for lifelong program analysis & transformation," in Proceedings of the International Symposium on Code Generation and Optimization, 2004, pp. 75-86.
LLVM Project, "LLVM Language Reference Manual," 2024. [Online]. Available: https://llvm.org/docs/LangRef.html
R. Cytron, J. Ferrante, B. K. Rosen, M. N. Wegman, and F. K. Zadeck, "Efficiently computing static single assignment form and the control dependence graph," ACM Transactions on Programming Languages and Systems, vol. 13, no. 4, pp. 451-490, 1991.
Continuum Analytics, "llvmlite documentation," 2024. [Online]. Available: https://llvmlite.readthedocs.io/
A. V. Aho, M. S. Lam, R. Sethi, and J. D. Ullman, Compilers: Principles, Techniques, and Tools, 2nd ed. Boston: Addison-Wesley, 2006.
E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software. Boston: Addison-Wesley, 1994.
S. K. Lam, A. Pitrou, and S. Seibert, "Numba: A LLVM-based Python JIT compiler," in Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in HPC, 2015, pp. 1-6.
P. Tillet, H.-T. Kung, and D. Cox, "Triton: An intermediate language and compiler for tiled neural network computations," in Proceedings of the 3rd ACM SIGPLAN International Workshop on Machine Learning and Programming Languages, 2019, pp. 10-19.
Article Statistics
Copyright License
Copyright (c) 2025 Abduaziz Ziyodov

This work is licensed under a Creative Commons Attribution 4.0 International License.