Support line comments.
Chris Pressey
6 years ago
5 | 5 |
|
6 | 6 |
* Added `byte table` type locations and indexed addressing (`+ x`, `+ y`).
|
7 | 7 |
* Integer literals may be given in hexadecimal.
|
|
8 |
* Line comments may be included in source code by prefixing them with `//`.
|
8 | 9 |
|
9 | 10 |
0.4
|
10 | 11 |
---
|
|
0 |
// Displays 256 hearts at the top of the Commodore 64's screen.
|
|
1 |
|
|
2 |
// Define where the screen starts in memory:
|
0 | 3 |
byte table screen @ 1024
|
1 | 4 |
|
2 | 5 |
routine main
|
|
6 |
// These are the values that will be written to by this routine:
|
3 | 7 |
trashes a, x, z, n, screen
|
4 | 8 |
{
|
5 | 9 |
ld x, 0
|
6 | |
ld a, 83
|
|
10 |
ld a, 83 // 83 = screen code for heart
|
7 | 11 |
repeat {
|
8 | 12 |
st a, screen + x
|
9 | 13 |
inc x
|
10 | |
} until z
|
|
14 |
} until z // this flag will be set when x wraps around from 255 to 0
|
11 | 15 |
}
|
28 | 28 |
|
29 | 29 |
def scan(self):
|
30 | 30 |
self.scan_pattern(r'[ \t\n\r]*', 'whitespace')
|
|
31 |
while self.scan_pattern(r'\/\/.*?[\n\r]', 'comment'):
|
|
32 |
self.scan_pattern(r'[ \t\n\r]*', 'whitespace')
|
31 | 33 |
if not self.text:
|
32 | 34 |
self.token = None
|
33 | 35 |
self.type = 'EOF'
|
15 | 15 |
| routine main {
|
16 | 16 |
| ld a, 0
|
17 | 17 |
| add a, 1
|
|
18 |
| }
|
|
19 |
= ok
|
|
20 |
|
|
21 |
Program with comments.
|
|
22 |
|
|
23 |
| // Welcome to my program.
|
|
24 |
|
|
|
25 |
| routine main {
|
|
26 |
| ld a, 0
|
|
27 |
| add a, 1 // We are adding the thing.
|
18 | 28 |
| }
|
19 | 29 |
= ok
|
20 | 30 |
|