From 1caaa27732028b8f42955582c93224fbe984b6ba Mon Sep 17 00:00:00 2001 From: plugd Date: Thu, 9 Mar 2023 15:04:19 +0100 Subject: [PATCH] Added parse error on empty program. --- parser.scm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/parser.scm b/parser.scm index c112cf9..b075e5a 100644 --- a/parser.scm +++ b/parser.scm @@ -75,8 +75,8 @@ (accept-token redcode-irx #t) (let loop ((instrs '()) (offset 0) - (name '()) - (author '())) + (name #f) + (author "Unspecified")) (let ((this-line (line))) (if this-line (case (car this-line) @@ -85,7 +85,10 @@ ((comment) (loop instrs offset name author)) ((org) (loop instrs (cdr this-line) name author)) ((instr) (loop (cons (cdr this-line) instrs) offset name author))) - (make-prog name author (reverse instrs) offset))))) + (begin + (if (and name (not (null? instrs))) + (make-prog name author (reverse instrs) offset) + (error "Failed to parse name and/or instructions"))))))) (define (line) (or (name-line) -- 2.20.1