dev-elider-3
Matthew Butterick 9 years ago
parent cca2376b9b
commit b410e97b8f

@ -3,14 +3,21 @@
(rename-out [basic-module-begin #%module-begin])
(rename-out [basic-top #%top])
(all-defined-out))
(require (for-syntax racket/syntax racket/list))
(require (for-syntax racket/syntax racket/list br/datum))
(define-for-syntax alphasyms (for/list ([i (in-string "ABCDEFGHIJKLMNOPQRSTUVWXYZ")])
(string->symbol (format "~a" i))))
(define-for-syntax stringsyms (map (λ(s) (format-datum "~a$" s)) alphasyms))
(define-syntax (basic-module-begin stx)
(syntax-case stx ()
[(_ PARSE-TREE ...)
(with-syntax ([(VARNAME ...) (map (λ(c) (format-id stx "~a" (integer->char c))) (range 65 91))])
(with-syntax ([(VARNAME ...) (datum->syntax stx alphasyms)]
[(STRINGVARNAME ...) (datum->syntax stx stringsyms)])
#'(#%module-begin
(define VARNAME 0) ...
(define STRINGVARNAME "") ...
(provide VARNAME ... STRINGVARNAME ...)
(println (quote PARSE-TREE ...))
PARSE-TREE ...))]))
@ -38,8 +45,7 @@
idx)))
(add1 line-idx)))))
(define-cases #'cr-line
[#'(_ ARG ...) #'(begin ARG ...)])
(define #'(cr-line ARG ...) #'(begin ARG ...))
(define #'(line NUMBER STATEMENT ...)
#'(cons NUMBER (λ _ STATEMENT ...)))

@ -1,8 +1,6 @@
#lang br/demo/basic
10 PRINT 2 + 3 * 10 + 1
20 PRINT 6 * 7 / 8
1 A = 2
10 PRINT A < 2
12 C$ = "string thing"
15 PRINT A;: PRINT C$

@ -27,7 +27,7 @@
[(union ";" "=" "(" ")") lexeme]
[(union "+" "-" "*" "/"
"<=" ">=" "<>" "><" "<" ">" "=" ) (string->symbol 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))]
[whitespace (token 'WHITESPACE lexeme #:skip? #t)]
[(:seq "\"" (complement (:: any-string "\"" any-string)) "\"") (token 'STRING (string-trim lexeme "\""))]

Loading…
Cancel
Save