pull/10/head
Matthew Butterick 8 years ago
parent 4032a65eb8
commit 85ecc17a9d

@ -1,15 +1,16 @@
#lang br #lang br
(require brag/support) (require brag/support)
(define-lex-abbrev digits (:+ (char-set "0123456789")))
(define basic-lexer (define basic-lexer
(lexer-srcloc (lexer-srcloc
[(eof) (return-without-srcloc eof)] [(eof) (return-without-srcloc eof)]
[whitespace (token lexeme #:skip? #t)] [whitespace (token lexeme #:skip? #t)]
[(from/to "rem" #\newline) (token 'REM lexeme)] [(from/to "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end" "+" ":") lexeme] [(:or "print" "goto" "end" "+" ":") lexeme]
[(:+ numeric) (token 'INTEGER (string->number lexeme))] [digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:+ numeric) ".") [(:or (:seq digits ".") (:seq (:? digits) "." digits))
(:seq (:* numeric) "." (:+ numeric)))
(token 'DECIMAL (string->number lexeme))] (token 'DECIMAL (string->number lexeme))]
[(from/to "\"" "\"") [(from/to "\"" "\"")
(token 'STRING (trim-ends "\"" lexeme "\""))])) (token 'STRING (trim-ends "\"" lexeme "\""))]))

@ -2,7 +2,7 @@
30 rem print "ignored" 30 rem print "ignored"
50 print "never gets here" 50 print "never gets here"
40 end 40 end
60 print "three" : print 2 + 2 60 print "three" : print 1.0 + 3
70 goto 11 + 10.5 + 8.5 70 goto 11. + 18.5 + .5
10 print "one" 10 print "one"
20 print : goto 60 : end 20 print : goto 60.0 : end
Loading…
Cancel
Save