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/br-bf/parser.rkt

28 lines
771 B
Racket

9 years ago
#lang ragg
9 years ago
;; use uppercase TOKEN-IDENTIFIERS for classes of tokens
;; too numerous to indicate individually
;; (e.g., numbers, strings)
9 years ago
9 years ago
;; parser imposes structure:
;; takes a flat list of tokens
;; and arranges them into an (often hierarchical / recursive) shape.
;; produces a parse tree, which is like an annotated, structured version of the source code.
;; gives us the parenthesized expressions we need for the expander.
9 years ago
bf-program : (op | loop)*
op : ">" | "<" | "+" | "-" | "." | ","
loop : "[" (op | loop)* "]"
;; Alternate ways of specifying grammar
;; bf-program : op*
;; op : ">" | "<" | "+" | "-" | "." | "," | loop
;; loop : "[" op* "]"
;; bf-program : expr*
;; expr : op | loop
;; op : ">" | "<" | "+" | "-" | "." | ","
;; loop : "[" bf-program "]"