# 文法的記法與遞迴下降分析法

接下來，要加上乘除法和決定優先順序的括號，也就是`*`、`/`、`()`到我們的語言裡，但是要達到這一步，有一個重大的技術挑戰。那就是在算式中，有規定要先計算乘法或除法（譯注：四則運算的先乘除後加減規則）。舉例來說，`1+2*3`這個算式必須要算成`1+(2*3)`，不能用`(1+2)*3`來計算。像這樣，決定哪個運算子要先「結合」的規則就叫作「運算子優先順序」（operator precedence）。

該怎麼處理運算子優先順序呢？至今為止的編譯器，只會照順序從頭讀取標記列並輸出組合語言指令，如果直接追加`*`或`/`的話，`1+2*3`會被編譯成`(1+2)*3`。

現有的編譯器，理所當然可以處理運算子的優先順序。編譯器的語法分析非常厲害，無論再複雜的程式，只要遵循文法，就可以正確解讀。編譯器如此的行為看似是具有超越人類的智能，但是實際上，電腦並不俱備像人類一般的文章解讀能力，其實只是機械性地遵照語法分析方法的結構在運作而已。那具體來說，到底是根據什麼規則來進行分析的呢？

本章將會先暫時停下寫程式的腳步，來學習語法分析的技巧。本章針對語法分析，會依照下列順序來進行說明：

1. 了解分析器（parser）輸出的資料結構，掌握最終的目標。
2. 學習定義文法的規則。
3. 根據文法的規則，學習寫分析器的技巧。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://koshizuow.gitbook.io/compilerbook/calculator_level_language/recursive_descendent_parsing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
