Skip to content

Commit a1a4abe

Browse files
committed
nossembly: Document Number grammar
1 parent 78c8cc9 commit a1a4abe

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

docs/dialects/nossembly.md

+36-9
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ project.
1414
```bnf
1515
program ::= (line "\n")* line?
1616
line ::=
17-
| trim* inst junk? trim*
18-
| pragma trim*
17+
| whitespace* inst junk? whitespace*
18+
| pragma whitespace*
1919
| comment
20-
| trim*
20+
| whitespace*
2121
inst ::=
2222
| "Push" space number
2323
| "Duplicate"
@@ -51,8 +51,7 @@ pragma ::=
5151
| "#if" space key space value space inst junk?
5252
| "#define" space key space value
5353
word ::= (NOT space)+
54-
# TODO: JavaScript Number.
55-
number ::= …
54+
number ::= to_number
5655
label ::= word
5756
key ::= word
5857
value ::= word
@@ -67,18 +66,37 @@ junk ::= (space word)+
6766
space ::= " "
6867
comment ::= "# " [^\n]*
6968
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
7191
# (ref. https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.trim).
72-
trim ::=
92+
whitespace ::=
7393
| U+0009 | U+000B | U+000C | U+000D | U+0020 | U+00A0 | U+1680 | U+2000
7494
| U+2001 | U+2002 | U+2003 | U+2004 | U+2005 | U+2006 | U+2007 | U+2008
7595
| U+2009 | U+200A | U+2028 | U+2029 | U+202F | U+205F | U+3000 | U+FEFF
7696
```
7797

7898
Mnemonics are case sensitive.
7999

80-
TODO: Grammar for numbers.
81-
82100
### Semantics
83101

84102
`#if` and `#define` take a key and a value. `#define` sets the key to the value
@@ -119,6 +137,7 @@ Assembler:
119137
- Extra arguments are ignored for all instructions.
120138
- `UnknownInstruction` is a valid mnemonic.
121139
- `Strict` instruction seems unused.
140+
- It should use `BigInt`.
122141

123142
Typechecker:
124143

@@ -134,3 +153,11 @@ spaces.
134153
Built-in types are resolved to their name (`Never`, `Any`, `Unknown`, `Int`, or
135154
`Char`) and custom types are resolved as the form `Type{id}`, where `{id}` is an
136155
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

Comments
 (0)