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.
28 lines
925 B
Racket
28 lines
925 B
Racket
#lang br/quicklang
|
|
(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
|
|
(provide read-syntax))
|
|
|
|
(define (read-syntax src ip)
|
|
(strip-context
|
|
(with-syntax ([PT (parse src (λ () (tokenize ip)))])
|
|
#'(module hdl-mod hdl-demo/expander
|
|
PT)))) |