From 9235c6eaccd6ec3ead1fe848a1e63ff0dbb13eb0 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Sun, 18 Oct 2015 18:54:28 +0100 Subject: [PATCH] Support line comments. --- HISTORY.markdown | 1 + README.markdown | 2 -- eg/screen2.60p | 8 ++++++-- src/sixtypical/parser.py | 2 ++ tests/SixtyPical Syntax.md | 10 ++++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/HISTORY.markdown b/HISTORY.markdown index d364a1c..2ab97be 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -6,6 +6,7 @@ History of SixtyPical * Added `byte table` type locations and indexed addressing (`+ x`, `+ y`). * Integer literals may be given in hexadecimal. +* Line comments may be included in source code by prefixing them with `//`. 0.4 --- diff --git a/README.markdown b/README.markdown index 2662c15..17ec850 100644 --- a/README.markdown +++ b/README.markdown @@ -33,8 +33,6 @@ TODO For 0.5: -* source code comments. - For 0.6: * `interrupt` routines. diff --git a/eg/screen2.60p b/eg/screen2.60p index 221263b..eb45824 100644 --- a/eg/screen2.60p +++ b/eg/screen2.60p @@ -1,12 +1,16 @@ +// Displays 256 hearts at the top of the Commodore 64's screen. + +// Define where the screen starts in memory: byte table screen @ 1024 routine main + // These are the values that will be written to by this routine: trashes a, x, z, n, screen { ld x, 0 - ld a, 83 + ld a, 83 // 83 = screen code for heart repeat { st a, screen + x inc x - } until z + } until z // this flag will be set when x wraps around from 255 to 0 } diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index ee3aa2b..5361484 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -29,6 +29,8 @@ class Scanner(object): def scan(self): self.scan_pattern(r'[ \t\n\r]*', 'whitespace') + while self.scan_pattern(r'\/\/.*?[\n\r]', 'comment'): + self.scan_pattern(r'[ \t\n\r]*', 'whitespace') if not self.text: self.token = None self.type = 'EOF' diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index 6f8da22..7931771 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -19,6 +19,16 @@ Rudimentary program. | } = ok +Program with comments. + + | // Welcome to my program. + | + | routine main { + | ld a, 0 + | add a, 1 // We are adding the thing. + | } + = ok + Hex literals. | routine main {