Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zh-CN: create Glossary/Syntax #22231

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions files/zh-cn/glossary/syntax/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: 语法
slug: Glossary/Syntax
l10n:
sourceCommit: ada5fa5ef15eadd44b549ecf906423b4a2092f34
---

{{GlossarySidebar}}

语法指定了组成正确结构代码所需的{{Glossary("character", "字符")}}的组合和顺序。语法通常包括语法规则和适用于书写的规则,例如 Python 中的缩进要求。

语法因语言而异(例如,{{Glossary("HTML")}} 和 {{Glossary("JavaScript")}} 的语法不同)。尽管语言在语法方面可能有一些相似之处,比如 JavaScript 和 Python 语言都有一条“操作数 运算符 操作数”语法规则,但这并不意味着两种语言的语法相似。

语法既适用于编程语言(对计算机的命令),也适用于标记语言(文档结构信息)。

语法只管顺序和结构;指令还必须*有意义*,这就是{{Glossary("semantics", "语义")}}的范畴。

代码必须符合正确的语法才能正确{{Glossary("compile", "编译")}},否则会出现{{Glossary("syntax error", "语法错误")}}。即使是小错误,比如缺少一个括号,也会导致源代码无法成功编译。

如果框架具有“干净”的语法,则表示它们生成简单、可读、简洁的结果。如果代码库使用“很多语法”,则意味着它需要更多字符来实现相同的功能。

## 参见

- 维基百科上的[语法](<https://en.wikipedia.org/wiki/Syntax_(programming_languages)>)