From 85ecc17a9d27b00e9e770fca882c8990f39f5a2a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 30 Jan 2017 08:47:45 -0800 Subject: [PATCH] more --- beautiful-racket-demo/basic-demo/lexer.rkt | 9 +++++---- beautiful-racket-demo/basic-demo/sample.rkt | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/beautiful-racket-demo/basic-demo/lexer.rkt b/beautiful-racket-demo/basic-demo/lexer.rkt index 842d221..94e9a77 100644 --- a/beautiful-racket-demo/basic-demo/lexer.rkt +++ b/beautiful-racket-demo/basic-demo/lexer.rkt @@ -1,15 +1,16 @@ #lang br (require brag/support) +(define-lex-abbrev digits (:+ (char-set "0123456789"))) + (define basic-lexer (lexer-srcloc [(eof) (return-without-srcloc eof)] [whitespace (token lexeme #:skip? #t)] - [(from/to "rem" #\newline) (token 'REM lexeme)] + [(from/to "rem" "\n") (token 'REM lexeme)] [(:or "print" "goto" "end" "+" ":") lexeme] - [(:+ numeric) (token 'INTEGER (string->number lexeme))] - [(:or (:seq (:+ numeric) ".") - (:seq (:* numeric) "." (:+ numeric))) + [digits (token 'INTEGER (string->number lexeme))] + [(:or (:seq digits ".") (:seq (:? digits) "." digits)) (token 'DECIMAL (string->number lexeme))] [(from/to "\"" "\"") (token 'STRING (trim-ends "\"" lexeme "\""))])) diff --git a/beautiful-racket-demo/basic-demo/sample.rkt b/beautiful-racket-demo/basic-demo/sample.rkt index 3f01722..f306001 100644 --- a/beautiful-racket-demo/basic-demo/sample.rkt +++ b/beautiful-racket-demo/basic-demo/sample.rkt @@ -2,7 +2,7 @@ 30 rem print "ignored" 50 print "never gets here" 40 end -60 print "three" : print 2 + 2 -70 goto 11 + 10.5 + 8.5 +60 print "three" : print 1.0 + 3 +70 goto 11. + 18.5 + .5 10 print "one" -20 print : goto 60 : end \ No newline at end of file +20 print : goto 60.0 : end \ No newline at end of file