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/hdl-demo/main.rkt

29 lines
950 B
Racket

8 years ago
#lang br/quicklang
6 years ago
(require "grammar.rkt"
brag/support)
(define-lex-abbrev reserved-terms
(union "CHIP" "IN" "OUT" "PARTS:" (char-set "[]{}(),;=.")))
(define tokenize
(lexer-srcloc
[(:or (from/to "/*" "*/") (from/to "//" #\newline))
(token 'COMMENT lexeme #:skip? #t)]
[(:or #\tab #\space #\newline) (token 'WS #:skip? #t)]
[reserved-terms lexeme]
["true" (token 'TRUE #t)]
["false" (token 'FALSE #f)]
;; bugaboo: "10" is ambiguous: number or binary number?
[(:+ numeric) (token 'NUMBER (string->number lexeme))]
[(:+ (char-set "01")) (token 'BINARY-NUMBER (string->number lexeme 2))]
[(:seq alphabetic (:* (:or alphabetic numeric "-"))) (token 'ID (string->symbol lexeme))]))
(module+ reader
8 years ago
(provide read-syntax))
6 years ago
(define (read-syntax src ip)
6 years ago
(port-count-lines! ip)
6 years ago
(strip-context
(with-syntax ([PT (parse src (λ () (tokenize ip)))])
#'(module hdl-mod hdl-demo/expander
PT))))