# 2.1 简介

程序源代码是符合该语言文法的结构化文本，但对编译器而言，源代码只是一个很长的字符串，准确的说应该是一个字节流（byte stream），如何将程序的结构化信息从该字节流中提取出来，并构建出对应的数据结构，是编译器首先要做的事情。

从程序语言的层面来看，字节并不是构成程序的基本单元，当我们开始学习一门语言时，首先学习的是：

* 关键字： 用来声明程序的不同组件，例如函数、对象、控制语句、变量等
* 命名规则： 什么样的名字是合法的，什么样的是不合法的
* 基础数据类型： 数字、字符及字符串、布尔值、枚举类型等，以及数据类型的合法表达式，例如不同进制的数字如何表示，Unicode 字符如何表示，多行字符串如何表示等
* 操作符： 数字的加减乘除、指数运算等；字符串的串联；函数调用；位运算等

在编译器中，描述这些程序结构的基础组建的叫 Token, Token 中一般包含如下信息：

* 类型：标识该 Token 是一个数字，还是一个变量名，还是一个关键字
* 词素：从源码中识别出来的具体值，例如一个类型为数字的 Token 的词素可能是：3.1415
* 属性：例如该 Token 所在源代码中的哪行哪列

词法分析的目的就是将输入的字节流识别成一个个的 Token, 让原先的字节流变成 Token 流，如果 Token 的构成不符合规范，则报告错误信息。


---

# 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://gocompiler.shizhz.me/2.-golang-bian-yi-qi-ci-fa-fen-xi/2.1-jian-jie.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.
