How does a compiler translate source code into bytecode?(Python Virtual Machine 2)
Learn how a compiler translates source code into bytecode through lexical and syntactic analysis, abstract syntax tree generation, and more, in this comprehensive guide.
Welcome to the "Python Virtual Machine" Series
From the basic history of programming language development in the previous lesson, we can understand that the development of programming languages provides the driving force for virtual machine technology, while the development of virtual machine technology provides fundamental support for the development of programming languages.
Many technologies in virtual machines were invented to support corresponding language features, and similarly, many useful language features were made possible by the significant development of virtual machine technology.
Thus, we can say that programming languages and virtual machine technology are interdependent and in a dialectical unity.
In this lesson, based on the content from the previous lesson, we will use a basic expression evaluation example to explain how a compiler of a programming language translates source code into a structure that the computer can understand and ultimately execute.
We will first create a text file containing an expression consisting only of numbers and arithmetic operations, and write a program to compute the result of this expression.
The basic process includes lexical analysis, syntactical analysis, abstract syntax tree generation, bytecode generation, and virtual machine execution, with five steps in total.
In this lesson, we will implement the first four steps. Virtual machine execution is a large topic, and we will go into detail in Lecture 3.