aboutsummaryrefslogtreecommitdiff
path: root/racket/circuits/parser.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'racket/circuits/parser.rkt')
-rw-r--r--racket/circuits/parser.rkt35
1 files changed, 35 insertions, 0 deletions
diff --git a/racket/circuits/parser.rkt b/racket/circuits/parser.rkt
new file mode 100644
index 0000000..6287be3
--- /dev/null
+++ b/racket/circuits/parser.rkt
@@ -0,0 +1,35 @@
+#lang racket/base
+(require parser-tools/yacc)
+
+;; Needed for tokens
+(require "lexer.rkt")
+
+;; Parser for circuits DSL
+(define circuits-parser
+ (parser
+ [start decls]
+ [end EOF]
+ [error void]
+ [tokens basic-tokens punct-tokens keyword-tokens]
+ [grammar
+ (decls
+ [(decl) $1]
+ [(decl decls) (append $1 $2)])
+ (decl
+ [(wire-decl) $1]
+ [(module-decl) (list $1)]
+ [(module-inst-decl) (list $1)])
+ (idents
+ [(ID) (list $1)]
+ [(ID COMMA idents) (cons $1 $3)])
+ (wire-decl
+ [(WIRE idents SEMICOLON)
+ (map (lambda (x) `(define ,x (new-node))) $2)])
+ (module-decl
+ [(MODULE ID LPAREN idents RPAREN LBRACE decls RBRACE)
+ `(define (,$2 ,@$4) ,@$7)])
+ (module-inst-decl
+ [(ID LPAREN idents RPAREN SEMICOLON)
+ `(,$1 ,@$3)])]))
+
+(provide circuits-parser)