Skip to content

Hazel Grammar

Xiang (Kevin) Li edited this page Aug 24, 2023 · 9 revisions
<exp> ::=
| <bool>
| <integer>
| <float>
| <string>
| <variable>
| "()"
| "[]"
| "?"
| <constructor>
| <constructor>"(" <exp> ")"
| "(" <exp> ")"
| <exp> "::" <exp>
| <exp> {"," <exp>}
| "[" <exp> {"," <exp>} "]"
| <unary-op> <exp>
| <exp> <binary-op> <exp>
| <exp>"("<exp>")"
| "let" <pat> (":" <typ>)? "=" <exp> "in" <exp>
| "if" <exp> "then" <exp> "else" <exp>
| "case" <exp> {"|" <pat> "=>" <exp>} "end"
| <exp> ";" <exp>
| "test" <exp> "end"
| "type" <type-variable> "=" <typ> "in" <exp>

<type-variable> := regexp("^[A-Z][A-Za-z0-9_]*$")
<constructor> := regexp("^[A-Z][A-Za-z0-9_]*$")
<variable> :== := regexp("^[a-z][A-Za-z0-9_]*$")
<bool> ::= "true" | "false"
<integer> :== regexp("^[0-9_]*$")
<float> :== regexp("^[0-9]*\\.[0-9]*$") (needs updating)
<string> :== := regexp("^\"[^\"]*\"$")


<unary-op> ::= "-" | "!"
<binary-op-bool> ::= "&&" | "\/"
<binary-op-int> ::= "+" | "-" | "*" | "/" | "<" | ">" | "<=" | ">=" | "==" | "!="
<binary-op-float> ::= "+." | "-." | "*." | "/." | "<." | ">." | "<=." | ">=." | "==." | "!=."
<binary-op-string> ::= "$==" | "++"
<binary-op-list> ::= "@"
<binary-op> ::= <binary-op-bool> | <binary-op-int> | <binary-op-float> | <binary-op-string> | <binary-op-list>

<pat> ::=
| <bool>
| <integer>
| <float>
| <string>
| <variable>
| "()"
| "[]"
| <constructor>
| <constructor>"(" <pat> ")"
| "(" <pat> ")"
| <pat> "::" <pat>
| <pat> {"," <pat>}
| "[" <pat> {"," <pat>} "]"
| "_"
| <pat> ":" <typ>

<typ> ::=
| "()"
| "Int"
| "Float"
| "Bool"
| "String"
| <type-variable>
| <typ-constructor-def> ("+" <typ-constructor-def>)+
| "?"
| "(" <typ> ")"
| "[" <typ> "]"
| <typ> "->" <typ>
| <typ> {"," <typ>}

<typ-constructor-def> ::= <constructor> | <constructor "(" <typ> ")"
Clone this wiki locally