add multiple print args

pull/10/head
Matthew Butterick 8 years ago
parent f9d6aa5d18
commit a48b7824f1

@ -46,7 +46,8 @@
(add1 line-idx))))) (add1 line-idx)))))
(define (b-rem val) (void)) (define (b-rem val) (void))
(define (b-print [val ""]) (displayln val)) (define (b-print . vals)
(define (b-sum . nums) (apply + nums)) (displayln (string-append* (map ~a vals))))
(define (b-num-expr expr) (define (b-sum . vals) (apply + vals))
(define (b-expr expr)
(if (integer? expr) (inexact->exact expr) expr)) (if (integer? expr) (inexact->exact expr) expr))

@ -9,7 +9,8 @@
["\n" (token 'NEWLINE lexeme)] ["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)] [whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)] [(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end" "+" ":") lexeme] [(:or "print" "goto" "end"
"+" ":" ";") (token lexeme lexeme)]
[digits (token 'INTEGER (string->number lexeme))] [digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:? digits) "." digits) [(:or (:seq (:? digits) "." digits)
(:seq digits ".")) (:seq digits "."))

@ -5,8 +5,9 @@ b-line : b-line-number [b-statement] (/":" [b-statement])*
@b-statement : b-rem | b-end | b-print | b-goto @b-statement : b-rem | b-end | b-print | b-goto
b-rem : REM b-rem : REM
b-end : /"end" b-end : /"end"
b-print : /"print" [STRING | b-num-expr] b-print : /"print" [b-printable] (/";" [b-printable])*
b-goto : /"goto" b-num-expr @b-printable : STRING | b-expr
b-num-expr : b-sum b-goto : /"goto" b-expr
b-expr : b-sum
b-sum : b-number (/"+" b-number)* b-sum : b-number (/"+" b-number)*
@b-number : INTEGER | DECIMAL @b-number : INTEGER | DECIMAL

@ -4,5 +4,5 @@
(define (40) (end)) (define (40) (end))
(define (60) (print "three") (print (+ 1.0 3))) (define (60) (print "three") (print (+ 1.0 3)))
(define (70) (goto (+ 11 18.5 0.5))) (define (70) (goto (+ 11 18.5 0.5)))
(define (10) (print "one")) (define (10) (print "o" "n" "e"))
(define (20) (print) (goto 60) (end)) (define (20) (print) (goto 60) (end))

@ -5,5 +5,5 @@
40 end 40 end
60 print 'three' : print 1.0 + 3 60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 70 goto 11. + 18.5 + .5
10 print "one" 10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end 20 print : goto 60.0 : end
Loading…
Cancel
Save