Example code:
1 if (A = = Ten) {2 printf ("hoge\n"); 3 Else {4 printf ("piyo\n"); 5 }
The syntax of a general programming language (which is not related to a compiled or interpreted language) will have the following process:
- Lexical analysis, the source code is divided into a number of tokens (token) processing;
The sample part of the code is split into the following notation after the lexical parsing process is performed.
The procedure for performing lexical analysis is called the lexical Analyzer (lexical analyzer), and Lex's job is to automatically generate a lexical parser based on the word rules.
- Syntax analysis, that is, the processing of the analysis tree from the notation, the analysis tree is also called the syntax tree, or is an abstract syntax tree;
The program that performs the parsing is called the parser (parser), and YACC is the program that automatically generates the parser based on the syntax rules.
- Semantic analysis, parsing tree generated by parsing, does not contain semantic information such as data type, so in the semantic analysis phase, it checks whether the program contains errors with correct syntax but there are logic problems.
The parsing process of programming language