Lecture
How to write a program that will receive at the input a line containing a numeric expression, for example (10 - 5) * 3, and produce the corresponding result? If there are "high priests" among programmers, then these are those who know how to solve a similar problem. Many, moreover, highly skilled in other areas, programmers have no idea how translators, designed to compile programs written in high-level languages, convert algebraic expressions into computer-executed commands. This procedure is called expression parsing (expression parsing) and is the basis of all compilers and interpreters of languages, spreadsheets, and all other programs in which you want to turn numeric expressions into a form understandable to a computer.
Despite its mysteriousness, parsing expressions is a fairly straightforward process and in many aspects is simpler than some other programming tasks. This is due to the fact that the task of parsing is clearly defined and solved in accordance with strict rules of algebra. In this chapter, a recursive descending parser , or a recursive-descent parser, as well as all the functions necessary for evaluating expressions will be developed. Having mastered the principle of this program, you can easily modify and modify it in accordance with their tasks.
On a note | The C language interpreter presented in Part VI of this book uses an improved version of the parser developed here. If you study the C interpreter, the material in this chapter will be especially useful for you. |
Comments
To leave a comment
Structures and data processing algorithms.
Terms: Structures and data processing algorithms.