@@ -14,10 +14,10 @@ project.
14
14
``` bnf
15
15
program ::= (line "\n")* line?
16
16
line ::=
17
- | trim * inst junk? trim *
18
- | pragma trim *
17
+ | whitespace * inst junk? whitespace *
18
+ | pragma whitespace *
19
19
| comment
20
- | trim *
20
+ | whitespace *
21
21
inst ::=
22
22
| "Push" space number
23
23
| "Duplicate"
@@ -51,8 +51,7 @@ pragma ::=
51
51
| "#if" space key space value space inst junk?
52
52
| "#define" space key space value
53
53
word ::= (NOT space)+
54
- # TODO: JavaScript Number.
55
- number ::= …
54
+ number ::= to_number
56
55
label ::= word
57
56
key ::= word
58
57
value ::= word
@@ -67,18 +66,37 @@ junk ::= (space word)+
67
66
space ::= " "
68
67
comment ::= "# " [^\n]*
69
68
70
- # Whitespace according to String.prototype.trim, excluding LF
69
+ # JavaScript Number constructor (ref. https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tonumber).
70
+ to_number ::=
71
+ | whitespace*
72
+ | whitespace* numeric_literal whitespace*
73
+ numeric_literal ::=
74
+ | decimal_literal
75
+ | non_decimal_integer_literal
76
+ decimal_literal ::= ("+" | "-")? unsigned_decimal_literal
77
+ unsigned_decimal_literal ::=
78
+ | "Infinity"
79
+ | decimal_digits "." decimal_digits? exponent_part?
80
+ | "." decimal_digits exponent_part?
81
+ | decimal_digits exponent_part?
82
+ decimal_digits ::= [0-9]+
83
+ exponent_part ::= ("e" | "E") ("+" | "-")? decimal_digits
84
+ non_decimal_integer_literal ::=
85
+ | ("0b" | "0B") [01]+
86
+ | ("0o" | "0O") [0-7]+
87
+ | ("0x" | "0X") [0-9a-fA-F]+
88
+
89
+ # JavaScript whitespace, specifically ECMAScript WhiteSpace and LineTerminator
90
+ # productions, excluding LF. It is used by String.prototype.trim and Number
71
91
# (ref. https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.trim).
72
- trim ::=
92
+ whitespace ::=
73
93
| U+0009 | U+000B | U+000C | U+000D | U+0020 | U+00A0 | U+1680 | U+2000
74
94
| U+2001 | U+2002 | U+2003 | U+2004 | U+2005 | U+2006 | U+2007 | U+2008
75
95
| U+2009 | U+200A | U+2028 | U+2029 | U+202F | U+205F | U+3000 | U+FEFF
76
96
```
77
97
78
98
Mnemonics are case sensitive.
79
99
80
- TODO: Grammar for numbers.
81
-
82
100
### Semantics
83
101
84
102
` #if ` and ` #define ` take a key and a value. ` #define ` sets the key to the value
@@ -119,6 +137,7 @@ Assembler:
119
137
- Extra arguments are ignored for all instructions.
120
138
- ` UnknownInstruction ` is a valid mnemonic.
121
139
- ` Strict ` instruction seems unused.
140
+ - It should use ` BigInt ` .
122
141
123
142
Typechecker:
124
143
@@ -134,3 +153,11 @@ spaces.
134
153
Built-in types are resolved to their name (` Never ` , ` Any ` , ` Unknown ` , ` Int ` , or
135
154
` Char ` ) and custom types are resolved as the form ` Type{id} ` , where ` {id} ` is an
136
155
integer, increasing from 0 in order of first occurrence of types.
156
+
157
+ ## Interpreter
158
+
159
+ ### Bugs
160
+
161
+ - ` WriteChar ` and ` ReadChar ` use UTF-16 code units instead of Unicode
162
+ codepoints.
163
+ - ` ReadInt ` only parses the next UTF-16 code unit instead of the full line.
0 commit comments