From a933c8176841d58e5513cd3b6c5199a8783dc56b Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Sun, 18 Oct 2015 18:47:47 +0100 Subject: [PATCH] Well, that's a hack. But it works. --- HISTORY.markdown | 1 + README.markdown | 1 - src/sixtypical/parser.py | 5 +++++ tests/SixtyPical Execution.md | 2 +- tests/SixtyPical Syntax.md | 12 ++++++++++-- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/HISTORY.markdown b/HISTORY.markdown index 34bdf67..d364a1c 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -5,6 +5,7 @@ History of SixtyPical ------- * Added `byte table` type locations and indexed addressing (`+ x`, `+ y`). +* Integer literals may be given in hexadecimal. 0.4 --- diff --git a/README.markdown b/README.markdown index 9c226c1..2662c15 100644 --- a/README.markdown +++ b/README.markdown @@ -33,7 +33,6 @@ TODO For 0.5: -* hexadecimal literals. * source code comments. For 0.6: diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index ca75a51..ee3aa2b 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -37,6 +37,11 @@ class Scanner(object): return if self.scan_pattern(r'\d+', 'integer literal'): return + if self.scan_pattern(r'\$([0-9a-fA-F]+)', 'integer literal', + token_group=2, rest_group=3): + # ecch + self.token = str(eval('0x' + self.token)) + return if self.scan_pattern(r'\"(.*?)\"', 'string literal', token_group=2, rest_group=3): return diff --git a/tests/SixtyPical Execution.md b/tests/SixtyPical Execution.md index a9d8bf8..421776e 100644 --- a/tests/SixtyPical Execution.md +++ b/tests/SixtyPical Execution.md @@ -61,7 +61,7 @@ Add honours carry. = z: 1 | routine main { - | ld a, 255 + | ld a, $ff | st off, c | add a, 1 | } diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index 393c1de..6f8da22 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -19,7 +19,15 @@ Rudimentary program. | } = ok -Syntax error +Hex literals. + + | routine main { + | ld a, $ff + | add a, $01 + | } + = ok + +Syntax error. | routine foo ( | ld a, 0 @@ -27,7 +35,7 @@ Syntax error | ) ? SyntaxError -Another syntax error +Another syntax error. | byte glee | {