v6.3-exception
Matthew Butterick 6 years ago
parent fe20dade03
commit 1826f8a00f

@ -8,9 +8,9 @@
(define-lex-abbrev reserved-toks (define-lex-abbrev reserved-toks
(:or "fun" "(" ")" "=" "+" ",")) (:or "fun" "(" ")" "=" "+" ","))
(define lex (define tokenize
(lexer (lexer
[whitespace (lex input-port)] [whitespace (tokenize input-port)]
[reserved-toks lexeme] [reserved-toks lexeme]
[alphabetic (token 'ID (string->symbol lexeme))] [alphabetic (token 'ID (string->symbol lexeme))]
[(:+ (char-set "0123456789")) (token 'INT (string->number lexeme))])) [(:+ (char-set "0123456789")) (token 'INT (string->number lexeme))]))
@ -27,8 +27,7 @@
(define-macro func-app #'#%app) (define-macro func-app #'#%app)
(define (read-syntax src ip) (define (read-syntax src ip)
(define token-thunk (λ () (lex ip))) (define parse-tree (parse (λ () (tokenize ip))))
(define parse-tree (parse token-thunk))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module mod-name algebra-demo #'(module mod-name algebra-demo

@ -6,7 +6,8 @@ assignment : /"var" id /"=" expr
@expr : comparison @expr : comparison
comparison : [comparison ("!=" | "==")] sumlike comparison : [comparison ("!=" | "==")] sumlike
sumlike : [@sumlike /"+"] value sumlike : [@sumlike /"+"] value
@value : id | INTEGER | STRING | object | func-def | func-app | increment @value : id | INTEGER | STRING | object
| func-def | func-app | increment
increment : id /"++" increment : id /"++"
object : /"{" @kvs /"}" object : /"{" @kvs /"}"
kvs : [kv (/"," kv)*] kvs : [kv (/"," kv)*]

@ -9,7 +9,7 @@
":" "," "(" ")" "//" "/*" "*/" ":" "," "(" ")" "//" "/*" "*/"
"if" "while" "==" "!=" "function" "return" "++")) "if" "while" "==" "!=" "function" "return" "++"))
(define lex (define tokenize
(lexer (lexer
[(:or (from/stop-before "//" "\n") [(:or (from/stop-before "//" "\n")
(from/to "/*" "*/")) (token 'COMMENT #:skip? #t)] (from/to "/*" "*/")) (token 'COMMENT #:skip? #t)]
@ -26,8 +26,8 @@
[any-char lexeme])) [any-char lexeme]))
(define (read-syntax src ip) (define (read-syntax src ip)
(define parse-tree (parse (λ () (lex ip)))) (define parse-tree (parse (λ () (tokenize ip))))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module _ javascriptlike-demo/expander #'(module you-win javascriptlike-demo/expander
PT)))) PT))))

@ -8,10 +8,10 @@
(define-lex-abbrev reserved-toks (define-lex-abbrev reserved-toks
(:or "fun" "(" ")" "=" "+" "*" "/" "-" ",")) (:or "fun" "(" ")" "=" "+" "*" "/" "-" ","))
(define lex (define tokenize
(lexer (lexer
[(:or (from/to "//" "\n") (from/to "/*" "*/")) (token 'COMMENT #:skip? #t)] [(:or (from/to "//" "\n") (from/to "/*" "*/")) (token 'COMMENT #:skip? #t)]
[whitespace (lex input-port)] [whitespace (tokenize input-port)]
[reserved-toks lexeme] [reserved-toks lexeme]
[alphabetic (token 'ID (string->symbol lexeme))] [alphabetic (token 'ID (string->symbol lexeme))]
[(:+ (char-set "0123456789")) (token 'INT (string->number lexeme))])) [(:+ (char-set "0123456789")) (token 'INT (string->number lexeme))]))
@ -35,8 +35,7 @@
(define-macro func-app #'#%app) (define-macro func-app #'#%app)
(define (read-syntax src ip) (define (read-syntax src ip)
(define token-thunk (λ () (lex ip))) (define parse-tree (parse (λ () (tokenize ip))))
(define parse-tree (parse token-thunk))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module mod-name precalc-demo #'(module mod-name precalc-demo

@ -8,7 +8,7 @@
(define-lex-abbrev xml-reserved (define-lex-abbrev xml-reserved
(:or "<" "/>" "</" ">" "<!--" "-->" "=" "\"")) (:or "<" "/>" "</" ">" "<!--" "-->" "=" "\""))
(define lex (define tokenize
(lexer (lexer
[(:+ whitespace) (token 'SP " ")] [(:+ whitespace) (token 'SP " ")]
["&amp;" (token 'AMP "&")] ["&amp;" (token 'AMP "&")]
@ -36,7 +36,7 @@
(string->symbol (apply string strs))) (string->symbol (apply string strs)))
(define (read-syntax src ip) (define (read-syntax src ip)
(define parse-tree (parse (λ () (lex ip)))) (define parse-tree (parse (λ () (tokenize ip))))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module mel xmlish-demo #'(module mel xmlish-demo

Loading…
Cancel
Save