summaryrefslogtreecommitdiff
path: root/chapter31/docs/31-grammar.md
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-11 15:40:22 -0800
committerCliff Click <cliffc@acm.org>2026-11-12 13:48:30 -0800
commit0720fd8ed0aa92248622a9f3c3ebd522b002fd91 (patch)
tree3ba939eb4e786373cedc54e1afe0bbdbfd16dc01 /chapter31/docs/31-grammar.md
parent18c04fd4aab0ad0bf3b3eece9551cc7aa7b9f796 (diff)
downloadSimple-0720fd8ed0aa92248622a9f3c3ebd522b002fd91.tar.gz
Simple-0720fd8ed0aa92248622a9f3c3ebd522b002fd91.zip
graphic tictactoe
Hex & octal digits
Diffstat (limited to 'chapter31/docs/31-grammar.md')
-rw-r--r--chapter31/docs/31-grammar.md11
1 files changed, 10 insertions, 1 deletions
diff --git a/chapter31/docs/31-grammar.md b/chapter31/docs/31-grammar.md
index 1aa31d42..19f834af 100644
--- a/chapter31/docs/31-grammar.md
+++ b/chapter31/docs/31-grammar.md
@@ -11,6 +11,14 @@ language; it is not input to a parser generator.
`int` is an alias for `i32`; `i64` explicitly selects 64-bit integer storage.
This alias does not change literal inference or intermediate arithmetic.
+Integer literals use decimal (`42`), leading-zero octal (`052`), or hexadecimal
+(`0x2a`, `0X2A`). Octal digits are 0–7; `08` and `09` are errors. Hexadecimal
+and octal literals can spell any 64-bit bit pattern: the high bit gives the
+usual signed value, so `0xffffffffffffffff` is -1. Decimal literals retain
+their signed 64-bit limit. Floating literals remain decimal, including forms
+such as `012.5` and `012f`. A radix prefix does not change integer inference
+or storage width.
+
```antlrv4
grammar SimpleLanguage;
@@ -179,7 +187,7 @@ argumentList : assignment (',' assignment)* ','? ;
// earlier chapters are replaced by constructor arguments.
newExpression : 'new' type ('[' assignment ']' | callSuffix)? ;
-INTEGER_LITERAL : '0' | [1-9] DIGIT* ;
+INTEGER_LITERAL : [1-9] DIGIT* | '0' [0-7]* | '0' [xX] HEX_DIGIT+ ;
// The f suffix also accepts an integer-shaped token, e.g. 12f.
FLOAT_LITERAL : DIGIT+ ('.' DIGIT* ('e' DIGIT+)? | 'e' '-'? DIGIT+) 'f'?
| DIGIT+ 'f' ;
@@ -197,6 +205,7 @@ fragment ESCAPE : '\\' [0ntr\\'"%] ;
IDENTIFIER : NON_DIGIT (NON_DIGIT | DIGIT)* ;
fragment NON_DIGIT : [a-zA-Z_] ;
fragment DIGIT : [0-9] ;
+fragment HEX_DIGIT : [0-9a-fA-F] ;
WHITESPACE : [ \t\r\n]+ -> skip ;
LINE_COMMENT : '//' ~[\r\n]* -> skip ;
BLOCK_COMMENT : '/*' .*? '*/' -> skip ;