Commit 1265a0c2 authored by Robert Griesemer's avatar Robert Griesemer

- essentially reverted my change of yesterday with respect to char/string syntax

- fixed indentation in many places
- fixed a couple of typos

SVN=116120
parent 75bbce9e
The Go Programming Language
----
(April 17, 2008)
(April 18, 2008)
This document is an informal specification/proposal for a new systems programming
language.
......@@ -194,12 +194,14 @@ Notation
The syntax is specified using Extended Backus-Naur Form (EBNF).
In particular:
- "" encloses lexical symbols (a backslash precedes a literal quote within a symbol)
- | separates alternatives
- | separates alternatives (least binding strength)
- () groups
- [] specifies an option (0 or 1 times)
- {} specifies repetition (0 to n times)
Lexical symbols are enclosed in double quotes '''' (the
double quote symbol is written as ''"'').
A production may be referenced from various places in this document
but is usually defined close to its first use. Productions and code
examples are indented.
......@@ -356,7 +358,7 @@ point value that is constrained only upon assignment.
fractional_lit = { dec_digit } ( dec_digit "." | "." dec_digit )
{ dec_digit } [ exponent ] .
exponential_lit = dec_digit { dec_digit } exponent .
exponent = ( "e" | "E" ) [ sign ] dec_digit { dec_digit }
exponent = ( "e" | "E" ) [ sign ] dec_digit { dec_digit } .
07
0xFF
......@@ -373,15 +375,15 @@ Strings behave like arrays of bytes, with the following properties:
contents of a string.
- No internal pointers: it is illegal to create a pointer to an inner
element of a string.
- They can be indexed: given string s1, s1[i] is a byte value.
- They can be concatenated: given strings s1 and s2, s1 + s2 is a value
combining the elements of s1 and s2 in sequence.
- Known length: the length of a string s1 can be obtained by the function/
operator len(s1). The length of a string is the number of bytes within.
- They can be indexed: given string "s1", "s1[i]" is a byte value.
- They can be concatenated: given strings "s1" and "s2", "s1 + s2" is a value
combining the elements of "s1" and "s2" in sequence.
- Known length: the length of a string "s1" can be obtained by the function/
operator "len(s1)". The length of a string is the number of bytes within.
Unlike in C, there is no terminal NUL byte.
- Creation 1: a string can be created from an integer value by a conversion;
the result is a string containing the UTF-8 encoding of that code point.
string('x') yields "x"; string(0x1234) yields the equivalent of "\u1234"
"string('x')" yields "x"; "string(0x1234)" yields the equivalent of "\u1234"
- Creation 2: a string can by created from an array of integer values (maybe
just array of bytes) by a conversion
a [3]byte; a[0] = 'a'; a[1] = 'b'; a[2] = 'c'; string(a) == "abc";
......@@ -390,38 +392,36 @@ Strings behave like arrays of bytes, with the following properties:
Character and string literals
----
Character and string literals are almost the same as in C, but with
UTF-8 required. This section is precise but can be skipped on first
reading.
Character and string literals are almost the same as in C, with the
following differences:
Character and string literals are similar to C except:
- Octal character escapes are always 3 digits (\077 not \77)
- Hexadecimal character escapes are always 2 digits (\x07 not \x7)
- Strings are UTF-8 and represent Unicode
- The encoding is UTF-8
- `` strings exist; they do not interpret backslashes
The rules are:
char_lit = "'" ( utf8_char_no_single_quote | "\" esc_seq ) "'" .
esc_seq =
"a" | "b" | "f" | "n" | "r" | "t" | "v" | "\" | "'" | "\"" |
oct_digit oct_digit oct_digit |
"x" hex_digit hex_digit |
"u" hex_digit hex_digit hex_digit hex_digit |
"U" hex_digit hex_digit hex_digit hex_digit
- Octal character escapes are always 3 digits ("\077" not "\77")
- Hexadecimal character escapes are always 2 digits ("\x07" not "\x7")
This section is precise but can be skipped on first reading. The rules are:
char_lit = "'" ( unicode_value | byte_value ) "'" .
unicode_value = utf8_char | little_u_value | big_u_value | escaped_char .
byte_value = octal_byte_value | hex_byte_value .
octal_byte_value = "\" oct_digit oct_digit oct_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_digit
hex_digit hex_digit hex_digit hex_digit .
escaped_char = "\" ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | "\" | "'" | """ ) .
A unicode_value takes one of four forms:
* The UTF-8 encoding of a Unicode code point. Since Go source
text is in UTF-8, this is the obvious translation from input
text into Unicode characters.
* The usual list of C backslash escapes: \n \t etc.
* A `little u' value, such as \u12AB. This represents the Unicode
* The usual list of C backslash escapes: "\n", "\t", etc.
* A `little u' value, such as "\u12AB". This represents the Unicode
code point with the corresponding hexadecimal value. It always
has exactly 4 hexadecimal digits.
* A `big U' value, such as \U00101234. This represents the
* A `big U' value, such as "\U00101234". This represents the
Unicode code point with the corresponding hexadecimal value.
It always has exactly 8 hexadecimal digits.
......@@ -457,8 +457,8 @@ Double-quoted strings have the usual properties; back-quoted strings
do not interpret backslashes at all.
string_lit = raw_string_lit | interpreted_string_lit .
raw_string_lit = "`" { utf8_char_no_back_quote } "`" .
interpreted_string_lit = "\"" { utf8_char_no_double_quote | "\\" esc_seq } "\"" .
raw_string_lit = "`" { utf8_char } "`" .
interpreted_string_lit = """ { unicode_value | byte_value } """ .
A string literal has type 'string'. Its value is constructed by
taking the byte values formed by the successive elements of the
......@@ -769,7 +769,7 @@ a method indicates the type of the struct by declaring a receiver of type
the declaration
func (p *Point) distance(float scale) float {
func (p *Point) distance(scale float) float {
return scale * (p.x*p.x + p.y*p.y);
}
......@@ -1732,5 +1732,5 @@ TODO
- TODO: type switch?
- TODO: words about slices
- TODO: what is nil? do we type-test by a nil conversion or something else?
- TODO: I (gri) would like to say that sizeof(int) == sizeof(pointer), always.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment