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

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

@ -6,7 +6,8 @@ assignment : /"var" id /"=" expr
@expr : comparison
comparison : [comparison ("!=" | "==")] sumlike
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 /"++"
object : /"{" @kvs /"}"
kvs : [kv (/"," kv)*]

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

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

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

Loading…
Cancel
Save