Go 语言规范学习(1)
文章目录
- Introduction
- Notation
- 示例(Go 语言的 `if` 语句):
- Source code representation
- Characters
- 例子:变量名可以是中文
- Letters and digits
- Lexical elements
- Comments
- Tokens
- Semicolons
- 例子:查看程序所有的token
- Identifiers
- Keywords
- Operators and punctuation【运算符和标点符号】
- Integer literals
- Floating-point literals
- Imaginary literals
- Rune literals
- String literals
- Constants
Language version go1.24 (Dec 30, 2024)
Introduction
Go is a general-purpose language designed with systems programming in mind. It is strongly typed and garbage-collected and has explicit support for concurrent programming. Programs are constructed from packages, whose properties allow efficient management of dependencies.
The syntax is compact and simple to parse, allowing for easy analysis by automatic tools such as integrated development environments.
Notation
The syntax is specified using a variant of Extended Backus-Naur Form (EBNF):
Syntax = { Production } .
Production = production_name "=" [ Expression ] "." .
Expression = Term { "|" Term } .
Term = Factor { Factor } .
Factor = production_name | token [ "…" token ] | Group | Option | Repetition .
Group = "(" Expression ")" .
Option = "[" Expression "]" .
Repetition = "{" Expression "}" .
Productions are expressions constructed from terms and the following operators, in increasing precedence:
| alternation
() grouping
[] option (0 or 1 times)
{} repetition (0 to n times)
Lowercase production names are used to identify lexical (terminal【终结符】) tokens.
Non-terminals【非终结符】 are in CamelCase.
Lexical tokens are enclosed in double quotes ""
or back quotes ````.
在形式语言理论(Formal Language Theory)和编译原理中,产生式(Production) 是描述语言语法规则的表达式,它定义了如何从一个符号(非终结符)推导出其他符号(终结符或非终结符)的组合。产生式是 上下文无关文法(Context-Free Grammar, CFG) 的核心组成部分。
一个产生式通常写成:
非终结符 = 符号序列 .
其中:
- 非终结符(Non-terminal):表示语法结构的抽象概念(如
Expression
、Statement
)。 - 符号序列:由终结符(Token)或其他非终结符组成的序列。
.
表示产生式的结束。
示例(Go 语言的 if
语句):
IfStmt = "if" [ SimpleStmt ";" ] Expression Block [ "else" ( IfStmt | Block ) ] .
IfStmt
是非终结符。"if"
、";"
、"else"
是终结符(Token)。SimpleStmt
、Expression
、Block
是其他非终结符。
The form a … b
represents the set of characters from a
through b
as alternatives.
The horizontal ellipsis …
is also used elsewhere in the spec to informally denote various enumerations or code snippets that are not further specified.
The character …
【单个unicode字符】 (as opposed to the three characters ...
) is not a token of the Go language.
Source code representation
Source code is Unicode text encoded in UTF-8. The text is not canonicalized, so a single accented code point is distinct from the same character constructed from combining an accent and a letter; those are treated as two code points. For simplicity, this document will use the unqualified term character to refer to a Unicode code point in the source text.
Go 不会对源代码进行 Unicode 规范化(Canonicalization)。这意味着:
- 组合字符序列(如
é
的两种表示方式)会被视为不同的代码点(Code Points):- 单一代码点:
é
(U+00E9
,带重音的拉丁小写字母 e) - 组合序列:
e
(U+0065
) +́
(U+0301
,组合重音符号)
- 单一代码点:
- 虽然这两种形式在显示上相同,但 Go 会将其视为 两个不同的字符序列
Each code point is distinct; for instance, uppercase and lowercase letters are different characters.
Implementation restriction: For compatibility with other tools, a compiler may disallow the NUL character (U+0000) in the source text.
Implementation restriction: For compatibility with other tools, a compiler may ignore a UTF-8-encoded byte order mark (U+FEFF) if it is the first Unicode code point in the source text. A byte order mark may be disallowed anywhere else in the source.
Characters
The following terms are used to denote specific Unicode character categories:
newline = /* the Unicode code point U+000A */ .
unicode_char = /* an arbitrary Unicode code point except newline */ .
unicode_letter = /* a Unicode code point categorized as "Letter" */ .
unicode_digit = /* a Unicode code point categorized as "Number, decimal digit" */ .
In The Unicode Standard 8.0, Section 4.5 “General Category” defines a set of character categories. Go treats all characters in any of the Letter categories Lu, Ll, Lt, Lm, or Lo as Unicode letters, and those in the Number category Nd as Unicode digits.
Go 将以下 Unicode 字母类别的所有字符视为「字母」,可用于标识符(变量名、函数名等):
Lu
(Letter, uppercase):大写字母(如A
,Ω
,Д
)Ll
(Letter, lowercase):小写字母(如a
,ω
,д
)Lt
(Letter, titlecase):标题字母(如某些连字字符的首字母形式,例如Dž
)Lm
(Letter, modifier):修饰字母(如上标字母ʰ
)Lo
(Letter, other):其他字母(如汉字中
、日文假名あ
、希伯来字母א
)
Go 仅将以下类别的字符视为「数字」:
Nd
(Number, decimal digit):十进制数字(如0-9
、阿拉伯数字٠
、中文数字0
等)
例子:变量名可以是中文
package mainimport "fmt"var 名字 = "Go" // 汉字(Lo)
const π = 3.14 // 希腊字母(Ll)
func Δx(x int) int { // 大写希腊字母(Lu)return x + 1
}func main() {fmt.Println(Δx(2))
}
Letters and digits
The underscore character _
(U+005F) is considered a lowercase letter.
letter = unicode_letter | "_" .
decimal_digit = "0" … "9" .
binary_digit = "0" | "1" .
octal_digit = "0" … "7" .
hex_digit = "0" … "9" | "A" … "F" | "a" … "f" .
Lexical elements
Comments
Comments serve as program documentation. There are two forms:
- Line comments start with the character sequence
//
and stop at the end of the line. - General comments start with the character sequence
/*
and stop with the first subsequent character sequence*/
.
A comment cannot start inside a rune or string literal, or inside a comment.
A general comment containing no newlines acts like a space. Any other comment acts like a newline.
Tokens
Tokens form the vocabulary of the Go language. There are four classes: identifiers, keywords, operators and punctuation, and literals. 【标识符,关键字,运算符和标点符号,字面值】
White space, formed from spaces (U+0020), horizontal tabs (U+0009), carriage returns (U+000D), and newlines (U+000A), is ignored except as it separates tokens that would otherwise combine into a single token.
Also, a newline or end of file may trigger the insertion of a semicolon.
While breaking the input into tokens, the next token is the longest sequence of characters that form a valid token.
Semicolons
The formal syntax uses semicolons ";"
as terminators in a number of productions. Go programs may omit most of these semicolons using the following two rules:
- When the input is broken into tokens, a semicolon is automatically inserted into the token stream immediately after a line’s final token if that token is
- an identifier
- an integer, floating-point, imaginary, rune, or string literal
- one of the keywords
break
,continue
,fallthrough
, orreturn
- one of the operators and punctuation
++
,--
,)
,]
, or}
- To allow complex statements to occupy a single line, a semicolon may be omitted before a closing
")"
or"}"
.
To reflect idiomatic use, code examples in this document elide semicolons using these rules.
例子:查看程序所有的token
package mainimport ("fmt""go/scanner""go/token"
)func main() {src := []byte(`
package mainimport "fmt"func main() {s := "Hello, tokens!"fmt.Println(s)
}
`)// 初始化 scannerfset := token.NewFileSet()file := fset.AddFile("example.go", fset.Base(), len(src))var s scanner.Scanners.Init(file, src, nil, scanner.ScanComments)// 扫描 tokensfor {pos, tok, lit := s.Scan()if tok == token.EOF {break}fmt.Printf("%-10s %-15s %q\n", fset.Position(pos), tok, lit)}
}
输出
example.go:2:1 package "package"
example.go:2:9 IDENT "main"
example.go:2:13 ; "\n"
example.go:4:1 import "import"
example.go:4:8 STRING "\"fmt\""
example.go:4:13 ; "\n"
example.go:6:1 func "func"
example.go:6:6 IDENT "main"
example.go:6:10 ( ""
example.go:6:11 ) ""
example.go:6:13 { ""
example.go:7:2 IDENT "s"
example.go:7:4 := ""
example.go:7:7 STRING "\"Hello, tokens!\""
example.go:7:23 ; "\n"
example.go:8:2 IDENT "fmt"
example.go:8:5 . ""
example.go:8:6 IDENT "Println"
example.go:8:13 ( ""
example.go:8:14 IDENT "s"
example.go:8:15 ) ""
example.go:8:16 ; "\n"
example.go:9:1 } ""
example.go:9:2 ; "\n"
Identifiers
Identifiers name program entities such as variables and types. An identifier is a sequence of one or more letters and digits. The first character in an identifier must be a letter.
identifier = letter { letter | unicode_digit } .
a
_x9
ThisVariableIsExported
αβ
Some identifiers are predeclared.
预先声明的标识符如下:
Types:any bool byte comparablecomplex64 complex128 error float32 float64int int8 int16 int32 int64 rune stringuint uint8 uint16 uint32 uint64 uintptrConstants:true false iotaZero value:nilFunctions:append cap clear close complex copy delete imag lenmake max min new panic print println real recover
Keywords
The following keywords are reserved and may not be used as identifiers.
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
Operators and punctuation【运算符和标点符号】
The following character sequences represent operators (including assignment operators) and punctuation [Go 1.18]:
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :&^ &^= ~
Integer literals
An integer literal is a sequence of digits representing an integer constant.
An optional prefix sets a non-decimal base: 0b
or 0B
for binary【二进制】, 0
, 0o
, or 0O
for octal【八进制】, and 0x
or 0X
for hexadecimal 【十六进制】[Go 1.13].
A single 0
is considered a decimal【十进制】 zero.
In hexadecimal literals, letters a
through f
and A
through F
represent values 10 through 15.
For readability, an underscore character _
may appear after a base prefix or between successive digits; such underscores do not change the literal’s value.
int_lit = decimal_lit | binary_lit | octal_lit | hex_lit .
decimal_lit = "0" | ( "1" … "9" ) [ [ "_" ] decimal_digits ] .
binary_lit = "0" ( "b" | "B" ) [ "_" ] binary_digits .
octal_lit = "0" [ "o" | "O" ] [ "_" ] octal_digits .
hex_lit = "0" ( "x" | "X" ) [ "_" ] hex_digits .decimal_digits = decimal_digit { [ "_" ] decimal_digit } .
binary_digits = binary_digit { [ "_" ] binary_digit } .
octal_digits = octal_digit { [ "_" ] octal_digit } .
hex_digits = hex_digit { [ "_" ] hex_digit } .
42
4_2
0600
0_600
0o600
0O600 // second character is capital letter 'O'
0xBadFace
0xBad_Face
0x_67_7a_2f_cc_40_c6
170141183460469231731687303715884105727
170_141183_460469_231731_687303_715884_105727_42 // an identifier, not an integer literal
42_ // invalid: _ must separate successive digits
4__2 // invalid: only one _ at a time
0_xBadFace // invalid: _ must separate successive digits
Floating-point literals
A floating-point literal is a decimal or hexadecimal representation of a floating-point constant.
A decimal floating-point literal consists of an integer part 【整数部分】(decimal digits), a decimal point【小数点】, a fractional part 【小数部分】(decimal digits), and an exponent part【指数部分】 (e
or E
followed by an optional sign and decimal digits).
One of the integer part or the fractional part may be elided; one of the decimal point or the exponent part may be elided. An exponent value exp scales the mantissa【尾数】 (integer and fractional part) by 10exp.
A hexadecimal floating-point literal consists of a 0x
or 0X
prefix, an integer part (hexadecimal digits), a radix point【基数点。在 任意进制(如二进制、八进制、十六进制)的浮点数中,用于分隔整数部分和小数部分的点符号 .
】, a fractional part (hexadecimal digits), and an exponent part (p
or P
followed by an optional sign and decimal digits).
One of the integer part or the fractional part may be elided; the radix point may be elided as well, but the exponent part is required. (This syntax matches the one given in IEEE 754-2008 §5.12.3.) An exponent value exp scales the mantissa (integer and fractional part) by 2exp [Go 1.13].
For readability, an underscore character _
may appear after a base prefix or between successive digits; such underscores do not change the literal value.
float_lit = decimal_float_lit | hex_float_lit .decimal_float_lit = decimal_digits "." [ decimal_digits ] [ decimal_exponent ] |decimal_digits decimal_exponent |"." decimal_digits [ decimal_exponent ] .
decimal_exponent = ( "e" | "E" ) [ "+" | "-" ] decimal_digits .hex_float_lit = "0" ( "x" | "X" ) hex_mantissa hex_exponent .
hex_mantissa = [ "_" ] hex_digits "." [ hex_digits ] |[ "_" ] hex_digits |"." hex_digits .
hex_exponent = ( "p" | "P" ) [ "+" | "-" ] decimal_digits .
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
1_5. // == 15.0
0.15e+0_2 // == 15.00x1p-2 // == 0.25
0x2.p10 // == 2048.0
0x1.Fp+0 // == 1.9375
0X.8p-0 // == 0.5
0X_1FFFP-16 // == 0.1249847412109375
0x15e-2 // == 0x15e - 2 (integer subtraction)0x.p1 // invalid: mantissa has no digits
1p-2 // invalid: p exponent requires hexadecimal mantissa
0x1.5e-2 // invalid: hexadecimal mantissa requires p exponent
1_.5 // invalid: _ must separate successive digits
1._5 // invalid: _ must separate successive digits
1.5_e1 // invalid: _ must separate successive digits
1.5e_1 // invalid: _ must separate successive digits
1.5e1_ // invalid: _ must separate successive digits
Imaginary literals
An imaginary literal represents the imaginary part【虚部】 of a complex constant. It consists of an integer or floating-point literal followed by the lowercase letter i
. The value of an imaginary literal is the value of the respective integer or floating-point literal multiplied by the imaginary unit i [Go 1.13]
imaginary_lit = (decimal_digits | int_lit | float_lit) "i" .
For backward compatibility, an imaginary literal’s integer part consisting entirely of decimal digits (and possibly underscores) is considered a decimal integer, even if it starts with a leading 0
.
0i
0123i // == 123i for backward-compatibility
0o123i // == 0o123 * 1i == 83i
0xabci // == 0xabc * 1i == 2748i
0.i
2.71828i
1.e+0i
6.67428e-11i
1E6i
.25i
.12345E+5i
0x1p-2i // == 0x1p-2 * 1i == 0.25i
Rune literals
A rune literal represents a rune constant, an integer value identifying a Unicode code point. A rune literal is expressed as one or more characters enclosed in single quotes, as in 'x'
or '\n'
.
Within the quotes, any character may appear except newline and unescaped single quote. A single quoted character represents the Unicode value of the character itself, while multi-character sequences beginning with a backslash encode values in various formats.
The simplest form represents the single character within the quotes; since Go source text is Unicode characters encoded in UTF-8, multiple UTF-8-encoded bytes may represent a single integer value. For instance, the literal 'a'
holds a single byte representing a literal a
, Unicode U+0061, value 0x61
, while 'ä'
holds two bytes (0xc3
0xa4
) representing a literal a
-dieresis, U+00E4, value 0xe4
.
Several backslash escapes allow arbitrary values to be encoded as ASCII text. There are four ways to represent the integer value as a numeric constant: \x
followed by exactly two hexadecimal digits; \u
followed by exactly four hexadecimal digits; \U
followed by exactly eight hexadecimal digits, and a plain backslash \
followed by exactly three octal digits. In each case the value of the literal is the value represented by the digits in the corresponding base.
Although these representations all result in an integer, they have different valid ranges. Octal escapes must represent a value between 0 and 255 inclusive. Hexadecimal escapes satisfy this condition by construction. The escapes \u
and \U
represent Unicode code points so within them some values are illegal, in particular those above 0x10FFFF
and surrogate halves.
After a backslash, certain single-character escapes represent special values:
\a U+0007 alert or bell
\b U+0008 backspace
\f U+000C form feed
\n U+000A line feed or newline
\r U+000D carriage return
\t U+0009 horizontal tab
\v U+000B vertical tab
\\ U+005C backslash
\' U+0027 single quote (valid escape only within rune literals)
\" U+0022 double quote (valid escape only within string literals)
An unrecognized character following a backslash in a rune literal is illegal.
rune_lit = "'" ( unicode_value | byte_value ) "'" .
unicode_value = unicode_char | little_u_value | big_u_value | escaped_char .
byte_value = octal_byte_value | hex_byte_value .
octal_byte_value = `\` octal_digit octal_digit octal_digit .
hex_byte_value = `\` "x" hex_digit hex_digit .
little_u_value = `\` "u" hex_digit hex_digit hex_digit hex_digit .
big_u_value = `\` "U" hex_digit hex_digit hex_digit hex_digithex_digit hex_digit hex_digit hex_digit .
escaped_char = `\` ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | `\` | "'" | `"` ) .
'a'
'ä'
'本'
'\t'
'\000'
'\007'
'\377'
'\x07'
'\xff'
'\u12e4'
'\U00101234'
'\'' // rune literal containing single quote character
'aa' // illegal: too many characters
'\k' // illegal: k is not recognized after a backslash
'\xa' // illegal: too few hexadecimal digits
'\0' // illegal: too few octal digits
'\400' // illegal: octal value over 255
'\uDFFF' // illegal: surrogate half
'\U00110000' // illegal: invalid Unicode code point
String literals
A string literal represents a string constant obtained from concatenating a sequence of characters.
There are two forms: raw string literals and interpreted string literals.
Raw string literals are character sequences between back quotes【反引号】 as in `foo`. Within the quotes, any character may appear except back quote. The value of a raw string literal is the string composed of the uninterpreted (implicitly UTF-8-encoded) characters between the quotes; in particular, backslashes have no special meaning and the string may contain newlines. Carriage return characters (‘\r’) inside raw string literals are discarded from the raw string value.
Interpreted string literals are character sequences between double quotes【双引号】, as in "bar"
. Within the quotes, any character may appear except newline and unescaped double quote. The text between the quotes forms the value of the literal, with backslash escapes interpreted as they are in rune literals (except that \'
is illegal and \"
is legal), with the same restrictions. The three-digit octal (\
nnn) and two-digit hexadecimal (\x
nn) escapes represent individual bytes of the resulting string; all other escapes represent the (possibly multi-byte) UTF-8 encoding of individual characters. Thus inside a string literal \377
and \xFF
represent a single byte of value 0xFF
=255, while ÿ
, \u00FF
, \U000000FF
and \xc3\xbf
represent the two bytes 0xc3
0xbf
of the UTF-8 encoding of character U+00FF.
string_lit = raw_string_lit | interpreted_string_lit .
raw_string_lit = "`" { unicode_char | newline } "`" .
interpreted_string_lit = `"` { unicode_value | byte_value } `"` .
`abc` // same as "abc"
`\n
\n` // same as "\\n\n\\n"
"\n"
"\"" // same as `"`
"Hello, world!\n"
"日本語"
"\u65e5本\U00008a9e"
"\xff\u00FF"
"\uD800" // illegal: surrogate half
"\U00110000" // illegal: invalid Unicode code point
These examples all represent the same string:
"日本語" // UTF-8 input text
`日本語` // UTF-8 input text as a raw literal
"\u65e5\u672c\u8a9e" // the explicit Unicode code points
"\U000065e5\U0000672c\U00008a9e" // the explicit Unicode code points
"\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" // the explicit UTF-8 bytes
If the source code represents a character as two code points, such as a combining form involving an accent and a letter, the result will be an error if placed in a rune literal (it is not a single code point), and will appear as two code points if placed in a string literal.
Constants
There are boolean constants, rune constants, integer constants, floating-point constants, complex constants, and string constants.
Rune, integer, floating-point, and complex constants are collectively called numeric constants.
A constant value is represented by a rune, integer, floating-point, imaginary, or string literal, an identifier denoting a constant, a constant expression, a conversion with a result that is a constant, or the result value of some built-in functions such as min
or max
applied to constant arguments, unsafe.Sizeof
applied to certain values, cap
or len
applied to some expressions, real
and imag
applied to a complex constant and complex
applied to numeric constants.
The boolean truth values are represented by the predeclared constants true
and false
. The predeclared identifier iota denotes an integer constant.
In general, complex constants are a form of constant expression and are discussed in that section.
Numeric constants represent exact values of arbitrary precision and do not overflow. Consequently, there are no constants denoting the IEEE 754 negative zero, infinity, and not-a-number values.
在 Go 语言中,数值常量(Numeric Constants) 的设计非常独特,与其他编程语言(如 C、Java)中的常量或变量有本质区别。
1. 任意精度(Arbitrary Precision)
- 无限精度计算:
Go 的数值常量在编译时不受固定位数(如 32/64 位)限制,可以表示任意大的整数或任意小的小数,只要代码能写出来(受限于源码长度)。 - 精确无舍入:
计算过程中不会丢失精度(不像浮点数有 IEEE 754 舍入误差)。
2. 不会溢出(No Overflow)
- 自动扩展表示范围:
编译器会动态调整常量的存储方式,确保计算时永远不会溢出(直到内存耗尽)。
Constants may be typed or untyped. 【有类型的常量和无类型的常量】
Literal constants, true
, false
, iota
, and certain constant expressions containing only untyped constant operands are untyped.
A constant may be given a type explicitly by a constant declaration or conversion, or implicitly when used in a variable declaration or an assignment statement or as an operand in an expression. It is an error if the constant value cannot be represented as a value of the respective type. If the type is a type parameter, the constant is converted into a non-constant value of the type parameter.
An untyped constant has a default type which is the type to which the constant is implicitly converted in contexts where a typed value is required, for instance, in a short variable declaration such as i := 0
where there is no explicit type. The default type of an untyped constant is bool
, rune
, int
, float64
, complex128
, or string
respectively, depending on whether it is a boolean, rune, integer, floating-point, complex, or string constant.
Implementation restriction: Although numeric constants have arbitrary precision in the language, a compiler may implement them using an internal representation with limited precision. That said, every implementation must:
- Represent integer constants with at least 256 bits.
- Represent floating-point constants, including the parts of a complex constant, with a mantissa of at least 256 bits and a signed binary exponent of at least 16 bits.
- Give an error if unable to represent an integer constant precisely.
- Give an error if unable to represent a floating-point or complex constant due to overflow.
- Round to the nearest representable constant if unable to represent a floating-point or complex constant due to limits on precision.
These requirements apply both to literal constants and to the result of evaluating constant expressions.
相关文章:
Go 语言规范学习(1)
文章目录 IntroductionNotation示例(Go 语言的 if 语句): Source code representationCharacters例子:变量名可以是中文 Letters and digits Lexical elementsCommentsTokensSemicolons例子:查看程序所有的token Ident…...
深入理解椭圆曲线密码学(ECC)与区块链加密
椭圆曲线密码学(ECC)在现代加密技术中扮演着至关重要的角色,广泛应用于区块链、数字货币、数字签名等领域。由于其在提供高安全性和高效率上的优势,椭圆曲线密码学成为了数字加密的核心技术之一。本文将详细介绍椭圆曲线的基本原理…...
nginx优化(持续更新!!!)
1.调整文件描述符 # 查看当前系统文件描述符限制 ulimit -n# 永久修改文件描述符限制 # 编辑 /etc/security/limits.conf 文件,添加以下内容 * soft nofile 65535 * hard nofile 65535# 编辑 /etc/sysctl.conf 文件,添加以下内容 fs.file-max 655352.调…...
ARCGIS PRO SDK 创建右键菜单
ArcGIS Pro SDK中的弹出式右键菜单常见的在地图视图、布局视图、文件目录等地方,随便右键点击某个文件、要素、要素类,一般都会弹出一个右键菜单。 操作对象右键菜单 refID要素图层esri_mapping_layerContextMenushp图层esri_mapping_unregisteredLaye…...
编译原理——LR分析
文章目录 LR分析概述一、LR分析概述二、LR(0)分析概述(一)可归前缀和子前缀(二)识别活前缀的有限自动机(三)活前缀及可归前缀的一般计算方法(四)LR(0)项目集规范族的构造 三、SLR(1)…...
css100个问题
一、基础概念 CSS的全称及作用是什么?行内样式、内部样式表、外部样式表的优先级?解释CSS的层叠性(Cascading)CSS选择器优先级计算规则伪类与伪元素的区别?举例说明!important的作用及使用注意事项如何继承父元素字体…...
js文字两端对齐
目录 一、问题 二、原因及解决方法 三、总结 一、问题 1.text-align: justify; 不就可以了吗?但是实际测试无效 二、原因及解决方法 1.原因:text-align只对非最后一行文字有效。只有一行文字时,text-align无效,要用text-alig…...
Java-面向对象-多态和抽象类
目录 什么是多态? 多态的优点 多态存在的三个必要条件 虚函数 重写 多态的实现方式 什么是抽象类? 继承抽象类 实现抽象方法 抽象类总结 什么是多态? 多态就是一个行为具有多种不同的表现形式。 举例: 我们按下 F1 键…...
前端性能优化:深入解析哈希算法与TypeScript实践
/ 示例:开放寻址哈希表核心实现 class OpenAddressingHashTable<T> {private size: number;private keys: (string | null)[];private values: (T | null)[];private tombstone Symbol(Deleted);constructor(size: number 53) {this.size size;this.keys …...
车架号查询车牌号接口如何用Java对接
一、什么是车架号查询车牌号接口? 车架号查询车牌号接口,即传入车架号,返回车牌号、车型编码、初次登记日期信息。车架号又称车辆VIN码,车辆识别码。 二、如何用Java对接该接口? 下面我们以阿里云接口为例࿰…...
linux input子系统深度剖析
input 就是输入的意思,因此 input 子系统就是管理输入的子系统,和 pinctrl 、 gpio 子系统 一样,都是 Linux 内核针对某一类设备而创建的框架。比如按键输入、键盘、鼠标、触摸屏等 等这些都属于输入设备,不同的输入设备…...
香蕉派 BPI-CM6 工业级核心板采用进迭时空K1 8核 RISC-V 芯片开发
BPI-CM6 产品介绍 香蕉派BPI-CM6是一款工业级RISC-V核心板,它采用SpacemiT K1 8核RISC-V芯片设计,CPU集成2.0 TOPs AI计算能力。8/16G DDR和8/16/32/128G eMMC。设计了板对板连接器,以增强稳定性,与树莓派CM4尺寸相同,…...
9.4分漏洞!Next.js Middleware鉴权绕过漏洞安全风险通告
今日,亚信安全CERT监控到安全社区研究人员发布安全通告,Next.js 存在一个授权绕过漏洞,编号为 CVE-2025-29927。攻击者可能通过发送精心构造的 x-middleware-subrequest 请求头绕过中间件安全控制,从而在未授权的情况下访问受保护…...
【Unity3D实现UI轮播效果】
系列文章目录 unity工具 文章目录 系列文章目录👉前言👉一、效果展示👉二、实现步骤👉2-1、搭建UI👉2-2、代码实现👉2-3、代码挂载使用👉三、扩展实现👉壁纸分享👉总结👉前言 功能需求如图所示,点击下一个按钮,所有卡片向右滚动,其中最后一张需要变更…...
谈谈 Webpack 中的 Loader 和 Plugin,它们的区别是什么?
Webpack Loader与Plugin深度解析 作为前端工程化的核心工具,Webpack的Loader和Plugin机制是其强大扩展能力的基石。 理解它们的差异和适用场景,是构建高效打包体系的关键。 我们将从底层原理到实际应用,深入剖析两者的区别。 核心概念对比…...
C#单例模式
单例模式 (Singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点。通常我们可以让一个全局变量使得一个对象被访问,但它不能防止你实例化对个对象,一个最好的办法就是,让类自身负责保护它的唯一实例。这个类可以保证没…...
Oracle 数据库通过exp/imp工具迁移指定数据表
项目需求:从prod数据库迁移和复制2个表(BANK_STATE,HBS)的数据到uat数据库环境。 数据库版本:Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 迁移工具:客户端exp/imp工具 -- 执行命令 从Prod数据库导出数据exp us…...
MongoDB 与 Elasticsearch 使用场景区别及示例
一、核心定位差异 MongoDB 定位:通用型文档数据库,侧重数据的存储、事务管理及结构化查询,支持 ACID 事务。典型场景: 动态数据结构存储(如用户信息、商品详情)。需事务支持的场景…...
PyTorch生成式人工智能实战:从零打造创意引擎
PyTorch生成式人工智能实战:从零打造创意引擎 0. 前言1. 生成式人工智能1.1 生成式人工智能简介1.2 生成式人工智能技术 2. Python 与 PyTorch2.1 Python 编程语言2.2 PyTorch 深度学习库 3. 生成对抗网络3.1 生成对抗网络概述3.2 生成对抗网络应用 4. Transformer4…...
蓝桥杯高频考点——二分(含C++源码)
二分 基本框架整数查找(序列二分的模版题 建议先做)满分代码及思路solution 子串简写满分代码及思路solution 1(暴力 模拟双指针70分)solution 2(二分 AC) 管道满分代码及思路样例解释与思路分析solution 最…...
VUE3项目VITE打包优化
VUE3项目VITE打包优化 代码加密依赖配置效果对比图 自动导入依赖配置 代码压缩依赖配置效果对比图 图片压缩依赖配置效果对比图 字体压缩总结与实践运用效果 代码加密 依赖 npm install -D vite-plugin-bundle-obfuscator配置 import vitePluginBundleObfuscator from "…...
IP 分片重组与 TCP 会话重组
1. IP 分片重组(IP Fragmentation & Reassembly) (1)分片原因 当 IP 数据包长度超过 MTU(Maximum Transmission Unit)(如以太网默认 1500 字节)时,路由器或发送端会…...
《Python实战进阶》No34:卷积神经网络(CNN)图像分类实战
第34集:卷积神经网络(CNN)图像分类实战 摘要 卷积神经网络(CNN)是计算机视觉领域的核心技术,特别擅长处理图像分类任务。本集将深入讲解 CNN 的核心组件(卷积层、池化层、全连接层)…...
【Django】教程-1-安装+创建项目+目录结构介绍
欢迎关注我!后续会更新django教程。一周2-3更,欢迎跟进,本周会更新第一个Demo的单独一个模块的增删改查【Django】教程-4-一个增删改查的Demo【Django】教程-2-前端-目录结构介绍【Django】教程-3-数据库相关介绍 1.项目创建 1.1 安装 Djan…...
力扣DAY29 | 热100 | 删除链表的倒数第N个结点
前言 中等 √ 链表心得:考虑好边界情况。 题目 给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。 示例 1: 输入:head [1,2,3,4,5], n 2 输出:[1,2,3,5]示例 2: 输入&#…...
渗透测试过-关于学习Token、JWT、Cookie等验证授权方式的总结
关于学习Token、JWT、Cookie等验证授权方式的总结 目录 一、为什么Cookie无法防止CSRF攻击,而Token可以? 二、为什么无论采用Cookie-session的方式,还是Token(JWT)的方式,在一个浏览器里,同一个…...
C#从入门到精通(3)
目录 第九章 窗体 (1)From窗体 (2)MDI窗体 (3)继承窗体 第十章 控件 (1)控件常用操作 (2)Label控件 (3)Button控件 &…...
greenhill编译出现:3201原因错误
ecom800: 21Mar25 16:26:45.609351: No licenses available for ecom800 Reason: ecom800 (3201): The License Manager cannot be contacted. 解决方式:重新加载lincese驱动。 检查是否安装正确: 检查驱动是否正确识别: 以上检查都正常,…...
Docker 快速入门指南
Docker 快速入门指南 1. Docker 常用指令 Docker 是一个轻量级的容器化平台,可以帮助开发者快速构建、测试和部署应用程序。以下是一些常用的 Docker 命令。 1.1 镜像管理 # 搜索镜像 docker search <image_name># 拉取镜像 docker pull <image_name>…...
RISC-V AIA学习2---IMSIC
我在学习文档这章时,对技术术语不太理解,所以用比较恰当的比喻来让自己更好的理解。 比较通俗的理解: 将 RISC-V 系统比作一个工厂: hart → 工厂的一条独立生产线IMSIC → 每条生产线配备的「订单接收员」MSI 中断 → 客户通过…...
C#基础学习(五)函数中的ref和out
1. 引言:为什么需要ref和out? 问题背景:函数参数默认按值传递,值类型在函数内修改不影响外部变量;引用类型重新赋值时外部对象不变。核心作用:允许函数内部修改外部变量的值,实现“双向传参…...
【每日算法】Day 9-1:贪心算法精讲——区间调度与最优选择(C++实现)
掌握高效决策的核心思想!今日深入解析贪心算法的底层逻辑,聚焦区间调度与最优选择两大高频场景,结合大厂真题与严谨证明,彻底掌握“局部最优即全局最优”的算法哲学。 一、贪心算法核心思想 贪心算法(Greedy Algorit…...
Netty源码—8.编解码原理二
大纲 1.读数据入口 2.拆包原理 3.ByteToMessageDecoder解码步骤 4.解码器抽象的解码过程总结 5.Netty里常见的开箱即用的解码器 6.writeAndFlush()方法的大体步骤 7.MessageToByteEncoder的编码步骤 8.unsafe.write()写队列 9.unsafe.flush()刷新写队列 10.如何把对象…...
【踩坑系列】使用httpclient调用第三方接口返回javax.net.ssl.SSLHandshakeException异常
1. 踩坑经历 最近做了个需求,需要调用第三方接口获取数据,在联调时一直失败,代码抛出javax.net.ssl.SSLHandshakeException异常, 具体错误信息如下所示: javax.net.ssl.SSLHandshakeException: sun.security.validat…...
双目云台摄像头全方位监控方案
双目云台摄像头是一种具有两个镜头的摄像头设备,通常配备云台功能,能够实现水平和垂直方向的旋转,从而提供全方位的监控视角: 一、工作原理与特点 工作原理 :双目云台摄像头利用仿生学原理,通过两个标定后的…...
测谎仪策略思路
来源:【东吴金工 金工专题】“高频价量相关性拥抱CTA”系列研究(四):CPV因子期货版3.0—CPV测谎机 原创 高子剑 量化邻距离 2024年09月20日 14:37 该报告主要介绍了“高频价量相关性拥抱CTA”系列研究中CPV因子期货版的相关内容,…...
2025年移动端开发性能优化实践与趋势分析
启动速度优化 本质:缩短首次可见帧渲染时间。 方法: iOS:利用Core ML本地模型轻量化部署,减少云端等待。Android:强制启用SplashScreen API,通过setKeepOnScreenCondition控制动画时长。冷启动需将耗时操…...
VScode-i18n-ally-Vue
参考这篇文章,做Vue项目的国际化配置,本篇文章主要解释,下载了i18n之后,该如何对Vscode进行配置 https://juejin.cn/post/7271964525998309428 i18n Ally全局配置项 Vscode中安装i18n Ally插件,并设置其配置项&#…...
vue vue3 走马灯Carousel
背景: 在项目中需要展示多张图片,但在页面上只有一张图片的有限位置,此时考虑使用轮播图实现多张图片的展示。element组件官网有走马灯Carousel的组件详细介绍。 实现效果: 官网链接:点击跳转 核心代码: …...
Android设计模式之Builder模式
一、定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。 二、核心思想: 分离构造与表示:将对象的构建过程(如参数组合、校验逻辑)与对象本身分离。 链式调用:通…...
【时时三省】(C语言基础)关系运算符和关系表达式
山不在高,有仙则名。水不在深,有龙则灵。 ----CSDN 时时三省 在if语句中对关系表达式disc > 0进行判断。其中的“>”是一个比较符,用来对两个数值进行比较。在C语言中,比较符(或称比较运算符)称为关…...
运算放大器(二)运算放大器的选型与应用
1.运算放大器的工艺决定Vos和Ib 2.TI放大器的命名规律 3.TI精密放大器家族 4.精密运放的选型指南 5.高共模抑制比放大器 6.TI其他的精密放大器 7.选型时需考虑的问题 8.TI精密运放选型实例 先确定供电电压 9.确定放大器的步骤 参考: 注:本文出自对b…...
vulhub靶场jangow-01-1.0.1
启动靶机时点shift停在这个界面 点e进入编辑页面,把ro改成rw signie init/bin/bash Ctrlx保存,ip a查看网卡信息 vim /etc/network/interfaces 把enp0s17改为ens33,保存退出 重启靶机,nmap扫ip ip为192.168.93.179 nmap扫端口 扫…...
android 一步完成 aab 安装到手机
家人们谁懂!在 Android 系统安装 aab 应用超麻烦。满心期待快速体验,却发现 aab 无法直装,得先转为 apks 格式,这过程复杂易错。好不容易转好,还得安装 apks,一番折腾,时间与耐心全耗尽。别愁&a…...
mysqlworkbench导入.sql文件
1、MySQL Workbench 新建数据库 或者 在左侧导航栏的 Schemas 区域右键选择 Create Schema...输入数据库名称(例如 mydatabase),点击 Apply确认创建,点击 Finish 2、选择目标数据库 在左侧导航栏的 Schemas 列表中&a…...
pyqt 信号与槽
PySide6 信号与槽机制详解 引言 PySide6 是 Qt for Python 的官方绑定库,为 Python 提供了强大的 GUI 开发能力。其中,信号与槽(Signals and Slots) 机制是 Qt 事件处理系统的核心,它允许对象之间进行松耦合的通信&a…...
深入探索C++:从基础到实践
目录 引言 一、C 基础语法与特性 (一)命名空间(Namespace) 单独使用 嵌套使用 调用形式 (二)输入输出流(I/O Streams) (三)变量作用域 二、C 的…...
从零开始完成冒泡排序(0基础)——C语言版
文章目录 前言一、冒泡排序的基本思想二、冒泡排序的执行过程(一)第一轮排序(二)第二轮排序(三)第三轮排序(四)第四轮排序 三、冒泡排序的代码实现(C语言)&am…...
Echars插入的柱状图条形图,鼠标放在图上显示坐标值
只需要将axiosPointer改为cross axisPointer.type支持类型及作用: line:默认直线型指向线shadow:显示坐标轴方向的阴影区域cross:交叉线(横向纵向双线)none:不显示指向器inside:结合…...
机械臂如何稳稳上桌?Mujoco场景修改实操
视频讲解: 机械臂如何稳稳上桌?Mujoco场景修改实操 前面《常见机械臂模型不用找!Mujoco这儿都有!》中介绍的mujoco-menagerie中机械臂大多都是base_link放在地上的,这些场景往往和真实的场景对应不上,比如机…...