JAVA implements a simple algebraic operation language compiler (1) - written in front

Write in front:

Not long after the compiling principle class in the second semester of the sophomore year, our teacher asked us to use C, C++ or Java language to write a simple calculator that supports algebraic operations, so as to experience the process of program compilation.

The specific requirements are as follows:


An overview of the job is as follows:
  
   1. The calculator has two types of statements, namely assignment statement and output statement.
   2. The variable name of the calculator consists of letters and numbers, and must start with a letter.
   3. The use of variables does not need to be declared, but must be assigned. Using uninitialized variables for calculation should report an error.
   4. There is only one reserved word for print.
   5. You cannot use third-party libraries.
 

We did learn C++ in our freshman year, and the data structure in the last semester of our sophomore year was also taught in C++. However, I still know little about C++, but I am more familiar with java, so I chose to use java to implement this project.

case analysis:
We know that most compilers are nothing more than lexical, syntactic, and semantic analysis, and built-in symbol sets, reserved words, etc., to provide code optimization, error diagnosis and other mechanisms. Our project can be said to be a very simple compiler case, so we have to follow these steps step by step. Therefore, in the first step, I want to set up the pre-made symbol set and reserved words in the system, and then analyze the lexical, grammatical, and semantic analysis respectively, and finally add an error diagnosis mechanism.

This is the first article in this series and my first article on CSDN, mainly to pave the way for this simple calculator project that I will do next.
In the next article, we will officially enter the writing of the project.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325726040&siteId=291194637