Problem Description
By designing, compiling and debugging a specific lexical analysis program, deepen the understanding of the principle of lexical analysis. And master the lexical analysis method of decomposing it into various words in the process of scanning the source program of the programming language.
Compile a word-reading process. From the input source program, identify each word with independent meaning, namely the five categories of basic reserved words, identifiers, constants, operators, and separators. And output the internal code of each word and the value of the word symbol in turn. (You can display "Error" when you encounter an error, and then skip the error part and continue to display)
(1) Program requirements:
Program input/output example: For
example, the source program is C language. Enter the following paragraph:
main()
{
int a,b;
a = 10;
b = a + 20;
}
The required output is shown on the right.
Requirements:
Recognize reserved words: if, int, for, while, do, return, break, continue; the
word type code is 1.
Everything else is recognized as an identifier; the word type code is 2.
The constant is an unsigned integer; the word type code is 3.
Operators include: +, -, *, /, =, >, <, >=, <=, !=; the
word type code is 4.
Separator includes: ,,;, {,}, (,); The word type code is 5.
DEV C++ project implementation will not build a project, look at this -> how to create a project
Code link (Baidu network disk): https://pan.baidu.com/s/1apwwCtLIjkrtSyFVJEAEgQ
Extraction code: g93s