- Expert C++
- Vardan Grigoryan Shunguang Wu
- 246字
- 2021-06-24 16:33:54
Syntax analysis
When speaking about programming language compilation, we usually differentiate two terms: syntax and semantics. The syntax is the structure of the code; it defines the rules by which tokens combined make structural sense. For example, day nice is a syntactically correct phrase in English because it doesn't contain errors in either of the tokens. Semantics, on the other hand, concerns the actual meaning of the code. That is, day nice is semantically incorrect and should be corrected as a nice day.
Syntax analysis is a crucial part of source analysis, because tokens will be analyzed syntactically and semantically, that is, as to whether they bear any meaning that conforms to the general grammar rules. Take the following, for example:
int b = a + 0;
It may not make sense for us, because adding zero to the variable won't change its value, but the compiler doesn't look on logical meaning here—it looks for the syntactic correctness of the code (a missing semicolon, a missing closing parenthesis, and more). Checking the syntactic correctness of the code is done in the syntax analysis phase of compilation. The lexical analysis divides the code into tokens; syntax analysis checks for syntactic correctness, which means that the aforementioned expression will produce a syntax error if we have missed a semicolon:
int b = a + 0
g++ will complain with the expected ';' at end of declaration error.
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- 基于粒計算模型的圖像處理
- Computer Vision for the Web
- MATLAB定量決策五大類問題
- 你不知道的JavaScript(中卷)
- Python面向?qū)ο缶幊蹋簶?gòu)建游戲和GUI
- Linux命令行與shell腳本編程大全(第4版)
- Mastering Linux Security and Hardening
- Distributed Computing in Java 9
- Developer,Advocate!
- Mastering PostgreSQL 11(Second Edition)
- C語言從入門到精通(微視頻精編版)
- 編寫高質(zhì)量代碼之Java(套裝共2冊)
- Splunk Developer's Guide(Second Edition)
- Practical Linux Security Cookbook