1
1
---
2
2
title : Lexical Syntax
3
3
layout : default
4
- tag : lexical
4
+ chapter : 1
5
5
---
6
6
7
7
# Lexical Syntax
@@ -100,15 +100,15 @@ _ : = => <- <: <% >: # @
100
100
The Unicode operators ` \u21D2 $\Rightarrow$ ` and ` \u2190 $\leftarrow$ ` , which have the ASCII
101
101
equivalents ` => ` and ` <- ` , are also reserved.
102
102
103
- ###### Example: here are some identifiers :
103
+ ### Example:
104
104
105
105
```
106
106
x Object maxIndex p2p empty_?
107
107
+ `yield` αρετη _y dot_product_*
108
108
__system _MAX_LEN_
109
109
```
110
110
111
- ###### Example: backquote-enclosed strings
111
+ ### Example:
112
112
When one needs to access Java identifiers that are reserved words in Scala, use backquote-enclosed strings.
113
113
For instance, the statement ` Thread.yield() ` is illegal, since
114
114
` yield ` is a reserved word in Scala. However, here's a
@@ -207,7 +207,7 @@ A single new line token is accepted
207
207
- in front of a [ parameter clause] ( 06-basic-declarations-and-definitions.html#function-declarations-and-definitions ) , and
208
208
- after an [ annotation] ( 13-user-defined-annotations.html#user-defined-annotations ) .
209
209
210
- ###### Example: four well-formed statements, each on two lines
210
+ ### Example:
211
211
212
212
The newline tokens between the two lines are not
213
213
treated as statement separators.
226
226
IntList = List[Int]
227
227
```
228
228
229
- ###### Example: an anonymous class
229
+ ### Example:
230
230
231
231
```
232
232
new Iterator[Int]
@@ -250,7 +250,7 @@ new Iterator[Int]
250
250
}
251
251
```
252
252
253
- ###### Example: a single expression
253
+ ### Example:
254
254
255
255
```
256
256
x < 0 ||
@@ -266,7 +266,7 @@ two expressions:
266
266
x > 10
267
267
```
268
268
269
- ###### Example: a single, curried function definition
269
+ ### Example:
270
270
271
271
```
272
272
def func(x: Int)
@@ -282,7 +282,7 @@ def func(x: Int)
282
282
(y: Int) = x + y
283
283
```
284
284
285
- ###### Example: an attributed definition
285
+ ### Example:
286
286
287
287
```
288
288
@serializable
@@ -356,7 +356,7 @@ is _pt_. The numeric ranges given by these types are:
356
356
| ` Char ` | $0$ to $2^{16}-1$ |
357
357
358
358
359
- ###### Example: some integer literals
359
+ ### Example:
360
360
361
361
```
362
362
0 21 0xFFFFFFFF -42L
@@ -385,18 +385,18 @@ If a floating point literal in a program is followed by a token
385
385
starting with a letter, there must be at least one intervening
386
386
whitespace character between the two tokens.
387
387
388
- ###### Example: some floating point literals
388
+ ### Example:
389
389
390
390
```
391
391
0.0 1e30f 3.14159f 1.0e-100 .1
392
392
```
393
393
394
- ###### Example: tokenizing
394
+ ### Example:
395
395
396
396
The phrase ` 1.toString ` parses as three different tokens:
397
397
the integer literal ` 1 ` , a ` . ` , and the identifier ` toString ` .
398
398
399
- ###### Example: invalid floating point literal
399
+ ### Example:
400
400
401
401
` 1. ` is not a valid floating point literal because the mandatory digit after the ` . ` is missing.
402
402
@@ -420,7 +420,7 @@ A character literal is a single character enclosed in quotes.
420
420
The character is either a printable unicode character or is described
421
421
by an [ escape sequence] ( #escape-sequences ) .
422
422
423
- ###### Example: some character literals
423
+ ### Example:
424
424
425
425
```
426
426
'a' '\u0041' '\n' '\t'
@@ -447,7 +447,7 @@ contains a double quote character, it must be escaped,
447
447
i.e. ` "\"" ` . The value of a string literal is an instance of
448
448
class ` String ` .
449
449
450
- ###### Example: some string literals
450
+ ### Example:
451
451
452
452
```
453
453
"Hello,\nWorld!"
@@ -469,7 +469,7 @@ must not necessarily be printable; newlines or other
469
469
control characters are also permitted. Unicode escapes work as everywhere else, but none
470
470
of the escape sequences [ here] ( #escape-sequences ) are interpreted.
471
471
472
- ###### Example: a multi-line string literal :
472
+ ### Example:
473
473
474
474
```
475
475
"""the present string
@@ -600,7 +600,7 @@ The scanner switches from XML mode to Scala mode if either
600
600
Note that no Scala tokens are constructed in XML mode, and that comments are interpreted
601
601
as text.
602
602
603
- ###### Example: XML literals
603
+ ### Example:
604
604
605
605
The following value definition uses an XML literal with two embedded
606
606
Scala expressions:
0 commit comments