You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-demo/algebra-demo/main.rkt

34 lines
834 B
Racket

#lang br/quicklang
(require brag/support "grammar.rkt")
(provide (all-defined-out) #%module-begin)
(module+ reader
(provide read-syntax))
(define-lex-abbrev reserved-toks
(:or "fun" "(" ")" "=" "+" ","))
6 years ago
(define tokenize
(lexer
6 years ago
[whitespace (tokenize input-port)]
[reserved-toks lexeme]
[alphabetic (token 'ID (string->symbol lexeme))]
[(:+ (char-set "0123456789")) (token 'INT (string->number lexeme))]))
(define-macro top #'begin)
6 years ago
(define-macro (func-def VAR VARS EXPR)
6 years ago
#'(define (VAR . VARS) EXPR))
(define-macro-cases expr
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
[(_ OTHER) #'OTHER])
6 years ago
(define-macro func-app #'#%app)
(define (read-syntax src ip)
6 years ago
(define parse-tree (parse (λ () (tokenize ip))))
(strip-context
6 years ago
(with-syntax ([PT parse-tree])
6 years ago
#'(module mod-name algebra-demo
PT))))