summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-06-21 10:49:10 -0400
committerOri Bernstein <ori@eigenstate.org>2013-06-21 10:49:10 -0400
commit0f2de28c580dd78160230b5b973c903378527623 (patch)
tree9ef9d7aaafd01ab2efcb10b2101e4a84e6d32d6c
parent2944ebad62186a50bdab83488755287d9596b283 (diff)
downloadmc-0f2de28c580dd78160230b5b973c903378527623.tar.gz
Add support for '_' in number literals for readability.
-rw-r--r--parse/tok.c4
-rw-r--r--test/add.myr4
2 files changed, 6 insertions, 2 deletions
diff --git a/parse/tok.c b/parse/tok.c
index 339fc41..0c323aa 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -514,8 +514,10 @@ static Tok *number(int base)
t = NULL;
isfloat = 0;
start = fidx;
- for (c = peek(); isxdigit(c) || c == '.'; c = peek()) {
+ for (c = peek(); isxdigit(c) || c == '.' || c == '_'; c = peek()) {
next();
+ if (c == '_')
+ continue;
if (c == '.')
isfloat = 1;
else if (hexval(c) > base)
diff --git a/test/add.myr b/test/add.myr
index 5d264c1..cc85319 100644
--- a/test/add.myr
+++ b/test/add.myr
@@ -3,8 +3,10 @@ use std
const main = {
var a
var b
+ var c
a = 42
b = 11
- -> a + b
+ c = 0_0
+ -> a + b + c
}