介绍
Go的初衷为了设计一门系统编程语言。Go拥有强大类型定义,垃圾回收器,以及对并发编程强大支持。
程序由包构造的,包的属性允许有效地管理依赖关系。语法结构紧凑容易理解,在集成开发环境中通过自动化工具很容易分析。
Go采用的EBNF扩展语法。
`
Production = production_name "=" [ Expression ] "." .
Expression = Alternative { "|" Alternative } .
Alternative = Term { Term } .
Term = production_name | token [ "…" token ] | Group | Option | Repetition .
Group = "(" Expression ")" .
Option = "[" Expression "]" .
Repetition = "{" Expression "}" .
`
下列表达式结构和以下操作符级别依次升高:
`
| alternation
() grouping
[] option (0 or 1 times)
{} repetition (0 to n times)
`
|表示或,()代表组,[]表示选项,{}表示可以包含多个重复。
源代码格式
源代码是用UTF-8编码的Unicode文本。文本不是规范化的,因此单个重音代码点与由重音和字母组合而成的相同字符不同;这些字符被视为两个代码点。为简单起见,本文档将使用非限定术语字符来引用源文本中的Unicode代码点。
每个代码标点都是不同的;例如,大写和小写字母是不同的字符。
字符
` newline = /* the Unicode code point U+000A */ .
unicode_char = /* an arbitrary Unicode code point except newline */ .
unicode_letter = /* a Unicode code point classified as "Letter" */ .
unicode_digit = /* a Unicode code point classified as "Number, decimal digit" */ .
` 以上字符采用了unicode字符类型。
在Unicode标准8.0中,第4.5节“一般类别”定义了一组字符类别。Go将字母类别Lu、Ll、Lt、Lm或Lo中的所有字符视为Unicode字母,将数字类别Nd中的所有字符视为Unicode数字。
字母和数字
` letter = unicode_letter | "_" .
decimal_digit = "0" … "9" .
binary_digit = "0" | "1" .
octal_digit = "0" … "7" .
hex_digit = "0" … "9" | "A" … "F" | "a" … "f" .
` 下划线字符(U+005F)被认为是一个字母。