Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Mar 11, 2024
1 parent 9ef50df commit e95144b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions docs/grammar/cicada.grammar
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
(define-grammar <operator>
(var (let name identifier))
(ap (let target operator)
(let arg-entries-group (one-or-more "(" arg-entries ")")))
(sequence-begin (let sequence sequence))
(car "car" "(" (let target exp) ")")
(cdr "cdr" "(" (let target exp) ")")
(dot-field (let target operator) "." (let name identifier))
(dot-method
(let target operator) "." (let name identifier)
(let arg-entries-group (one-or-more "(" arg-entries ")")))
(recursion
"recursion" "(" (let target exp) ")"
"{" (let case-entries (zero-or-more case-entry)) "}")
(induction
"induction" "(" (let target exp) ")"
"{" "motive" (let motive "exp")
(let case-entries (zero-or-more case-entry)) "}"))

(define-grammar <operator>
[var (let name <identifier>) => (Exp::Var (match-string name))]
[ap (let target <operator>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))
=> (Exp::Ap (match <exp> target)
(match-list ...))]
[sequence-begin (let sequence <sequence>)
=> (Exp::Sequence (match <sequence> sequence))]
[car "car" "(" (let target <exp>) ")"
=> (Exp::Car (match <exp> target))]
[cdr "cdr" "(" (let target <exp>) ")"
=> (Exp::Cdr (match <exp> target))]
[dot-field (let target <operator>) "." (let name <identifier>)
=> (Exp::Dot (match <exp> target) (match <identifier> name))]
[dot-method
(let target <operator>) "." (let name <identifier>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))]
[recursion
"recursion" "(" (let target <exp>) ")"
"{" (let case-entries (zero-or-more <case-entry>)) "}"]
[induction
"induction" "(" (let target exp) ")"
"{" "motive" (let motive "exp")
(let case-entries (zero-or-more <case-entry>)) "}"])

(define-grammar <operator>
[var (let name <identifier>) => (Exp::Var name)]
[ap (let target <operator>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))
=> (Exp::Ap target
(TODO arg-entries-group))]
[sequence-begin (let sequence <sequence>)
=> (Exp::Sequence sequence)]
[car "car" "(" (let target <exp>) ")"
=> (Exp::Car target)]
[cdr "cdr" "(" (let target <exp>) ")"
=> (Exp::Cdr target)]
[dot-field (let target <operator>) "." (let name <identifier>)
=> (Exp::Dot target name)]
[dot-method
(let target <operator>) "." (let name <identifier>)
(let arg-entries-group (one-or-more "(" <arg-entries> ")"))]
[recursion
"recursion" "(" (let target <exp>) ")"
"{" (let case-entries (zero-or-more <case-entry>)) "}"]
[induction
"induction" "(" (let target exp) ")"
"{" "motive" (let motive "exp")
(let case-entries (zero-or-more <case-entry>)) "}"])

0 comments on commit e95144b

Please sign in to comment.