搵緊程式語言嘅話，請睇〈**Parser (程式語言)**〉。
解析數學公式嘅示意圖
電算同語言學入面，**解析**（英文：**parsing**，又叫 **syntactic analysis** ）係指分析一串語言資訊，決定佢喺某種形式語法（英文：formal grammar）（formal grammar）中嘅語法結構（grammatical structure）嘅過程。

喺電算，上面講嘅語言資訊並唔係源碼，而係一種叫 token（臺譯 ｢符記｣）嘅數據，token 係已經用掃描器（scanner，又叫 lexer）將原碼掃咗一次，而得出嘅識別碼、保留字、字串、數字或者其他符號，而解析就係指將 token 重新組合成一種對應原內容語法結構嘅數據結構，方便以後處理，用嘅數據結構通常會係一棵樹，叫解析樹（parse tree），而做呢樣嘢嘅嘢就叫解析器（parser）。

下面段文未譯好，歡迎你幫手。
Parsing is also an earlier term for the diagramming of sentences of natural languages, and is still used for the diagramming of inflected languages, such as the Roman languages or Latin.

There are tools, called parser generators, that can automatically generate a parser (in some programming language) from a grammar written in Backus-Naur form (e.g. Yacc - yet another compiler compiler).

人話
--

下面段文未譯好，歡迎你幫手。
In some machine translation and natural language processing systems, human languages are parsed by computer programs. Human sentences are not easily parsed by programs, as there is substantial ambiguity in the structure of human language. In order to parse natural language data, researchers must first agree on the grammar to be used. The choice of syntax is affected by both linguistic and computational concerns; for instance some parsing systems use lexical functional grammar, but in general, parsing for grammars of this type is known to be NP-complete. Head-driven phrase structure grammar is another linguistic formalism which has been popular in the parsing community, but other research efforts have focused on less complex formalisms such as the one used in the Penn Treebank. Shallow parsing aims to find only the boundaries of major constituents such as noun phrases. Another popular strategy for avoiding linguistic controversy is dependency grammar parsing.

Most modern parsers are at least partly statistical; that is, they rely on a corpus of training data which has already been annotated (parsed by hand). This approach allows the system to gather information about the frequency with which various constructions occur in specific contexts. *(See machine learning.)* Approaches which have been used include straightforward PCFGs (probabilistic context free grammars), maximum entropy, and neural nets. Most of the more successful systems use *lexical* statistics (that is, they consider the identities of the words involved, as well as their part of speech). However such systems are vulnerable to overfitting and require some kind of smoothing to be effective.

Parsing algorithms for natural language cannot rely on the grammar having 'nice' properties as with manually-designed grammars for programming languages. As mentioned earlier some grammar formalisms are very computationally difficult to parse; in general, even if the desired structure is not context-free, some kind of context-free approximation to the grammar is used to perform a first pass. Algorithms which use context-free grammars often rely on some variant of the CKY algorithm, usually with some heuristic to prune away unlikely analyses to save time. *(See chart parsing.)* However some systems trade speed for accuracy using, eg, linear-time versions of the shift-reduce algorithm. A somewhat recent development has been parse reranking in which the parser proposes some large number of analyses, and a more complex system selects the best option.

程式語言
----

下面段文未譯好，歡迎你幫手。
The most common use of a parser is as a component of a compiler. This parses the source code of a computer programming language to create some form of internal representation. Programming languages tend to be specified in terms of a context-free grammar because fast and efficient parsers can be written for them. Parsers are usually not written by hand but are generated by parser generators.

Context-free grammars are limited in the extent to which they can express all of the requirements of a language. Informally, the reason is that the memory of such a language is limited. The grammar cannot remember the presence of a construct over an arbitrarily long input; this is necessary for a language in which, for example, a name must be declared before it may be referenced. More powerful grammars that can express this constraint, however, cannot be parsed efficiently. Thus, it is a common strategy to create a relaxed parser for a context-free grammar which accepts a superset of the desired language constructs (that is, it accepts some invalid constructs); later, the unwanted constructs can be filtered out.

### Overview of process

The following example demonstrates the common case of parsing a computer language with two levels of grammar: lexical and syntactic. 

The first stage is the token generation, or lexical analysis, by which the input character stream is split into meaningful symbols defined by a grammar of regular expressions. For example, a calculator program would look at an input such as "12\*(3+4)^2" and split it into the tokens 12, \*, (, 3, +, 4, ), ^ and 2, each of which is a meaningful symbol in the context of an arithmetic expression. The parser would contain rules to tell it that the characters \*, +, ^, ( and ) mark the start of a new token, so meaningless tokens like "12\*" or "(3" will not be generated.

The next stage is syntactic parsing or syntactic analysis, which is checking that the tokens form an allowable expression. This is usually done with reference to a context-free grammar which recursively defines components that can make up an expression and the order in which they must appear. However, not all rules defining programming languages can be expressed by context-free grammars alone, for example type validity and proper declaration of identifiers. These rules can be formally expressed with attribute grammars.

The final phase is semantic parsing or analysis, which is working out the implications of the expression just validated and taking the appropriate action. In the case of a calculator, the action is to evaluate the expression; a compiler, on the other hand, would generate code. Attribute grammars can also be used to define these actions.

解析器嘅款
-----

下面段文未譯好，歡迎你幫手。
The task of the parser is essentially to determine if and how the input can be derived from the start symbol of the grammar. This can be done in essentially two ways:

* Top-down parsing - A parser can start with the start symbol and try to transform it to the input. Intuitively, the parser starts from the largest elements and breaks them down into incrementally smaller parts. LL parsers are examples of top-down parsers.
* Bottom-up parsing - A parser can start with the input and attempt to rewrite it to the start symbol. Intuitively, the parser attempts to locate the most basic elements, then the elements containing these, and so on. LR parsers are examples of bottom-up parsers. Another term used for this type of parser is Shift-Reduce parsing.

Another important distinction is whether the parser generates a *leftmost derivation* or a *rightmost derivation* (see context-free grammar). LL parsers will generate a leftmost derivation and LR parsers will generate a rightmost derivation (although usually in reverse).

解析器嘅例
-----

下面段文未譯好，歡迎你幫手。
### Top-down parsers

Some of the parsers that use top-down parsing include:

* Recursive descent parser
* LL parser

### Bottom-up parsers

Some of the parsers that use bottom-up parsing include:

* Precedence parser
	+ Operator-precedence parser
	+ Simple precedence parser
* BC (bounded context) parsing
* LR parser
	+ SLR parser
	+ LALR parser (Shift Reduce)
	+ Canonical LR parser
	+ GLR parser
* CYK parser

參攷
--

* Parsing Techniques - A Practical Guide web page of book includes downloadable pdf.

再睇下
---

### 解析器嘅概念

* Chart parser
* Compiler-compiler
* Deterministic parsing
* Lexing
* Shallow parsing

### 整解析器嘅軟件

See also: List of Parsers comparison table.

#### 自由軟件

* ANTLR
* Bison
* Coco/R
* GOLD
* JavaCC
* Lemon Parser
* Lex
* Rebol
* SableCC
* Spirit Parser Framework
* SYNTAX
* YACC

##### 維基媒體

#### 商

* LRGen
* Visual BNF

註
-

1. ↑  喺語言學，parsing 有多過一個意思，可以指將連續嘅說話分做音素，如果要指明係語法分析，可以講明係 syntactic parsing 或者 syntactic analysis。

  


| * 睇
* 傾
* 改
自然語言處理（NLP） |
| --- |
| 教 AI 處理自然語言嘅技術 |
| 語言數據 | 
* Corpus（口語語料庫 · Treebank · PropBank（英文：PropBank））
* 詞庫資源
* 機械可讀字典
* 受控詞表
* 索引典
* 語言模型

* 語義網絡（WordNet · BabelNet · 語義相似度網絡）
* 對等字詞
* Universal Dependencies（英文：Universal Dependencies）

 |  |
| 字句層次 | 

|  |  |
| --- | --- |
| 文字分割 | 
* 字切割
* 句子切割
* 記號化
* 詞法分析
* 淺度解析同分析樹

 |
| 
* N-gram（2-gram · 3-gram）
* 詞形還原
* 字幹提取
* 命名實體識別
* 合成詞處理
* 語言辨認

* 停用詞
* 詞性標注
* 字袋模型
* 搭配詞抽取
* Regex
* 解析
* Tf-idf
* Truecasing

 |

 |
| 語義層次 | 

|  |
| --- |
| 
* 詞義消歧同詞義歸納
* 語義角色標籤
* 指代解決
* 情感分析
* 自然語言理解
* 本體學習

* 自動總結（句子提取 · 文字簡化 · 多文件總結）
* 主題模型（文檔分類）
* 概念探勘
* 文本蘊涵

 |
| 分佈語義 | 
* 語義距離
* 文件詞彙矩陣
* 外顯同潛在語義分析
* 字嵌入
* Word2vec

 |

 |
| 機械翻譯 | 
* 翻譯器
* 例子為本、規則為本同統計
* 轉移為本
* 神經為本

 |
| 用家介面 | 
* 聲用家介面
* 傾偈機械人
* 問答系統
* 虛擬助理
* 互動式小說

 |
| 第啲應用 | 
* 資訊提取同抽取（詞彙抽取）
* 電腦輔助評閱（拼寫檢查 · 文法檢查 · 自動評分）
* 反垃圾電郵技術
* 網頁刮料

* 自動資料收集（語音識別同分割 · 光學字符識別）
* 語音合成
* 自然語言生成
* 文本探勘同遙距閱讀
* 提示工程

 |
| 相關技術 | 
* 語言資源
* NLTK
* spaCy
* DBpedia
* ROUGE
* 語義網
* 機械學習同人工智能完全
* 字串搜尋
* 困惑度
* ChatGPT

 |
| 相關領域 | 
* 語言學（語料庫語言學同運算語言學）
* 圖書館學同資訊科學
* 數碼人文學
* 文獻計量學
* 市場學
* 心理測量學

 |
| NLP 類 |