dev-elider-3
Matthew Butterick 9 years ago
parent dfab2a25bf
commit 3efb3b7f2b

@ -90,7 +90,7 @@
_TRUE-RESULT
_FALSE-RESULT)]
[#'(_ _COND "THEN" _TRUE-RESULT)
#'(when (true? COND)
#'(when (true? _COND)
_TRUE-RESULT)])
(define-cases #'value
@ -131,7 +131,7 @@
(match args
[(list) (displayln "")]
[(list print-list-item ... ";" pl) (begin (for-each display print-list-item)
(print pl))]
(basic:PRINT pl))]
[(list print-list-item ... ";") (for-each display print-list-item)]
[(list print-list-item ...) (for-each displayln print-list-item)]))

@ -0,0 +1,5 @@
#lang br/demo/basic
300 B=INT(RND(3*2))
400 PRINT B

@ -26,8 +26,8 @@ sum : product [("+" | "-") sum]
product : value [("*" | "/") product]
value : "(" expr ")"
| ID ["(" expr* ")"]
value : ID ["(" expr* ")"]
| "(" expr ")"
| STRING
| NUMBER

@ -1,15 +1,14 @@
#lang br
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre)
(require parser-tools/lex parser-tools/lex-sre
ragg/support
racket/string)
(provide tokenize)
(define-lex-abbrevs
(natural (repetition 1 +inf.0 numeric))
(integer (:seq (:? "-") natural))
(number (:seq integer (:? (:seq "." natural))))
(quoted-string (:seq "\"" (repetition 0 +inf.0 (char-complement "\"")) "\"")))
(number (union (seq (? "-") natural)
(seq (? "-") (? natural) (seq "." natural))))
(quoted-string (seq "\"" (repetition 0 +inf.0 (char-complement "\"")) "\"")))
(define (tokenize input-port)
(define (next-token)
@ -17,17 +16,17 @@
(lexer
[(eof) eof]
[(union #\tab #\space
(:seq number " REM" (repetition 1 +inf.0 (char-complement #\newline)) #\newline)) (get-token input-port)]
[(:seq #\newline (repetition 0 +inf.0 whitespace)) (token 'CR "cr")]
(seq number " REM" (repetition 1 +inf.0 (char-complement #\newline)) #\newline)) (get-token input-port)]
[(seq #\newline (repetition 0 +inf.0 whitespace)) (token 'CR "cr")]
[(union "PRINT" "FOR" "TO" "STEP" "IF" "GOTO"
"INPUT" "LET" "NEXT" "RETURN"
"CLEAR" "LIST" "RUN" "END"
"THEN" "ELSE" "GOSUB" "AND" "OR"
";" "=" "(" ")" "+" "-" "*" "/"
"<=" ">=" "<>" "><" "<" ">" "=" ":") lexeme]
"<=" ">=" "<>" "<" ">" "=" ":") lexeme]
[(union ",") (get-token input-port)]
[number (token 'NUMBER (string->number lexeme))]
[(:seq (repetition 1 +inf.0 upper-case) (:? "$")) (token 'ID (string->symbol lexeme))]
[(seq (repetition 1 +inf.0 upper-case) (? "$")) (token 'ID (string->symbol lexeme))]
[upper-case (token 'UPPERCASE (string->symbol lexeme))]
[quoted-string (token 'STRING (string-trim lexeme "\""))]))
(get-token input-port))

Loading…
Cancel
Save