add multiple print args

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

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

@ -9,7 +9,8 @@
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(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))]
[(:or (:seq (:? digits) "." 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-rem : REM
b-end : /"end"
b-print : /"print" [STRING | b-num-expr]
b-goto : /"goto" b-num-expr
b-num-expr : b-sum
b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr
b-goto : /"goto" b-expr
b-expr : b-sum
b-sum : b-number (/"+" b-number)*
@b-number : INTEGER | DECIMAL

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

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