pull/23/head
Matthew Butterick 5 years ago
parent 310651e374
commit 0a625a17ee

@ -11,14 +11,13 @@
(define-lex-abbrev digits (char-set "0123456789")) (define-lex-abbrev digits (char-set "0123456789"))
(define tokenize-1 (define tokenize-1
(lexer-srcloc (lexer
[whitespace (token lexeme #:skip? #t)] [whitespace (token lexeme #:skip? #t)]
[(:or (from/stop-before "#" "\n") [(:or (from/stop-before "#" "\n")
(from/to "/*" "*/")) (token 'COMMENT #:skip? #t)] (from/to "/*" "*/")) (token 'COMMENT #:skip? #t)]
[reserved-toks lexeme] [reserved-toks lexeme]
[(:seq (:? "-") (:+ digits)) (token 'INT (string->number lexeme))] [(:seq (:? "-") (:+ digits)) (token 'INT (string->number lexeme))]
[(:+ (:- (:or alphabetic digits) reserved-toks)) [(:+ alphabetic) (token 'ID (string->symbol lexeme))]))
(token 'ID (string->symbol lexeme))]))
(define-macro top #'#%module-begin) (define-macro top #'#%module-begin)
@ -38,8 +37,6 @@
(define-macro app #'#%app) (define-macro app #'#%app)
(define (read-syntax src ip) (define (read-syntax src ip)
(port-count-lines! ip)
(lexer-file-path src)
(define parse-tree (parse src (λ () (tokenize-1 ip)))) (define parse-tree (parse src (λ () (tokenize-1 ip))))
(strip-bindings (strip-bindings
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])

@ -1,10 +1,10 @@
#lang precalc-demo #lang precalc-demo
fun f(x, y, z) = x + x + x * (y + y) + y * z - z - z fun f(x, y, z) = x + x + x * (y + y) + y * z - z - z
fun g42(z) = f(z, z, z) # line comment fun g(z) = f(z, z, z) # line comment
g42(-10) # = 300 g(-10) # = 300
fun h() = g42(10) fun h() = g(10)
h() # = 300 h() # = 300
fun k(x) = x / 10 / 10 / (x / x) fun k(x) = x / 10 / 10 / (x / x)

Loading…
Cancel
Save